From 3a0e4b61479b9c7231a702e8acd6794bfd312874 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Wed, 6 Nov 2024 15:59:22 +0100 Subject: [PATCH] Freetype: Fix transformed text when subpixel AA is on 6ba003f73295b896aa6dc1fba099daadb4760209 fixed transforming bitmap fonts for the case where 8 bit antialiasing is used. This is the case when a transform is set on the painter by the user, but for some reason it is not when high-dpi is enabled, triggering QTBUG-111796. An attempt was made at fixing this by drawing the untransformed glyphs into the cache and then transforming them as they were put on the screen. This worked with Qt Quick, but the raster engine does not support this and instead falls back to QPainterPath rendering in that case. So b492582b9c4cf679109ed4875aff912e186263cb caused a regression and was reverted. A simpler fix which works for both Qt Quick and QPainter is to draw the pre-transformed image of the glyph into the cache for 24-bit AA, same as for 8-bit AA. In addition, this changes the transformation to nearest neighbor instead of interpolating, because bitmap fonts are typically intended to look crisp and it also matches how native rendered fonts are scaled in Qt Quick. Fixes: QTBUG-111796 Change-Id: I2d9fd9d98d32820e677916c3d1c744331a72175b Reviewed-by: Paul Olav Tvete (cherry picked from commit b6247ced7e83af4d51ba20be8068f28cc8c006bc) Reviewed-by: Qt Cherry-pick Bot --- src/gui/text/freetype/qfontengine_ft.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/gui/text/freetype/qfontengine_ft.cpp b/src/gui/text/freetype/qfontengine_ft.cpp index 958d8d12936..35f5a544402 100644 --- a/src/gui/text/freetype/qfontengine_ft.cpp +++ b/src/gui/text/freetype/qfontengine_ft.cpp @@ -2095,7 +2095,7 @@ QImage QFontEngineFT::alphaMapForGlyph(glyph_t g, QImage img = alphaMapFromGlyphData(glyph, neededFormat); if (needsImageTransform) - img = img.transformed(t, Qt::SmoothTransformation); + img = img.transformed(t, Qt::FastTransformation); else img = img.copy(); @@ -2112,12 +2112,19 @@ QImage QFontEngineFT::alphaRGBMapForGlyph(glyph_t g, if (t.type() > QTransform::TxRotate) return QFontEngine::alphaRGBMapForGlyph(g, subPixelPosition, t); + const bool needsImageTransform = !FT_IS_SCALABLE(freetype->face) + && t.type() > QTransform::TxTranslate; + + const GlyphFormat neededFormat = Format_A32; Glyph *glyph = loadGlyphFor(g, subPixelPosition, neededFormat, t, false, true); QImage img = alphaMapFromGlyphData(glyph, neededFormat); - img = img.copy(); + if (needsImageTransform) + img = img.transformed(t, Qt::FastTransformation); + else + img = img.copy(); if (!cacheEnabled && glyph != &emptyGlyph) delete glyph;