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>
This commit is contained in:
Eskil Abrahamsen Blomfeldt 2020-06-05 08:07:14 +02:00
parent 69795835f3
commit 3279c8e7d7
7 changed files with 287 additions and 245 deletions

View File

@ -56,9 +56,6 @@ private slots:
void drawNonExistentGlyphs();
void drawMultiScriptText1();
void drawMultiScriptText2();
void drawStruckOutText();
void drawOverlinedText();
void drawUnderlinedText();
void drawRightToLeft();
void detach();
void setRawData();
@ -511,135 +508,6 @@ void tst_QGlyphRun::detach()
QCOMPARE(glyphs.glyphIndexes(), QVector<quint32>() << 1 << 2 << 3);
}
void tst_QGlyphRun::drawStruckOutText()
{
QPixmap textLayoutDraw(1000, 1000);
QPixmap drawGlyphs(1000, 1000);
textLayoutDraw.fill(Qt::white);
drawGlyphs.fill(Qt::white);
QString s = QString::fromLatin1("Foobar");
QFont font;
font.setStrikeOut(true);
font.setStyleStrategy(QFont::ForceIntegerMetrics);
QTextLayout layout(s);
layout.setFont(font);
layout.setCacheEnabled(true);
layout.beginLayout();
layout.createLine();
layout.endLayout();
{
QPainter p(&textLayoutDraw);
layout.draw(&p, QPointF(50, 50));
}
QGlyphRun glyphs = layout.glyphRuns().size() > 0
? layout.glyphRuns().at(0)
: QGlyphRun();
{
QPainter p(&drawGlyphs);
p.drawGlyphRun(QPointF(50, 50), glyphs);
}
#if defined(DEBUG_SAVE_IMAGE)
textLayoutDraw.save("drawStruckOutText_textLayoutDraw.png");
drawGlyphs.save("drawStruckOutText_drawGlyphIndexes.png");
#endif
QCOMPARE(textLayoutDraw, drawGlyphs);
}
void tst_QGlyphRun::drawOverlinedText()
{
QPixmap textLayoutDraw(1000, 1000);
QPixmap drawGlyphs(1000, 1000);
textLayoutDraw.fill(Qt::white);
drawGlyphs.fill(Qt::white);
QString s = QString::fromLatin1("Foobar");
QFont font;
font.setOverline(true);
font.setStyleStrategy(QFont::ForceIntegerMetrics);
QTextLayout layout(s);
layout.setFont(font);
layout.setCacheEnabled(true);
layout.beginLayout();
layout.createLine();
layout.endLayout();
{
QPainter p(&textLayoutDraw);
layout.draw(&p, QPointF(50, 50));
}
QGlyphRun glyphs = layout.glyphRuns().size() > 0
? layout.glyphRuns().at(0)
: QGlyphRun();
{
QPainter p(&drawGlyphs);
p.drawGlyphRun(QPointF(50, 50), glyphs);
}
#if defined(DEBUG_SAVE_IMAGE)
textLayoutDraw.save("drawOverlineText_textLayoutDraw.png");
drawGlyphs.save("drawOverlineText_drawGlyphIndexes.png");
#endif
QCOMPARE(textLayoutDraw, drawGlyphs);
}
void tst_QGlyphRun::drawUnderlinedText()
{
QPixmap textLayoutDraw(1000, 1000);
QPixmap drawGlyphs(1000, 1000);
textLayoutDraw.fill(Qt::white);
drawGlyphs.fill(Qt::white);
QString s = QString::fromLatin1("Foobar");
QFont font;
font.setUnderline(true);
font.setStyleStrategy(QFont::ForceIntegerMetrics);
QTextLayout layout(s);
layout.setFont(font);
layout.setCacheEnabled(true);
layout.beginLayout();
layout.createLine();
layout.endLayout();
{
QPainter p(&textLayoutDraw);
layout.draw(&p, QPointF(50, 50));
}
QGlyphRun glyphs = layout.glyphRuns().size() > 0
? layout.glyphRuns().at(0)
: QGlyphRun();
{
QPainter p(&drawGlyphs);
p.drawGlyphRun(QPointF(50, 50), glyphs);
}
#if defined(DEBUG_SAVE_IMAGE)
textLayoutDraw.save("drawUnderlineText_textLayoutDraw.png");
drawGlyphs.save("drawUnderlineText_drawGlyphIndexes.png");
#endif
QCOMPARE(textLayoutDraw, drawGlyphs);
}
void tst_QGlyphRun::drawRightToLeft()
{
QString s;

View File

@ -87,10 +87,6 @@ private slots:
void setPenRichText();
void richTextOverridesPen();
void drawStruckOutText();
void drawOverlinedText();
void drawUnderlinedText();
void unprintableCharacter_qtbug12614();
#ifdef QT_BUILD_INTERNAL
@ -774,113 +770,6 @@ void tst_QStaticText::richTextOverridesPen()
errorMessage.constData());
}
void tst_QStaticText::drawStruckOutText()
{
QPixmap imageDrawText(1000, 1000);
QPixmap imageDrawStaticText(1000, 1000);
imageDrawText.fill(Qt::white);
imageDrawStaticText.fill(Qt::white);
QString s = QString::fromLatin1("Foobar");
QFont font;
font.setStrikeOut(true);
font.setStyleStrategy(QFont::ForceIntegerMetrics);
{
QPainter p(&imageDrawText);
p.setFont(font);
p.drawText(QPointF(50, 50), s);
}
{
QPainter p(&imageDrawStaticText);
QStaticText text = QStaticText(s);
p.setFont(font);
p.drawStaticText(QPointF(50, 50 - QFontMetricsF(p.font()).ascent()), text);
}
#if defined(DEBUG_SAVE_IMAGE)
imageDrawText.save("drawStruckOutText_imageDrawText.png");
imageDrawStaticText.save("drawStruckOutText_imageDrawStaticText.png");
#endif
QVERIFY(imageDrawText.toImage() != m_whiteSquare);
QCOMPARE(imageDrawText, imageDrawStaticText);
}
void tst_QStaticText::drawOverlinedText()
{
QPixmap imageDrawText(1000, 1000);
QPixmap imageDrawStaticText(1000, 1000);
imageDrawText.fill(Qt::white);
imageDrawStaticText.fill(Qt::white);
QString s = QString::fromLatin1("Foobar");
QFont font;
font.setOverline(true);
font.setStyleStrategy(QFont::ForceIntegerMetrics);
{
QPainter p(&imageDrawText);
p.setFont(font);
p.drawText(QPointF(50, 50), s);
}
{
QPainter p(&imageDrawStaticText);
QStaticText text = QStaticText(s);
p.setFont(font);
p.drawStaticText(QPointF(50, 50 - QFontMetricsF(p.font()).ascent()), text);
}
#if defined(DEBUG_SAVE_IMAGE)
imageDrawText.save("drawOverlinedText_imageDrawText.png");
imageDrawStaticText.save("drawOverlinedText_imageDrawStaticText.png");
#endif
QVERIFY(imageDrawText.toImage() != m_whiteSquare);
QCOMPARE(imageDrawText, imageDrawStaticText);
}
void tst_QStaticText::drawUnderlinedText()
{
QPixmap imageDrawText(1000, 1000);
QPixmap imageDrawStaticText(1000, 1000);
imageDrawText.fill(Qt::white);
imageDrawStaticText.fill(Qt::white);
QString s = QString::fromLatin1("Foobar");
QFont font;
font.setUnderline(true);
font.setStyleStrategy(QFont::ForceIntegerMetrics);
{
QPainter p(&imageDrawText);
p.setFont(font);
p.drawText(QPointF(50, 50), s);
}
{
QPainter p(&imageDrawStaticText);
QStaticText text = QStaticText(s);
p.setFont(font);
p.drawStaticText(QPointF(50, 50 - QFontMetricsF(p.font()).ascent()), text);
}
#if defined(DEBUG_SAVE_IMAGE)
imageDrawText.save("drawUnderlinedText_imageDrawText.png");
imageDrawStaticText.save("drawUnderlinedText_imageDrawStaticText.png");
#endif
QCOMPARE(imageDrawText, imageDrawStaticText);
}
void tst_QStaticText::unprintableCharacter_qtbug12614()
{
QString s(QChar(0x200B)); // U+200B, ZERO WIDTH SPACE

View File

@ -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]);

View File

@ -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);

View File

@ -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

View File

@ -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

View File

@ -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