diff options
author | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com> | 2010-02-23 16:26:59 (GMT) |
---|---|---|
committer | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com> | 2010-02-23 16:47:40 (GMT) |
commit | 6566f5e341c18912f7f1a9fbf4727e0ac92a1a9f (patch) | |
tree | 7f01eabffcea2c3ece4d953470e0d1db76a3bc02 /src/gui | |
parent | 283b6815586a87e458732534bc3c9c76b38ba49f (diff) | |
download | Qt-6566f5e341c18912f7f1a9fbf4727e0ac92a1a9f.zip Qt-6566f5e341c18912f7f1a9fbf4727e0ac92a1a9f.tar.gz Qt-6566f5e341c18912f7f1a9fbf4727e0ac92a1a9f.tar.bz2 |
Add private qt_draw_glyphs() API
In some use cases where you use an external font engine and want to
use Qt's font engine for painting, you might need a function which will
give you direct access to the underlying font. A generic API for this
requires a lot of API changes, so in the meantime, we implement an
internal, specialized API to support the use cases where it is
required. The API is considered internal and experimental, and not
guaranteed to be stable or even exist across releases.
This is API which provides several fun ways to shoot yourself in the
foot, but if used properly, it will allow you to paint glyph ids at
precalculated positions.
Task-number: QTBUG-7844
Reviewed-by: Trond
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/image/qpaintengine_pic.cpp | 5 | ||||
-rw-r--r-- | src/gui/painting/qpainter.cpp | 55 | ||||
-rw-r--r-- | src/gui/painting/qpainter_p.h | 8 | ||||
-rw-r--r-- | src/gui/painting/qprintengine_win.cpp | 3 | ||||
-rw-r--r-- | src/gui/text/qfont.h | 1 |
5 files changed, 70 insertions, 2 deletions
diff --git a/src/gui/image/qpaintengine_pic.cpp b/src/gui/image/qpaintengine_pic.cpp index 1aeb524..029154b 100644 --- a/src/gui/image/qpaintengine_pic.cpp +++ b/src/gui/image/qpaintengine_pic.cpp @@ -486,8 +486,11 @@ void QPicturePaintEngine::drawTextItem(const QPointF &p , const QTextItem &ti) qDebug() << " -> drawTextItem():" << p << ti.text(); #endif + const QTextItemInt &si = static_cast<const QTextItemInt &>(ti); + if (si.chars == 0) + QPaintEngine::drawTextItem(p, ti); // Draw as path + if (d->pic_d->formatMajor >= 9) { - const QTextItemInt &si = static_cast<const QTextItemInt &>(ti); int pos; SERIALIZE_CMD(QPicturePrivate::PdcDrawTextItem); QFont fnt = ti.font(); diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp index 6f5c732..eee3a47 100644 --- a/src/gui/painting/qpainter.cpp +++ b/src/gui/painting/qpainter.cpp @@ -5699,6 +5699,61 @@ void QPainter::drawImage(const QRectF &targetRect, const QImage &image, const QR d->engine->drawImage(QRectF(x, y, w, h), image, QRectF(sx, sy, sw, sh), flags); } + +void qt_draw_glyphs(QPainter *painter, const quint32 *glyphArray, const QPointF *positionArray, + int glyphCount) +{ + QPainterPrivate *painter_d = QPainterPrivate::get(painter); + painter_d->drawGlyphs(glyphArray, positionArray, glyphCount); +} + +void QPainterPrivate::drawGlyphs(const quint32 *glyphArray, const QPointF *positionArray, + int glyphCount) +{ + updateState(state); + + QFontEngine *fontEngine = state->font.d->engineForScript(QUnicodeTables::Common); + + QVarLengthArray<QFixedPoint, 128> positions; + for (int i=0; i<glyphCount; ++i) { + QFixedPoint fp = QFixedPoint::fromPointF(positionArray[i]); + positions.append(fp); + } + + if (extended != 0) { + QStaticTextItem staticTextItem; + staticTextItem.color = state->pen.color(); + staticTextItem.font = state->font; + staticTextItem.fontEngine = fontEngine; + staticTextItem.numGlyphs = glyphCount; + staticTextItem.glyphs = reinterpret_cast<glyph_t *>(const_cast<glyph_t *>(glyphArray)); + staticTextItem.glyphPositions = positions.data(); + + extended->drawStaticTextItem(&staticTextItem); + } else { + QTextItemInt textItem; + textItem.f = &state->font; + textItem.fontEngine = fontEngine; + + QVarLengthArray<QFixed, 128> advances(glyphCount); + QVarLengthArray<QGlyphJustification, 128> glyphJustifications(glyphCount); + QVarLengthArray<HB_GlyphAttributes, 128> glyphAttributes(glyphCount); + qMemSet(glyphAttributes.data(), 0, glyphAttributes.size() * sizeof(HB_GlyphAttributes)); + qMemSet(advances.data(), 0, advances.size() * sizeof(QFixed)); + qMemSet(glyphJustifications.data(), 0, glyphJustifications.size() * sizeof(QGlyphJustification)); + + textItem.glyphs.numGlyphs = glyphCount; + textItem.glyphs.glyphs = reinterpret_cast<HB_Glyph *>(const_cast<quint32 *>(glyphArray)); + textItem.glyphs.offsets = positions.data(); + textItem.glyphs.advances_x = advances.data(); + textItem.glyphs.advances_y = advances.data(); + textItem.glyphs.justifications = glyphJustifications.data(); + textItem.glyphs.attributes = glyphAttributes.data(); + + engine->drawTextItem(QPointF(0, 0), textItem); + } +} + /*! \fn void QPainter::drawStaticText(const QPoint &position, const QStaticText &staticText) diff --git a/src/gui/painting/qpainter_p.h b/src/gui/painting/qpainter_p.h index 02a91aa..9362dbe 100644 --- a/src/gui/painting/qpainter_p.h +++ b/src/gui/painting/qpainter_p.h @@ -228,6 +228,7 @@ public: void draw_helper(const QPainterPath &path, DrawOperation operation = StrokeAndFillDraw); void drawStretchedGradient(const QPainterPath &path, DrawOperation operation); void drawOpaqueBackground(const QPainterPath &path, DrawOperation operation); + void drawGlyphs(const quint32 *glyphArray, const QPointF *positionArray, int glyphCount); void updateMatrix(); void updateInvMatrix(); @@ -238,6 +239,11 @@ public: void checkEmulation(); + static QPainterPrivate *get(QPainter *painter) + { + return painter->d_ptr.data(); + } + QTransform viewTransform() const; static bool attachPainterPrivate(QPainter *q, QPaintDevice *pdev); void detachPainterPrivate(QPainter *q); @@ -252,6 +258,8 @@ public: }; Q_GUI_EXPORT void qt_draw_helper(QPainterPrivate *p, const QPainterPath &path, QPainterPrivate::DrawOperation operation); +Q_GUI_EXPORT void qt_draw_glyphs(QPainter *painter, const quint32 *glyphArray, + const QPointF *positionArray, int glyphCount); QString qt_generate_brush_key(const QBrush &brush); diff --git a/src/gui/painting/qprintengine_win.cpp b/src/gui/painting/qprintengine_win.cpp index d029b1e..ea9dc5d 100644 --- a/src/gui/painting/qprintengine_win.cpp +++ b/src/gui/painting/qprintengine_win.cpp @@ -368,7 +368,8 @@ void QWin32PrintEngine::drawTextItem(const QPointF &p, const QTextItem &textItem } // We only want to convert the glyphs to text if the entire string is compatible with ASCII - bool convertToText = true; + // and if we actually have access to the chars. + bool convertToText = ti.chars != 0; for (int i=0; i < ti.num_chars; ++i) { if (ti.chars[i].unicode() >= 0x80) { convertToText = false; diff --git a/src/gui/text/qfont.h b/src/gui/text/qfont.h index a2fff70..5adf237 100644 --- a/src/gui/text/qfont.h +++ b/src/gui/text/qfont.h @@ -291,6 +291,7 @@ private: friend class QFontMetricsF; friend class QFontInfo; friend class QPainter; + friend class QPainterPrivate; friend class QPSPrintEngineFont; friend class QApplication; friend class QWidget; |