How to convert .otf to .ttf (with Postscript outlines) using Fontforge scripting?

Sept picture Sept · Sep 26, 2015 · Viewed 8k times · Source

I'm trying to use Fontforge scripting to convert an .otf font to a .ttf font (with Postscript outlines).

Default options convert to a .ttf with Truetype outlines.

I would appreciate if anyone can give some directions.

Answer

Mike 'Pomax' Kamermans picture Mike 'Pomax' Kamermans · Sep 26, 2015

Quick lesson in how OpenType works: there are two flavours of OpenType: OpenType-with-CFF-Data, and OpenType-with-Truetype-Outlines

  1. OpenType fonts with a CFF block use Type2 "charstring" outline definitions, which allow cubic curve modelling. They're similar to Postscript, but aren't technically Postscript. People just keep calling it that for historical reasons.

  2. OpenType fonts with TrueType tables use TrueType outlines definitions, which allow for quadratic curve modelling only.

    (2018 edit: there are now two more types: OpenType-with-SVG-Outlines, which is not the same as "an SVG font", and OpenType-with-CFF2-Outlines, which is an overhaul of CFF specifically for use in OpenType rather than as an embed-agnostic outline language)

These two outline models are mutually exclusive, so you can pick whichever one you like, but not both at the same time.

Now, by convention, CFF-OT (and CFF2-OT) fonts use the .otf extension and TTF-OT (and SVG-OT) use the .ttf extension, but they're both just OpenType fonts, only differing in the CFF/TFF(/CFF2/SVG) data blocks. As such, when we talk about otf fonts we really mean "Postscript opentype font" (which is a misnomer because CFF uses the Type2 language, not the PostScript language), and when we talk about ttf fonts, we really mean "TrueType opentype font". However, an important thing to realise is that the extension does not in any way define the font; only its content does. We could rename the font to have a .gif extension and it'd still be the kind of font the content specifies. So, for font engines, the extension doesn't matter in the slightest, in the same way that an image previewer will happily open a .jpg file even if it has a .png extension.

Asking about turning an otf, which by convention is a "postscript" font (but again, not really, it's Type2) into a ttf, which by convention is a "truetype" font, and thus cannot contain "postscript" (but still, really Type2), with the added request that the ttf should contain "postscript outlines", doesn't make any sense: it's like asking how to convert a soft lead pencil into a hard lead pencil, but with soft lead: you're already done, you were asking how to create the thing you started with.

An Opentype font with "postscript" outlines is an otf.

Of course, you can convert a CFF font to a TrueType font, but it's a lossy conversion: it is mathematically impossible to perfectly convert cubic Bezier curves (used in Type2) to quadratic Bezier curves (used in TrueType), so you're going to end up with a font that is an approximation of the original font.

So my advice is: don't bother. Any engine that supports OpenType fonts supports both CFF and TrueType, and converting to .ttf will not do anything meaningful, while either blowing up the font size (for perceptually perfect conversion) or rendering the font incorrect with respect to the original due to lossy outline conversion.