{"record":{"id":"7fe9625e71fd3e77","repo":"subframe7536/maple-font","slug":"glyph-glyph-name-not-found-in-font","errorCode":null,"errorMessage":"Glyph '{glyph_name}' not found in font.","messagePattern":"Glyph '(.+?)' not found in font\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"warning","filePath":"source/py/task/merge_font/utils.py","lineNumber":166,"sourceCode":"        max_value = a.maxValue\n        val = config.get(axis_tag, a.defaultValue)\n        if min_value > val or max_value < val:\n            raise Exception(f\"Invalid axe value, range: [{min_value}, {max_value}]\")\n        coordinates[axis_tag] = val\n\n    instance.coordinates = coordinates\n\n    static_font, file_base_name = var2static(f, instance)\n    static_font.save(output_font_path)\n    static_font.close()\n    f.close()\n\n\ndef _get_glyph_bounds(font, glyph_name):\n    \"\"\"Get (yMin, yMax) of a glyph by name from 'glyf' table.\"\"\"\n    glyph_order = font.getGlyphOrder()\n    if glyph_name not in glyph_order:\n        raise ValueError(f\"Glyph '{glyph_name}' not found in font.\")\n    glyf = font[\"glyf\"]\n    glyph = glyf[glyph_name]\n    if glyph.numberOfContours == 0:\n        # Empty glyph\n        return (0, 0)\n    y_min = glyph.yMin\n    y_max = glyph.yMax\n    return (y_min, y_max)\n\n\ndef auto_xheight_capheight(font: TTFont):\n    if \"OS/2\" not in font:\n        raise ValueError(\"Font does not have an OS/2 table.\")\n    if \"glyf\" not in font:\n        raise ValueError(\n            \"This script only supports TrueType (glyf) fonts. CFF support not implemented.\"\n        )\n","sourceCodeStart":148,"sourceCodeEnd":184,"githubUrl":"https://github.com/subframe7536/maple-font/blob/c08fda97fef73d68c1755219852150770f6e6578/source/py/task/merge_font/utils.py#L148-L184","documentation":"_get_glyph_bounds() reads yMin/yMax of a named glyph (used for 'z' and 'Z' to derive x-height/cap-height). It first checks font.getGlyphOrder(); if the requested glyph name is absent from the font's glyph set it raises this ValueError. This is an internal helper of auto_xheight_capheight.","triggerScenarios":"auto_xheight_capheight() calls it with \"z\" or \"Z\" and the font's glyph order does not contain a glyph named exactly 'z' or 'Z' (e.g. CJK-only font, subset font, or a font using non-standard/unencoded glyph naming).","commonSituations":"Merging or polishing subset fonts that lack Latin glyphs; fonts whose glyphs are named 'uni007A' style or use CFF-style naming; icon fonts; auto_xheight_capheight catches exceptions and only prints them, so the ValueError may surface as a printed message and OS/2 sxHeight/sCapHeight left stale.","solutions":["Ensure the font includes the Latin lowercase 'z' and uppercase 'Z' glyphs before running polish().","If working with a subset/custom-named font, extend _get_glyph_bounds to map via cmap (font.getBestCmap()[ord('z')]) instead of fixed names.","Since auto_xheight_capheight swallows the error, manually set OS/2 sxHeight/sCapHeight if the glyphs are genuinely missing."],"exampleFix":"# before\nz_ymin, z_ymax = _get_glyph_bounds(font, \"z\")\n\n# after\ncmap = font.getBestCmap()\nif ord('z') in cmap:\n    z_ymin, z_ymax = _get_glyph_bounds(font, cmap[ord('z')])\nelse:\n    return  # or fall back to default metrics","handlingStrategy":"validation","validationCode":"order = set(font.getGlyphOrder())\nassert \"z\" in order and \"Z\" in order, \"font lacks z/Z glyphs needed for x-height/cap-height\"","typeGuard":"def has_latin_z_glyphs(font) -> bool:\n    order = set(font.getGlyphOrder())\n    return \"z\" in order and \"Z\" in order","tryCatchPattern":"try:\n    _get_glyph_bounds(font, \"z\")\nexcept ValueError as e:\n    cmap = font.getBestCmap()\n    gname = cmap.get(ord(\"z\"))\n    bounds = _get_glyph_bounds(font, gname) if gname else (0, 0)","preventionTips":["Only run auto x-height/cap-height on fonts with full Latin coverage.","Resolve glyph names through cmap rather than assuming fixed names.","Remember auto_xheight_capheight only prints exceptions — check logs for stale OS/2 metrics."],"tags":["python","fonts","glyphs","fonttools"],"backgroundTag":"glyph-not-found-in-font","analyzedSha":"c08fda97fef73d68c1755219852150770f6e6578","analyzedAt":"2026-08-28T22:07:29.503Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}