myNameXYZ
myNameXYZ

Reputation: 11

C# get font style from .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).

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?

Upvotes: 0

Views: 2719

Answers (1)

LocEngineer
LocEngineer

Reputation: 2917

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

Will not work with Postscript OTF though.

Edit: Credits to C# lib for processing font files - TTF (TrueType), others

Upvotes: 2

Related Questions