C#从.ttf获取字体样式

时间:2015-10-21 08:56:35

标签: c# fonts

我现在写了一个程序,它从C:\Windows\WinSxS dictonary搜索所有.ttf文件并将它们复制到另一个dictonary(我想我不必在这里发布一些代码,因为它运行良好)。

现在问题。例如,字体arial以名称arial.ttf保存,但此文件存在多次,名称相同。现在我在这里找到了这个链接:get font name of ttf file,但输出名称仍然相同(始终为arial)。我认为这些文件之间的区别是fontstyle(斜体,粗体,......),但是如何获得每个*.ttf文件的fontstyle?

1 个答案:

答案 0 :(得分:1)

您需要引用PresentationCore。 有了它,你可以使用GlyphTypeface来检查样式和重量: 例如:

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。

修改:致C# lib for processing font files - TTF (TrueType), others

的积分
相关问题