nothings / stb

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

stb_truetype: missing glyphs on Windows (macOS and Linux ok) #1505

Closed andykt closed 1 year ago

andykt commented 1 year ago

I've been using stb_truetype.h in a C++ app (free, open source, cross platform) with various ttf files for the last couple of months without any problems (thanks Sean!). After downloading NotoSansSymbols2-Regular.ttf from https://fonts.google.com/noto/specimen/Noto+Sans+Symbols+2 I'm now getting lots of missing glyphs, but only on Windows (macOS and Linux are fine). Is this likely to be a problem in the font, or in the stb_truetype code? If the latter, any idea where I should start looking? (I'm not all that familiar with Windows, more a Mac guy.) Attached are a couple of images showing the problem:

On macOS:

symbols-mac

On Windows 10:

symbols-win
andykt commented 1 year ago

Possible clue: looks like I'm getting 2 rectangles for each missing character.

nothings commented 1 year ago

There is no reason why handing the same ttf to stb_truetype on different platforms would change its output. However, if you have installed the font into the OS, it's possible the OS modifies the file. The ttf specification has multiple ways to locate the glyphs for each character, including methods intended for windows and for macos. But stb_truetype just uses the first method it finds regardless of OS. So possibly one of the OSes added a new codepoint-to-glyph mapping table or deleted one and that changed the behavior. But if you're actually handing the exact same ttf to stb_truetype in both cases, it should behave identically.

andykt commented 1 year ago

Looks like the bug is due to some wxWidgets code I'm using to iterate over all codepoints in a UTF-8 encoded string. Works on macOS and Linux but fails on Windows for codepoints >= 0x10000. Sorry for the noise!