Skip to content

Function: parseFontMetrics() ​

parseFontMetrics(data, opts?): Promise<FontMetrics>

Parse a font file into a FontMetrics. Lazily imports opentype.js.

Reads plain TTF/OTF and font collections (.ttc/.otc); for a collection, pass font to say which member, since a collection has no single answer. The underlying parser does not read the ttcf wrapper, so the selected member is unwrapped into a standalone sfnt first (see measure/font-collection.ts).

Parameters ​

ParameterTypeDescription
dataUint8Arraythe font file's bytes
opts?ParseFontMetricsOptionswhich font, for a file holding several

Returns ​

Promise<FontMetrics>

advance widths and cmap coverage for that font

Examples ​

ts
await parseFontMetrics(bytes) // a plain .ttf
ts
await parseFontMetrics(ttcBytes, { font: 'MS PGothic' })