Open user23333 opened 2 years ago
Could you provide an example?
@RobLoach it comes with some CJK fonts, i'm stucked in the same problem.
eg, specified the rune ranges like using nk_font_chinese_glyph_ranges
NK_API const nk_rune*
nk_font_chinese_glyph_ranges(void)
{
NK_STORAGE const nk_rune ranges[] = {
0x0020, 0x00FF,
0x3000, 0x30FF,
0x31F0, 0x31FF,
0xFF00, 0xFFEF,
0x4e00, 0x9FAF,
0
};
return ranges;
}
nk_font_atlas_bake
will gets the total number of glyphs specified above, ignores it can be found in the font or not, it is ok.
when starts stbtt_PackFontRangesGatherRects
, this
int glyph = stbtt_FindGlyphIndex(info, codepoint);
if (glyph == 0 && (spc->skip_missing || missing_glyph_added)) {
rects[k].w = rects[k].h = 0;
} else {
indicates that the glyph not found, but the index of the rects which is k
is still increase.
at last, in the nk_font_bake
/* query glyph bounds from stb_truetype */
const stbtt_packedchar *pc = &range->chardata_for_range[char_idx];
if (!pc->x0 && !pc->x1 && !pc->y0 && !pc->y1) continue;
codepoint = (nk_rune)(range->first_unicode_codepoint_in_range + char_idx);
as @user23333 mentioned, the continue
causes the glyph_count
miss increasing, that is the problem.
next codes:
/* fill own glyph type with data */
glyph = &glyphs[dst_font->glyph_offset + dst_font->glyph_count + (unsigned int)glyph_count];
glyph->codepoint = codepoint;
glyph->x0 = q.x0; glyph->y0 = q.y0;
glyph->x1 = q.x1; glyph->y1 = q.y1;
after some glyphs not found, the index of the current glyph which goes to be baking now is mismatch with the rects stored before.
maybe there is a new question: how to specify the 'correct' rune ranges before font loading?
@user23333 @robotoxico
I get the same situation. have you fixed it? thank you.
Is this still an issue now that https://github.com/Immediate-Mode-UI/Nuklear/pull/531 has been merged?
Some fonts have incorrect glyph indexes because when a font fails to parse (maybe?) the glyph index is not increase, so the index is wrong
The above is a translation, sorry for my poor English
https://github.com/Immediate-Mode-UI/Nuklear/blob/9486833f617c6c50d15f6040f184ca9f2c98c6ad/src/nuklear_font.c#L357 Here glyph_count is not increased