From b0d395e27c7bbc6ee34a12ec07426581e013be08 Mon Sep 17 00:00:00 2001 From: Vladimir Belyavsky Date: Fri, 17 Feb 2023 19:31:50 +0300 Subject: [PATCH] Text: fix Soft hyphen rendering in QTextLayout::glyphRuns() When calculating the position offset of QGlyphRuns, either when fetching substrings or when applying fallback fonts, we would include the advances of non-printable glyphs, such as the soft hyphen. This was an oversight, and the other code which calculates the advance (like in QFontEngine::getGlyphPositions()) does this correctly. We apply the same logic as there and only include the advance if the dontPrint flag is unset. [ChangeLog][QtGui][Text] Fixed an issue where spaces would sometimes be shown in soft hyphen positions in a string. Fixes: QTBUG-46990 Fixes: QTBUG-62620 Fixes: QTBUG-67038 Fixes: QTBUG-102483 Change-Id: I4e583fb74f7a51424f14917d7cc0894beefec48b Reviewed-by: Eskil Abrahamsen Blomfeldt (cherry picked from commit 0fe6f818d23495f07100f82c12e4232b8e56daf4) Reviewed-by: Qt Cherry-pick Bot --- src/gui/text/qtextlayout.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/gui/text/qtextlayout.cpp b/src/gui/text/qtextlayout.cpp index 752c6180f8d..486e04544af 100644 --- a/src/gui/text/qtextlayout.cpp +++ b/src/gui/text/qtextlayout.cpp @@ -2492,14 +2492,18 @@ QList QTextLine::glyphRuns(int from, // when we're breaking a RTL script item, since the expected position passed into // getGlyphPositions() is the left-most edge of the left-most glyph in an RTL run. if (relativeFrom != (iterator.itemStart - si.position) && !rtl) { - for (int i=itemGlyphsStart; iglyphsEnd; --i) { - QFixed justification = QFixed::fromFixed(glyphLayout.justifications[i].space_18d6); - pos.rx() += (glyphLayout.advances[i] + justification).toReal(); + for (int i = itemGlyphsEnd; i > glyphsEnd; --i) { + if (!glyphLayout.attributes[i].dontPrint) { + QFixed justification = QFixed::fromFixed(glyphLayout.justifications[i].space_18d6); + pos.rx() += (glyphLayout.advances[i] + justification).toReal(); + } } } @@ -2554,8 +2558,10 @@ QList QTextLine::glyphRuns(int from, glyphRuns.append(glyphRun); } for (int i = 0; i < subLayout.numGlyphs; ++i) { - QFixed justification = QFixed::fromFixed(subLayout.justifications[i].space_18d6); - pos.rx() += (subLayout.advances[i] + justification).toReal(); + if (!subLayout.attributes[i].dontPrint) { + QFixed justification = QFixed::fromFixed(subLayout.justifications[i].space_18d6); + pos.rx() += (subLayout.advances[i] + justification).toReal(); + } } if (rtl)