summaryrefslogtreecommitdiffstats
path: root/src/gui/text/qdistancefield.cpp
diff options
context:
space:
mode:
authorJiang Jiang <jiang.jiang@nokia.com>2012-02-28 12:50:27 +0100
committerQt by Nokia <qt-info@nokia.com>2012-03-08 09:39:26 +0100
commit7de046db735ffc1e17d11dca1bb815876e796cdc (patch)
treeeeff468b1456bbd4f0d9608b388b3ad746041dc4 /src/gui/text/qdistancefield.cpp
parenta44da8fc12bdd1fc62311307b7cae391858a206e (diff)
Enablers for shared graphics cache in raster paint engine
Required changes for using shared graphics cache for distance field raster glyph rendering. Most of the logic is in platform plugins. Platform plugins should implement QPlatformIntegration::createImagePaintEngine() to create a subclass of QRasterEngine. Change-Id: Icf0a396e722e43b4caa2c1849aae38753cde38f1 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>
Diffstat (limited to 'src/gui/text/qdistancefield.cpp')
-rw-r--r--src/gui/text/qdistancefield.cpp67
1 files changed, 52 insertions, 15 deletions
diff --git a/src/gui/text/qdistancefield.cpp b/src/gui/text/qdistancefield.cpp
index fb06a26c8f..a1deb47175 100644
--- a/src/gui/text/qdistancefield.cpp
+++ b/src/gui/text/qdistancefield.cpp
@@ -692,17 +692,8 @@ static QImage makeDistanceField(int imgSize, const QPainterPath &path, int dfSca
return image;
}
-bool qt_fontHasNarrowOutlines(const QRawFont &f)
+static bool imageHasNarrowOutlines(const QImage &im)
{
- QRawFont font = f;
- font.setPixelSize(QT_DISTANCEFIELD_DEFAULT_BASEFONTSIZE);
- Q_ASSERT(font.isValid());
-
- QVector<quint32> glyphIndices = font.glyphIndexesForString(QLatin1String("O"));
- if (glyphIndices.size() < 1)
- return false;
-
- QImage im = font.alphaMapForGlyph(glyphIndices.at(0), QRawFont::PixelAntialiasing);
if (im.isNull())
return false;
@@ -742,6 +733,56 @@ bool qt_fontHasNarrowOutlines(const QRawFont &f)
return minHThick == 1 || minVThick == 1;
}
+bool qt_fontHasNarrowOutlines(QFontEngine *fontEngine)
+{
+ QFontEngine *fe = fontEngine->cloneWithSize(QT_DISTANCEFIELD_DEFAULT_BASEFONTSIZE);
+
+ QGlyphLayout glyphs;
+ glyph_t glyph;
+ glyphs.glyphs = &glyph;
+ int numGlyphs;
+ QChar *chars = QString(QLatin1String("O")).data();
+ fe->stringToCMap(chars, 1, &glyphs, &numGlyphs, QTextEngine::GlyphIndicesOnly);
+ QImage im = fe->alphaMapForGlyph(glyph, QFixed(), QTransform());
+ delete fe;
+
+ return imageHasNarrowOutlines(im);
+}
+
+bool qt_fontHasNarrowOutlines(const QRawFont &f)
+{
+ QRawFont font = f;
+ font.setPixelSize(QT_DISTANCEFIELD_DEFAULT_BASEFONTSIZE);
+ Q_ASSERT(font.isValid());
+
+ QVector<quint32> glyphIndices = font.glyphIndexesForString(QLatin1String("O"));
+ if (glyphIndices.size() < 1)
+ return false;
+
+ return imageHasNarrowOutlines(font.alphaMapForGlyph(glyphIndices.at(0),
+ QRawFont::PixelAntialiasing));
+}
+
+static QImage renderDistanceFieldPath(const QPainterPath &path, bool doubleResolution)
+{
+ QImage im = makeDistanceField(QT_DISTANCEFIELD_TILESIZE(doubleResolution),
+ path,
+ QT_DISTANCEFIELD_SCALE(doubleResolution),
+ QT_DISTANCEFIELD_RADIUS(doubleResolution) / QT_DISTANCEFIELD_SCALE(doubleResolution));
+ return im;
+}
+
+QImage qt_renderDistanceFieldGlyph(QFontEngine *fe, glyph_t glyph, bool doubleResolution)
+{
+ QFixedPoint position;
+ QPainterPath path;
+ fe->addGlyphsToPath(&glyph, &position, 1, &path, 0);
+ path.translate(-path.boundingRect().topLeft());
+ path.setFillRule(Qt::WindingFill);
+
+ return renderDistanceFieldPath(path, doubleResolution);
+}
+
QImage qt_renderDistanceFieldGlyph(const QRawFont &font, glyph_t glyph, bool doubleResolution)
{
QRawFont renderFont = font;
@@ -751,11 +792,7 @@ QImage qt_renderDistanceFieldGlyph(const QRawFont &font, glyph_t glyph, bool dou
path.translate(-path.boundingRect().topLeft());
path.setFillRule(Qt::WindingFill);
- QImage im = makeDistanceField(QT_DISTANCEFIELD_TILESIZE(doubleResolution),
- path,
- QT_DISTANCEFIELD_SCALE(doubleResolution),
- QT_DISTANCEFIELD_RADIUS(doubleResolution) / QT_DISTANCEFIELD_SCALE(doubleResolution));
- return im;
+ return renderDistanceFieldPath(path, doubleResolution);
}
QT_END_NAMESPACE