From 8c6bfd9f2d34822e39812c07e821fa17ab3fdcb2 Mon Sep 17 00:00:00 2001 From: Jason Barron Date: Fri, 26 Feb 2010 13:47:45 +0100 Subject: Ensure glyphs are upright instead of upside-down. The OpenVG paint engine traditionally takes glyph images from the alphaMapForGlyph() function which returns the glyph image in the upright projection. When it constructs a VGImage from this image, it passes a positive data stride which will read the top scanline of the source image into the bottom scanline of the VGImage due to the VG coordinate system. It then uses the path transform where the 'sy' value of the matrix is set to -1 and this re-inverts everything when drawing. With the Symbian based glyph cache, the VGImage is constructed from a RSgImage which is a hardware resource and compensates for the coordinate system used by VG and GL at the time it is created. In the case of the hardware glyph cache, the glyph image is read into the RSgImage using a negative data stride so it does not need to be inverted when drawn. To allow for this, introduce a flag which indicates that the 'sy' entry of the matrix should be flipped such that the glyph is drawn normally. Also in this patch is a change to the glyph origin which now uses the bottom of the glyph metric bounding rect instead of the top due to orientation of the glyph inside the VGImage. Reviewed-by: Alessandro Portale --- src/openvg/qpaintengine_vg.cpp | 6 ++++++ src/openvg/qvg_symbian.cpp | 7 ++++++- src/openvg/qvgfontglyphcache_p.h | 3 +++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/openvg/qpaintengine_vg.cpp b/src/openvg/qpaintengine_vg.cpp index 01c7a7e..4992ef5 100644 --- a/src/openvg/qpaintengine_vg.cpp +++ b/src/openvg/qpaintengine_vg.cpp @@ -3272,6 +3272,7 @@ QVGFontGlyphCache::QVGFontGlyphCache() { font = vgCreateFont(0); scaleX = scaleY = 0.0; + invertedGlyphs = false; memset(cachedGlyphsMask, 0, sizeof(cachedGlyphsMask)); } @@ -3430,6 +3431,11 @@ void QVGPaintEngine::drawStaticTextItem(QStaticTextItem *textItem) #if defined(QVG_NO_IMAGE_GLYPHS) glyphTransform.scale(glyphCache->scaleX, glyphCache->scaleY); #endif + + // Some glyph caches can create the VGImage upright + if (glyphCache->invertedGlyphs) + glyphTransform.scale(1, -1); + d->setTransform(VG_MATRIX_GLYPH_USER_TO_SURFACE, glyphTransform); // Add the glyphs from the text item into the glyph cache. diff --git a/src/openvg/qvg_symbian.cpp b/src/openvg/qvg_symbian.cpp index e6086d0..8c954e6 100644 --- a/src/openvg/qvg_symbian.cpp +++ b/src/openvg/qvg_symbian.cpp @@ -322,6 +322,11 @@ void* QVGPixmapData::toNativeType(NativeType type) return 0; } +QSymbianVGFontGlyphCache::QSymbianVGFontGlyphCache() : QVGFontGlyphCache() +{ + invertedGlyphs = true; +} + void QSymbianVGFontGlyphCache::cacheGlyphs(QVGPaintEnginePrivate *d, const QTextItemInt &ti, const QVarLengthArray &glyphs) @@ -359,7 +364,7 @@ void QSymbianVGFontGlyphCache::cacheGlyphs(QVGPaintEnginePrivate *d, VGfloat origin[2]; VGfloat escapement[2]; origin[0] = -glyphBounds.iTl.iX + 0.5f; - origin[1] = -glyphBounds.iTl.iY + 0.5f; + origin[1] = glyphBounds.iBr.iY + 0.5f; escapement[0] = metrics.HorizAdvance(); escapement[1] = 0; vgSetGlyphToImage(font, iter.GlyphCode(), vgImage, origin, escapement); diff --git a/src/openvg/qvgfontglyphcache_p.h b/src/openvg/qvgfontglyphcache_p.h index ee11082..8f25322 100644 --- a/src/openvg/qvgfontglyphcache_p.h +++ b/src/openvg/qvgfontglyphcache_p.h @@ -74,6 +74,7 @@ public: VGFont font; VGfloat scaleX; VGfloat scaleY; + bool invertedGlyphs; uint cachedGlyphsMask[256 / 32]; QSet cachedGlyphs; @@ -82,6 +83,8 @@ public: #if defined(Q_OS_SYMBIAN) class QSymbianVGFontGlyphCache : public QVGFontGlyphCache { +public: + QSymbianVGFontGlyphCache(); void cacheGlyphs(QVGPaintEnginePrivate *d, const QTextItemInt &ti, const QVarLengthArray &glyphs); -- cgit v0.12