Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extract fonts from TTF containing multiple fonts?

I have a .ttf file which, when I open it in Windows, has an option in the top right corner to select one of the font's variations. How can I extract these variations into their own separate .ttf files? The different variants all have a different "font name".enter image description here

like image 695
Goedendag Avatar asked Oct 13 '25 09:10

Goedendag


1 Answers

That font is not a font collection, but rather is a variable font.

A variable font doesn't contain multiple, discrete fonts (as in a collection), but rather contains a single font that includes data describing ways in which glyph outlines can vary, along with a description of a design space over which the design can vary. For example, a variable font might support variation across a design space with weights from 300 to 700 (say) as one axis, and widths from 75 to 150 (say) on a second axis. Each point within the design space is an "instance". A variable font can also have a set of named instances, which are instances within the design space for which the font designer gave particular style names.

In the Windows font previewer, when it shows "OpenType Font Variations" at the top, the "Previous" and "Next" buttons will step through named instances in the font.

If the font uses TrueType outlines, the font data contains outline data in a 'glyf' table, as in any other TrueType-flavoured font, but also contains delta data in a separate 'gvar' table. For each control point in the glyph outlines, the delta data describes how a given control point is moved from its default position for some instance in the design space. For other instances between that instance and the default instance, the deltas are scaled using linear interpolation.

Thus, when text is displayed, a particular instance is selected, and the rasterizer takes the default glyph outlines and applies scaled deltas to the control points of those outlines using the delta data in the 'gvar' table, scaled as applicable for the selected instance.

(I mentioned only deltas applied to glyph outlines. There can also be deltas applied to other data in the font, such as font or glyph metrics, positioning data in the GPOS table, etc.)

Given that, what you're asking isn't a matter of extracting separate fonts from a collection, but rather is one of how to export the font data that can be derived by selecting a particular instance and then applying all of the scaled deltas for that instance.

Windows itself needs to be able to generate instance font data for scenarios such as printing or generating PDFs. That's done internally, though, and there aren't public APIs that output instance font data.

There are tools that can export derived instance font data, though. For example, the instancer module within FontTools supports that.

like image 56
Peter Constable Avatar answered Oct 16 '25 07:10

Peter Constable