From 7fb31670f080c224249279c35240a8eb95f8d877 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Tue, 20 Jul 2010 14:26:06 +0200 Subject: Add QTextFragment::glyphs() accessor Add a function to retrieve fonts, glyph indexes and positions needed to visualize the text in a QTextFragment to allow converting the text of a QTextDocument to QGlyphs objects. Reviewed-by: Simon Hausmann --- src/gui/text/qtextobject.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'src/gui/text/qtextobject.cpp') diff --git a/src/gui/text/qtextobject.cpp b/src/gui/text/qtextobject.cpp index 5fb3384d51..e366f7766b 100644 --- a/src/gui/text/qtextobject.cpp +++ b/src/gui/text/qtextobject.cpp @@ -1650,6 +1650,35 @@ QTextBlock::iterator &QTextBlock::iterator::operator--() than the \a other text fragment; otherwise returns false. */ +/*! + Returns the glyphs of this text fragment. The positions of the glyphs are + relative to the position of the QTextBlock's layout. + + \sa QGlyphs, QTextBlock::layout(), QTextLayout::position(), QPainter::drawGlyphs() +*/ +QList QTextFragment::glyphs() const +{ + if (!p || !n) + return QList(); + + int pos = position(); + int len = length(); + if (len == 0) + return QList(); + + int blockNode = p->blockMap().findNode(pos); + + const QTextBlockData *blockData = p->blockMap().fragment(blockNode); + QTextLayout *layout = blockData->layout; + + QList ret; + for (int i=0; ilineCount(); ++i) { + QTextLine textLine = layout->lineAt(i); + ret += textLine.glyphs(pos, len); + } + + return ret; +} /*! Returns the position of this text fragment in the document. -- cgit v1.2.3