summaryrefslogtreecommitdiffstats
path: root/tests/baseline/shared/paintcommands.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/baseline/shared/paintcommands.cpp')
-rw-r--r--tests/baseline/shared/paintcommands.cpp116
1 files changed, 109 insertions, 7 deletions
diff --git a/tests/baseline/shared/paintcommands.cpp b/tests/baseline/shared/paintcommands.cpp
index 4a3de0168b..20201b66b0 100644
--- a/tests/baseline/shared/paintcommands.cpp
+++ b/tests/baseline/shared/paintcommands.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include "paintcommands.h"
#include <qdir.h>
@@ -173,6 +173,7 @@ const char *PaintCommands::imageFormatTable[] = {
"RGBx32FPx4",
"RGBA32FPx4",
"RGBA32FPx4_Premultiplied",
+ "CMYK32",
};
const char *PaintCommands::renderHintTable[] = {
@@ -469,6 +470,20 @@ void PaintCommands::staticInit()
"^fillRectF\\s+(-?[.\\w]*)\\s+(-?[.\\w]*)\\s+(-?[.\\w]*)\\s+(-?[.\\w]*)\\s*(\\w*)?$",
"fillRectF <x> <y> <w> <h> [color]\n - Uses current brush if no color given",
"fillRectF 10.5 10.5 20.2 20.2 blue");
+ DECL_PAINTCOMMAND("drawPixmapFragments", command_drawPixmapFragments,
+ "^drawPixmapFragments\\s+([\\w.:\\/]*)"
+ "\\s+(-?\\w*)"
+ "\\s+(-?[.\\w]*)\\s*(-?[.\\w]*)"
+ "\\s+(-?[.\\w]*)\\s*(-?[.\\w]*)\\s*(-?[.\\w]*)\\s*(-?[.\\w]*)"
+ "\\s+(-?[.\\w]*)\\s*(-?[.\\w]*)\\s*(-?[.\\w]*)\\s*(-?[.\\w]*)"
+ "\\s*(-?[.\\w]*)?\\s*(-?[.\\w]*)?"
+ "\\s*(-?[.\\w]*)?\\s*(-?[.\\w]*)?\\s*(-?[.\\w]*)?\\s*(-?[.\\w]*)?"
+ "\\s*(-?[.\\w]*)?\\s*(-?[.\\w]*)\\s*(-?[.\\w]*)?\\s*(-?[.\\w]*)?$",
+ "drawPixmapFragments <image filename> <count>"
+ " <centerx0> <centery0> <x0> <y0> <w0> <h0> <sx0> <sy0> <r0> <o0>"
+ " <centerx1> <centery1> <x1> <y1> <w1> ..."
+ "\n - where count is 1 or 2, and followed by centerPos, sourceRect, scaleX, scaleY, rotation, opacity <count> times",
+ "drawPixmapFragments :/images/sign.png 1 50 50 10 10 60 60 10 10 30 1");
DECL_PAINTCOMMANDSECTION("painterPaths");
DECL_PAINTCOMMAND("path_moveTo", command_path_moveTo,
@@ -731,8 +746,8 @@ void PaintCommands::runCommand(const QString &scriptLine)
return;
}
QString firstWord = scriptLine.section(separators, 0, 0);
- QList<int> indices = s_commandHash.values(firstWord);
- foreach(int idx, indices) {
+ const QList<int> indices = s_commandHash.values(firstWord);
+ for (int idx : indices) {
PaintCommandInfos command = s_commandInfoTable.at(idx);
Q_ASSERT(command.regExp.isValid());
QRegularExpressionMatch match = command.regExp.match(scriptLine);
@@ -907,7 +922,7 @@ void PaintCommands::command_import(QRegularExpressionMatch re)
if (m_verboseMode) {
printf(" -(lance) Command buffer now looks like:\n");
- for (int i = 0; i < m_commands.count(); ++i)
+ for (int i = 0; i < m_commands.size(); ++i)
printf(" ---> {%s}\n", qPrintable(m_commands.at(i)));
}
delete file;
@@ -925,7 +940,7 @@ void PaintCommands::command_begin_block(QRegularExpressionMatch re)
m_commands[m_currentCommandIndex] = QLatin1String("# begin block (") + blockName + QLatin1Char(')');
QStringList newBlock;
int i = m_currentCommandIndex + 1;
- for (; i < m_commands.count(); ++i) {
+ for (; i < m_commands.size(); ++i) {
const QString &nextCmd = m_commands.at(i);
if (nextCmd.startsWith("end_block")) {
m_commands[i] = QLatin1String("# end block (") + blockName + QLatin1Char(')');
@@ -935,10 +950,10 @@ void PaintCommands::command_begin_block(QRegularExpressionMatch re)
}
if (m_verboseMode)
- for (int j = 0; j < newBlock.count(); ++j)
+ for (int j = 0; j < newBlock.size(); ++j)
printf(" %d: %s\n", j, qPrintable(newBlock.at(j)));
- if (i >= m_commands.count())
+ if (i >= m_commands.size())
printf(" - Warning! Block doesn't have an 'end_block' marker!\n");
m_blockMap.insert(blockName, newBlock);
@@ -1452,6 +1467,93 @@ void PaintCommands::command_fillRectF(QRegularExpressionMatch re)
}
}
+void PaintCommands::command_drawPixmapFragments(QRegularExpressionMatch re)
+{
+ QPixmap pm;
+ pm = m_pixmapMap[re.captured(1)]; // try cache first
+ if (pm.isNull())
+ pm = image_load<QPixmap>(re.captured(1));
+ if (pm.isNull()) {
+ QFileInfo fi(m_filepath);
+ QDir dir = fi.absoluteDir();
+ dir.cdUp();
+ dir.cd("images");
+ QString fileName = dir.absolutePath() + QLatin1Char('/') + re.captured(1);
+ pm = QPixmap(fileName);
+ if (pm.isNull() && !fileName.endsWith(".png")) {
+ fileName.append(".png");
+ pm = QPixmap(fileName);
+ }
+ }
+ if (pm.isNull()) {
+ fprintf(stderr, "ERROR(drawPixmapFragments): failed to load pixmap: '%s'\n",
+ qPrintable(re.captured(1)));
+ return;
+ }
+
+ int count = convertToInt(re.captured(2));
+
+ struct Fragment {
+ double posx;
+ double posy;
+ double srcx;
+ double srcy;
+ double srcw;
+ double srch;
+ double sx;
+ double sy;
+ double rotation;
+ double opacity;
+ };
+
+ QList<Fragment> fragments;
+ for (int i = 0; i < count; ++i) {
+ int captureIndexStart = 3 + i * 10;
+ if (re.hasCaptured(captureIndexStart)) {
+ Fragment f;
+ f.posx = convertToDouble(re.captured(captureIndexStart));
+ f.posy = convertToDouble(re.captured(captureIndexStart + 1));
+ f.srcx = convertToDouble(re.captured(captureIndexStart + 2));
+ f.srcy = convertToDouble(re.captured(captureIndexStart + 3));
+ f.srcw = convertToDouble(re.captured(captureIndexStart + 4));
+ f.srch = convertToDouble(re.captured(captureIndexStart + 5));
+ f.sx = convertToDouble(re.captured(captureIndexStart + 6));
+ f.sy = convertToDouble(re.captured(captureIndexStart + 7));
+ f.rotation = convertToDouble(re.captured(captureIndexStart + 8));
+ f.opacity = convertToDouble(re.captured(captureIndexStart + 9));
+ fragments.append(f);
+ } else {
+ break;
+ }
+ }
+
+ if (m_verboseMode) {
+ printf(" -(lance) drawPixmapFragments('%s' count=%d ",
+ qPrintable(re.captured(1)), int(fragments.count()));
+ for (int i = 0; i < fragments.count(); ++i) {
+ printf("pos=(%.2f, %.2f) srcrect=(%.2f %.2f %.2f %.2f) scale=(%.2f %.2f) rotation=%.2f opacity=%.2f ",
+ fragments[i].posx, fragments[i].posy,
+ fragments[i].srcx, fragments[i].srcy, fragments[i].srcw, fragments[i].srch,
+ fragments[i].sx, fragments[i].sy,
+ fragments[i].rotation,
+ fragments[i].opacity);
+ }
+ printf("\n");
+ }
+
+ QList<QPainter::PixmapFragment> pixmapFragments;
+ for (int i = 0; i < fragments.count(); ++i) {
+ pixmapFragments.append(
+ QPainter::PixmapFragment::create(QPointF(fragments[i].posx, fragments[i].posy),
+ QRectF(fragments[i].srcx, fragments[i].srcy, fragments[i].srcw, fragments[i].srch),
+ fragments[i].sx, fragments[i].sy,
+ fragments[i].rotation,
+ fragments[i].opacity));
+ }
+
+ m_painter->drawPixmapFragments(pixmapFragments.constData(), pixmapFragments.count(), pm);
+}
+
/***************************************************************************************************/
void PaintCommands::command_noop(QRegularExpressionMatch)
{