summaryrefslogtreecommitdiffstats
path: root/tests/auto/other/lancelot
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/other/lancelot')
-rw-r--r--tests/auto/other/lancelot/paintcommands.cpp25
-rw-r--r--tests/auto/other/lancelot/paintcommands.h1
-rw-r--r--tests/auto/other/lancelot/scripts/cosmetic.qps55
-rw-r--r--tests/auto/other/lancelot/scripts/linedashes2.qps48
-rw-r--r--tests/auto/other/lancelot/scripts/tinydashes.qps34
-rw-r--r--tests/auto/other/lancelot/tst_lancelot.cpp49
6 files changed, 207 insertions, 5 deletions
diff --git a/tests/auto/other/lancelot/paintcommands.cpp b/tests/auto/other/lancelot/paintcommands.cpp
index e98df3781e..0dab5376a0 100644
--- a/tests/auto/other/lancelot/paintcommands.cpp
+++ b/tests/auto/other/lancelot/paintcommands.cpp
@@ -376,6 +376,10 @@ void PaintCommands::staticInit()
"^drawLine\\s+(-?[\\w.]*)\\s+(-?[\\w.]*)\\s+(-?[\\w.]*)\\s+(-?[\\w.]*)$",
"drawLine <x1> <y1> <x2> <y2>",
"drawLine 10.0 10.0 20.0 20.0");
+ DECL_PAINTCOMMAND("drawLines", command_drawLines,
+ "^drawLines\\s+\\[([\\w\\s\\-.]*)\\]$",
+ "drawLines <[ <l1x1> <l1y1> <l1x2> <l1y2> <l2x1> <l2y1> ... ]>",
+ "drawLines [ 10 10 50 10 50 20 10 20 ]");
DECL_PAINTCOMMAND("drawRect", command_drawRect,
"^drawRect\\s+(-?[\\w.]*)\\s+(-?[\\w.]*)\\s+(-?[\\w.]*)\\s+(-?[\\w.]*)$",
"drawRect <x> <y> <w> <h>",
@@ -433,7 +437,7 @@ void PaintCommands::staticInit()
"drawConvexPolygon <[ <x1> <y1> ... <xn> <yn> ]>",
"drawConvexPolygon [ 1 4 6 8 5 3 ]");
DECL_PAINTCOMMAND("drawPolyline", command_drawPolyline,
- "^drawPolyline\\s+\\[([\\w\\s]*)\\]$",
+ "^drawPolyline\\s+\\[([\\w\\s\\-.]*)\\]$",
"drawPolyline <[ <x1> <y1> ... <xn> <yn> ]>",
"drawPolyline [ 1 4 6 8 5 3 ]");
DECL_PAINTCOMMAND("drawText", command_drawText,
@@ -975,6 +979,25 @@ void PaintCommands::command_drawLine(QRegularExpressionMatch re)
}
/***************************************************************************************************/
+void PaintCommands::command_drawLines(QRegularExpressionMatch re)
+{
+ static QRegularExpression separators("\\s");
+ QStringList numbers = re.captured(1).split(separators, Qt::SkipEmptyParts);
+
+ QVector<QLineF> array;
+ for (int i = 0; i + 3 < numbers.size(); i += 4) {
+ QPointF pt1(numbers.at(i).toFloat(), numbers.at(i + 1).toFloat());
+ QPointF pt2(numbers.at(i + 2).toFloat(), numbers.at(i + 3).toFloat());
+ array.append(QLineF(pt1, pt2));
+ }
+
+ if (m_verboseMode)
+ printf(" -(lance) drawLines(size=%zd)\n", size_t(array.size()));
+
+ m_painter->drawLines(array);
+}
+
+/***************************************************************************************************/
void PaintCommands::command_drawPath(QRegularExpressionMatch re)
{
if (m_verboseMode)
diff --git a/tests/auto/other/lancelot/paintcommands.h b/tests/auto/other/lancelot/paintcommands.h
index 816ecd6fa2..4a1a89556d 100644
--- a/tests/auto/other/lancelot/paintcommands.h
+++ b/tests/auto/other/lancelot/paintcommands.h
@@ -187,6 +187,7 @@ private:
void command_drawEllipse(QRegularExpressionMatch re);
void command_drawImage(QRegularExpressionMatch re);
void command_drawLine(QRegularExpressionMatch re);
+ void command_drawLines(QRegularExpressionMatch re);
void command_drawPath(QRegularExpressionMatch re);
void command_drawPie(QRegularExpressionMatch re);
void command_drawPixmap(QRegularExpressionMatch re);
diff --git a/tests/auto/other/lancelot/scripts/cosmetic.qps b/tests/auto/other/lancelot/scripts/cosmetic.qps
new file mode 100644
index 0000000000..3c730cf26f
--- /dev/null
+++ b/tests/auto/other/lancelot/scripts/cosmetic.qps
@@ -0,0 +1,55 @@
+drawRect 0 0 800 800
+
+setRenderHint Antialiasing true
+image_load dome_argb32.png img
+
+save
+setBrush springgreen SolidPattern
+
+begin_block primitives
+
+setPen black 2 DashLine
+pen_setCosmetic true
+drawLine 10 60 60 10
+drawRect 80 10.0 30 50
+drawText 130 50 "Foo"
+drawImage img 160 10 50 50
+
+pen_setCosmetic false
+drawLine 10 160 60 110
+drawRect 80 110.0 30 50
+drawText 130 150 "Foo"
+drawImage img 160 110 50 50
+
+setPen NoPen
+drawLine 10 260 60 210
+drawRect 80 210.0 30 50
+drawText 130 250 "Foo"
+drawImage img 160 210 50 50
+
+end_block primitives
+
+
+translate 250 0
+rotate 10
+scale 2.5 1
+repeat_block primitives
+
+resetMatrix
+# Force non-simple pen in Pdf
+setOpacity 0.5
+translate 0 400
+repeat_block primitives
+
+translate 250 0
+rotate 10
+scale 2.5 1
+repeat_block primitives
+
+restore
+setPen blue 4 DotLine
+setBrush olive SolidPattern
+pen_setCosmetic true
+translate 50 720
+scale 2 2
+drawRect 0 0 30 30
diff --git a/tests/auto/other/lancelot/scripts/linedashes2.qps b/tests/auto/other/lancelot/scripts/linedashes2.qps
index 1dc4fd310e..b9a4cb9566 100644
--- a/tests/auto/other/lancelot/scripts/linedashes2.qps
+++ b/tests/auto/other/lancelot/scripts/linedashes2.qps
@@ -111,8 +111,9 @@ translate 0 780
repeat_block vertical
resetMatrix
-translate 40 400
-setPen 0xffff0000 5 dashdotline flatcap
+translate 20 380
+setPen 0xffff00ff 5 dashdotline flatcap
+begin_block offset
pen_setDashPattern [1 1 4 1 1 4]
pen_setDashOffset -4
drawLine 0 0 300 0
@@ -146,9 +147,50 @@ drawLine 0 0 300 0
translate 0 8
pen_setDashOffset 16
drawLine 0 0 300 0
+end_block offset
+
+resetMatrix
+translate 420 380
+setPen 0xffff00ff 5 dashdotline roundcap
+repeat_block offset
resetMatrix
setPen black 3 dashdotline
pen_setCosmetic true
translate 0 -150
-drawLine 500 160 500 410 \ No newline at end of file
+drawLine 500 160 500 410
+
+resetMatrix
+translate 300 480
+setPen blue 0
+
+begin_block clip_lines
+pen_setDashPattern [ 20 4 5 4 1 4 ]
+pen_setDashOffset 26.0
+drawLines [0 0 1000000 10 1000000 10 -1000000 20 -1000000 20 0 30]
+end_block clip_lines
+
+translate 0 45
+setPen blue 5
+repeat_block clip_lines
+
+translate 0 45
+setPen blue 5 SolidLine RoundCap
+repeat_block clip_lines
+
+translate 0 45
+setPen green 0
+
+begin_block clip_poly
+pen_setDashPattern [ 20 4 5 4 1 4 ]
+pen_setDashOffset 26.0
+drawPolyline [0 0 1000000 10 -1000000 20 0 30]
+end_block clip_poly
+
+translate 0 45
+setPen green 5
+repeat_block clip_poly
+
+translate 0 45
+setPen green 5 SolidLine RoundCap
+repeat_block clip_poly
diff --git a/tests/auto/other/lancelot/scripts/tinydashes.qps b/tests/auto/other/lancelot/scripts/tinydashes.qps
new file mode 100644
index 0000000000..d41ced7f5f
--- /dev/null
+++ b/tests/auto/other/lancelot/scripts/tinydashes.qps
@@ -0,0 +1,34 @@
+# Version: 1
+# CheckVsReference: 5%
+
+path_addEllipse mypath 20.0 20.0 200.0 200.0
+
+save
+setPen blue 20 SolidLine FlatCap
+pen_setCosmetic true
+pen_setDashPattern [ 0.0004 0.0004 ]
+setBrush yellow
+
+drawPath mypath
+translate 300 0
+setRenderHint Antialiasing true
+drawPath mypath
+restore
+
+path_addEllipse bigpath 200000.0 200000.0 2000000.0 2000000.0
+
+setPen blue 20 DotLine FlatCap
+setBrush yellow
+
+save
+translate 0 300
+scale 0.0001 0.00011
+drawPath bigpath
+restore
+
+save
+translate 300 300
+setRenderHint Antialiasing true
+scale 0.0001 0.00011
+drawPath bigpath
+restore
diff --git a/tests/auto/other/lancelot/tst_lancelot.cpp b/tests/auto/other/lancelot/tst_lancelot.cpp
index 7c0d809c01..516cf09f2f 100644
--- a/tests/auto/other/lancelot/tst_lancelot.cpp
+++ b/tests/auto/other/lancelot/tst_lancelot.cpp
@@ -30,6 +30,9 @@
#include <qbaselinetest.h>
#include <QDir>
#include <QPainter>
+#include <QPdfWriter>
+#include <QTemporaryFile>
+#include <QProcess>
#ifndef QT_NO_OPENGL
#include <QOpenGLFramebufferObjectFormat>
@@ -53,7 +56,8 @@ public:
private:
enum GraphicsEngine {
Raster = 0,
- OpenGL = 1
+ OpenGL = 1,
+ Pdf = 2
};
void setupTestSuite(const QStringList& blacklist = QStringList());
@@ -88,6 +92,9 @@ private slots:
void testRasterRGBA64PM_data();
void testRasterRGBA64PM();
+ void testPdf_data();
+ void testPdf();
+
#ifndef QT_NO_OPENGL
void testOpenGL_data();
void testOpenGL();
@@ -239,6 +246,21 @@ void tst_Lancelot::testRasterRGBA64PM()
}
+void tst_Lancelot::testPdf_data()
+{
+#ifdef Q_OS_MACOS
+ setupTestSuite();
+#else
+ QSKIP("Pdf testing only implemented for macOS");
+#endif
+}
+
+void tst_Lancelot::testPdf()
+{
+ runTestSuite(Pdf, QImage::Format_RGB32);
+}
+
+
#ifndef QT_NO_OPENGL
bool tst_Lancelot::checkSystemGLSupport()
{
@@ -370,6 +392,28 @@ void tst_Lancelot::runTestSuite(GraphicsEngine engine, QImage::Format format, co
paint(&pdv, engine, format, script, QFileInfo(filePath).absoluteFilePath());
rendered = fbo.toImage().convertToFormat(format);
#endif
+ } else if (engine == Pdf) {
+ QString tempStem(QDir::tempPath() + QLatin1String("/lancelot_XXXXXX_") + qpsFile.chopped(4));
+
+ QTemporaryFile pdfFile(tempStem + QLatin1String(".pdf"));
+ pdfFile.open();
+ QPdfWriter writer(&pdfFile);
+ writer.setPdfVersion(QPdfWriter::PdfVersion_1_6);
+ writer.setResolution(150);
+ paint(&writer, engine, format, script, QFileInfo(filePath).absoluteFilePath());
+ pdfFile.close();
+
+ // Convert pdf to something we can read into a QImage, using macOS' sips utility
+ QTemporaryFile pngFile(tempStem + QLatin1String(".png"));
+ pngFile.open(); // Just create the file name
+ pngFile.close();
+ QProcess proc;
+ const char *rawArgs = "-s format png --cropOffset 20 20 -c 800 800 -o";
+ QStringList argList = QString::fromLatin1(rawArgs).split(QLatin1Char(' '));
+ proc.start(QLatin1String("sips"), argList << pngFile.fileName() << pdfFile.fileName());
+ proc.waitForFinished(2 * 60 * 1000); // May need some time
+
+ rendered = QImage(pngFile.fileName());
}
QBASELINE_TEST(rendered);
@@ -384,6 +428,9 @@ void tst_Lancelot::paint(QPaintDevice *device, GraphicsEngine engine, QImage::Fo
case OpenGL:
pcmd.setType(OpenGLBufferType); // version/profile is communicated through the context's format()
break;
+ case Pdf:
+ pcmd.setType(PdfType);
+ break;
case Raster: // fallthrough
default:
pcmd.setType(ImageType);