{"record":{"id":"0ef2db59cd64457d","repo":"subframe7536/maple-font","slug":"original-reference-width-must-be-positive","errorCode":null,"errorMessage":"Original reference width must be positive","messagePattern":"Original reference width must be positive","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"source/py/transform.py","lineNumber":229,"sourceCode":"        final_lsb = new_lsb\n\n    hmtx[glyph_name] = (new_width, final_lsb)\n\n\ndef smart_change_width(\n    font: TTFont,\n    target_width: int,\n    original_ref_width: int,\n    also_scale_y: bool = False,\n) -> None:\n    \"\"\"\n    Global font resizer. Scales all glyphs horizontally and applies\n    smart thickening to counteract the \"squashed\" look.\n\n    For non-CN glyphs in the build process.\n    \"\"\"\n    if original_ref_width <= 0:\n        raise ValueError(\"Original reference width must be positive\")\n\n    font[\"hhea\"].advanceWidthMax = target_width  # type: ignore\n    hmtx: Any = font[\"hmtx\"]\n    glyf: Any = font[\"glyf\"]\n\n    scale_factor = target_width / original_ref_width\n    composites: list[str] = []\n\n    for glyph_name in font.getGlyphOrder():\n        _change_glyph_width(\n            glyf=glyf,\n            hmtx=hmtx,\n            glyph_name=glyph_name,\n            scale_x=scale_factor,\n            scale_y=scale_factor if also_scale_y else 1.0,\n            match_width=original_ref_width,\n            target_width=target_width,\n        )","sourceCodeStart":211,"sourceCodeEnd":247,"githubUrl":"https://github.com/subframe7536/maple-font/blob/c08fda97fef73d68c1755219852150770f6e6578/source/py/transform.py#L211-L247","documentation":"smart_change_width() scales all glyph advances horizontally by target_width/original_ref_width. The reference width is the denominator of the scale factor, so it must be positive; if original_ref_width <= 0 the function raises this ValueError before modifying the font.","triggerScenarios":"Calling smart_change_width (via build_nf_by_prebuild_nerd_font or build_variable_fonts) with original_ref_width of 0, a negative number, or a width read from an uninitialized/empty font metric (e.g. xHea/advanceWidthMax == 0 or a computed average over zero glyphs).","commonSituations":"Broken or stub font lacking real advance widths (hmtx all zeros); a pre-build Nerd Font whose measured reference width is 0; passing width_scale config mistake propagating as an invalid reference; division-by-zero guard doing its job.","solutions":["Check the input font's advance widths (hmtx/hhea.advanceWidthMax) — use a valid font with positive advances.","In calling code, validate/clamp original_ref_width > 0 (fall back to a sane default like the font's unitsPerEm) before invoking.","If the width is auto-computed, fix the computation so it averages only glyphs with nonzero advances."],"exampleFix":"// before\nsmart_change_width(font, 1000, original_ref_width)\n\n// after\nref = original_ref_width if original_ref_width > 0 else font[\"head\"].unitsPerEm\nsmart_change_width(font, 1000, ref)","handlingStrategy":"validation","validationCode":"ref = font[\"hhea\"].advanceWidthMax or font[\"head\"].unitsPerEm\nassert ref > 0, f\"reference width must be positive, got {ref}\"","typeGuard":"def has_positive_ref_width(ref: float) -> bool:\n    return isinstance(ref, (int, float)) and ref > 0","tryCatchPattern":"try:\n    smart_change_width(font, target_width, original_ref_width)\nexcept ValueError as e:\n    if \"reference width\" in str(e):\n        smart_change_width(font, target_width, font[\"head\"].unitsPerEm)\n    else:\n        raise","preventionTips":["Verify input fonts have nonzero advance widths (hmtx/hhea) before width scaling.","Fall back to unitsPerEm when a measured reference width is 0 or negative.","Sanity-check auto-computed widths (average advance) for empty/degenerate glyph sets."],"tags":["python","fonts","width-scale","fonttools"],"backgroundTag":"invalid-width-parameter","analyzedSha":"c08fda97fef73d68c1755219852150770f6e6578","analyzedAt":"2026-08-28T22:07:29.503Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}