diff options
author | Tor Arne Vestbø <tor.arne.vestbo@digia.com> | 2013-01-10 15:09:32 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-01-10 15:45:49 +0100 |
commit | 8927084d0acfea2bb3fc8a932069c1d5ceb001d0 (patch) | |
tree | 9a2cb26c708d69ab9ae86e904feff62022b264fb /src/gui/painting/qpaintengine_raster.cpp | |
parent | 5fb6331a17a5c43b91daddf4a30e46ccbd1419b5 (diff) |
Refactor paint/font-engine shouldDrawCachedGlyphs and supportsTransformations
Some cruft had built up over time, and this is an attempt at cleaning up
the naming and use of these functions, and should not have any behavioral
effects.
The function supportsTransformations() has been renamed in QPaintEngineEx
to reflect its use, which is to decide if QPainter needs to pre-transform
the coordinates of the static text before asking the paint-engine to draw
it. The new name is requiresPretransformedGlyphPositions().
The OpenGL and CoreGraphics (Mac) paint engines keep their behavior of
not needing pre-transformed text, while the raster engine needs this
when using cached glyphs. The base-class implementation assumes that
all transforms that include a projection will need pre-transform,
which is also the case for the raster engine.
All decisions in the paint engines about whether or not to use the
glyph cache when drawing text are now deferred to the function
shouldDrawCachedGlyphs(), which has been refactored for the GL paint
engine(s) to share more logic. All implementations call the base
class implementation, which ensures that large font sizes will not
be cached. The raster engine will in addition ask the font engine
whether or not it can produce glyphs for the glyph-cache with the
given transform.
This is the only remaining instance of the supportsTransformations()
function, and will for all font engines except the CoreText engine
support affine transformations. The CoreText engine on the other hand
only supports translations (for now).
Change-Id: I8fb5e43e3de3ef62a526a79a6dfeda7f9546771d
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>
Diffstat (limited to 'src/gui/painting/qpaintengine_raster.cpp')
-rw-r--r-- | src/gui/painting/qpaintengine_raster.cpp | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/src/gui/painting/qpaintengine_raster.cpp b/src/gui/painting/qpaintengine_raster.cpp index 0e9129f8c0..53fdd42b8a 100644 --- a/src/gui/painting/qpaintengine_raster.cpp +++ b/src/gui/painting/qpaintengine_raster.cpp @@ -3010,13 +3010,15 @@ void QRasterPaintEngine::drawStaticTextItem(QStaticTextItem *textItem) ensurePen(); ensureRasterState(); + QTransform matrix = state()->matrix; + QFontEngine *fontEngine = textItem->fontEngine(); - if (!supportsTransformations(fontEngine)) { + if (shouldDrawCachedGlyphs(fontEngine, matrix)) { drawCachedGlyphs(textItem->numGlyphs, textItem->glyphs, textItem->glyphPositions, fontEngine); - } else if (state()->matrix.type() < QTransform::TxProject) { + } else if (matrix.type() < QTransform::TxProject) { bool invertible; - QTransform invMat = state()->matrix.inverted(&invertible); + QTransform invMat = matrix.inverted(&invertible); if (!invertible) return; @@ -3055,7 +3057,7 @@ void QRasterPaintEngine::drawTextItem(const QPointF &p, const QTextItem &textIte QRasterPaintEngineState *s = state(); QTransform matrix = s->matrix; - if (!supportsTransformations(ti.fontEngine)) { + if (shouldDrawCachedGlyphs(ti.fontEngine, matrix)) { QVarLengthArray<QFixedPoint> positions; QVarLengthArray<glyph_t> glyphs; @@ -3299,21 +3301,25 @@ void QRasterPaintEngine::releaseDC(HDC) const /*! \internal */ -bool QRasterPaintEngine::supportsTransformations(QFontEngine *fontEngine) const +bool QRasterPaintEngine::requiresPretransformedGlyphPositions(QFontEngine *fontEngine, const QTransform &m) const { - const QTransform &m = state()->matrix; - return supportsTransformations(fontEngine, m); + // Cached glyphs always require pretransformed positions + if (shouldDrawCachedGlyphs(fontEngine, m)) + return true; + + // Otherwise let the base-class decide based on the transform + return QPaintEngineEx::requiresPretransformedGlyphPositions(fontEngine, m); } -/*! - \internal -*/ -bool QRasterPaintEngine::supportsTransformations(QFontEngine *fontEngine, const QTransform &m) const +bool QRasterPaintEngine::shouldDrawCachedGlyphs(QFontEngine *fontEngine, const QTransform &m) const { - if (fontEngine->supportsTransformations(m)) - return true; + // The font engine might not support filling the glyph cache + // with the given transform applied, in which case we need to + // fall back to the QPainterPath code-path. + if (!fontEngine->supportsTransformation(m)) + return false; - return !shouldDrawCachedGlyphs(fontEngine, m); + return QPaintEngineEx::shouldDrawCachedGlyphs(fontEngine, m); } /*! |