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
Pick-to: 5.15 6.2 6.4 6.5
Change-Id: I4e583fb74f7a51424f14917d7cc0894beefec48b
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
This commit is contained in:
Vladimir Belyavsky 2023-02-17 19:31:50 +03:00 committed by Eskil Abrahamsen Blomfeldt
parent 1ca1fb86ac
commit 0fe6f818d2

View File

@ -2493,15 +2493,19 @@ QList<QGlyphRun> QTextLine::glyphRuns(int from,
// 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; i < glyphsStart; ++i) {
if (!glyphLayout.attributes[i].dontPrint) {
QFixed justification = QFixed::fromFixed(glyphLayout.justifications[i].space_18d6);
pos.rx() += (glyphLayout.advances[i] + justification).toReal();
}
}
} else if (relativeTo != (iterator.itemEnd - si.position - 1) && rtl) {
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();
}
}
}
glyphLayout = glyphLayout.mid(glyphsStart, glyphsEnd - glyphsStart + 1);
@ -2554,9 +2558,11 @@ QList<QGlyphRun> QTextLine::glyphRuns(int from,
glyphRuns.append(glyphRun);
}
for (int i = 0; i < subLayout.numGlyphs; ++i) {
if (!subLayout.attributes[i].dontPrint) {
QFixed justification = QFixed::fromFixed(subLayout.justifications[i].space_18d6);
pos.rx() += (subLayout.advances[i] + justification).toReal();
}
}
if (rtl)
end = start - 1;