mirror of
https://github.com/ocornut/imgui.git
synced 2026-01-11 00:04:24 +00:00
Font: Fixed MergeMode adding duplicate glyphs data instead of reusing existing (broken by 072d6d8cb5)
This commit is contained in:
parent
3dfac93ebe
commit
1ef1acbd8d
5 changed files with 16 additions and 3 deletions
|
|
@ -1817,6 +1817,8 @@ bool ImFontAtlasBuildWithStbTruetype(ImFontAtlas* atlas)
|
|||
ImFontConfig& cfg = atlas->ConfigData[input_i];
|
||||
ImFontTempBuildData& tmp = tmp_array[input_i];
|
||||
ImFont* dst_font = cfg.DstFont; // We can have multiple input fonts writing into a same destination font (when using MergeMode=true)
|
||||
if (cfg.MergeMode)
|
||||
dst_font->BuildLookupTable();
|
||||
|
||||
const float font_scale = stbtt_ScaleForPixelHeight(&tmp.FontInfo, cfg.SizePixels);
|
||||
int unscaled_ascent, unscaled_descent, unscaled_line_gap;
|
||||
|
|
@ -1960,7 +1962,8 @@ void ImFontAtlasBuildFinish(ImFontAtlas* atlas)
|
|||
|
||||
// Build all fonts lookup tables
|
||||
for (int i = 0; i < atlas->Fonts.Size; i++)
|
||||
atlas->Fonts[i]->BuildLookupTable();
|
||||
if (atlas->Fonts[i]->DirtyLookupTables)
|
||||
atlas->Fonts[i]->BuildLookupTable();
|
||||
}
|
||||
|
||||
// Retrieve list of range (2 int per range, values are inclusive)
|
||||
|
|
@ -2165,6 +2168,7 @@ void ImFont::ClearOutputData()
|
|||
ConfigData = NULL;
|
||||
ContainerAtlas = NULL;
|
||||
Ascent = Descent = 0.0f;
|
||||
DirtyLookupTables = true;
|
||||
MetricsTotalSurface = 0;
|
||||
}
|
||||
|
||||
|
|
@ -2177,6 +2181,7 @@ void ImFont::BuildLookupTable()
|
|||
IM_ASSERT(Glyphs.Size < 0xFFFF); // -1 is reserved
|
||||
IndexAdvanceX.clear();
|
||||
IndexLookup.clear();
|
||||
DirtyLookupTables = false;
|
||||
GrowIndex(max_codepoint + 1);
|
||||
for (int i = 0; i < Glyphs.Size; i++)
|
||||
{
|
||||
|
|
@ -2241,6 +2246,7 @@ void ImFont::AddGlyph(ImWchar codepoint, float x0, float y0, float x1, float y1,
|
|||
glyph.AdvanceX = (float)(int)(glyph.AdvanceX + 0.5f);
|
||||
|
||||
// Compute rough surface usage metrics (+1 to account for average padding, +0.99 to round)
|
||||
DirtyLookupTables = true;
|
||||
MetricsTotalSurface += (int)((glyph.U1 - glyph.U0) * ContainerAtlas->TexWidth + 1.99f) * (int)((glyph.V1 - glyph.V0) * ContainerAtlas->TexHeight + 1.99f);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue