Skip to content

Commit 0828a1f

Browse files
committed
Fixed computation of ImFont::MetricsTotalSurface not taking oversampling into account
1 parent bd9868f commit 0828a1f

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

imgui_demo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1752,7 +1752,7 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref)
17521752
ImGui::SameLine(); ShowHelpMarker("Note than the default embedded font is NOT meant to be scaled.\n\nFont are currently rendered into bitmaps at a given size at the time of building the atlas. You may oversample them to get some flexibility with scaling. You can also render at multiple sizes and select which one to use at runtime.\n\n(Glimmer of hope: the atlas system should hopefully be rewritten in the future to make scaling more natural and automatic.)");
17531753
ImGui::Text("Ascent: %f, Descent: %f, Height: %f", font->Ascent, font->Descent, font->Ascent - font->Descent);
17541754
ImGui::Text("Fallback character: '%c' (%d)", font->FallbackChar, font->FallbackChar);
1755-
ImGui::Text("Texture surface: %d pixels (approx)", font->MetricsTotalSurface);
1755+
ImGui::Text("Texture surface: %d pixels (approx) ~ %dx%d", font->MetricsTotalSurface, (int)sqrtf((int)font->MetricsTotalSurface), (int)sqrtf((int)font->MetricsTotalSurface));
17561756
for (int config_i = 0; config_i < font->ConfigDataCount; config_i++)
17571757
{
17581758
ImFontConfig* cfg = &font->ConfigData[config_i];

imgui_draw.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1456,7 +1456,7 @@ bool ImFontAtlas::Build()
14561456
glyph.XAdvance = (pc.xadvance + cfg.GlyphExtraSpacing.x); // Bake spacing into XAdvance
14571457
if (cfg.PixelSnapH)
14581458
glyph.XAdvance = (float)(int)(glyph.XAdvance + 0.5f);
1459-
dst_font->MetricsTotalSurface += (int)(glyph.X1 - glyph.X0 + 1.99f) * (int)(glyph.Y1 - glyph.Y0 + 1.99f); // +1 to account for average padding, +0.99 to round
1459+
dst_font->MetricsTotalSurface += (int)((glyph.U1 - glyph.U0) * TexWidth + 1.99f) * (int)((glyph.V1 - glyph.V0) * TexHeight + 1.99f); // +1 to account for average padding, +0.99 to round
14601460
}
14611461
}
14621462
cfg.DstFont->BuildLookupTable();

0 commit comments

Comments
 (0)