summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>2010-07-20 14:26:06 +0200
committerEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>2010-08-02 11:01:30 +0200
commit7fb31670f080c224249279c35240a8eb95f8d877 (patch)
tree44eac011bf5e64d681a3ff7ef4eff634875ad0d7 /src/gui
parentd4da5248006e4a9f4d6a454bf754407a34a09407 (diff)
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
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/text/qtextlayout.cpp15
-rw-r--r--src/gui/text/qtextlayout.h3
-rw-r--r--src/gui/text/qtextobject.cpp29
-rw-r--r--src/gui/text/qtextobject.h3
4 files changed, 46 insertions, 4 deletions
diff --git a/src/gui/text/qtextlayout.cpp b/src/gui/text/qtextlayout.cpp
index aff88f63b5..531e46b430 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 f6aaf22d0f..32d6d0eaf0 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 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<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 a573a263ac..332458db9b 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;