summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Sheldon <elleo@gnu.org>2016-05-26 16:20:33 +0100
committerjian liang <jianliang79@gmail.com>2016-07-19 06:44:00 +0000
commit267c01390544ba12f81783c8b0e37ed38db231d6 (patch)
treed004eff0f474f2503378bc76ca6a006f92d86fb9
parentb75fe73700bae85af4de3e4159a16276b844557b (diff)
Preserve the scale of fonts when caching the font engine
Associates the scalableBitmapFactor with the freetype QFontEngine so that it is preserved when caching the engine Task-number: QTBUG-53652 Change-Id: I010f9d235ccf30679b112e0c05e01bc247a3693f Reviewed-by: jian liang <jianliang79@gmail.com> Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
-rw-r--r--src/gui/text/qfontengine_ft.cpp36
-rw-r--r--src/gui/text/qfontengine_ft_p.h4
2 files changed, 20 insertions, 20 deletions
diff --git a/src/gui/text/qfontengine_ft.cpp b/src/gui/text/qfontengine_ft.cpp
index e89522f5af..26ed81a091 100644
--- a/src/gui/text/qfontengine_ft.cpp
+++ b/src/gui/text/qfontengine_ft.cpp
@@ -259,7 +259,6 @@ QFreetypeFace *QFreetypeFace::getFace(const QFontEngine::FaceId &face_id,
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;
@@ -335,10 +334,11 @@ void QFreetypeFace::release(const QFontEngine::FaceId &face_id)
}
-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)) {
@@ -376,7 +376,7 @@ void QFreetypeFace::computeSize(const QFontDef &fontDef, int *xsize, int *ysize,
// 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 = face->available_sizes[best].x_ppem;
*ysize = face->available_sizes[best].y_ppem;
} else {
@@ -729,7 +729,7 @@ bool QFontEngineFT::init(FaceId faceId, bool antialias, GlyphFormat format,
symbol = bool(fontDef.family.contains(QLatin1String("symbol"), Qt::CaseInsensitive));
}
- freetype->computeSize(fontDef, &xsize, &ysize, &defaultGlyphSet.outline_drawing);
+ freetype->computeSize(fontDef, &xsize, &ysize, &defaultGlyphSet.outline_drawing, &scalableBitmapScaleFactor);
FT_Face face = lockFace();
@@ -1294,24 +1294,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;
}
@@ -1326,7 +1326,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();
}
@@ -1352,8 +1352,8 @@ QFixed QFontEngineFT::averageCharWidth() const
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();
}
@@ -1639,7 +1639,7 @@ bool QFontEngineFT::shouldUseDesignMetrics(QFontEngine::ShaperFlags flags) const
QFixed QFontEngineFT::scaledBitmapMetrics(QFixed m) const
{
- return m * freetype->scalableBitmapScaleFactor;
+ return m * scalableBitmapScaleFactor;
}
glyph_metrics_t QFontEngineFT::scaledBitmapMetrics(const glyph_metrics_t &m) const
@@ -1677,8 +1677,8 @@ void QFontEngineFT::recalcAdvances(QGlyphLayout *glyphs, QFontEngine::ShaperFlag
delete g;
}
- if (freetype->scalableBitmapScaleFactor != 1)
- glyphs->advances[i] *= freetype->scalableBitmapScaleFactor;
+ if (scalableBitmapScaleFactor != 1)
+ glyphs->advances[i] *= scalableBitmapScaleFactor;
}
if (face)
unlockFace();
@@ -1981,9 +1981,9 @@ QImage QFontEngineFT::bitmapForGlyph(glyph_t g, QFixed subPixelPosition, const Q
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);
}
diff --git a/src/gui/text/qfontengine_ft_p.h b/src/gui/text/qfontengine_ft_p.h
index 3f4bf84753..3cdf0cda47 100644
--- a/src/gui/text/qfontengine_ft_p.h
+++ b/src/gui/text/qfontengine_ft_p.h
@@ -75,7 +75,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;
@@ -96,7 +96,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;
@@ -340,6 +339,7 @@ private:
FT_Size_Metrics metrics;
mutable bool kerning_pairs_loaded;
+ QFixed scalableBitmapScaleFactor;
};
inline uint qHash(const QFontEngineFT::GlyphAndSubPixelPosition &g)