Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access OTF font

Tags:

c#

fonts

truetype

I try to use OTF font installed on my system but I failed:

FontFamily family = new FontFamily(name_for_my_font);

I have tried to list all my fonts in system and indeed I haven't seen required font:

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

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

UPDATE: Sorry the problem is with OTF access but not TTF! I have made corrections in my answer

like image 345
Michael Z Avatar asked May 14 '12 12:05

Michael Z


People also ask

Can PCS use OTF fonts?

OpenType fonts are cross-platform compatible and the same font file can be installed and work on both Macintosh and Windows computers.

How do I open an OTF TTF file?

You can open an OTF file in Microsoft Windows Font Viewer (Windows) or Apple Font Book (Mac).


1 Answers

The problem is that OpenType fonts come in several flavors, one based on TrueType outlines and another based on PostScript Type 1 outlines. The Windows GDI+ graphics API does not support PostScript type 1 outlines. This is kind of ironic as the OpenType font format was created by Microsoft as a result of not being able to license some font technology from Apple.

So if a Windows application is based on GDI+ it will not be able to render OpenType fonts having 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 to fonts using TrueType outlines.

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

like image 122
Martin Liversage Avatar answered Oct 28 '22 02:10

Martin Liversage