C# - Read & Preview Font

后端 未结 2 1379
春和景丽
春和景丽 2021-01-03 04:45

Can I read and preview fonts (mainly ttf and otf) in C#? What other languages can/should I use?

Read:

  • Info like font family, font name

2条回答
  •  爱一瞬间的悲伤
    2021-01-03 05:18

    Caution: don't use System.Drawing / System.Windows.Forms if you want to preview OTF fonts. Unless they're TTF's in disguise, you won't get them to show. System.Drawing, based on GDI+, only supports TTF fonts!

    However, if you can use .NET 3.0, you could use

    Fonts.GetFontFamilies(location)
    

    from System.Windows.Media namespace (just reference PresentationCore.dll).

    From a FontFamily, you can get the individual Typefaces (.ttc files contain more than one 'font', but a FontFamily also combines the various weights and variants). And from a Typeface, you can call TryGetGlyphTypeface to get the GlyphTypeface, which has a CharacterToGlyphMap property, which should tell you which unicode codepoints are physically supported.

    It also seems possible to use GlyphTypeface directly, but I see no way that you can handle .ttc files. However, if that's not relevant, just create a GlyphTypeface per file.

    I'd advice against trying all Unicode codepoints sequentially though.

提交回复
热议问题