summaryrefslogtreecommitdiffstats
path: root/src/gui/painting/qpainter.cpp
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>2010-02-23 16:26:59 (GMT)
committerEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>2010-02-23 16:47:40 (GMT)
commit6566f5e341c18912f7f1a9fbf4727e0ac92a1a9f (patch)
tree7f01eabffcea2c3ece4d953470e0d1db76a3bc02 /src/gui/painting/qpainter.cpp
parent283b6815586a87e458732534bc3c9c76b38ba49f (diff)
downloadQt-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/painting/qpainter.cpp')
-rw-r--r--src/gui/painting/qpainter.cpp55
1 files changed, 55 insertions, 0 deletions
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)