From 8a4dec618fc7e8176f1ba402a9e4d5ed342b1cf9 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Wed, 27 May 2020 11:33:57 +0200 Subject: Fix offset on native text rendering with high-dpi scaling The glyph positions are scaled *after* they have been positioned, so when we subtracted the margin unmodified, we would actually offset by the scaled margin (so for scale factor=2 it would be 2 pixels off, and for scale factor=4 it would be 6 pixels off, etc.) We have to also prescale the margin by the inverse of the scale we will apply later. [ChangeLog][Text] Fixed an offset on text position when combining NativeRendering with high-dpi scaling. Task-number: QTBUG-84454 Pick-to: 5.15 Change-Id: I703aeb7fbd717bee5d88cc61e9a56c6422558889 Reviewed-by: Lars Knoll --- src/quick/scenegraph/qsgdefaultglyphnode_p.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/quick/scenegraph/qsgdefaultglyphnode_p.cpp') diff --git a/src/quick/scenegraph/qsgdefaultglyphnode_p.cpp b/src/quick/scenegraph/qsgdefaultglyphnode_p.cpp index f73b64f537..44fef4ddef 100644 --- a/src/quick/scenegraph/qsgdefaultglyphnode_p.cpp +++ b/src/quick/scenegraph/qsgdefaultglyphnode_p.cpp @@ -809,6 +809,7 @@ void QSGTextMaskMaterial::populate(const QPointF &p, qreal glyphCacheScaleY = cache->transform().m22(); qreal glyphCacheInverseScaleX = 1.0 / glyphCacheScaleX; qreal glyphCacheInverseScaleY = 1.0 / glyphCacheScaleY; + qreal scaledMargin = margin * glyphCacheInverseScaleX; Q_ASSERT(geometry->indexType() == GL_UNSIGNED_SHORT); geometry->allocate(glyphIndexes.size() * 4, glyphIndexes.size() * 6); @@ -833,14 +834,14 @@ void QSGTextMaskMaterial::populate(const QPointF &p, // apply the inverse scale to get back to the coordinate system of the node. qreal x = (qFloor(glyphPosition.x() * glyphCacheScaleX) * glyphCacheInverseScaleX) + - (c.baseLineX * glyphCacheInverseScaleX) - margin; + (c.baseLineX * glyphCacheInverseScaleX) - scaledMargin; qreal y = (qRound(glyphPosition.y() * glyphCacheScaleY) * glyphCacheInverseScaleY) - - (c.baseLineY * glyphCacheInverseScaleY) - margin; + (c.baseLineY * glyphCacheInverseScaleY) - scaledMargin; qreal w = c.w * glyphCacheInverseScaleX; qreal h = c.h * glyphCacheInverseScaleY; - *boundingRect |= QRectF(x + margin, y + margin, w, h); + *boundingRect |= QRectF(x + scaledMargin, y + scaledMargin, w, h); float cx1 = x - margins.left(); float cx2 = x + w + margins.right(); -- cgit v1.2.3