{"record":{"id":"3a91fa3df247dfd8","repo":"subframe7536/maple-font","slug":"no-os-2-table-found-3a91fa","errorCode":null,"errorMessage":"No OS/2 table found.","messagePattern":"No OS/2 table found\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"source/py/utils.py","lineNumber":417,"sourceCode":"    axisValRec.Flags = 0\n    axisValRec.Format = 1\n    axisValRec.ValueNameID = id\n    axisValRec.Value = 1.0\n    stat_table.AxisValueArray.AxisValue.append(axisValRec)\n    stat_table.AxisValueCount += 1\n\n\ndef adjust_line_height(\n    font: TTFont, factor: float, metric: tuple[float, float]\n) -> None:\n    \"\"\"\n    Adjust the line height of the font by modifying the hhea and OS/2 table.\n    \"\"\"\n\n    if \"hhea\" not in font:\n        raise ValueError(\"No hhea table found.\")\n    if \"OS/2\" not in font:\n        raise ValueError(\"No OS/2 table found.\")\n\n    head = font[\"head\"]\n    hhea = font[\"hhea\"]\n    os2 = font[\"OS/2\"]\n\n    asc, desc = metric\n    # Maintain original ascender/descender ratio\n    ascender_ratio = asc / (asc - desc)  # type: ignore\n    # Calculate target total height\n    target_total_height = int(round(factor * (asc - desc)))\n\n    # Calculate new metrics\n    new_ascender = int(round(target_total_height * ascender_ratio))\n    new_descender = new_ascender - target_total_height\n\n    print(f\"Change vertical metric to [{new_ascender}, {new_descender}]\")\n\n    # Apply changes to hhea table","sourceCodeStart":399,"sourceCodeEnd":435,"githubUrl":"https://github.com/subframe7536/maple-font/blob/c08fda97fef73d68c1755219852150770f6e6578/source/py/utils.py#L399-L435","documentation":"adjust_line_height modifies both hhea and OS/2 line-gap/typo metrics; the OS/2 table holds the Windows typo ascender/descender values. This ValueError is raised when the 'OS/2' table is absent from the font object. Without OS/2, the function cannot keep Windows-platform line metrics in sync, so it refuses to run.","triggerScenarios":"Calling adjust_line_height (via build_nf, build_cn, or build_variable_fonts) on a font where \"OS/2\" not in font — typically a legacy font lacking OS/2, a stripped/subsetted font, or a corrupted/incorrectly converted font object.","commonSituations":"Using an old Type 1 or legacy-converted font lacking OS/2; a subsetting tool dropped the OS/2 table; passing a font object whose tables weren't lazily loaded properly; building from a source font produced by an unusual toolchain.","solutions":["Rebuild/repair the source font so it includes an OS/2 table (fonttools or a font editor can add one).","Confirm \"OS/2\" in font after loading with fontTools TTFont before calling adjust_line_height.","Check the subsetting/conversion step didn't drop OS/2 (use --no-subset-tables or equivalent options).","Point the build at the correct upstream TTF source file."],"exampleFix":"// before\n# adjust_line_height(font, metric)  # raises: No OS/2 table found.\n// after\n# if \"OS/2\" not in font or \"hhea\" not in font:\n#     raise RuntimeError(\"font lacks required hhea/OS/2 tables\")\n# adjust_line_height(font, metric)","handlingStrategy":"type-guard","validationCode":"from fontTools.ttLib import TTFont\n\ndef require_tables(path, tables=(\"hhea\", \"OS/2\")):\n    font = TTFont(path)\n    missing = [t for t in tables if t not in font]\n    if missing:\n        raise ValueError(f\"{path} missing tables: {missing}\")\n    return font","typeGuard":"def has_os2(font) -> bool:\n    return \"OS/2\" in font  # fontTools TTFont supports __contains__","tryCatchPattern":"try:\n    adjust_line_height(font, metric)\nexcept ValueError as e:\n    if str(e) == \"No OS/2 table found.\":\n        raise RuntimeError(\"Font lacks OS/2 table; use a font exported with OS/2 metrics\") from e\n    raise","preventionTips":["Use modern TTF sources that always include OS/2.","Verify subsetting/conversion options preserve the OS/2 table.","Check \"OS/2\" in font before any metric-mutation call.","Prefer upstream-built TTFs over legacy converted fonts."],"tags":["font","fonttools","line-height","missing-table"],"backgroundTag":"missing-font-table","analyzedSha":"c08fda97fef73d68c1755219852150770f6e6578","analyzedAt":"2026-08-28T22:07:29.503Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}