Bake glyphs from a host's own face - #79
Merged
Merged
Conversation
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.
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.
tile57_bake_glyph_sdfand_facerasterize 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_codepointsreads 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.buildrecorded 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_presentreadsstbtt_FindGlyphIndex, andbuildskips 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_coversreports whether given bytes draw a codepoint, andtile57_label_font_coversasks 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'scidgtable rather than glyf or CFF, and no glyph comes out of it.zig build,zig build testandzig fmt --check src/ tools/ build.zigpass. The three prebaked sheets are byte identical: 145151, 152039 and 157845 PNG bytes, space present in each. Baking 富民沙路 and 合心 fromHiragino Sans GB.ttcgives a 9908 byte sheet with correct metrics; the same call againstPingFangUI.ttcfails with "the face draws none of those codepoints", and against the bundled facetile57_label_font_coversreports yes for U+00C4 and no for U+1403, U+6C49, U+3042 and U+0E01.