From 7a42679a98f637999dd52575e5a0ce9491ddbe9b Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Mon, 5 Jun 2023 15:35:23 +0200 Subject: [PATCH] Freetype: Don't do image transform for translations In 6ba003f73295b896aa6dc1fba099daadb4760209, we added support for transforming bitmap fonts in Freetype by rotating the rendered glyphs as images rather than using FT_Set_Transform(). However, we enabled this for all transforms, even the ones that were only doing translations, which is unnecessary and also caused some issues. We restrict the condition to only cover rotations, scales and shears and let translations be handled as before. [ChangeLog][Text][Freetype] Fixed an issue where setting a translation matrix on text using a bitmap font would cause rendering artifacts. Fixes: QTBUG-114229 Change-Id: Ib3f2870e57c881364c85432a7937f15f3664eda7 Reviewed-by: Lars Knoll (cherry picked from commit 90e3f0bd73e5fea6e0ed3fec65e3a5864d5e132f) Reviewed-by: Qt Cherry-pick Bot --- src/gui/text/freetype/qfontengine_ft.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/gui/text/freetype/qfontengine_ft.cpp b/src/gui/text/freetype/qfontengine_ft.cpp index 5b48ad979b1..d5c6f20db24 100644 --- a/src/gui/text/freetype/qfontengine_ft.cpp +++ b/src/gui/text/freetype/qfontengine_ft.cpp @@ -1828,7 +1828,8 @@ glyph_metrics_t QFontEngineFT::alphaMapBoundingBox(glyph_t glyph, // outline drawing. To ensure the bounding box matches the rendered glyph, we // need to do the same here. - const bool needsImageTransform = !FT_IS_SCALABLE(freetype->face) && !matrix.isIdentity(); + const bool needsImageTransform = !FT_IS_SCALABLE(freetype->face) + && matrix.type() > QTransform::TxTranslate; if (needsImageTransform && format == QFontEngine::Format_Mono) format = QFontEngine::Format_A8; Glyph *g = loadGlyphFor(glyph, subPixelPosition, format, matrix, true, true); @@ -1957,7 +1958,8 @@ QImage QFontEngineFT::alphaMapForGlyph(glyph_t g, const QFixedPoint &subPixelPosition, const QTransform &t) { - const bool needsImageTransform = !FT_IS_SCALABLE(freetype->face) && !t.isIdentity(); + const bool needsImageTransform = !FT_IS_SCALABLE(freetype->face) + && t.type() > QTransform::TxTranslate; const GlyphFormat neededFormat = antialias || needsImageTransform ? Format_A8 : Format_Mono; Glyph *glyph = loadGlyphFor(g, subPixelPosition, neededFormat, t, false, true);