hmtx — Horizontal Metrics Table

The horizontal metrics table provides horizontal metrics for each glyph — advance widths and left side bearings. (The right side bearing can be derived from these values plus bounding-box information in the glyph description. See below for more details.) In a font with TrueType outline data, these values can be computed from the 'glyf' table. Even so, this table is recommended since it provides performance benefits for text layout engines. In fonts with CFF or CFF2 outline data, this table is required.

The table uses a longHorMetric record to give the advance width and left side bearing of a glyph. Records are indexed by glyph ID. As an optimization, the number of records can be less than the number of glyphs, in which case the advance width value of the last record applies to all remaining glyph IDs. This can be useful in monospaced fonts, or in fonts that have a large number of glyphs with the same advance width (provided the glyphs are ordered appropriately). The number of longHorMetric records is determined by the numberOfHMetrics field in the 'hhea' table.

If the longHorMetric array is less than the total number of glyphs, then that array is followed by an array for the left side bearing values of the remaining glyphs. The number of elements in the left side bearing will be derived from numberOfHMetrics plus the numGlyphs field in the 'maxp' table.

Horizontal Metrics Table:

Type Name Description
longHorMetric hMetrics[numberOfHMetrics] Paired advance width and left side bearing values for each glyph. Records are indexed by glyph ID.
int16 leftSideBearing[numGlyphs - numberOfHMetrics] Left side bearings for glyph IDs greater than or equal to numberOfHMetrics.

longHorMetric Record:

Type Name Description
uint16 advanceWidth Glyph advance width, in font design units.
int16 lsb Glyph left side bearing, in font design units.

A font rendering engine must use the advanceWidths in the hmtx table for the advances of a CFF OFF font, even though the CFF table specifies its own glyph widths.

Note that fonts in a Font Collection that share a 'glyph', 'CFF' or 'CFF2' table may specify different advanceWidths for a particular glyph index in font-specific 'hmtx' tables.

In a font with TrueType glyph outlines, xmax and xmin values for each glyph are given in 'glyf' table. The advance width (“aw”) and left side bearing (“lsb”) values can be derived from the glyph “phantom points”, which are computed by the TrueType rasterizer, or they are given in 'hmtx' table. From those values, the right side bearing (“rsb”) is calculated as follows:

rsb = aw - (lsb + xmax - xmin)

If pp1 and pp2 are phantom points used to control lsb and rsb, their initial position in x is calculated as follows:

pp1 = xmin - lsb
pp2 = pp1 + aw