From d6cc8f19f1dffe9083f5b70b6d5de33a2082f12f Mon Sep 17 00:00:00 2001 From: Andy Nichols Date: Wed, 26 Sep 2018 15:28:26 +0200 Subject: Software Adaptation: Improve bounding rect claculation for glyph nodes It is not enough to call QGlyphRun::boundingRect() to determine the true bounding rect of a series of glyphs. This issue would manifest itself when rendering italic text. Now we calculate the bounding rect for a QGlyphRun when they are changed in the node so that that the clip rect for glyphnodes reflect what is set on the node. Task-number: QTBUG-68085 Change-Id: I834a7312052c8c5a4ad62f28333108c051d7f7b8 Reviewed-by: Laszlo Agocs --- .../adaptations/software/qsgsoftwareglyphnode.cpp | 30 +++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'src/quick/scenegraph') diff --git a/src/quick/scenegraph/adaptations/software/qsgsoftwareglyphnode.cpp b/src/quick/scenegraph/adaptations/software/qsgsoftwareglyphnode.cpp index 7ab9c15d9b..dd789b78c7 100644 --- a/src/quick/scenegraph/adaptations/software/qsgsoftwareglyphnode.cpp +++ b/src/quick/scenegraph/adaptations/software/qsgsoftwareglyphnode.cpp @@ -49,12 +49,40 @@ QSGSoftwareGlyphNode::QSGSoftwareGlyphNode() setGeometry(&m_geometry); } +namespace { +QRectF calculateBoundingRect(const QPointF &position, const QGlyphRun &glyphs) +{ + qreal minX = 0; + qreal minY = 0; + qreal maxX = 0; + qreal maxY = 0; + + for (int i = 0, n = qMin(glyphs.glyphIndexes().size(), glyphs.positions().size()); i < n; ++i) { + QRectF glyphRect = glyphs.rawFont().boundingRect(glyphs.glyphIndexes()[i]); + glyphRect.translate(glyphs.positions()[i]); + + if (i == 0) { + minX = glyphRect.left(); + minY = glyphRect.top(); + maxX = glyphRect.right(); + maxY = glyphRect.bottom(); + } else { + minX = qMin(glyphRect.left(), minX); + minY = qMin(glyphRect.top(), minY); + maxX = qMax(glyphRect.right(),maxX); + maxY = qMax(glyphRect.bottom(), maxY); + } + } + QRectF boundingRect(QPointF(minX, minY), QPointF(maxX, maxY)); + return boundingRect.translated(position - QPointF(0.0, glyphs.rawFont().ascent())); +} +} void QSGSoftwareGlyphNode::setGlyphs(const QPointF &position, const QGlyphRun &glyphs) { m_position = position; m_glyphRun = glyphs; - m_bounding_rect = glyphs.boundingRect().translated(m_position - QPointF(0.0, glyphs.rawFont().ascent())); + m_bounding_rect = calculateBoundingRect(position, glyphs); } void QSGSoftwareGlyphNode::setColor(const QColor &color) -- cgit v1.2.3