diff options
author | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com> | 2010-01-26 12:02:40 (GMT) |
---|---|---|
committer | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com> | 2010-01-26 12:02:40 (GMT) |
commit | a16d9ed3f202147b6c315d5e2008c08a3ad909b6 (patch) | |
tree | 7ddad3a3b583cc1555749fd2bd03483fa32bd5e9 /src/openvg | |
parent | 20f1d1e7d3178a5fe67e3fd7a8ba80a9fc134a50 (diff) | |
download | Qt-a16d9ed3f202147b6c315d5e2008c08a3ad909b6.zip Qt-a16d9ed3f202147b6c315d5e2008c08a3ad909b6.tar.gz Qt-a16d9ed3f202147b6c315d5e2008c08a3ad909b6.tar.bz2 |
Attempt at making OpenVG work with QStaticText
Done in the blind, so I don't expect this to compile, but it's to make
it easier to get it over into a Symbian-ready repository.
Diffstat (limited to 'src/openvg')
-rw-r--r-- | src/openvg/qpaintengine_vg.cpp | 59 | ||||
-rw-r--r-- | src/openvg/qpaintengine_vg_p.h | 3 |
2 files changed, 37 insertions, 25 deletions
diff --git a/src/openvg/qpaintengine_vg.cpp b/src/openvg/qpaintengine_vg.cpp index cc9ba77..9088d66 100644 --- a/src/openvg/qpaintengine_vg.cpp +++ b/src/openvg/qpaintengine_vg.cpp @@ -54,6 +54,7 @@ #include <QtGui/private/qtextengine_p.h> #include <QtGui/private/qfontengine_p.h> #include <QtGui/private/qpainterpath_p.h> +#include <QtGui/private/qstatictext_p.h> #include <QDebug> #include <QSet> @@ -86,10 +87,8 @@ public: QVGFontGlyphCache(); ~QVGFontGlyphCache(); - void cacheGlyphs(QVGPaintEnginePrivate *d, - const QTextItemInt &ti, - const QVarLengthArray<glyph_t> &glyphs); - void setScaleFromText(const QTextItemInt &ti); + void cacheGlyphs(QVGPaintEnginePrivate *d, QFontEngine *fontEngine, glyph_t *g, int count); + void setScaleFromText(const QFont &font, QFontEngine *fontEngine); VGFont font; VGfloat scaleX; @@ -3135,22 +3134,20 @@ QVGFontGlyphCache::~QVGFontGlyphCache() vgDestroyFont(font); } -void QVGFontGlyphCache::setScaleFromText(const QTextItemInt &ti) +void QVGFontGlyphCache::setScaleFromText(const QFont &font, QFontEngine *fontEngine) { - QFontInfo fi(ti.font()); + QFontInfo fi(font); qreal pixelSize = fi.pixelSize(); - qreal emSquare = ti.fontEngine->properties().emSquare.toReal(); + qreal emSquare = fontEngine->properties().emSquare.toReal(); scaleX = scaleY = static_cast<VGfloat>(pixelSize / emSquare); } void QVGFontGlyphCache::cacheGlyphs - (QVGPaintEnginePrivate *d, const QTextItemInt &ti, - const QVarLengthArray<glyph_t> &glyphs) + (QVGPaintEnginePrivate *d, QFontEngine *fontEngine, + glyph_t *g, int count); { VGfloat origin[2]; VGfloat escapement[2]; - const glyph_t *g = glyphs.constData(); - int count = glyphs.size(); glyph_metrics_t metrics; // Some Qt font engines don't set yoff in getUnscaledGlyph(). // Zero the metric structure so that everything has a default value. @@ -3169,9 +3166,9 @@ void QVGFontGlyphCache::cacheGlyphs } #if !defined(QVG_NO_IMAGE_GLYPHS) Q_UNUSED(d); - QImage scaledImage = ti.fontEngine->alphaMapForGlyph(glyph); + QImage scaledImage = fontEngine->alphaMapForGlyph(glyph); VGImage vgImage = VG_INVALID_HANDLE; - metrics = ti.fontEngine->boundingBox(glyph); + metrics = fontEngine->boundingBox(glyph); if (!scaledImage.isNull()) { // Not a space character if (scaledImage.format() == QImage::Format_Indexed8) { vgImage = vgCreateImage(VG_A_8, scaledImage.width(), scaledImage.height(), VG_IMAGE_QUALITY_FASTER); @@ -3195,7 +3192,7 @@ void QVGFontGlyphCache::cacheGlyphs #else // Calculate the path for the glyph and cache it. QPainterPath path; - ti.fontEngine->getUnscaledGlyph(glyph, &path, &metrics); + fontEngine->getUnscaledGlyph(glyph, &path, &metrics); VGPath vgPath; if (!path.isEmpty()) { vgPath = d->painterPathToVGPath(path); @@ -3236,8 +3233,25 @@ void QVGPaintEngine::drawTextItem(const QPointF &p, const QTextItem &textItem) ti.fontEngine->getGlyphPositions (ti.glyphs, matrix, ti.flags, glyphs, positions); + drawCachedGlyphs(glyphs.size(), glyphs.data(), positions.data(), ti.font, ti.fontEngine, p); +#else + // OpenGL 1.0 does not have support for VGFont and glyphs, + // so fall back to the default Qt path stroking algorithm. + QPaintEngineEx::drawTextItem(p, textItem); +#endif +} + +void QVGPaintengine::drawStaticText(QStaticTextItem *textItem) +{ + drawCachedGlyphs(textItem->numGlyphs, textItem->glyphs, textItem->font, textItem->fontEngine, + QPointF(0, 0)); +} + + void QVGPaintEngine::drawCachedGlyphs(int numGlyphs, const glyph_t *glyphs, const QFont &font, + QFontEngine *fontEngine, const QPointF &p) + { // Find the glyph cache for this font. - QVGFontCache::ConstIterator it = d->fontCache.constFind(ti.fontEngine); + QVGFontCache::ConstIterator it = d->fontCache.constFind(fontEngine); QVGFontGlyphCache *glyphCache; if (it != d->fontCache.constEnd()) { glyphCache = it.value(); @@ -3249,11 +3263,11 @@ void QVGPaintEngine::drawTextItem(const QPointF &p, const QTextItem &textItem) QPaintEngineEx::drawTextItem(p, textItem); return; } - glyphCache->setScaleFromText(ti); - d->fontCache.insert(ti.fontEngine, glyphCache); + glyphCache->setScaleFromText(font, fontEngine); + d->fontCache.insert(fontEngine, glyphCache); if (!d->fontEngineCleaner) d->fontEngineCleaner = new QVGFontEngineCleaner(d); - QObject::connect(ti.fontEngine, SIGNAL(destroyed()), + QObject::connect(fontEngine, SIGNAL(destroyed()), d->fontEngineCleaner, SLOT(fontEngineDestroyed())); } @@ -3266,7 +3280,7 @@ void QVGPaintEngine::drawTextItem(const QPointF &p, const QTextItem &textItem) d->setTransform(VG_MATRIX_GLYPH_USER_TO_SURFACE, glyphTransform); // Add the glyphs from the text item into the glyph cache. - glyphCache->cacheGlyphs(d, ti, glyphs); + glyphCache->cacheGlyphs(d, fontEngine, glyphs.constData(), glyphs.size()); // Set the glyph drawing origin. VGfloat origin[2]; @@ -3285,13 +3299,8 @@ void QVGPaintEngine::drawTextItem(const QPointF &p, const QTextItem &textItem) // Draw the glyphs. We need to fill with the brush associated with // the Qt pen, not the Qt brush. d->ensureBrush(state()->pen.brush()); - vgDrawGlyphs(glyphCache->font, glyphs.size(), (VGuint*)glyphs.data(), + vgDrawGlyphs(glyphCache->font, numGlyphs, (VGuint*)glyphs.data(), NULL, NULL, VG_FILL_PATH, VG_TRUE); -#else - // OpenGL 1.0 does not have support for VGFont and glyphs, - // so fall back to the default Qt path stroking algorithm. - QPaintEngineEx::drawTextItem(p, textItem); -#endif } void QVGPaintEngine::setState(QPainterState *s) diff --git a/src/openvg/qpaintengine_vg_p.h b/src/openvg/qpaintengine_vg_p.h index 3f87a72..c70e1c1 100644 --- a/src/openvg/qpaintengine_vg_p.h +++ b/src/openvg/qpaintengine_vg_p.h @@ -139,6 +139,9 @@ public: void drawPixmaps(const QDrawPixmaps::Data *drawingData, int dataCount, const QPixmap &pixmap, QFlags<QDrawPixmaps::DrawingHint> hints); void drawTextItem(const QPointF &p, const QTextItem &textItem); + void drawStaticTextItem(QStaticTextItem *staticTextItem); + void drawCachedGlyphs(int numGlyphs, const glyph_t *glyphs, const QFont &font, + QFontEngine *fontEngine, const QPointF &p); void setState(QPainterState *s); QVGPainterState *state() { return static_cast<QVGPainterState *>(QPaintEngineEx::state()); } |