Accept error margin in QGlyphRun/QStaticText test for decorations

When calculating the width of a text for drawing decorations on top,
we use the effective advance of the whole text after it has been
through the shaper.

However, in the case of QStaticText and QGlyphRun, there is shortcut:
Since we only have the glyph indexes and position of each glyph,
we use the position + advance of the right-most glyph to find the
right-most edge of the decoration. For this, however, we use the
advance of the glyph *out of context* of the rest of the string,
because the whole idea is to avoid doing the shaping of the string
with every draw call. In some rare cases, the advance of the
right-most character, in the context of the string, is different
from the advance of the standalone glyph.

Now, one way of fixing this would be to store the width of the
text in QStaticText and QGlyphRun, but since it is a very rare
artifact which is barely visible, I have opted to just work around
it in the test instead, the workaround being to force integer
metrics so that we don't get the small 0.2 pixel error.

Task-number: QTBUG-55217
Change-Id: I8d16d52f2ef27275cabb7d3865aeeaa31617ba3d
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
bb10
Eskil Abrahamsen Blomfeldt 2017-02-02 12:29:44 +01:00
parent 89501f9a7b
commit 3e238113f8
2 changed files with 6 additions and 0 deletions

View File

@ -527,6 +527,7 @@ void tst_QGlyphRun::drawStruckOutText()
QFont font;
font.setStrikeOut(true);
font.setStyleStrategy(QFont::ForceIntegerMetrics);
QTextLayout layout(s);
layout.setFont(font);
@ -569,6 +570,7 @@ void tst_QGlyphRun::drawOverlinedText()
QFont font;
font.setOverline(true);
font.setStyleStrategy(QFont::ForceIntegerMetrics);
QTextLayout layout(s);
layout.setFont(font);
@ -611,6 +613,7 @@ void tst_QGlyphRun::drawUnderlinedText()
QFont font;
font.setUnderline(true);
font.setStyleStrategy(QFont::ForceIntegerMetrics);
QTextLayout layout(s);
layout.setFont(font);

View File

@ -716,6 +716,7 @@ void tst_QStaticText::drawStruckOutText()
QFont font;
font.setStrikeOut(true);
font.setStyleStrategy(QFont::ForceIntegerMetrics);
{
QPainter p(&imageDrawText);
@ -751,6 +752,7 @@ void tst_QStaticText::drawOverlinedText()
QFont font;
font.setOverline(true);
font.setStyleStrategy(QFont::ForceIntegerMetrics);
{
QPainter p(&imageDrawText);
@ -786,6 +788,7 @@ void tst_QStaticText::drawUnderlinedText()
QFont font;
font.setUnderline(true);
font.setStyleStrategy(QFont::ForceIntegerMetrics);
{
QPainter p(&imageDrawText);