aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.Client/Common/UI/UIBitmapFont.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Minecraft.Client/Common/UI/UIBitmapFont.cpp')
-rw-r--r--Minecraft.Client/Common/UI/UIBitmapFont.cpp96
1 files changed, 65 insertions, 31 deletions
diff --git a/Minecraft.Client/Common/UI/UIBitmapFont.cpp b/Minecraft.Client/Common/UI/UIBitmapFont.cpp
index afc2b139..31eef281 100644
--- a/Minecraft.Client/Common/UI/UIBitmapFont.cpp
+++ b/Minecraft.Client/Common/UI/UIBitmapFont.cpp
@@ -250,15 +250,22 @@ rrbool UIBitmapFont::GetGlyphBitmap(S32 glyph,F32 pixel_scale,IggyBitmapCharacte
// Choose a reasonable glyph scale.
float glyphScale = 1.0f, truePixelScale = 1.0f / m_cFontData->getFontData()->m_fAdvPerPixel;
- F32 targetPixelScale = pixel_scale;
- //if(!RenderManager.IsWidescreen())
- //{
- // // Fix for different scales in 480
- // targetPixelScale = pixel_scale*2/3;
- //}
- while ( (0.5f + glyphScale) * truePixelScale < targetPixelScale)
+ while ( (0.5f + glyphScale) * truePixelScale < pixel_scale)
glyphScale++;
+ // Debug: log each unique (font, pixel_scale) pair
+ {
+ static std::unordered_set<int> s_loggedScaleKeys;
+ // Encode font pointer + quantized scale into a key to log each combo once
+ int scaleKey = (int)(pixel_scale * 100.0f) ^ (int)(uintptr_t)m_cFontData;
+ if (s_loggedScaleKeys.find(scaleKey) == s_loggedScaleKeys.end() && s_loggedScaleKeys.size() < 50) {
+ s_loggedScaleKeys.insert(scaleKey);
+ float tps = truePixelScale;
+ app.DebugPrintf("[FONT-DBG] GetGlyphBitmap: font=%s glyph=%d pixel_scale=%.3f truePixelScale=%.1f glyphScale=%.0f\n",
+ m_cFontData->getFontName().c_str(), glyph, pixel_scale, tps, glyphScale);
+ }
+ }
+
// 4J-JEV: Debug code to check which font sizes are being used.
#if (!defined _CONTENT_PACKAGE) && (VERBOSE_FONT_OUTPUT > 0)
@@ -303,9 +310,6 @@ rrbool UIBitmapFont::GetGlyphBitmap(S32 glyph,F32 pixel_scale,IggyBitmapCharacte
}
#endif
- //app.DebugPrintf("Request glyph_%d (U+%.4X) at %f, converted to %f (%f)\n",
- // glyph, GetUnicode(glyph), pixel_scale, targetPixelScale, glyphScale);
-
// It is not necessary to shrink the glyph width here
// as its already been done in 'GetGlyphMetrics' by:
// > metrics->x1 = m_kerningTable[glyph] * ratio;
@@ -324,27 +328,57 @@ rrbool UIBitmapFont::GetGlyphBitmap(S32 glyph,F32 pixel_scale,IggyBitmapCharacte
bitmap->top_left_y = -((S32) m_cFontData->getFontData()->m_uiGlyphHeight) * m_cFontData->getFontData()->m_fAscent;
bitmap->oversample = 0;
- bitmap->point_sample = true;
-
- // 4J-JEV:
- // pixel_scale == font size chosen in flash.
- // bitmap->pixel_scale_correct = (float) m_glyphHeight; // Scales the glyph to desired size.
- // bitmap->pixel_scale_correct = pixel_scale; // Always the same size (not desired size).
- // bitmap->pixel_scale_correct = pixel_scale * 0.5; // Doubles original size.
- // bitmap->pixel_scale_correct = pixel_scale * 2; // Halves original size.
-
- // Actual scale, and possible range of scales.
- bitmap->pixel_scale_correct = pixel_scale / glyphScale;
- bitmap->pixel_scale_max = 99.0f;
- bitmap->pixel_scale_min = 0.0f;
-
- /* 4J-JEV: Some of Sean's code.
- int glyphScaleMin = 1;
- int glyphScaleMax = 3;
- float actualScale = pixel_scale / glyphScale;
- bitmap->pixel_scale_correct = actualScale;
- bitmap->pixel_scale_min = actualScale * glyphScaleMin * 0.999f;
- bitmap->pixel_scale_max = actualScale * glyphScaleMax * 1.001f; */
+
+#ifdef _WINDOWS64
+ // On Windows64 the window can be any size, producing fractional
+ // pixel_scale values that don't align to integer multiples of
+ // truePixelScale. The original console code cached glyphs with a
+ // broad [truePixelScale, 99] range in the "normal" branch, which
+ // works on consoles (fixed 1080p — font sizes are exact multiples)
+ // but causes cache pollution on Windows: the first glyph cached in
+ // that range sets pixel_scale_correct for ALL subsequent requests,
+ // so different font sizes get scaled by wrong ratios, producing
+ // mixed letter sizes on screen.
+ //
+ // Fix: always use pixel_scale_correct = truePixelScale so every
+ // cache entry is consistent. Two ranges: downscale (bilinear for
+ // smooth reduction) and upscale (point_sample for crisp pixel-art).
+ bitmap->pixel_scale_correct = truePixelScale;
+ if (pixel_scale < truePixelScale)
+ {
+ bitmap->pixel_scale_min = 0.0f;
+ bitmap->pixel_scale_max = truePixelScale;
+ bitmap->point_sample = false;
+ }
+ else
+ {
+ bitmap->pixel_scale_min = truePixelScale;
+ bitmap->pixel_scale_max = 99.0f;
+ bitmap->point_sample = true;
+ }
+#else
+ if (glyphScale <= 1 && pixel_scale < truePixelScale)
+ {
+ // Small display: pixel_scale is less than the native glyph size.
+ // Report the bitmap at its true native scale so Iggy downscales it
+ // to match the layout metrics (bilinear for smooth downscaling).
+ bitmap->pixel_scale_correct = truePixelScale;
+ bitmap->pixel_scale_min = 0.0f;
+ bitmap->pixel_scale_max = truePixelScale * 1.001f;
+ bitmap->point_sample = false;
+ }
+ else
+ {
+ // Normal/upscale case: integer-multiple scaling for pixel-art look.
+ // Console-only — fixed resolution means pixel_scale values are exact
+ // integer multiples of truePixelScale, so cache sharing is safe.
+ float actualScale = pixel_scale / glyphScale;
+ bitmap->pixel_scale_correct = actualScale;
+ bitmap->pixel_scale_min = truePixelScale;
+ bitmap->pixel_scale_max = 99.0f;
+ bitmap->point_sample = true;
+ }
+#endif
// 4J-JEV: Nothing to do with glyph placement,
// entirely to do with cropping your glyph out of an archive.