Four of the required tables hold the font’s global settings and the width of every
glyph. A reader needs head and maxp before it can read the
glyphs: head says whether loca uses short or long offsets and
maxp how many glyphs there are. hhea says how many entries
hmtx has. Types are those on the
table directory page. The
examples are from KaTeX’s Size2 Regular font, used throughout these pages.
head: font header
54 bytes.
| Offset | Type | Name | Description |
|---|---|---|---|
0 | uint16 | majorVersion | 1. |
2 | uint16 | minorVersion | 0. |
4 | Fixed | fontRevision | The font’s revision, set by its maker. Windows does not use it; it reads the version string, name ID 5, instead. Example: 0x00010000, 1.0. |
8 | uint32 | checksumAdjustment | 0xB1B0AFBA minus the checksum of the whole font: see checksums. Ignored in a collection. Example: 0x544806C4. |
12 | uint32 | magicNumber | Always 0x5F0F3CF5. |
16 | uint16 | flags | See flags. Example: 0x000F, bits 0 to 3. |
18 | uint16 | unitsPerEm | Font design units per em, the grid all coordinates are on: 16 to 16,384 in OpenType, 64 to 16,384 in Apple’s specification. A power of 2 such as 2,048 is recommended for TrueType outlines; 1,000 is common too. Example: 1,000. |
20 | LONGDATETIME | created | When the font was created, in seconds since 1 January 1904 UTC. Example: 0, not set. |
28 | LONGDATETIME | modified | When it was last modified. Example: 0. |
36 | int16 | xMin | The smallest x of any glyph’s bounding box. Glyphs with no contours are left out of all four values. Example: −1,005. |
38 | int16 | yMin | The smallest y. Example: −862. |
40 | int16 | xMax | The largest x. Example: 1,980. |
42 | int16 | yMax | The largest y. Example: 1,360. |
44 | uint16 | macStyle | See macStyle. Example: 0, regular. |
46 | uint16 | lowestRecPPEM | The smallest readable size, in pixels per em. Example: 8. |
48 | int16 | fontDirectionHint | Deprecated; set to 2. See direction hint. Example: 2. |
50 | int16 | indexToLocFormat | The format of loca: 0 for short offsets (Offset16, the offset divided by 2), 1 for long offsets (Offset32). Example: 0. |
52 | int16 | glyphDataFormat | 0, the current glyf format. |
flags
| Bit | Mask | OpenType | Apple |
|---|---|---|---|
| 0 | 0x0001 | The baseline is at y = 0. | The same. |
| 1 | 0x0002 | The left side bearing point is at x = 0: every glyph’s left side bearing equals its xMin. Matters only to TrueType rasterisers; required in variable TrueType fonts. | The same. |
| 2 | 0x0004 | Instructions may depend on point size. | Scaled and actual point sizes differ: a 24-point glyph is not the 12-point one doubled. |
| 3 | 0x0008 | Force pixels per em to whole numbers in all the scaler’s internal maths; strongly recommended in hinted fonts. | Use integer scaling instead of fractional. |
| 4 | 0x0010 | Instructions may change advance widths, which then may not scale linearly. | Used by Microsoft’s TrueType scaler. |
| 5 | 0x0020 | Not used; should be clear, and must be in variable fonts. | The font is meant to be laid out vertically, with x = 0 as the vertical baseline. |
| 6 | 0x0040 | Not used; clear. | Must be 0. |
| 7 | 0x0080 | Not used; clear. | The font needs layout for correct linguistic rendering, as Arabic fonts do. |
| 8 | 0x0100 | Not used; clear. | An AAT font with metamorphosis effects that apply by default. |
| 9 | 0x0200 | Not used; clear. | The font contains strong right-to-left glyphs. |
| 10 | 0x0400 | Not used; clear. | The font contains Indic-style rearrangement effects. |
| 11 | 0x0800 | Lossless font data: the font has been through an optimising transformation or compression, such as WOFF2 or MicroType Express, that keeps what it does but not its exact bytes. A DSIG may no longer be valid. | Defined by Adobe. |
| 12 | 0x1000 | Font converted: produce compatible metrics. | Defined by Adobe. |
| 13 | 0x2000 | Optimised for ClearType. Fonts that rely on embedded bitmaps should leave it clear. | Defined by Adobe. |
| 14 | 0x4000 | Last Resort font: the glyphs in cmap are generic symbols for ranges of code points, not real support for them. | The same. |
| 15 | 0x8000 | Reserved; 0. | Not defined. |
macStyle
| Bit | Mask | Style |
|---|---|---|
| 0 | 0x0001 | Bold |
| 1 | 0x0002 | Italic |
| 2 | 0x0004 | Underline |
| 3 | 0x0008 | Outline |
| 4 | 0x0010 | Shadow |
| 5 | 0x0020 | Condensed |
| 6 | 0x0040 | Extended |
| 7 to 15 | 0xFF80 | Reserved; 0 |
The bits must agree with fsSelection in the OS/2 table,
which Windows uses instead.
Direction hint
| Value | Meaning |
|---|---|
| 0 | Fully mixed directional glyphs |
| 1 | Only strongly left-to-right glyphs |
| 2 | Like 1, but also neutrals such as spaces and punctuation; the value to use |
| −1 | Only strongly right-to-left glyphs |
| −2 | Like −1, but also neutrals |
hhea: horizontal header
36 bytes. The side bearing and extent values are over glyphs that have contours.
| Offset | Type | Name | Description |
|---|---|---|---|
0 | uint16 | majorVersion | 1. |
2 | uint16 | minorVersion | 0. |
4 | FWORD | ascender | Typographic ascent, distance above the baseline. Used by Apple; Windows uses the OS/2 values instead. Example: 1,360. |
6 | FWORD | descender | Typographic descent, negative below the baseline. Example: −862. |
8 | FWORD | lineGap | Typographic line gap. Some older systems treat a negative value as 0. Example: 90. |
10 | UFWORD | advanceWidthMax | The largest advance width in hmtx. Example: 1,592. |
12 | FWORD | minLeftSideBearing | The smallest left side bearing in hmtx. Example: −1,005. |
14 | FWORD | minRightSideBearing | The smallest of advance width − (lsb + xMax − xMin). Example: −388. |
16 | FWORD | xMaxExtent | The largest of lsb + (xMax − xMin). Example: 1,980. |
18 | int16 | caretSlopeRise | The slope of the text cursor, rise over run: 1 for upright. Example: 1. |
20 | int16 | caretSlopeRun | 0 for upright; an italic font sets rise and run to its slant. |
22 | int16 | caretOffset | How far to shift a slanted highlight for the best look; 0 for upright fonts. |
24 | int16 × 4 | reserved | 0. |
32 | int16 | metricDataFormat | 0, the current format. |
34 | uint16 | numberOfHMetrics | The number of advance width and side bearing pairs in hmtx. Example: 39. |
In a variable font, the caret values can vary through the MVAR table,
under the tags hcrs (rise), hcrn (run) and
hcof (offset).
maxp: maximum profile
How much memory the font needs. TrueType fonts must use version 1.0, 32 bytes; fonts with CFF outlines use version 0.5, which has only the first two fields.
| Offset | Type | Name | Description |
|---|---|---|---|
0 | Version16Dot16 | version | 0x00010000 for 1.0; 0x00005000 for 0.5. |
4 | uint16 | numGlyphs | The number of glyphs. Example: 40. |
6 | uint16 | maxPoints | The most points in a simple glyph. Example: 189. |
8 | uint16 | maxContours | The most contours in a simple glyph. Example: 5. |
10 | uint16 | maxCompositePoints | The most points in a composite glyph. Example: 0, none. |
12 | uint16 | maxCompositeContours | The most contours in a composite glyph. |
14 | uint16 | maxZones | 1 if instructions do not use the twilight zone (zone 0), 2 if they do; 2 in most fonts. Example: 2. |
16 | uint16 | maxTwilightPoints | The most points used in the twilight zone. |
18 | uint16 | maxStorage | The number of storage area locations. |
20 | uint16 | maxFunctionDefs | The number of function definitions (FDEFs): the highest function number + 1. Example: 141. |
22 | uint16 | maxInstructionDefs | The number of instruction definitions (IDEFs). |
24 | uint16 | maxStackElements | The deepest the interpreter’s stack gets, across fpgm, prep and every glyph’s instructions. |
26 | uint16 | maxSizeOfInstructions | The most bytes of instructions in any glyph. |
28 | uint16 | maxComponentElements | The most components at the top level of a composite glyph. |
30 | uint16 | maxComponentDepth | How deep composite glyphs nest: 1 when components are simple glyphs. |
hmtx: horizontal metrics
The advance width and left side bearing of every glyph, indexed by glyph ID. There is no header; the sizes come from the other tables.
| Type | Name | Count | Description |
|---|---|---|---|
LongHorMetric | hMetrics | numberOfHMetrics (from hhea) | Pairs of advanceWidth (UFWORD) and lsb (FWORD), 4 bytes each, for glyphs 0 upwards. |
FWORD | leftSideBearings | numGlyphs (from maxp) − numberOfHMetrics | Left side bearings of the remaining glyphs, which all take the advance width of the last pair. |
The short form suits monospaced fonts, or fonts whose last glyphs share one width.
The right side bearing is not stored: it is advance width − (lsb + xMax − xMin), with
xMin and xMax from the glyph in glyf. A glyph with no contours should have
a left side bearing of 0. When bit 1 of the head flags is set, every left
side bearing equals the glyph’s xMin; a variable TrueType font must work
that way. The rasteriser’s first two phantom points come from these values:
pp1 = xMin − lsb and pp2 = pp1 + advance width.
Example: with 40 glyphs and 39 pairs, hmtx is 39 × 4 + 1 × 2 = 158
bytes. It starts 00 FA 00 32: glyph 0 has an advance width of 250 and a
left side bearing of 50. Its last two bytes, 00 37, are the left side
bearing of glyph 39, 55, whose advance width is that of glyph 38, 1,111.