rougier / freetype-gl

OpenGL text using one vertex buffer, one texture and FreeType
Other
1.65k stars 266 forks source link

Fix loading of codepoints. #174

Closed zxchris closed 7 years ago

zxchris commented 7 years ago

texture_font_load_glyphs() is incorrectly processing the passed in codepoints list. It increments the index offset by each codepoint length correctly, but is using that bytecount as a codepoint count.

Thus it stops processing when it has read utf8_strlen(codepoints) bytes, not utf8_strlen(codepoints) glyphs. So if your codepoint list had 147 codepoints, only 147 bytes were being consumed.

forthy42 commented 7 years ago

Simpler solution, just use the strlen of codepoints. No second variable needed.

for( i = 0; i < strlen(codepoints); i += utf8_surrogate_len(codepoints + i) ) {
rougier commented 7 years ago

@zxchris Does the @forthy42 solution works for you ?

zxchris commented 7 years ago

Yes works fine, it's effectively the same thing, but counting bytes not glyphs. And it's arguably more efficient too, not doing the glyph count up front.