diff options
author | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io> | 2020-06-05 08:07:14 +0200 |
---|---|---|
committer | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io> | 2020-06-08 06:45:49 +0200 |
commit | 3279c8e7d72c5eee379fa8e4a2789acfe40445c0 (patch) | |
tree | 7d944b86759be03bd9334675d735e4fd45497852 /tests/auto/other/lancelot/paintcommands.cpp | |
parent | 69795835f3a578f60b16f09943feee6326087342 (diff) |
Move some flaky text tests into Lancelot
There are some slight differences between normal drawText()
and QGlyphRuns/QStaticText for decoration widths in certain
fonts. We decided to accept this and tried working around it
in the test by using ForceIntegerMetrics (since the difference
is < 0.5 pixel). This enum has been deprecated, so we move
the tests into Lancelot instead, since the idea here is to
test for regressions, not to compare the two painter commands.
Note that there is something off about decorations with
drawGlyphRuns() and drawStaticText() which is exposed
(not caused) by this, perhaps related to using a matrix
for positioning, since that was untested before.
This also takes the liberty of moving the emoji test string
from text.qps, since this was not in the statictext.qps yet.
Change-Id: Ib2d697095cbd11829cdd50b3c0268c85e9607c78
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
Diffstat (limited to 'tests/auto/other/lancelot/paintcommands.cpp')
-rw-r--r-- | tests/auto/other/lancelot/paintcommands.cpp | 48 |
1 files changed, 46 insertions, 2 deletions
diff --git a/tests/auto/other/lancelot/paintcommands.cpp b/tests/auto/other/lancelot/paintcommands.cpp index e98df3781e..2f6bd2872f 100644 --- a/tests/auto/other/lancelot/paintcommands.cpp +++ b/tests/auto/other/lancelot/paintcommands.cpp @@ -297,8 +297,8 @@ void PaintCommands::staticInit() "setCompositionMode <composition mode enum>", "setCompositionMode SourceOver"); DECL_PAINTCOMMAND("setFont", command_setFont, - "^setFont\\s+\"([\\w\\s]*)\"\\s*(\\w*)\\s*(\\w*)\\s*(\\w*)\\s*(\\w*)$", - "setFont <fontFace> [size] [font weight|font weight enum] [italic] [hinting enum]\n - font weight is an integer between 0 and 99", + "^setFont\\s+\"([\\w\\s]*)\"\\s*(\\w*)\\s*(\\w*)\\s*(\\w*)\\s*(\\w*)\\s*(\\w*)\\s*(\\w*)\\s*(\\w*)$", + "setFont <fontFace> [size] [font weight|font weight enum] [italic] [hinting enum] [underline] [strikeout] [overline]\n - font weight is an integer between 0 and 99", "setFont \"times\" 12"); DECL_PAINTCOMMAND("setPen", command_setPen, "^setPen\\s+#?(\\w*)$", @@ -444,6 +444,10 @@ void PaintCommands::staticInit() "^drawStaticText\\s+(-?\\w*)\\s+(-?\\w*)\\s+\"(.*)\"$", "drawStaticText <x> <y> <text>", "drawStaticText 10 10 \"my text\""); + DECL_PAINTCOMMAND("drawGlyphRun", command_drawGlyphRun, + "^drawGlyphRun\\s+(-?\\w*)\\s+(-?\\w*)\\s+\"(.*)\"$", + "drawGlyphRun <x> <y> <text> - Will create glyph run using QTextLayout and draw this", + "drawGlyphRun 10 10 \"my text\""); DECL_PAINTCOMMAND("drawTextDocument", command_drawTextDocument, "^drawTextDocument\\s+(-?\\w*)\\s+(-?\\w*)\\s+\"(.*)\"$", "drawTextDocument <x> <y> <html>", @@ -1328,6 +1332,38 @@ void PaintCommands::command_drawStaticText(QRegularExpressionMatch re) m_painter->drawStaticText(x, y, QStaticText(txt)); } +void PaintCommands::command_drawGlyphRun(QRegularExpressionMatch re) +{ + if (!m_shouldDrawText) + return; + QStringList caps = re.capturedTexts(); + int x = convertToInt(caps.at(1)); + int y = convertToInt(caps.at(2)); + QString txt = caps.at(3); + + if (m_verboseMode) + printf(" -(lance) drawGlyphRun(%d, %d, %s)\n", x, y, qPrintable(txt)); + + QTextLayout layout; + layout.setFont(m_painter->font()); + layout.setText(txt); + layout.beginLayout(); + qreal lineY = 0.0; + forever { + QTextLine line = layout.createLine(); + if (!line.isValid()) + break; + line.setPosition(QPointF(0.0, lineY)); + lineY += line.height(); + } + layout.endLayout(); + + QList<QGlyphRun> glyphRuns = layout.glyphRuns(); + + for (const QGlyphRun &glyphRun : glyphRuns) + m_painter->drawGlyphRun(QPointF(x, y), glyphRun); +} + void PaintCommands::command_drawTextDocument(QRegularExpressionMatch re) { if (!m_shouldDrawText) @@ -2070,6 +2106,14 @@ void PaintCommands::command_setFont(QRegularExpressionMatch re) hinting = 0; else font.setHintingPreference(QFont::HintingPreference(hinting)); + + bool underline = caps.at(6).toLower() == "true" || caps.at(6).toLower() == "underline"; + bool strikeOut = caps.at(7).toLower() == "true" || caps.at(7).toLower() == "strikeout"; + bool overline = caps.at(8).toLower() == "true" || caps.at(8).toLower() == "overline"; + font.setUnderline(underline); + font.setStrikeOut(strikeOut); + font.setOverline(overline); + if (m_verboseMode) printf(" -(lance) setFont(family=%s, size=%d, weight=%d, italic=%d hinting=%s\n", qPrintable(family), size, weight, italic, fontHintingTable[hinting]); |