summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>2010-03-23 12:13:06 (GMT)
committerEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>2010-03-23 12:13:06 (GMT)
commit2c18a5665f70cd7ff62bfffac2c3f2b5364d7392 (patch)
treed732c0085a6f5870d4d03008547d919d907c79fa /src
parent49b200a700c140510720e1ed5f1b791b406ad0d6 (diff)
downloadQt-2c18a5665f70cd7ff62bfffac2c3f2b5364d7392.zip
Qt-2c18a5665f70cd7ff62bfffac2c3f2b5364d7392.tar.gz
Qt-2c18a5665f70cd7ff62bfffac2c3f2b5364d7392.tar.bz2
Add new function QTextLine::horizontalAdvance()
Add a function to QTextLine which returns the accumulated advance of the glyphs in the text. Previously QTextLine::naturalTextWidth() was used for both this purpose and for calculating the pixel width of the text. Since these two metrics are not the same, either of the two usages would be wrong. QTextLine::naturalTextWidth() has been changed to do what its documentation claims it does, and horizontalAdvance() should now be used for laying out text horizontally. Reviewed-by: Simon Hausmann
Diffstat (limited to 'src')
-rw-r--r--src/gui/painting/qpainter.cpp2
-rw-r--r--src/gui/text/qtextlayout.cpp14
-rw-r--r--src/gui/text/qtextlayout.h1
3 files changed, 16 insertions, 1 deletions
diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp
index db4ace4..1c528fe 100644
--- a/src/gui/painting/qpainter.cpp
+++ b/src/gui/painting/qpainter.cpp
@@ -7999,7 +7999,7 @@ start_lengthVariant:
for (int i = 0; i < textLayout.lineCount(); i++) {
QTextLine line = textLayout.lineAt(i);
- qreal advance = textLayout.engine()->lines[i].textAdvance.toReal();
+ qreal advance = line.horizontalAdvance();
if (tf & Qt::AlignRight)
xoff = r.width() - advance;
else if (tf & Qt::AlignHCenter)
diff --git a/src/gui/text/qtextlayout.cpp b/src/gui/text/qtextlayout.cpp
index 766053c..2fc5d1a 100644
--- a/src/gui/text/qtextlayout.cpp
+++ b/src/gui/text/qtextlayout.cpp
@@ -1570,6 +1570,20 @@ qreal QTextLine::naturalTextWidth() const
return eng->lines[i].textWidth.toReal();
}
+/*! \since 4.7
+ Returns the horizontal advance of the text. The advance of the text
+ is the distance from its position to the next position at which
+ text would naturally be drawn.
+
+ By adding the advance to the position of the text line and using this
+ as the position of a second text line, you will be able to position
+ the two lines side-by-side without gaps in-between.
+*/
+qreal QTextLine::horizontalAdvance() const
+{
+ return eng->lines[i].textAdvance.toReal();
+}
+
/*!
Lays out the line with the given \a width. The line is filled from
its starting position with as many characters as will fit into
diff --git a/src/gui/text/qtextlayout.h b/src/gui/text/qtextlayout.h
index edae7de..8c93ed6 100644
--- a/src/gui/text/qtextlayout.h
+++ b/src/gui/text/qtextlayout.h
@@ -202,6 +202,7 @@ public:
bool leadingIncluded() const;
qreal naturalTextWidth() const;
+ qreal horizontalAdvance() const;
QRectF naturalTextRect() const;
enum Edge {