src/gui/text/qtextlayout.cpp
changeset 3 41300fa6a67c
parent 0 1918ee327afb
child 4 3b1da2848fc7
child 7 f7bc934e204c
child 18 2f34d5167611
--- a/src/gui/text/qtextlayout.cpp	Tue Jan 26 12:42:25 2010 +0200
+++ b/src/gui/text/qtextlayout.cpp	Tue Feb 02 00:43:10 2010 +0200
@@ -860,7 +860,7 @@
         ymin = qMin(ymin, si.y);
         xmax = qMax(xmax, si.x+qMax(si.width, si.textWidth));
         // ### shouldn't the ascent be used in ymin???
-        ymax = qMax(ymax, si.y+si.ascent+si.descent+1);
+        ymax = qMax(ymax, si.y+si.height());
     }
     return QRectF(xmin.toReal(), ymin.toReal(), (xmax-xmin).toReal(), (ymax-ymin).toReal());
 }
@@ -1071,10 +1071,10 @@
 
     QTextLineItemIterator iterator(eng, lineNumber, pos, selection);
 
-    const QFixed y = QFixed::fromReal(pos.y()) + line.y + line.ascent;
-
+
+
+    const qreal selectionY = pos.y() + line.y.toReal();
     const qreal lineHeight = line.height().toReal();
-    const qreal selectionY = (y - line.ascent).toReal();
 
     QFixed lastSelectionX = iterator.x;
     QFixed lastSelectionWidth;
@@ -1334,23 +1334,23 @@
     const qreal x = position.x() + l.cursorToX(cursorPosition);
 
     int itm = d->findItem(cursorPosition - 1);
-    QFixed ascent = sl.ascent;
+    QFixed base = sl.base();
     QFixed descent = sl.descent;
     bool rightToLeft = (d->option.textDirection() == Qt::RightToLeft);
     if (itm >= 0) {
         const QScriptItem &si = d->layoutData->items.at(itm);
         if (si.ascent > 0)
-            ascent = si.ascent;
+            base = si.ascent;
         if (si.descent > 0)
             descent = si.descent;
         rightToLeft = si.analysis.bidiLevel % 2;
     }
-    qreal y = position.y() + (sl.y + sl.ascent - ascent).toReal();
+    qreal y = position.y() + (sl.y + sl.base() - base).toReal();
     bool toggleAntialiasing = !(p->renderHints() & QPainter::Antialiasing)
                               && (p->transform().type() > QTransform::TxTranslate);
     if (toggleAntialiasing)
         p->setRenderHint(QPainter::Antialiasing);
-    p->fillRect(QRectF(x, y, qreal(width), (ascent + descent).toReal()), p->pen().brush());
+    p->fillRect(QRectF(x, y, qreal(width), (base + descent + 1).toReal()), p->pen().brush());
     if (toggleAntialiasing)
         p->setRenderHint(QPainter::Antialiasing, false);
     if (d->layoutData->hasBidi) {
@@ -1500,9 +1500,11 @@
 }
 
 /*!
-    Returns the line's height. This is equal to ascent() + descent() + 1.
-
-    \sa ascent() descent()
+    Returns the line's height. This is equal to ascent() + descent() + 1
+    if leading is not included. If leading is included, this equals to
+    ascent() + descent() + leading() + 1.
+
+    \sa ascent() descent() leading() setLeadingIncluded()
 */
 qreal QTextLine::height() const
 {
@@ -1510,6 +1512,51 @@
 }
 
 /*!
+    \since 4.6
+
+    Returns the line's leading.
+
+    \sa ascent() descent() height()
+*/
+qreal QTextLine::leading() const
+{
+    return eng->lines[i].leading.toReal();
+}
+
+/*! \since 4.6
+
+  Includes positive leading into the line's height if \a included is true;
+  otherwise does not include leading.
+
+  By default, leading is not included.
+
+  Note that negative leading is ignored, it must be handled
+  in the code using the text lines by letting the lines overlap.
+
+  \sa leadingIncluded()
+
+*/
+void QTextLine::setLeadingIncluded(bool included)
+{
+    eng->lines[i].leadingIncluded= included;
+
+}
+
+/*! \since 4.6
+
+  Returns true if positive leading is included into the line's height; otherwise returns false.
+
+  By default, leading is not included.
+
+  \sa setLeadingIncluded()
+*/
+bool QTextLine::leadingIncluded() const
+{
+    return eng->lines[i].leadingIncluded;
+}
+
+
+/*!
     Returns the width of the line that is occupied by text. This is
     always \<= to width(), and is the minimum width that could be used
     by layout() without changing the line break position.
@@ -1712,6 +1759,9 @@
         }
         const QScriptItem &current = eng->layoutData->items[item];
 
+        lbh.tmpData.leading = qMax(lbh.tmpData.leading + lbh.tmpData.ascent,
+                                   current.leading + current.ascent) - qMax(lbh.tmpData.ascent,
+                                                                            current.ascent);
         lbh.tmpData.ascent = qMax(lbh.tmpData.ascent, current.ascent);
         lbh.tmpData.descent = qMax(lbh.tmpData.descent, current.descent);
 
@@ -2042,7 +2092,9 @@
 
 
     QTextLineItemIterator iterator(eng, i, pos, selection);
-    const QFixed y = QFixed::fromReal(pos.y()) + line.y + line.ascent;
+    QFixed lineBase = line.base();
+
+    const QFixed y = QFixed::fromReal(pos.y()) + line.y + lineBase;
 
     bool suppressColors = (eng->option.flags() & QTextOption::SuppressColors);
     while (!iterator.atEnd()) {
@@ -2065,7 +2117,7 @@
             if (selection)
                 format.merge(selection->format);
 
-            setPenAndDrawBackground(p, pen, format, QRectF(iterator.x.toReal(), (y - line.ascent).toReal(),
+            setPenAndDrawBackground(p, pen, format, QRectF(iterator.x.toReal(), (y - lineBase).toReal(),
                                                            iterator.itemWidth.toReal(), line.height().toReal()));
 
             QTextCharFormat::VerticalAlignment valign = format.verticalAlignment();
@@ -2086,7 +2138,7 @@
                 if (si.analysis.flags == QScriptAnalysis::Object && eng->block.docHandle()) {
                     QFixed itemY = y - si.ascent;
                     if (format.verticalAlignment() == QTextCharFormat::AlignTop) {
-                        itemY = y - line.ascent;
+                        itemY = y - lineBase;
                     }
 
                     QRectF itemRect(iterator.x.toReal(), itemY.toReal(), iterator.itemWidth.toReal(), si.height().toReal());