Prevent consecutive images from climbing up a text node.
authorAndrew den Exter <andrew.den-exter@nokia.com>
Mon, 5 Dec 2011 01:29:04 +0000 (11:29 +1000)
committerQt by Nokia <qt-info@nokia.com>
Wed, 7 Dec 2011 04:49:46 +0000 (05:49 +0100)
Vertically position all nodes at the baseline minus their ascent.
Previously the bounding rect of a glyph run was postioned on the base
line and  images at the baseline minus the ascent.  This meant that
calculated position of an image was correct if it followed text but
if it followed another image it would be positioned above it.

Change-Id: I03f5e0b48f132f010d16c49620fa9463873f9492
Reviewed-by: Yann Bodson <yann.bodson@nokia.com>
src/quick/items/qquicktextnode.cpp

index bfb3591..d3b396d 100644 (file)
@@ -252,6 +252,9 @@ namespace {
             decorations |= (backgroundColor.isValid() ? QQuickTextNode::Background : QQuickTextNode::NoDecoration);
 
             qreal ascent = glyphRun.rawFont().ascent();
+            // ### QTBUG-22919 The bounding rect returned by QGlyphRun appears to start on the
+            // baseline, move it by the ascent so all bounding rects are at baseline - ascent.
+            searchRect.translate(0, -ascent);
             insert(binaryTree, BinaryTreeNode(glyphRun, selectionState, searchRect, decorations,
                                               textColor, backgroundColor, position, ascent));
         }
@@ -631,10 +634,10 @@ namespace {
                 const BinaryTreeNode *lastNode = m_currentLineTree.data() + m_currentLineTree.size() - 1;
                 if (lastNode->glyphRun.isRightToLeft()) {
                     QPointF lastPos = lastNode->boundingRect.topLeft();
-                    searchRect.moveTopRight(lastPos - QPointF(0, ascent));
+                    searchRect.moveTopRight(lastPos - QPointF(0, ascent - lastNode->ascent));
                 } else {
                     QPointF lastPos = lastNode->boundingRect.topRight();
-                    searchRect.moveTopLeft(lastPos - QPointF(0, ascent));
+                    searchRect.moveTopLeft(lastPos - QPointF(0, ascent - lastNode->ascent));
                 }
             }
         }