C#从.ttf获取字体样式 [英] C# get font style from .ttf
问题描述
此刻,我编写了一个程序,该程序从 C:\ Windows \ WinSxS
词典中搜索所有.ttf文件,然后将其复制到另一个词典中(我认为我不必在此处发布一些代码,因为它运作良好).
I write at the moment a programm that search all .ttf file's from the C:\Windows\WinSxS
dictonary and copy them to another dictonary (I think I dont have to post some code here, because its working well).
现在是问题所在.例如,字体 arial
以名称 arial.ttf
保存,但是该文件存在1次以上且具有相同的名称.现在,我在这里找到此链接:获取ttf文件的字体名称,但是输出名称仍然相同(总是 arial
).我认为这些文件之间的区别是 fontstyle
(斜体,粗体...),但是如何获取每个 *.ttf
文件的字体?
Now the problem. As example the font arial
is saved with the name arial.ttf
, but this file exists more than 1 time with the same name. Now I found this link here: get font name of ttf file, but the output name is still the same (always arial
). I think the difference between these file is the fontstyle
(italic, bold, ...), but how can I get the fontstyle of each *.ttf
file?
推荐答案
您需要对PresentationCore的引用.这样,您可以使用GlyphTypeface检查样式和权重:示例:
You need a reference to PresentationCore. With that you can use GlyphTypeface to check for Style and Weight: Example:
using System.Windows.Media;
GlyphTypeface ttf = new GlyphTypeface(new Uri(@"C:\Windows\Fonts\calibrii.ttf"));
Debug.Print(ttf.Style.ToString()); //=Italic or Normal
Debug.Print(ttf.Weight.ToString()); //=Bold or Normal
虽然不会与Postscript OTF一起使用.
Will not work with Postscript OTF though.
感谢用于处理字体的 C#库文件-TTF(TrueType),其他
这篇关于C#从.ttf获取字体样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!