Font: Fixed assert when specifying duplicate/overlapping ranges within a same font. (#2353, #2233)

This commit is contained in:
omar 2019-02-18 12:11:46 +01:00
parent db40699990
commit f5bf6e38d2
3 changed files with 7 additions and 10 deletions

View File

@ -73,6 +73,7 @@ Other Changes:
calculated text width. Among noticeable side-effects, it would make sequences of repeated Text/SameLine calls calculated text width. Among noticeable side-effects, it would make sequences of repeated Text/SameLine calls
not align the same as a single call, and create mismatch between high-level size calculation and those performed not align the same as a single call, and create mismatch between high-level size calculation and those performed
with the lower-level ImDrawList api. (#792) [@SlNPacifist] with the lower-level ImDrawList api. (#792) [@SlNPacifist]
- Font: Fixed building atlas when specifying duplicate/overlapping ranges within a same font. (#2353, #2233)
- ImDrawList: Fixed AddCircle(), AddCircleFilled() angle step being off, which was visible when drawing a "circle" - ImDrawList: Fixed AddCircle(), AddCircleFilled() angle step being off, which was visible when drawing a "circle"
with a small number of segments (e.g. an hexagon). (#2287) [@baktery] with a small number of segments (e.g. an hexagon). (#2287) [@baktery]
- ImGuiTextBuffer: Added append() function (unformatted). - ImGuiTextBuffer: Added append() function (unformatted).

View File

@ -1840,15 +1840,14 @@ bool ImFontAtlasBuildWithStbTruetype(ImFontAtlas* atlas)
{ {
ImFontBuildSrcData& src_tmp = src_tmp_array[src_i]; ImFontBuildSrcData& src_tmp = src_tmp_array[src_i];
ImFontBuildDstData& dst_tmp = dst_tmp_array[src_tmp.DstIndex]; ImFontBuildDstData& dst_tmp = dst_tmp_array[src_tmp.DstIndex];
ImFontConfig& cfg = atlas->ConfigData[src_i];
src_tmp.GlyphsSet.Resize(src_tmp.GlyphsHighest + 1); src_tmp.GlyphsSet.Resize(src_tmp.GlyphsHighest + 1);
if (dst_tmp.SrcCount > 1 && dst_tmp.GlyphsSet.Storage.empty()) if (dst_tmp.GlyphsSet.Storage.empty())
dst_tmp.GlyphsSet.Resize(dst_tmp.GlyphsHighest + 1); dst_tmp.GlyphsSet.Resize(dst_tmp.GlyphsHighest + 1);
for (const ImWchar* src_range = src_tmp.SrcRanges; src_range[0] && src_range[1]; src_range += 2) for (const ImWchar* src_range = src_tmp.SrcRanges; src_range[0] && src_range[1]; src_range += 2)
for (int codepoint = src_range[0]; codepoint <= src_range[1]; codepoint++) for (int codepoint = src_range[0]; codepoint <= src_range[1]; codepoint++)
{ {
if (cfg.MergeMode && dst_tmp.GlyphsSet.GetBit(codepoint)) // Don't overwrite existing glyphs. We could make this an option (e.g. MergeOverwrite) if (dst_tmp.GlyphsSet.GetBit(codepoint)) // Don't overwrite existing glyphs. We could make this an option for MergeMode (e.g. MergeOverwrite==true)
continue; continue;
if (!stbtt_FindGlyphIndex(&src_tmp.FontInfo, codepoint)) // It is actually in the font? if (!stbtt_FindGlyphIndex(&src_tmp.FontInfo, codepoint)) // It is actually in the font?
continue; continue;
@ -1857,8 +1856,7 @@ bool ImFontAtlasBuildWithStbTruetype(ImFontAtlas* atlas)
src_tmp.GlyphsCount++; src_tmp.GlyphsCount++;
dst_tmp.GlyphsCount++; dst_tmp.GlyphsCount++;
src_tmp.GlyphsSet.SetBit(codepoint, true); src_tmp.GlyphsSet.SetBit(codepoint, true);
if (dst_tmp.SrcCount > 1) dst_tmp.GlyphsSet.SetBit(codepoint, true);
dst_tmp.GlyphsSet.SetBit(codepoint, true);
total_glyphs_count++; total_glyphs_count++;
} }
} }

View File

@ -336,15 +336,14 @@ bool ImFontAtlasBuildWithFreeType(FT_Library ft_library, ImFontAtlas* atlas, uns
{ {
ImFontBuildSrcDataFT& src_tmp = src_tmp_array[src_i]; ImFontBuildSrcDataFT& src_tmp = src_tmp_array[src_i];
ImFontBuildDstDataFT& dst_tmp = dst_tmp_array[src_tmp.DstIndex]; ImFontBuildDstDataFT& dst_tmp = dst_tmp_array[src_tmp.DstIndex];
ImFontConfig& cfg = atlas->ConfigData[src_i];
src_tmp.GlyphsSet.Resize(src_tmp.GlyphsHighest + 1); src_tmp.GlyphsSet.Resize(src_tmp.GlyphsHighest + 1);
if (dst_tmp.SrcCount > 1 && dst_tmp.GlyphsSet.Storage.empty()) if (dst_tmp.GlyphsSet.Storage.empty())
dst_tmp.GlyphsSet.Resize(dst_tmp.GlyphsHighest + 1); dst_tmp.GlyphsSet.Resize(dst_tmp.GlyphsHighest + 1);
for (const ImWchar* src_range = src_tmp.SrcRanges; src_range[0] && src_range[1]; src_range += 2) for (const ImWchar* src_range = src_tmp.SrcRanges; src_range[0] && src_range[1]; src_range += 2)
for (int codepoint = src_range[0]; codepoint <= src_range[1]; codepoint++) for (int codepoint = src_range[0]; codepoint <= src_range[1]; codepoint++)
{ {
if (cfg.MergeMode && dst_tmp.GlyphsSet.GetBit(codepoint)) // Don't overwrite existing glyphs. We could make this an option (e.g. MergeOverwrite) if (dst_tmp.GlyphsSet.GetBit(codepoint)) // Don't overwrite existing glyphs. We could make this an option (e.g. MergeOverwrite)
continue; continue;
uint32_t glyph_index = FT_Get_Char_Index(src_tmp.Font.Face, codepoint); // It is actually in the font? (FIXME-OPT: We are not storing the glyph_index..) uint32_t glyph_index = FT_Get_Char_Index(src_tmp.Font.Face, codepoint); // It is actually in the font? (FIXME-OPT: We are not storing the glyph_index..)
if (glyph_index == 0) if (glyph_index == 0)
@ -354,8 +353,7 @@ bool ImFontAtlasBuildWithFreeType(FT_Library ft_library, ImFontAtlas* atlas, uns
src_tmp.GlyphsCount++; src_tmp.GlyphsCount++;
dst_tmp.GlyphsCount++; dst_tmp.GlyphsCount++;
src_tmp.GlyphsSet.SetBit(codepoint, true); src_tmp.GlyphsSet.SetBit(codepoint, true);
if (dst_tmp.SrcCount > 1) dst_tmp.GlyphsSet.SetBit(codepoint, true);
dst_tmp.GlyphsSet.SetBit(codepoint, true);
total_glyphs_count++; total_glyphs_count++;
} }
} }