d2lang/d2 · error

unsupported kern table version

Error message

unsupported kern table version

What it means

The legacy 'kern' table's first 16-bit field is a version number; only version 0 (legacy Apple/OpenType format) is supported. A non-zero version means the table uses an unrecognized format and parsing is refused.

Source

Thrown at lib/textmeasure/fontface.go:162

	x := int64(scale) * int64(units)
	if x >= 0 {
		x += int64(unitsPerEm) / 2
	} else {
		x -= int64(unitsPerEm) / 2
	}
	return fixed.Int26_6(x / int64(unitsPerEm))
}

func parseLegacyKern(src []byte) ([]kernPair, error) {
	table, err := sfntTable(src, "kern")
	if err != nil || table == nil {
		return nil, err
	}
	if len(table) < 18 {
		return nil, fmt.Errorf("invalid kern table: too short")
	}
	if binary.BigEndian.Uint16(table[0:2]) != 0 {
		return nil, fmt.Errorf("unsupported kern table version")
	}
	if binary.BigEndian.Uint16(table[2:4]) == 0 {
		return nil, fmt.Errorf("invalid kern table: no subtables")
	}

	length := int(binary.BigEndian.Uint16(table[6:8]))
	coverage := binary.BigEndian.Uint16(table[8:10])
	if coverage != 0x0001 {
		return nil, fmt.Errorf("unsupported kern table coverage 0x%04x", coverage)
	}
	n := int(binary.BigEndian.Uint16(table[10:12]))
	if length < 14 || 6*n != length-14 || 4+length > len(table) {
		return nil, fmt.Errorf("invalid kern table length")
	}

	pairs := make([]kernPair, n)
	for i := range pairs {
		offset := 18 + 6*i

View on GitHub (pinned to 0d69dca6f5)

Solutions

  1. Convert the font with fonttools to a standard OpenType font (which stores kerning in GPOS instead, or a version-0 kern table).
  2. Use a font known to be compatible with standard TrueType/OpenType kerning.
  3. If kerning is non-essential, strip the kern table so the library proceeds without kerning data.
Defensive patterns

Strategy: fallback

Validate before calling

// check kern table version before parsing
// version := binary.BigEndian.Uint16(kern[0:2]); usable := version == 0

Try / catch

pairs, err := parseLegacyKern(fontData)
if err != nil {
    log.Printf("kerning unavailable (%v), continuing without", err)
    pairs = nil
}

Prevention

When it happens

Trigger: parseFont encounters a font whose kern table header version field (bytes 0–2 big-endian) is not 0 — e.g. some AAT/Apple-format kern tables or future/variant versions.

Common situations: Mac-only fonts using Apple's AAT kern format variants; unusual or very new font formats; fonts modified by tools that bump the version field.

Related errors


AI-assisted analysis of d2lang/d2@0d69dca6f5 (2026-08-31). Data as JSON: /api/errors/88a54b02a1511462. Report an issue: GitHub.