summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com>2014-10-08 11:28:23 +0200
committerEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com>2014-10-08 13:07:58 +0200
commit183d04de908c4d759a823bb45dce142a6de15437 (patch)
tree9b1e8fd75a9fa8a9308ad2bf8eeb9d25b5d5f998
parentb883cee471f149b65048fa793007b12c6bb84b92 (diff)
Add text ranges to QGlyphRunPrivate
This is an enabler for using the QGlyphRun in the selection code of the scene graph node. In this case, we need to know exactly which of the characters in the text are represented by the glyph run, as a single range of text may result in several glyph runs. Change-Id: Ie8ec942693dceea45ab548f6cefc4f78e4c6d524 Task-number: QTBUG-41808 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
-rw-r--r--src/gui/text/qglyphrun_p.h7
-rw-r--r--src/gui/text/qtextlayout.cpp70
2 files changed, 69 insertions, 8 deletions
diff --git a/src/gui/text/qglyphrun_p.h b/src/gui/text/qglyphrun_p.h
index c9554d0d6d..d18d7129f9 100644
--- a/src/gui/text/qglyphrun_p.h
+++ b/src/gui/text/qglyphrun_p.h
@@ -63,6 +63,8 @@ public:
, glyphIndexDataSize(0)
, glyphPositionData(glyphPositions.constData())
, glyphPositionDataSize(0)
+ , textRangeStart(-1)
+ , textRangeEnd(-1)
{
}
@@ -77,6 +79,8 @@ public:
, glyphIndexDataSize(other.glyphIndexDataSize)
, glyphPositionData(other.glyphPositionData)
, glyphPositionDataSize(other.glyphPositionDataSize)
+ , textRangeStart(other.textRangeStart)
+ , textRangeEnd(other.textRangeEnd)
{
}
@@ -93,6 +97,9 @@ public:
const QPointF *glyphPositionData;
int glyphPositionDataSize;
+ int textRangeStart;
+ int textRangeEnd;
+
static QGlyphRunPrivate *get(const QGlyphRun &glyphRun)
{
return glyphRun.d.data();
diff --git a/src/gui/text/qtextlayout.cpp b/src/gui/text/qtextlayout.cpp
index eafd98d234..adc5663299 100644
--- a/src/gui/text/qtextlayout.cpp
+++ b/src/gui/text/qtextlayout.cpp
@@ -2027,12 +2027,39 @@ static void setPenAndDrawBackground(QPainter *p, const QPen &defaultPen, const Q
}
#if !defined(QT_NO_RAWFONT)
-static QGlyphRun glyphRunWithInfo(QFontEngine *fontEngine, const QGlyphLayout &glyphLayout,
- const QPointF &pos, const QGlyphRun::GlyphRunFlags &flags,
- const QFixed &selectionX, const QFixed &selectionWidth)
-{
+static QGlyphRun glyphRunWithInfo(QFontEngine *fontEngine,
+ const QGlyphLayout &glyphLayout,
+ const QPointF &pos,
+ const QGlyphRun::GlyphRunFlags &flags,
+ const QFixed &selectionX,
+ const QFixed &selectionWidth,
+ int glyphsStart,
+ int glyphsEnd,
+ unsigned short *logClusters,
+ int textPosition,
+ int textLength)
+{
+ Q_ASSERT(logClusters != 0);
+
QGlyphRun glyphRun;
+ QGlyphRunPrivate *d = QGlyphRunPrivate::get(glyphRun);
+
+ int rangeStart = textPosition;
+ while (*logClusters != glyphsStart && rangeStart < textPosition + textLength) {
+ ++logClusters;
+ ++rangeStart;
+ }
+
+ int rangeEnd = rangeStart;
+ while (*logClusters != glyphsEnd && rangeEnd < textPosition + textLength) {
+ ++logClusters;
+ ++rangeEnd;
+ }
+
+ d->textRangeStart = rangeStart;
+ d->textRangeEnd = rangeEnd;
+
// Make a font for this particular engine
QRawFont font;
QRawFontPrivate *fontD = QRawFontPrivate::get(font);
@@ -2219,7 +2246,16 @@ QList<QGlyphRun> QTextLine::glyphRuns(int from, int length) const
subFlags |= QGlyphRun::SplitLigature;
glyphRuns.append(glyphRunWithInfo(multiFontEngine->engine(which),
- subLayout, pos, subFlags, x, width));
+ subLayout,
+ pos,
+ subFlags,
+ x,
+ width,
+ glyphsStart + start,
+ glyphsStart + end,
+ logClusters,
+ iterator.itemStart,
+ iterator.itemLength));
for (int i = 0; i < subLayout.numGlyphs; ++i)
pos.rx() += subLayout.advances[i].toReal();
@@ -2238,14 +2274,32 @@ QList<QGlyphRun> QTextLine::glyphRuns(int from, int length) const
subFlags |= QGlyphRun::SplitLigature;
QGlyphRun glyphRun = glyphRunWithInfo(multiFontEngine->engine(which),
- subLayout, pos, subFlags, x, width);
+ subLayout,
+ pos,
+ subFlags,
+ x,
+ width,
+ glyphsStart + start,
+ glyphsStart + end,
+ logClusters,
+ iterator.itemStart,
+ iterator.itemLength);
if (!glyphRun.isEmpty())
glyphRuns.append(glyphRun);
} else {
if (startsInsideLigature || endsInsideLigature)
flags |= QGlyphRun::SplitLigature;
- QGlyphRun glyphRun = glyphRunWithInfo(mainFontEngine, glyphLayout, pos, flags, x,
- width);
+ QGlyphRun glyphRun = glyphRunWithInfo(mainFontEngine,
+ glyphLayout,
+ pos,
+ flags,
+ x,
+ width,
+ glyphsStart,
+ glyphsEnd,
+ logClusters,
+ iterator.itemStart,
+ iterator.itemLength);
if (!glyphRun.isEmpty())
glyphRuns.append(glyphRun);
}