imgui: Don't shrink fonts based on their line height

This commit is contained in:
TellowKrinkle
2025-11-20 22:08:15 -06:00
committed by Ty
parent bb3937cd69
commit 3a2bdc5def
4 changed files with 12 additions and 4 deletions
+4
View File
@@ -1,6 +1,10 @@
dear imgui
CHANGELOG
PCSX2 Changes (must be reapplied after each update, use git blame on this changelog to inspect the commit that originally applied the change):
- Don't shrink fonts based on their line height, and allow PCSX2 to specify a line height
- Issue: https://github.com/ocornut/imgui/issues/9063
This document holds the user-facing changelog that we also use in release notes.
We generally fold multiple commits pertaining to the same topic as a single entry.
Changes to backends are also included within the individual .cpp files of each backend.
+2
View File
@@ -3556,6 +3556,7 @@ struct ImFontConfig
float RasterizerMultiply; // 1.0f // Linearly brighten (>1.0f) or darken (<1.0f) font output. Brightening small fonts may be a good workaround to make them more readable. This is a silly thing we may remove in the future.
float RasterizerDensity; // 1.0f // [LEGACY: this only makes sense when ImGuiBackendFlags_RendererHasTextures is not supported] DPI scale multiplier for rasterization. Not altering other font metrics: makes it easy to swap between e.g. a 100% and a 400% fonts for a zooming display, or handle Retina screen. IMPORTANT: If you change this it is expected that you increase/decrease font scale roughly to the inverse of this, otherwise quality may look lowered.
float ExtraSizeScale; // 1.0f // Extra rasterizer scale over SizePixels.
float LineHeight; // 1.0f // [PCSX2 Custom] The spacing between lines of the font, in ems.
// [Internal]
ImFontFlags Flags; // Font flags (don't use just yet, will be exposed in upcoming 1.92.X updates)
@@ -3852,6 +3853,7 @@ struct ImFont
ImFontAtlas* OwnerAtlas; // 4-8 // What we have been loaded into.
ImFontFlags Flags; // 4 // Font flags.
float CurrentRasterizerDensity; // Current rasterizer density. This is a varying state of the font.
float LineHeight; // 4 // Line Height
// [Internal] Members: Cold ~24-52 bytes
// Conceptually Sources[] is the list of font sources merged to create this font.
+5 -3
View File
@@ -2425,6 +2425,7 @@ ImFontConfig::ImFontConfig()
GlyphMaxAdvanceX = FLT_MAX;
RasterizerMultiply = 1.0f;
RasterizerDensity = 1.0f;
LineHeight = 1.0f;
EllipsisChar = 0;
}
@@ -3046,6 +3047,7 @@ ImFont* ImFontAtlas::AddFont(const ImFontConfig* font_cfg_in)
font->Flags = font_cfg_in->Flags;
font->LegacySize = font_cfg_in->SizePixels;
font->CurrentRasterizerDensity = font_cfg_in->RasterizerDensity;
font->LineHeight = font_cfg_in->LineHeight;
Fonts.push_back(font);
}
else
@@ -5612,8 +5614,8 @@ ImVec2 ImFontCalcTextSizeEx(ImFont* font, float size, float max_width, float wra
text_end_display = text_end;
ImFontBaked* baked = font->GetFontBaked(size);
const float line_height = size;
const float scale = line_height / baked->Size;
const float line_height = ImCeil(size * font->LineHeight);
const float scale = size / baked->Size;
ImVec2 text_size = ImVec2(0, 0);
float line_width = 0.0f;
@@ -5753,7 +5755,7 @@ begin:
if (!text_end)
text_end = text_begin + ImStrlen(text_begin); // ImGui:: functions generally already provides a valid text_end, so this is merely to handle direct calls.
const float line_height = size;
const float line_height = ImCeil(size * LineHeight);
ImFontBaked* baked = GetFontBaked(size);
const float scale = size / baked->Size;
+1 -1
View File
@@ -439,7 +439,7 @@ static bool ImGui_ImplFreeType_FontBakedInit(ImFontAtlas* atlas, ImFontConfig* s
// (FT_Set_Pixel_Sizes() essentially calls FT_Request_Size() with FT_SIZE_REQUEST_TYPE_NOMINAL)
const float rasterizer_density = src->RasterizerDensity * baked->RasterizerDensity;
FT_Size_RequestRec req;
req.type = (bd_font_data->UserFlags & ImGuiFreeTypeLoaderFlags_Bitmap) ? FT_SIZE_REQUEST_TYPE_NOMINAL : FT_SIZE_REQUEST_TYPE_REAL_DIM;
req.type = FT_SIZE_REQUEST_TYPE_NOMINAL;
req.width = 0;
req.height = (uint32_t)(size * 64 * rasterizer_density);
req.horiResolution = 0;