Description: Fix caching of the scalableBitmapFactor for colour fonts Associate the scalableBitmapFactor with the freetype QFontEngine so that it is preserved when caching the engine. Author: Michael Sheldon Bug-Ubuntu: https://bugs.launchpad.net/bugs/1594851 Bug: https://bugreports.qt.io/browse/QTBUG-53652 Forwarded: https://codereview.qt-project.org/#/c/161161/ Last-Update: 2016-05-26 --- qtbase-opensource-src-5.4.1+dfsg.orig/src/gui/text/qfontengine_ft.cpp +++ qtbase-opensource-src-5.4.1+dfsg/src/gui/text/qfontengine_ft.cpp @@ -276,7 +276,6 @@ QFreetypeFace *QFreetypeFace::getFace(co newFreetype->ref.store(1); newFreetype->xsize = 0; newFreetype->ysize = 0; - newFreetype->scalableBitmapScaleFactor = 1; newFreetype->matrix.xx = 0x10000; newFreetype->matrix.yy = 0x10000; newFreetype->matrix.xy = 0; @@ -355,10 +354,11 @@ void QFreetypeFace::release(const QFontE } -void QFreetypeFace::computeSize(const QFontDef &fontDef, int *xsize, int *ysize, bool *outline_drawing) +void QFreetypeFace::computeSize(const QFontDef &fontDef, int *xsize, int *ysize, bool *outline_drawing, QFixed *scalableBitmapScaleFactor) { *ysize = qRound(fontDef.pixelSize * 64); *xsize = *ysize * fontDef.stretch / 100; + *scalableBitmapScaleFactor = 1; *outline_drawing = false; if (!(face->face_flags & FT_FACE_FLAG_SCALABLE)) { @@ -396,7 +396,7 @@ void QFreetypeFace::computeSize(const QF // to make sure we can select the desired bitmap strike index if (FT_Select_Size(face, best) == 0) { if (isScalableBitmap()) - scalableBitmapScaleFactor = QFixed::fromReal((qreal)fontDef.pixelSize / face->available_sizes[best].height); + *scalableBitmapScaleFactor = QFixed::fromReal((qreal)fontDef.pixelSize / face->available_sizes[best].height); *xsize = X_SIZE(face, best); *ysize = Y_SIZE(face, best); } else { @@ -734,7 +734,7 @@ bool QFontEngineFT::init(FaceId faceId, } lbearing = rbearing = SHRT_MIN; - freetype->computeSize(fontDef, &xsize, &ysize, &defaultGlyphSet.outline_drawing); + freetype->computeSize(fontDef, &xsize, &ysize, &defaultGlyphSet.outline_drawing, &scalableBitmapScaleFactor); FT_Face face = lockFace(); @@ -1284,24 +1284,24 @@ int QFontEngineFT::synthesized() const QFixed QFontEngineFT::ascent() const { QFixed v = QFixed::fromFixed(metrics.ascender); - if (freetype->scalableBitmapScaleFactor != 1) - v *= freetype->scalableBitmapScaleFactor; + if (scalableBitmapScaleFactor != 1) + v *= scalableBitmapScaleFactor; return v; } QFixed QFontEngineFT::descent() const { QFixed v = QFixed::fromFixed(-metrics.descender); - if (freetype->scalableBitmapScaleFactor != 1) - v *= freetype->scalableBitmapScaleFactor; + if (scalableBitmapScaleFactor != 1) + v *= scalableBitmapScaleFactor; return v; } QFixed QFontEngineFT::leading() const { QFixed v = QFixed::fromFixed(metrics.height - metrics.ascender + metrics.descender); - if (freetype->scalableBitmapScaleFactor != 1) - v *= freetype->scalableBitmapScaleFactor; + if (scalableBitmapScaleFactor != 1) + v *= scalableBitmapScaleFactor; return v; } @@ -1316,7 +1316,7 @@ QFixed QFontEngineFT::xHeight() const return answer; } } else { - return QFixed(freetype->face->size->metrics.y_ppem) * freetype->scalableBitmapScaleFactor; + return QFixed(freetype->face->size->metrics.y_ppem) * scalableBitmapScaleFactor; } return QFontEngine::xHeight(); } @@ -1342,8 +1342,8 @@ QFixed QFontEngineFT::averageCharWidth() qreal QFontEngineFT::maxCharWidth() const { QFixed max_advance = QFixed::fromFixed(metrics.max_advance); - if (freetype->scalableBitmapScaleFactor != 1) - max_advance *= freetype->scalableBitmapScaleFactor; + if (scalableBitmapScaleFactor != 1) + max_advance *= scalableBitmapScaleFactor; return max_advance.toReal(); } @@ -1675,7 +1675,7 @@ bool QFontEngineFT::shouldUseDesignMetri QFixed QFontEngineFT::scaledBitmapMetrics(QFixed m) const { - return m * freetype->scalableBitmapScaleFactor; + return m * scalableBitmapScaleFactor; } glyph_metrics_t QFontEngineFT::scaledBitmapMetrics(const glyph_metrics_t &m) const @@ -1713,8 +1713,8 @@ void QFontEngineFT::recalcAdvances(QGlyp delete g; } - if (freetype->scalableBitmapScaleFactor != 1) - glyphs->advances[i] *= freetype->scalableBitmapScaleFactor; + if (scalableBitmapScaleFactor != 1) + glyphs->advances[i] *= scalableBitmapScaleFactor; } if (face) unlockFace(); @@ -2084,9 +2084,9 @@ QImage QFontEngineFT::bitmapForGlyph(gly else if (defaultFormat == GlyphFormat::Format_Mono) img = QImage(glyph->data, glyph->width, glyph->height, QImage::Format_Mono).copy(); - if (!img.isNull() && (!t.isIdentity() || freetype->scalableBitmapScaleFactor != 1)) { + if (!img.isNull() && (!t.isIdentity() || scalableBitmapScaleFactor != 1)) { QTransform trans(t); - const qreal scaleFactor = freetype->scalableBitmapScaleFactor.toReal(); + const qreal scaleFactor = scalableBitmapScaleFactor.toReal(); trans.scale(scaleFactor, scaleFactor); img = img.transformed(trans, Qt::SmoothTransformation); } --- qtbase-opensource-src-5.4.1+dfsg.orig/src/gui/text/qfontengine_ft_p.h +++ qtbase-opensource-src-5.4.1+dfsg/src/gui/text/qfontengine_ft_p.h @@ -69,7 +69,7 @@ class QFontconfigDatabase; class QFreetypeFace { public: - void computeSize(const QFontDef &fontDef, int *xsize, int *ysize, bool *outline_drawing); + void computeSize(const QFontDef &fontDef, int *xsize, int *ysize, bool *outline_drawing, QFixed *scalableBitmapScaleFactor); QFontEngine::Properties properties() const; bool getSfntTable(uint tag, uchar *buffer, uint *length) const; @@ -90,7 +90,6 @@ public: FT_Face face; int xsize; // 26.6 int ysize; // 26.6 - QFixed scalableBitmapScaleFactor; FT_Matrix matrix; FT_CharMap unicode_map; FT_CharMap symbol_map; @@ -336,6 +335,7 @@ private: FT_Size_Metrics metrics; mutable bool kerning_pairs_loaded; + QFixed scalableBitmapScaleFactor; }; inline uint qHash(const QFontEngineFT::GlyphAndSubPixelPosition &g)