Skip to content

Commit f5bf6e3

Browse files
committed
Font: Fixed assert when specifying duplicate/overlapping ranges within a same font. (#2353, #2233)
1 parent db40699 commit f5bf6e3

File tree

3 files changed

+7
-10
lines changed

3 files changed

+7
-10
lines changed

docs/CHANGELOG.txt

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

imgui_draw.cpp

+3-5
Original file line numberDiff line numberDiff line change
@@ -1840,15 +1840,14 @@ bool ImFontAtlasBuildWithStbTruetype(ImFontAtlas* atlas)
18401840
{
18411841
ImFontBuildSrcData& src_tmp = src_tmp_array[src_i];
18421842
ImFontBuildDstData& dst_tmp = dst_tmp_array[src_tmp.DstIndex];
1843-
ImFontConfig& cfg = atlas->ConfigData[src_i];
18441843
src_tmp.GlyphsSet.Resize(src_tmp.GlyphsHighest + 1);
1845-
if (dst_tmp.SrcCount > 1 && dst_tmp.GlyphsSet.Storage.empty())
1844+
if (dst_tmp.GlyphsSet.Storage.empty())
18461845
dst_tmp.GlyphsSet.Resize(dst_tmp.GlyphsHighest + 1);
18471846

18481847
for (const ImWchar* src_range = src_tmp.SrcRanges; src_range[0] && src_range[1]; src_range += 2)
18491848
for (int codepoint = src_range[0]; codepoint <= src_range[1]; codepoint++)
18501849
{
1851-
if (cfg.MergeMode && dst_tmp.GlyphsSet.GetBit(codepoint)) // Don't overwrite existing glyphs. We could make this an option (e.g. MergeOverwrite)
1850+
if (dst_tmp.GlyphsSet.GetBit(codepoint)) // Don't overwrite existing glyphs. We could make this an option for MergeMode (e.g. MergeOverwrite==true)
18521851
continue;
18531852
if (!stbtt_FindGlyphIndex(&src_tmp.FontInfo, codepoint)) // It is actually in the font?
18541853
continue;
@@ -1857,8 +1856,7 @@ bool ImFontAtlasBuildWithStbTruetype(ImFontAtlas* atlas)
18571856
src_tmp.GlyphsCount++;
18581857
dst_tmp.GlyphsCount++;
18591858
src_tmp.GlyphsSet.SetBit(codepoint, true);
1860-
if (dst_tmp.SrcCount > 1)
1861-
dst_tmp.GlyphsSet.SetBit(codepoint, true);
1859+
dst_tmp.GlyphsSet.SetBit(codepoint, true);
18621860
total_glyphs_count++;
18631861
}
18641862
}

misc/freetype/imgui_freetype.cpp

+3-5
Original file line numberDiff line numberDiff line change
@@ -336,15 +336,14 @@ bool ImFontAtlasBuildWithFreeType(FT_Library ft_library, ImFontAtlas* atlas, uns
336336
{
337337
ImFontBuildSrcDataFT& src_tmp = src_tmp_array[src_i];
338338
ImFontBuildDstDataFT& dst_tmp = dst_tmp_array[src_tmp.DstIndex];
339-
ImFontConfig& cfg = atlas->ConfigData[src_i];
340339
src_tmp.GlyphsSet.Resize(src_tmp.GlyphsHighest + 1);
341-
if (dst_tmp.SrcCount > 1 && dst_tmp.GlyphsSet.Storage.empty())
340+
if (dst_tmp.GlyphsSet.Storage.empty())
342341
dst_tmp.GlyphsSet.Resize(dst_tmp.GlyphsHighest + 1);
343342

344343
for (const ImWchar* src_range = src_tmp.SrcRanges; src_range[0] && src_range[1]; src_range += 2)
345344
for (int codepoint = src_range[0]; codepoint <= src_range[1]; codepoint++)
346345
{
347-
if (cfg.MergeMode && dst_tmp.GlyphsSet.GetBit(codepoint)) // Don't overwrite existing glyphs. We could make this an option (e.g. MergeOverwrite)
346+
if (dst_tmp.GlyphsSet.GetBit(codepoint)) // Don't overwrite existing glyphs. We could make this an option (e.g. MergeOverwrite)
348347
continue;
349348
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..)
350349
if (glyph_index == 0)
@@ -354,8 +353,7 @@ bool ImFontAtlasBuildWithFreeType(FT_Library ft_library, ImFontAtlas* atlas, uns
354353
src_tmp.GlyphsCount++;
355354
dst_tmp.GlyphsCount++;
356355
src_tmp.GlyphsSet.SetBit(codepoint, true);
357-
if (dst_tmp.SrcCount > 1)
358-
dst_tmp.GlyphsSet.SetBit(codepoint, true);
356+
dst_tmp.GlyphsSet.SetBit(codepoint, true);
359357
total_glyphs_count++;
360358
}
361359
}

0 commit comments

Comments
 (0)