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?
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.