Fonts: avoid baking ExtraSizeScale twice into Ascent/Descent. (re)

Reapply 1bcc23e + offset for our current internal font using it.
This commit is contained in:
ocornut
2026-02-11 20:11:13 +01:00
parent 291787bcac
commit 42f28ba305
2 changed files with 3 additions and 3 deletions

View File

@@ -3175,7 +3175,7 @@ ImFont* ImFontAtlas::AddFontDefaultVector(const ImFontConfig* font_cfg_template)
if (font_cfg.Name[0] == '\0') if (font_cfg.Name[0] == '\0')
ImFormatString(font_cfg.Name, IM_COUNTOF(font_cfg.Name), "ProggyVector.ttf"); ImFormatString(font_cfg.Name, IM_COUNTOF(font_cfg.Name), "ProggyVector.ttf");
font_cfg.ExtraSizeScale = 1.140f; // Match ProggyClean font_cfg.ExtraSizeScale = 1.140f; // Match ProggyClean
font_cfg.GlyphOffset.y += -0.5f * (font_cfg.SizePixels / 13.0f); // Closer match ProggyClean + avoid descenders going too high (with current code). font_cfg.GlyphOffset.y += 1.0f * (font_cfg.SizePixels / 13.0f); // Closer match ProggyClean + avoid descenders going too high (with current code).
int ttf_compressed_size = 0; int ttf_compressed_size = 0;
const char* ttf_compressed = GetDefaultCompressedFontDataProggyVector(&ttf_compressed_size); const char* ttf_compressed = GetDefaultCompressedFontDataProggyVector(&ttf_compressed_size);
@@ -4699,7 +4699,7 @@ static bool ImGui_ImplStbTrueType_FontBakedInit(ImFontAtlas* atlas, ImFontConfig
{ {
// FIXME-NEWFONTS: reevaluate how to use sizing metrics // FIXME-NEWFONTS: reevaluate how to use sizing metrics
// FIXME-NEWFONTS: make use of line gap value // FIXME-NEWFONTS: make use of line gap value
float scale_for_layout = bd_font_data->ScaleFactor * baked->Size; const float scale_for_layout = bd_font_data->ScaleFactor * baked->Size / src->ExtraSizeScale;
int unscaled_ascent, unscaled_descent, unscaled_line_gap; int unscaled_ascent, unscaled_descent, unscaled_line_gap;
stbtt_GetFontVMetrics(&bd_font_data->FontInfo, &unscaled_ascent, &unscaled_descent, &unscaled_line_gap); stbtt_GetFontVMetrics(&bd_font_data->FontInfo, &unscaled_ascent, &unscaled_descent, &unscaled_line_gap);
baked->Ascent = ImCeil(unscaled_ascent * scale_for_layout); baked->Ascent = ImCeil(unscaled_ascent * scale_for_layout);

View File

@@ -451,7 +451,7 @@ static bool ImGui_ImplFreeType_FontBakedInit(ImFontAtlas* atlas, ImFontConfig* s
{ {
// Read metrics // Read metrics
FT_Size_Metrics metrics = bd_baked_data->FtSize->metrics; FT_Size_Metrics metrics = bd_baked_data->FtSize->metrics;
const float scale = 1.0f / rasterizer_density; const float scale = 1.0f / (rasterizer_density * src->ExtraSizeScale);
baked->Ascent = (float)FT_CEIL(metrics.ascender) * scale; // The pixel extents above the baseline in pixels (typically positive). baked->Ascent = (float)FT_CEIL(metrics.ascender) * scale; // The pixel extents above the baseline in pixels (typically positive).
baked->Descent = (float)FT_CEIL(metrics.descender) * scale; // The extents below the baseline in pixels (typically negative). baked->Descent = (float)FT_CEIL(metrics.descender) * scale; // The extents below the baseline in pixels (typically negative).
//LineSpacing = (float)FT_CEIL(metrics.height) * scale; // The baseline-to-baseline distance. Note that it usually is larger than the sum of the ascender and descender taken as absolute values. There is also no guarantee that no glyphs extend above or below subsequent baselines when using this distance. Think of it as a value the designer of the font finds appropriate. //LineSpacing = (float)FT_CEIL(metrics.height) * scale; // The baseline-to-baseline distance. Note that it usually is larger than the sum of the ascender and descender taken as absolute values. There is also no guarantee that no glyphs extend above or below subsequent baselines when using this distance. Think of it as a value the designer of the font finds appropriate.