From 151dd9c67cd60ea72d89fe9a82937f008b6e2ac8 Mon Sep 17 00:00:00 2001
From: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>
Date: Wed, 8 May 2013 13:32:18 +0200
Subject: [PATCH] Fix transformed raster fonts on Windows

We removed all Q_WS_WIN code when going to Qt 5. One of the things
removed was the condition that we do painter path text rendering
for transformed, non-ttf fonts, since the GDI engine does not support
transforming those. This has now been reintroduced and adapted to the
QPA way of doing things, by checking for it in the font engine subclass.

Then there was the problem that QStaticText only supports cases
where the font engine can transform the glyphs. Thus we need to fall
back to regular text drawing in drawStaticText() for unsupported cases,
and we need to skip the optimized path in the raster engine (which
goes to drawStaticTextItem)

Task-number: QTBUG-30932
Change-Id: I17ba7355ee127811b0e77bb3a9b9db092e99893b
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
---
 src/gui/painting/qpaintengine_raster.cpp        |  3 ++-
 src/gui/painting/qpainter.cpp                   | 17 ++++++++++-------
 .../platforms/windows/qwindowsfontengine.cpp    |  6 ++++++
 .../platforms/windows/qwindowsfontengine.h      |  1 +
 4 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/src/gui/painting/qpaintengine_raster.cpp b/src/gui/painting/qpaintengine_raster.cpp
index a123c147a25..66a4a43cbae 100644
--- a/src/gui/painting/qpaintengine_raster.cpp
+++ b/src/gui/painting/qpaintengine_raster.cpp
@@ -3078,7 +3078,8 @@ void QRasterPaintEngine::drawTextItem(const QPointF &p, const QTextItem &textIte
         ti.fontEngine->getGlyphPositions(ti.glyphs, matrix, ti.flags, glyphs, positions);
 
         drawCachedGlyphs(glyphs.size(), glyphs.constData(), positions.constData(), ti.fontEngine);
-    } else if (matrix.type() < QTransform::TxProject) {
+    } else if (matrix.type() < QTransform::TxProject
+               && ti.fontEngine->supportsTransformation(matrix)) {
         bool invertible;
         QTransform invMat = matrix.inverted(&invertible);
         if (!invertible)
diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp
index e42b70427ca..d950c4e45f3 100644
--- a/src/gui/painting/qpainter.cpp
+++ b/src/gui/painting/qpainter.cpp
@@ -5727,17 +5727,20 @@ void QPainter::drawStaticText(const QPointF &topLeftPosition, const QStaticText
         staticText_d->needsRelayout = true;
     }
 
-    // If we don't have an extended paint engine, or if the painter is projected,
-    // we go through standard code path
-    if (d->extended == 0 || !d->state->matrix.isAffine()) {
-        staticText_d->paintText(topLeftPosition, this);
-        return;
-    }
-
     QFontEngine *fe = staticText_d->font.d->engineForScript(QChar::Script_Common);
     if (fe->type() == QFontEngine::Multi)
         fe = static_cast<QFontEngineMulti *>(fe)->engine(0);
 
+    // If we don't have an extended paint engine, if the painter is projected,
+    // or if the font engine does not support the matrix, we go through standard
+    // code path
+    if (d->extended == 0
+            || !d->state->matrix.isAffine()
+            || !fe->supportsTransformation(d->state->matrix)) {
+        staticText_d->paintText(topLeftPosition, this);
+        return;
+    }
+
     bool engineRequiresPretransform = d->extended->requiresPretransformedGlyphPositions(fe, d->state->matrix);
     if (staticText_d->untransformedCoordinates && engineRequiresPretransform) {
         // The coordinates are untransformed, and the engine can't deal with that
diff --git a/src/plugins/platforms/windows/qwindowsfontengine.cpp b/src/plugins/platforms/windows/qwindowsfontengine.cpp
index 5757bcad4ea..a410708cebc 100644
--- a/src/plugins/platforms/windows/qwindowsfontengine.cpp
+++ b/src/plugins/platforms/windows/qwindowsfontengine.cpp
@@ -1412,5 +1412,11 @@ void QWindowsMultiFontEngine::loadEngine(int at)
     // TODO: increase cost in QFontCache for the font engine loaded here
 }
 
+bool QWindowsFontEngine::supportsTransformation(const QTransform &transform) const
+{
+    // Support all transformations for ttf files, and translations for raster fonts
+    return ttf || transform.type() <= QTransform::TxTranslate;
+}
+
 QT_END_NAMESPACE
 
diff --git a/src/plugins/platforms/windows/qwindowsfontengine.h b/src/plugins/platforms/windows/qwindowsfontengine.h
index 2bf6ead503e..9e92a8fbff6 100644
--- a/src/plugins/platforms/windows/qwindowsfontengine.h
+++ b/src/plugins/platforms/windows/qwindowsfontengine.h
@@ -123,6 +123,7 @@ public:
     virtual QImage alphaRGBMapForGlyph(glyph_t t, QFixed subPixelPosition, const QTransform &xform);
 
     virtual QFontEngine *cloneWithSize(qreal pixelSize) const;
+    virtual bool supportsTransformation(const QTransform &transform) const;
 
 #ifndef Q_CC_MINGW
     virtual void getGlyphBearings(glyph_t glyph, qreal *leftBearing = 0, qreal *rightBearing = 0);
-- 
GitLab