diff options
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/text/qtextlayout.cpp | 15 | ||||
-rw-r--r-- | src/gui/text/qtextlayout.h | 3 | ||||
-rw-r--r-- | src/gui/text/qtextobject.cpp | 29 | ||||
-rw-r--r-- | src/gui/text/qtextobject.h | 3 |
4 files changed, 46 insertions, 4 deletions
diff --git a/src/gui/text/qtextlayout.cpp b/src/gui/text/qtextlayout.cpp index aff88f6..531e46b 100644 --- a/src/gui/text/qtextlayout.cpp +++ b/src/gui/text/qtextlayout.cpp @@ -1134,7 +1134,7 @@ QList<QGlyphs> QTextLayout::glyphs() const { QList<QGlyphs> glyphs; for (int i=0; i<d->lines.size(); ++i) - glyphs += QTextLine(i, d).glyphs(); + glyphs += QTextLine(i, d).glyphs(-1, -1); return glyphs; } @@ -2198,13 +2198,16 @@ namespace { /*! \internal - Returns the glyph indexes and positions for all glyphs in this QTextLine. + Returns the glyph indexes and positions for all glyphs in this QTextLine which reside in + QScriptItems that overlap with the range defined by \a from and \a length. The arguments + specify characters, relative to the text in the layout. Note that it is not possible to + use this function to retrieve a subset of the glyphs in a QScriptItem. \since 4.8 \sa QTextLayout::glyphs() */ -QList<QGlyphs> QTextLine::glyphs() const +QList<QGlyphs> QTextLine::glyphs(int from, int length) const { const QScriptLine &line = eng->lines[i]; @@ -2217,7 +2220,13 @@ QList<QGlyphs> QTextLine::glyphs() const qreal y = line.y.toReal() + line.base().toReal(); while (!iterator.atEnd()) { QScriptItem &si = iterator.next(); + if (si.analysis.flags >= QScriptAnalysis::TabOrObject) + continue; + QPointF pos(iterator.x.toReal(), y); + if (from >= 0 && length >= 0 && + (from >= si.position + eng->length(&si) || from + length <= si.position)) + continue; QFont font = eng->font(si); diff --git a/src/gui/text/qtextlayout.h b/src/gui/text/qtextlayout.h index f6aaf22..32d6d0e 100644 --- a/src/gui/text/qtextlayout.h +++ b/src/gui/text/qtextlayout.h @@ -239,9 +239,10 @@ public: private: QTextLine(int line, QTextEngine *e) : i(line), eng(e) {} void layout_helper(int numGlyphs); - QList<QGlyphs> glyphs() const; + QList<QGlyphs> glyphs(int from, int length) const; friend class QTextLayout; + friend class QTextFragment; int i; QTextEngine *eng; }; diff --git a/src/gui/text/qtextobject.cpp b/src/gui/text/qtextobject.cpp index 5fb3384..e366f77 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<QGlyphs> QTextFragment::glyphs() const +{ + if (!p || !n) + return QList<QGlyphs>(); + + int pos = position(); + int len = length(); + if (len == 0) + return QList<QGlyphs>(); + + int blockNode = p->blockMap().findNode(pos); + + const QTextBlockData *blockData = p->blockMap().fragment(blockNode); + QTextLayout *layout = blockData->layout; + + QList<QGlyphs> ret; + for (int i=0; i<layout->lineCount(); ++i) { + QTextLine textLine = layout->lineAt(i); + ret += textLine.glyphs(pos, len); + } + + return ret; +} /*! Returns the position of this text fragment in the document. diff --git a/src/gui/text/qtextobject.h b/src/gui/text/qtextobject.h index a573a26..332458d 100644 --- a/src/gui/text/qtextobject.h +++ b/src/gui/text/qtextobject.h @@ -44,6 +44,7 @@ #include <QtCore/qobject.h> #include <QtGui/qtextformat.h> +#include <QtGui/qglyphs.h> QT_BEGIN_HEADER @@ -315,6 +316,8 @@ public: int charFormatIndex() const; QString text() const; + QList<QGlyphs> glyphs() const; + private: const QTextDocumentPrivate *p; int n; |