summaryrefslogtreecommitdiffstats
path: root/tests/auto/other/lancelot
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>2020-06-05 08:07:14 +0200
committerEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>2020-06-08 06:45:49 +0200
commit3279c8e7d72c5eee379fa8e4a2789acfe40445c0 (patch)
tree7d944b86759be03bd9334675d735e4fd45497852 /tests/auto/other/lancelot
parent69795835f3a578f60b16f09943feee6326087342 (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')
-rw-r--r--tests/auto/other/lancelot/paintcommands.cpp48
-rw-r--r--tests/auto/other/lancelot/paintcommands.h1
-rw-r--r--tests/auto/other/lancelot/scripts/glyphruns.qps175
-rw-r--r--tests/auto/other/lancelot/scripts/statictext.qps35
-rw-r--r--tests/auto/other/lancelot/scripts/text.qps30
5 files changed, 287 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]);
diff --git a/tests/auto/other/lancelot/paintcommands.h b/tests/auto/other/lancelot/paintcommands.h
index 816ecd6fa2..6085b9c088 100644
--- a/tests/auto/other/lancelot/paintcommands.h
+++ b/tests/auto/other/lancelot/paintcommands.h
@@ -198,6 +198,7 @@ private:
void command_drawRoundRect(QRegularExpressionMatch re);
void command_drawText(QRegularExpressionMatch re);
void command_drawStaticText(QRegularExpressionMatch re);
+ void command_drawGlyphRun(QRegularExpressionMatch re);
void command_drawTextDocument(QRegularExpressionMatch re);
void command_drawTiledPixmap(QRegularExpressionMatch re);
void command_fillRect(QRegularExpressionMatch re);
diff --git a/tests/auto/other/lancelot/scripts/glyphruns.qps b/tests/auto/other/lancelot/scripts/glyphruns.qps
new file mode 100644
index 0000000000..2b70c72610
--- /dev/null
+++ b/tests/auto/other/lancelot/scripts/glyphruns.qps
@@ -0,0 +1,175 @@
+drawGlyphRun -5 5 "Text that is drawn outside the bounds..."
+
+translate 20 20
+begin_block text_drawing
+save
+ setFont "sansserif" 10 normal
+ drawGlyphRun 0 20 "sansserif 10pt, normal"
+
+ setFont "sansserif" 12 normal
+ drawGlyphRun 0 40 "sansserif 12pt, normal"
+
+ setFont "sansserif" 12 bold
+ drawGlyphRun 0 60 "sansserif 12pt, bold"
+
+ setFont "sansserif" 10 bold italic
+ drawGlyphRun 0 80 "sansserif 10pt, bold italic"
+
+
+ translate 0 100
+ setPen #7fff0000
+
+ setFont "sansserif" 10 normal
+ drawGlyphRun 0 20 "alpha sansserif 10pt, normal"
+
+ setFont "sansserif" 12 normal
+ drawGlyphRun 0 40 "alpha sansserif 12pt, normal"
+
+ setFont "sansserif" 12 bold
+ drawGlyphRun 0 60 "alpha sansserif 12pt, bold"
+
+ setFont "sansserif" 10 bold italic
+ drawGlyphRun 0 80 "alpha sansserif 10pt, bold italic"
+
+
+ translate 0 100
+ setPen black
+ save
+ scale 0.9 0.9
+
+ setFont "sansserif" 10 normal
+ drawGlyphRun 0 20 "scaled sansserif 10pt, normal"
+
+ setFont "sansserif" 12 normal
+ drawGlyphRun 0 40 "scaled sansserif 12pt, normal"
+
+ setFont "sansserif" 12 bold
+ drawGlyphRun 0 60 "scaled sansserif 12pt, bold"
+
+ setFont "sansserif" 10 bold italic
+ drawGlyphRun 0 80 "scaled sansserif 10pt, bold italic"
+ restore
+
+ translate 200 200
+ setPen black
+ save
+ scale -1 -1
+
+ setFont "sansserif" 10 normal
+ drawGlyphRun 0 20 "flipped sansserif 10pt, normal"
+
+ setFont "sansserif" 12 normal
+ drawGlyphRun 0 40 "flipped sansserif 12pt, normal"
+
+ setFont "sansserif" 12 bold
+ drawGlyphRun 0 60 "flipped sansserif 12pt, bold"
+
+ setFont "sansserif" 10 bold italic
+ drawGlyphRun 0 80 "flipped sansserif 10pt, bold italic"
+ restore
+
+ translate -200 20
+ setPen black
+ save
+ translate 200 90
+ rotate 185
+
+ setFont "sansserif" 10 normal
+ drawGlyphRun 0 20 "rotated sansserif 10pt, normal"
+
+ setFont "sansserif" 12 normal
+ drawGlyphRun 0 40 "rotated sansserif 12pt, normal"
+
+ setFont "sansserif" 12 bold
+ drawGlyphRun 0 60 "rotated sansserif 12pt, bold"
+
+ setFont "sansserif" 10 bold italic
+ drawGlyphRun 0 80 "rotated sansserif 10pt, bold italic"
+ restore
+
+ translate 0 100
+ gradient_appendStop 0 red
+ gradient_appendStop 0.5 #00ff00
+ gradient_appendStop 1 blue
+ gradient_setLinear 0 0 200 0
+ setPen brush
+
+ setFont "sansserif" 10 normal
+ drawGlyphRun 0 0 "gradient sansserif 10pt, normal"
+
+ setFont "sansserif" 12 normal
+ drawGlyphRun 0 20 "gradient sansserif 12pt, normal"
+
+ setFont "sansserif" 12 bold
+ drawGlyphRun 0 40 "gradient sansserif 12pt, bold"
+
+ setFont "sansserif" 10 bold italic
+ drawGlyphRun 0 60 "gradient sansserif 10pt, bold italic"
+restore
+end_block
+
+translate 250 0
+drawGlyphRun 25 640 "clipped to rectangle"
+save
+ setPen #3f000000
+ setBrush nobrush
+ drawRect 20 0 100 620
+ setClipRect 20 0 100 620
+ setPen black
+ repeat_block text_drawing
+restore
+
+translate 150 0
+drawGlyphRun 25 640 "clipped to path"
+save
+ path_moveTo clip 20 0
+ path_cubicTo clip 0 200 40 400 20 400
+ path_lineTo clip 30 620
+ path_lineTo clip 30 0
+ path_lineTo clip 40 0
+ path_lineTo clip 40 620
+ path_lineTo clip 120 620
+ path_lineTo clip 120 0
+ path_lineTo clip 20 0
+ setPen #3f000000
+ setBrush nobrush
+ drawPath clip
+ setClipPath clip
+ setPen black
+ repeat_block text_drawing
+restore
+
+translate 150 0
+save
+ setPen black
+ setFont "sansserif" 16 normal
+ drawGlyphRun 0 40 "e😃m😇o😍j😜i😸!"
+restore
+
+translate 0 55
+save
+ setPen black
+ setFont "sansserif" 12 normal normal default underline
+ drawGlyphRun 0 20 "Underlined text drawing"
+restore
+
+translate 0 35
+save
+ setPen black
+ setFont "sansserif" 12 normal normal default normal strikeout
+ drawGlyphRun 0 20 "Struck out text drawing"
+restore
+
+translate 0 35
+save
+ setPen black
+ setFont "sansserif" 12 normal normal default normal normal overline
+ drawGlyphRun 0 20 "Overlined text drawing"
+restore
+
+translate 0 35
+save
+ setPen black
+ setFont "sansserif" 12 normal normal default underline strikeout overline
+ drawGlyphRun 0 20 "All the effects text drawing"
+restore
diff --git a/tests/auto/other/lancelot/scripts/statictext.qps b/tests/auto/other/lancelot/scripts/statictext.qps
index 6b7b97d8fa..c2a30d0864 100644
--- a/tests/auto/other/lancelot/scripts/statictext.qps
+++ b/tests/auto/other/lancelot/scripts/statictext.qps
@@ -138,3 +138,38 @@ save
setPen black
repeat_block text_drawing
restore
+
+translate 150 0
+save
+ setPen black
+ setFont "sansserif" 16 normal
+ drawStaticText 0 40 "e😃m😇o😍j😜i😸!"
+restore
+
+translate 0 55
+save
+ setPen black
+ setFont "sansserif" 12 normal normal default underline
+ drawStaticText 0 20 "Underlined text drawing"
+restore
+
+translate 0 35
+save
+ setPen black
+ setFont "sansserif" 12 normal normal default normal strikeout
+ drawStaticText 0 20 "Struck out text drawing"
+restore
+
+translate 0 35
+save
+ setPen black
+ setFont "sansserif" 12 normal normal default normal normal overline
+ drawStaticText 0 20 "Overlined text drawing"
+restore
+
+translate 0 35
+save
+ setPen black
+ setFont "sansserif" 12 normal normal default underline strikeout overline
+ drawStaticText 0 20 "All the effects text drawing"
+restore
diff --git a/tests/auto/other/lancelot/scripts/text.qps b/tests/auto/other/lancelot/scripts/text.qps
index 1b4fe4f064..4d81b3084c 100644
--- a/tests/auto/other/lancelot/scripts/text.qps
+++ b/tests/auto/other/lancelot/scripts/text.qps
@@ -167,3 +167,33 @@ save
setFont "sansserif" 16 normal
drawText 0 40 "e😃m😇o😍j😜i😸!"
restore
+
+translate 0 75
+save
+ setPen black
+ setFont "sansserif" 12 normal normal default underline
+ drawText 0 20 "Underlined text drawing"
+restore
+
+translate 0 35
+save
+ setPen black
+ setFont "sansserif" 12 normal normal default normal strikeout
+ drawText 0 20 "Struck out text drawing"
+restore
+
+translate 0 35
+save
+ setPen black
+ setFont "sansserif" 12 normal normal default normal normal overline
+ drawText 0 20 "Overlined text drawing"
+restore
+
+translate 0 35
+save
+ setPen black
+ setFont "sansserif" 12 normal normal default underline strikeout overline
+ drawText 0 20 "All the effects text drawing"
+restore
+
+