diff options
author | Rhys Weatherley <rhys.weatherley@nokia.com> | 2010-03-31 08:51:00 +1000 |
---|---|---|
committer | Rhys Weatherley <rhys.weatherley@nokia.com> | 2010-03-31 09:19:50 +1000 |
commit | 0d41d766d13bc6ee8a068aef4b88567c111d0e0c (patch) | |
tree | 3d391ab64babc6f4ce89254e26b885f4b684b8ec /src/openvg | |
parent | 7ffb18d137102553928f66209d13a85aa341392e (diff) | |
download | qt4-tools-0d41d766d13bc6ee8a068aef4b88567c111d0e0c.tar.gz |
Another "off by 1" problem in OpenVG - in paths this time.
Summary so far: paths and images do not need the 0.5 adjustment
to the transform, but glyphs do. Not sure why glyphs do, but the
fonts definitely look wrong without the adjustment.
Task-number: QT-3192
Reviewed-by: trustme
Diffstat (limited to 'src/openvg')
-rw-r--r-- | src/openvg/qpaintengine_vg.cpp | 41 |
1 files changed, 22 insertions, 19 deletions
diff --git a/src/openvg/qpaintengine_vg.cpp b/src/openvg/qpaintengine_vg.cpp index ce6e21ba69..ebf34f5a06 100644 --- a/src/openvg/qpaintengine_vg.cpp +++ b/src/openvg/qpaintengine_vg.cpp @@ -183,6 +183,7 @@ public: qreal penScale; // Pen scaling factor from "transform". QTransform pathTransform; // Calculated VG path transformation. + QTransform glyphTransform; // Calculated VG glyph transformation. QTransform imageTransform; // Calculated VG image transformation. bool pathTransformSet; // True if path transform set in the VG context. @@ -500,24 +501,31 @@ extern bool qt_scaleForTransform(const QTransform &transform, qreal *scale); void QVGPaintEnginePrivate::updateTransform(QPaintDevice *pdev) { - VGfloat devh = pdev->height() - 1; + VGfloat devh = pdev->height(); // Construct the VG transform by combining the Qt transform with // the following viewport transformation: - // | 1 0 0 | | 1 0 0.5 | | 1 0 0.5 | - // | 0 -1 devh | * | 0 1 -0.5 | = | 0 -1 (0.5 + devh) | - // | 0 0 1 | | 0 0 1 | | 0 0 1 | + // | 1 0 0 | + // | 0 -1 devh | + // | 0 0 1 | + // The glyph transform uses a slightly different transformation: + // | 1 0 0 | | 1 0 0.5 | | 1 0 0.5 | + // | 0 -1 devh - 1 | * | 0 1 -0.5 | = | 0 -1 (devh - 0.5) | + // | 0 0 1 | | 0 0 1 | | 0 0 1 | // The full VG transform is effectively: // 1. Apply the user's transformation matrix. - // 2. Translate by (0.5, -0.5) to correct for Qt and VG putting - // the centre of the pixel at different positions. + // 2. Translate glyphs by an extra (0.5, -0.5). // 3. Flip the co-ordinate system upside down. QTransform viewport(1.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, - 0.5f, devh + 0.5f, 1.0f); + 0.0f, devh, 1.0f); + QTransform gviewport(1.0f, 0.0f, 0.0f, + 0.0f, -1.0f, 0.0f, + 0.5f, devh - 0.5f, 1.0f); // Compute the path transform and determine if it is projective. pathTransform = transform * viewport; + glyphTransform = transform * gviewport; bool projective = (pathTransform.m13() != 0.0f || pathTransform.m23() != 0.0f || pathTransform.m33() != 1.0f); @@ -526,6 +534,7 @@ void QVGPaintEnginePrivate::updateTransform(QPaintDevice *pdev) // so we will have to convert the co-ordinates ourselves. // Change the matrix to just the viewport transformation. pathTransform = viewport; + glyphTransform = gviewport; simpleTransform = false; } else { simpleTransform = true; @@ -533,13 +542,7 @@ void QVGPaintEnginePrivate::updateTransform(QPaintDevice *pdev) pathTransformSet = false; // The image transform is always the full transformation, - // because it can be projective. It also does not need the - // (0.5, -0.5) translation because vgDrawImage() implicitly - // adds 0.5 to each co-ordinate. - QTransform viewport2(1.0f, 0.0f, 0.0f, - 0.0f, -1.0f, 0.0f, - 0.0f, devh + 1, 1.0f); - imageTransform = transform * viewport2; + imageTransform = transform * viewport; // Calculate the scaling factor to use for turning cosmetic pens // into ordinary non-cosmetic pens. @@ -3317,7 +3320,7 @@ void QVGPaintEngine::drawTextItem(const QPointF &p, const QTextItem &textItem) } // Set the transformation to use for drawing the current glyphs. - QTransform glyphTransform(d->pathTransform); + QTransform glyphTransform(d->glyphTransform); glyphTransform.translate(p.x(), p.y()); #if defined(QVG_NO_IMAGE_GLYPHS) glyphTransform.scale(glyphCache->scaleX, glyphCache->scaleY); @@ -3650,10 +3653,10 @@ void QVGCompositionHelper::fillBackground } else { // Set the path transform to the default viewport transformation. - VGfloat devh = screenSize.height() - 1; + VGfloat devh = screenSize.height(); QTransform viewport(1.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, - -0.5f, devh + 0.5f, 1.0f); + 0.0f, devh, 1.0f); d->setTransform(VG_MATRIX_PATH_USER_TO_SURFACE, viewport); // Set the brush to use to fill the background. @@ -3689,10 +3692,10 @@ void QVGCompositionHelper::drawCursorPixmap } // Set the image transformation and modes. - VGfloat devh = screenSize.height() - 1; + VGfloat devh = screenSize.height(); QTransform transform(1.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, - -0.5f, devh + 0.5f, 1.0f); + 0.0f, devh, 1.0f); transform.translate(offset.x(), offset.y()); d->setTransform(VG_MATRIX_IMAGE_USER_TO_SURFACE, transform); d->setImageMode(VG_DRAW_IMAGE_NORMAL); |