Get font name of .ttf file

后端 未结 2 799
心在旅途
心在旅途 2020-12-10 14:45

Lets say there is a .ttf (True Type Font) file. You can install it on windows with a click. The real name of the font is not the text that is before the .tff (lets say Super

相关标签:
2条回答
  • 2020-12-10 15:21

    You'll need to add the font to a private collection (PrivateFontCollection), then request the FontFamily instance and get its Name property.

    Like this:

    PrivateFontCollection fontCol = new PrivateFontCollection();
    fontCol.AddFontFile(@"PATH TO FONT");
    Console.WriteLine(fontCol.Families[0].Name);
    

    You'll need the namespaces:

    using System.Drawing;
    using System.Drawing.Text;
    

    MSDN: PrivateFontCollection, FontFamily

    0 讨论(0)
  • 2020-12-10 15:42

    Here is the another code to extract fontname without using System.Drawing dll

    foreach (FontFamily fontFamily in Fonts.GetFontFamilies("file:///D:/MyFonts/"))
    {
        string name = fontFamily .ToString().Split('#')[fontFamily .ToString().Split('#').Count() - 1];
    }
    
    0 讨论(0)
提交回复
热议问题