Font: Fixed MergeMode adding duplicate glyphs data instead of reusing existing (broken by 072d6d8cb5
)
This commit is contained in:
parent
3dfac93ebe
commit
1ef1acbd8d
@ -270,6 +270,7 @@ Other Changes:
|
||||
- ImGuiStorage: Added BuildSortByKey() helper to rebuild storage from stratch.
|
||||
- ImFont: Added GetDebugName() helper.
|
||||
- ImFontAtlas: Added missing Thai punctuation in the GetGlyphRangesThai() ranges. (#1396) [@nProtect]
|
||||
- ImFontAtlas: Fixed cfg.MergeMode not reusing existing glyphs if available (always overwrote).
|
||||
- ImDrawList: Removed 'bool anti_aliased = true' final parameter of ImDrawList::AddPolyline() and ImDrawList::AddConvexPolyFilled(). Anti-aliasing is controlled via the regular style.AntiAliased flags.
|
||||
- ImDrawList: Added ImDrawList::AddImageRounded() helper. (#845) [@thedmd]
|
||||
- ImDrawList: Refactored to make ImDrawList independant of ImGui. Removed static variable in PathArcToFast() which caused linking issues to some.
|
||||
|
5
TODO.txt
5
TODO.txt
@ -212,7 +212,10 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i
|
||||
- pie menus patterns (#434)
|
||||
- markup: simple markup language for color change? (#902)
|
||||
|
||||
- font: better vertical centering (based e.g on height of lowercase 'x'?). currently Roboto-Medium size 16 px isn't currently centered.
|
||||
!- font: need handling of missing glyphs by not packing/rasterizing glyph 0 of a given font.
|
||||
- font: MergeMode: flags to select overwriting or not.
|
||||
- font: MergeMode: duplicate glyphs are stored in the atlas texture which is suboptimal.
|
||||
- font: better vertical centering (based e.g on height of lowercase 'x'?). currently Roboto-Medium size 16 px isn't currently centered. (#1619)
|
||||
- font: free the Alpha buffer if user only requested RGBA.
|
||||
!- font: better CalcTextSizeA() API, at least for simple use cases. current one is horrible (perhaps have simple vs extended versions).
|
||||
- font: enforce monospace through ImFontConfig (for icons?) + create dual ImFont output from same input, reusing rasterized data but with different glyphs/AdvanceX
|
||||
|
1
imgui.h
1
imgui.h
@ -1775,6 +1775,7 @@ struct ImFont
|
||||
ImFontConfig* ConfigData; // // Pointer within ContainerAtlas->ConfigData
|
||||
ImFontAtlas* ContainerAtlas; // // What we has been loaded into
|
||||
float Ascent, Descent; // // Ascent: distance from top to bottom of e.g. 'A' [0..FontSize]
|
||||
bool DirtyLookupTables;
|
||||
int MetricsTotalSurface;// // Total surface in pixels to get an idea of the font rasterization/texture cost (not exact, we approximate the cost of padding between glyphs)
|
||||
|
||||
// Methods
|
||||
|
@ -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,6 +1962,7 @@ void ImFontAtlasBuildFinish(ImFontAtlas* atlas)
|
||||
|
||||
// Build all fonts lookup tables
|
||||
for (int i = 0; i < atlas->Fonts.Size; i++)
|
||||
if (atlas->Fonts[i]->DirtyLookupTables)
|
||||
atlas->Fonts[i]->BuildLookupTable();
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
|
@ -315,6 +315,8 @@ bool ImGuiFreeType::BuildFontAtlas(ImFontAtlas* atlas, unsigned int extra_flags)
|
||||
ImFontConfig& cfg = atlas->ConfigData[input_i];
|
||||
FreeTypeFont& font_face = fonts[input_i];
|
||||
ImFont* dst_font = cfg.DstFont;
|
||||
if (cfg.MergeMode)
|
||||
dst_font->BuildLookupTable();
|
||||
|
||||
const float ascent = font_face.Info.Ascender;
|
||||
const float descent = font_face.Info.Descender;
|
||||
|
Loading…
Reference in New Issue
Block a user