Calibrate font metrics against Labelary - #27
Draft
ValeHaas wants to merge 2 commits into
Draft
Conversation
Two font metric constants were tuned by sweeping each over the full golden corpus (110 fixtures) and taking the minimum of the total-diff curve. Font 0 width-to-height ratio 0.90 -> 0.91: our Helvetica Bold substitute is narrower than Zebra's CG Triumvirate, so long strings drifted left of the reference. The curve keeps falling to ~0.925 (total 267.8 -> 226.6), but "WWWWW" then renders 162 px and font_0_width_ratio_produces_narrower_text asserts < 160 -- Labelary itself renders that string 161 px, so the bound is stale. Capped at 0.91 to keep the suite green. ^FT baseline ascent 0.78 -> 0.76 of cell height. Total pixel diff 267.76 -> 252.53 (mean 2.434% -> 2.296%). 5 fixtures regress by <= 0.10 pp, all far inside tolerance; biggest gains fedex_express -0.71, usps_apo -0.62, pnldpd -0.60, posteit -0.55. Also ignore *.env so local Labelary API credentials cannot be committed. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Raises the font 0 width-to-height ratio from the 0.91 cap to 0.925, the actual minimum of the total-diff curve over the Labelary golden corpus. Total pixel diff 252.53 -> 226.64 (mean 2.296% -> 2.060%); against 858fc1b the combined calibration is 267.76 -> 226.64 (2.434% -> 2.060%). Labels drop from 15 to 9 moderate. Biggest gains fedex_express -2.14, kmart -2.11, ups_surepost -1.91, fedex_ground -1.58, usps_intl -1.55. KNOWN FAILING TEST: unit_renderer::font_0_width_ratio_produces_narrower_text. It renders ^A0N,40,40^FDWWWWW and asserts the ink width is < 160; we now render 162. Labelary renders that same string 161 px, so the bound rules out matching the reference, and the test's comment still describes a "~60% width ratio" the code has not used for some time. Left failing deliberately -- to be resolved in review. Nine fixtures regress, the largest by 0.36 pp (porterbuddy, brtit); all remain well inside their tolerances. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
ValeHaas
marked this pull request as draft
July 28, 2026 11:07
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Calibrate font metrics against Labelary
Two renderer constants were off; both were tuned by sweeping over the full
golden corpus (110 fixtures) and taking the minimum of the total-diff curve.
0.90→0.925— our Helvetica Boldsubstitute is narrower than Zebra's CG Triumvirate, so long strings drifted
left of the reference and the error accumulated across the line.
^FTbaseline ascent0.78→0.76of cell height.Also adds
*.envto.gitignoreso local Labelary API credentials can't becommitted.
Results
Nine fixtures regress: porterbuddy +0.36, brtit +0.34, encodings_013 +0.13,
six
text_fo/ft_*at +0.02…0.04 — all well inside their tolerances.The bitmap-font advance constant (1.931) was swept too and is already optimal;
left unchanged.
unit_renderer::font_0_width_ratio_produces_narrower_textfails. Everythingelse is green (16/17 test binaries, clippy clean).
It renders
^A0N,40,40^FDWWWWWand asserts the ink width is< 160. We nowrender 162. Labelary renders that exact string 161 px — so the bound
excludes the reference value itself and makes parity unreachable. The test's
comment still describes a "~60 % width ratio" the code stopped using some time
ago; at
0.90it rendered 158, which is why it passed.Suggested fix — keep the original intent (guard against a 1:1 ratio, which
would be ~200 px) but allow the reference value:
The alternative is capping the ratio at
0.91, the largest value satisfyingthe current bound — that yields 252.53 instead of 226.64, i.e. about a third
of the improvement.
Notes
0.925is a corpus-wide compromise, not a per-glyph fix: CG Triumvirate is adifferent typeface and the mismatch isn't uniform (at
0.90ourWwas ~2 %narrow while mixed proportional text was ~4 % narrow). A per-glyph advance
table would fix both but needs the real font metrics.