Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add custom ZebraFontD bitmap TrueType font to reduce Font D rendering diff#12

Draft
Copilot wants to merge 2 commits into
mainfrom
copilot/create-custom-font-similar-library
Draft

Add custom ZebraFontD bitmap TrueType font to reduce Font D rendering diff#12
Copilot wants to merge 2 commits into
mainfrom
copilot/create-custom-font-similar-library

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 7, 2026

Font D diffs (kmart, dpdpl, dhlparceluk) are driven by glyph shape mismatch — DejaVu Mono Bold's outlines don't resemble Zebra's built-in bitmap Font D characters at all. Replacing the backing font with one whose glyphs actually match Zebra's pixel patterns reduces this diff.

Changes

  • scripts/generate_zebra_font_d.py — fonttools-based generator that encodes pixel-accurate 12×14–17 bitmaps (uppercase, digits, punctuation) as filled TrueType rectangles. Characters extracted pixel-by-pixel from Labelary reference images (testdata/kmart.png); remaining characters designed in the same style with accurate 2-pixel-wide strokes matching Zebra Font D. Font metrics are intentionally kept identical to DejaVu Mono Bold (UPM=2048, ascent=1901, descent=-483, h_advance=1233) so the existing 2.317 advance-width ratio calibration in font.rs requires no changes.

    Key generator fixes:

    • Corrected Y_SCALE: ab_glyph uses v_scale_factor = scale.y / height_unscaled where height_unscaled = ascent − descent = 2384, not UPM. The old formula rendered each bitmap row at 0.859 px instead of 1 px. Fixed to Y_SCALE = 2384 / (18 × 7/6) ≈ 113.52.
    • Accurate 2-pixel-wide stroke bitmaps for all uppercase letters and digits extracted from the kmart Labelary reference.
    • ( and ) extended to 17 rows to match the reference descender zone.
  • src/assets/fonts/ZebraFontD.ttf — Regenerated font embedded as a static asset (~38 KB).

  • src/assets/mod.rs — Exposes FONT_ZEBRA_D static byte slice.

  • src/drawers/renderer.rs — Routes font name "D" to FONT_ZEBRA_D instead of DejaVu Mono Bold:

    "D" => FONT_ZEBRA_D,
    "B" | "P" | "Q" | "S" => FONT_DEJAVU_BOLD,

Diff impact

Label Before After
kmart 7.03% 6.93%
dpdpl 6.38% 6.08%
dhlparceluk 5.14% 4.82%

@GOODBOY008
Copy link
Copy Markdown
Owner

@copilot adjust the new font to enhance the diff report

Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 7, 2026

@copilot adjust the new font to enhance the diff report

Done in commit 507f81a. Two improvements were made:

  1. Fixed Y_SCALE formula: ab_glyph uses v_scale_factor = scale.y / height_unscaled where height_unscaled = ascent − descent = 2384, not UPM. The old formula gave 0.859 px/row instead of 1 px — characters were rendering shorter and blurry at row boundaries. Fixed to Y_SCALE = 2384 / (18 × 7/6) ≈ 113.52.

  2. Accurate 2-pixel-wide stroke bitmaps: Extracted all uppercase letters and digits pixel-by-pixel from the kmart Labelary reference. Zebra Font D uses 2-pixel-wide strokes throughout — H, N, L, P, T, I, E, C, D, G, O, R, S and the digits were all updated. ( and ) were extended to 17 rows to match the reference.

Label Before After
kmart 6.98% 6.93%
dpdpl 6.31% 6.08%
dhlparceluk 4.87% 4.82%

Copilot AI requested a review from GOODBOY008 May 7, 2026 16:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants