summaryrefslogtreecommitdiffstats
path: root/src/gui/text/qglyphrun.cpp
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>2011-06-01 15:33:38 +0200
committerQt by Nokia <qt-info@nokia.com>2011-08-19 10:18:04 +0200
commitb9224af92c128f7cc66bef11849db046f10dc81f (patch)
tree6cbf656d70aebeaffddda5c256840f952907a0d6 /src/gui/text/qglyphrun.cpp
parent1e0d1c5f2996da33db1e3e4c1f7c6ef3e1f29416 (diff)
Enablers for using QGlyphRun in SceneGraph
Several required fixes and changes to fix problems that arose when porting SceneGraph's QSGTextInput and QSGTextEdit to use QSGTextNode, especially related to having selections on the text. Also fixes crashes with the threaded renderer on Mac OS X when using the TextEdit or TextInput elements. Task-number: QTBUG-18019, QTBUG-20017 Change-Id: I67f24465352daa1d2cb12b6d2f378feb676c9804 Reviewed-on: http://codereview.qt.nokia.com/2864 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Gunnar Sletta <gunnar.sletta@nokia.com> Reviewed-by: Jiang Jiang <jiang.jiang@nokia.com>
Diffstat (limited to 'src/gui/text/qglyphrun.cpp')
-rw-r--r--src/gui/text/qglyphrun.cpp45
1 files changed, 44 insertions, 1 deletions
diff --git a/src/gui/text/qglyphrun.cpp b/src/gui/text/qglyphrun.cpp
index cc825525c4..be9c058693 100644
--- a/src/gui/text/qglyphrun.cpp
+++ b/src/gui/text/qglyphrun.cpp
@@ -45,6 +45,7 @@
#include "qglyphrun.h"
#include "qglyphrun_p.h"
+#include <qdebug.h>
QT_BEGIN_NAMESPACE
@@ -343,12 +344,44 @@ void QGlyphRun::setStrikeOut(bool strikeOut)
}
/*!
- Returns the smallest rectangle that contains all glyphs in this QGlyphRun.
+ Sets the bounding rect of the glyphs in this QGlyphRun to be \a boundingRect. This rectangle
+ will be returned by boundingRect() unless it is empty, in which case the bounding rectangle of the
+ glyphs in the glyph run will be returned instead.
+
+ \note Unless you are implementing text shaping, you should not have to use this function.
+ It is used specifically when the QGlyphRun should represent an area which is smaller than the
+ area of the glyphs it contains. This could happen e.g. if the glyph run is retrieved by calling
+ QTextLayout::glyphRuns() and the specified range only includes part of a ligature (where two or
+ more characters are combined to a single glyph.) When this is the case, the bounding rect should
+ only include the appropriate part of the ligature glyph, based on a calculation of the average
+ width of the characters in the ligature.
+
+ In order to support such a case (an example is selections which should be drawn with a different
+ color than the main text color), it is necessary to clip the painting mechanism to the rectangle
+ returned from boundingRect() to avoid drawing the entire ligature glyph.
+
+ \sa boundingRect()
+
+ \since 5.0
+*/
+void QGlyphRun::setBoundingRect(const QRectF &boundingRect)
+{
+ detach();
+ d->boundingRect = boundingRect;
+}
+
+/*!
+ Returns the smallest rectangle that contains all glyphs in this QGlyphRun. If a bounding rect
+ has been set using setBoundingRect(), then this will be returned. Otherwise the bounding rect
+ will be calculated based on the font metrics of the glyphs in the glyph run.
\since 5.0
*/
QRectF QGlyphRun::boundingRect() const
{
+ if (!d->boundingRect.isEmpty())
+ return d->boundingRect;
+
qreal minX, minY, maxX, maxY;
for (int i=0; i<qMin(d->glyphPositions.size(), d->glyphIndexes.size()); ++i) {
@@ -371,6 +404,16 @@ QRectF QGlyphRun::boundingRect() const
return QRectF(QPointF(minX, minY), QPointF(maxX, maxY));
}
+/*!
+ Returns true if the QGlyphRun does not contain any glyphs.
+
+ \since 5.0
+*/
+bool QGlyphRun::isEmpty() const
+{
+ return d->glyphIndexes.isEmpty();
+}
+
QT_END_NAMESPACE
#endif // QT_NO_RAWFONT