Access OTF Font

I am trying to use the OTF font installed on my system, but I failed:

FontFamily family = new FontFamily(name_for_my_font); 

I tried to list all my fonts in the system, and indeed, I did not see the required font:

 foreach (FontFamily font in System.Drawing.FontFamily.Families) { Console.WriteLine(font); } 

But I can see my font in the Fonts folder. It has an OTF extension. Maybe this is a problem? I see only TTF fonts. But why? How can I access the OTF font from my program?

UPDATE: sorry, the problem is related to OTF , but not TTF ! I have amended my answer

+8
c # fonts true-type-fonts
source share
2 answers

The problem is that OpenType fonts come in several flavors: one based on TrueType outlines and the other based on PostScript Type 1 outlines. The Windows GDI + graphical API does not support PostScript outlines of type 1. This is ironic since Microsoft created OpenType's font format the inability to license some font technology from Apple.

So, if a Windows application is based on GDI +, it will not be able to display OpenType fonts that have PostScript type 1 outlines or PostScript type 1 fonts, for that matter. Unfortunately, System.Drawing is implemented using GDI +. Your only option is to stick with fonts using TrueType outlines.

(Or, if you really desparate, you can P / Invoke to the "classic" GDI and render the font into a bitmap.)

+8
source share
0
source share

All Articles