From d6473eb1865cca088ebc97bafdca17dac75c5a2e Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Fri, 24 Nov 2017 15:52:09 +0100 Subject: [PATCH] Fix drawing color fonts with shear and perspective transforms Fixes the fallback painting used with complex transforms to be able to handle color bitmap fonts which can't be converted to a path. Change-Id: Id2851607f673b8fc1aea63f92043d0cdebc0fb9d Reviewed-by: Konstantin Ritt Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/gui/painting/qpaintengine.cpp | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/gui/painting/qpaintengine.cpp b/src/gui/painting/qpaintengine.cpp index f42fd4ff87e..1aee7d5f745 100644 --- a/src/gui/painting/qpaintengine.cpp +++ b/src/gui/painting/qpaintengine.cpp @@ -751,11 +751,29 @@ void QPaintEngine::drawPath(const QPainterPath &) void QPaintEngine::drawTextItem(const QPointF &p, const QTextItem &textItem) { const QTextItemInt &ti = static_cast(textItem); + if (ti.glyphs.numGlyphs == 0) + return; + + if (ti.fontEngine->glyphFormat == QFontEngine::Format_ARGB) { + QVarLengthArray positions; + QVarLengthArray glyphs; + QTransform matrix = QTransform::fromTranslate(p.x(), p.y() - ti.fontEngine->ascent().toReal()); + ti.fontEngine->getGlyphPositions(ti.glyphs, matrix, ti.flags, glyphs, positions); + painter()->save(); + painter()->setRenderHint(QPainter::SmoothPixmapTransform, + bool((painter()->renderHints() & QPainter::TextAntialiasing) + && !(painter()->font().styleStrategy() & QFont::NoAntialias))); + for (int i = 0; i < ti.glyphs.numGlyphs; ++i) { + QImage glyph = ti.fontEngine->bitmapForGlyph(glyphs[i], QFixed(), QTransform()); + painter()->drawImage(positions[i].x.toReal(), positions[i].y.toReal(), glyph); + } + painter()->restore(); + return; + } QPainterPath path; path.setFillRule(Qt::WindingFill); - if (ti.glyphs.numGlyphs) - ti.fontEngine->addOutlineToPath(0, 0, ti.glyphs, &path, ti.flags); + ti.fontEngine->addOutlineToPath(0, 0, ti.glyphs, &path, ti.flags); if (!path.isEmpty()) { painter()->save(); painter()->setRenderHint(QPainter::Antialiasing,