nothings / stb

stb single-file public domain libraries for C/C++
https://twitter.com/nothings
Other
26.84k stars 7.72k forks source link

stb_truetype: .notdef / Tofublock sometimes ignored #1334

Closed FrostKiwi closed 1 year ago

FrostKiwi commented 2 years ago

Describe the bug For some fonts, stb_truetype fails to bake the .notdef glyph, which results in font atlases without it. This becomes a possible issue when you hit a non-baked glyph and no fallback is present, which result in SefFaults of the target app.

This has been documented in Nuklear's Complete font-guide's "always bake the questionmark" chapter.

E.g.: Baking the FontAwesome font results in a properly baked tofu block. (yummy)

But even though .notdef is defined in the Google Noto font, no tofu block is found in the final font atlas.

nothings commented 2 years ago

stb_truetype will only bake the .notdef glyph if you ask for it. If you want the 26 uppercase characters in a font atlas, that's what you'll get; it would be weird to also put the .notdef glyph in it.

How do you ask for it? Indirectly: the baked font contains only the characters you asked to be baked. if one of the characters you ask to be baked isn't defined, then the .notdef glyph is substituted for it. if multiple characters you ask to be baked aren't defined, old versions of stb_truetype would embed multiple copies of the .notdef glyph, although IIRC that has been fixed for a few years thanks to Aras P.

Remember, once you bake the font, it's out of stb_truetype's hands. The font atlas doesn't know about the unicode-to-glyph mapping and can't tell you whether a given character is present in the atlas; that's up to you.