Skip to content

Bake glyphs from a host's own face - #79

Merged
beetlebugorg merged 3 commits into
mainfrom
feat/host-glyph-bake
Sep 9, 2026
Merged

beetlebugorg merged 3 commits into
mainfrom
feat/host-glyph-bake

Conversation

@beetlebugorg

Copy link
Copy Markdown
Owner

tile57_bake_glyph_sdf and _face rasterize printable ASCII and Latin-1 from the bundled Noto Sans. Labels come out blank where a chart's names are in another script, and CJK alone is around 20,000 glyphs, more than one prebaked sheet holds and far more than one chart uses. Stacked on #78.

tile57_bake_glyph_sdf_codepoints reads font bytes the host supplies and the codepoints to rasterize, at the em size and spread the prebaked sheets use, so both merge into one atlas. A host bakes the characters its labels actually ask for.

glyph.build recorded every codepoint it was given. A codepoint the face does not map resolves to .notdef, whose advance is real, so the index gained an entry that draws a box, and a face whose outlines stb_truetype cannot read produced entries of all zeros that a host packs into its atlas and lays out as blank text. tg_glyph_present reads stbtt_FindGlyphIndex, and build skips a codepoint the face does not map along with one that yields neither ink nor an advance. The codepoint bake fails when the face draws none of them.

tile57_font_covers reports whether given bytes draw a codepoint, and tile57_label_font_covers asks the same of the bundled face. A platform font store answers a different question: on macOS, CoreText returns PingFang UI for Chinese text, whose outlines are in Apple's cidg table rather than glyf or CFF, and no glyph comes out of it.

zig build, zig build test and zig fmt --check src/ tools/ build.zig pass. The three prebaked sheets are byte identical: 145151, 152039 and 157845 PNG bytes, space present in each. Baking 富民沙路 and 合心 from Hiragino Sans GB.ttc gives a 9908 byte sheet with correct metrics; the same call against PingFangUI.ttc fails with "the face draws none of those codepoints", and against the bundled face tile57_label_font_covers reports yes for U+00C4 and no for U+1403, U+6C49, U+3042 and U+0E01.

glyph.build recorded every codepoint it was asked for. A codepoint the
face does not map resolves to .notdef, whose advance is real, so the
index gained an entry that draws a box. A face whose outlines
stb_truetype cannot read produced entries of all zeros, which a host
packs into its atlas and lays out as blank text.

tg_glyph_present reads stbtt_FindGlyphIndex, and build skips a codepoint
the face does not map along with one that yields neither ink nor an
advance. The three prebaked sheets are byte identical, space included.
tile57_bake_glyph_sdf and _face rasterize printable ASCII and Latin-1
from the bundled Noto Sans. A chart that names its features in another
script is labelled from glyphs outside that set, and CJK alone is around
20,000, more than one sheet holds.

tile57_bake_glyph_sdf_codepoints reads font bytes the host supplies and
the codepoints to rasterize, at the em size and spread the prebaked
sheets use, so both merge into one atlas. It fails when the face draws
none of them, so an empty sheet does not read as success.
A host picking a face out of its platform's font store has two questions
and the store answers one. Apple's UI faces cover CJK and are what
CoreText returns for Chinese text, and their outlines are in Apple's
cidg table rather than glyf or CFF, so no glyph comes out of them.

tile57_font_covers rasterizes one codepoint from the given bytes and
reports whether anything came out. tile57_label_font_covers asks the
same of the bundled face, so a host can tell which of a chart's
languages need a platform font.
Base automatically changed from fix/language-cap to main September 9, 2026 17:32
@beetlebugorg
beetlebugorg merged commit 90e86ce into main Sep 9, 2026
5 checks passed
@beetlebugorg
beetlebugorg deleted the feat/host-glyph-bake branch September 9, 2026 17: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.

1 participant