diff options
Diffstat (limited to 'tests/baseline/shared/paintcommands.cpp')
-rw-r--r-- | tests/baseline/shared/paintcommands.cpp | 238 |
1 files changed, 181 insertions, 57 deletions
diff --git a/tests/baseline/shared/paintcommands.cpp b/tests/baseline/shared/paintcommands.cpp index d2e48688f9..a1d2b9e497 100644 --- a/tests/baseline/shared/paintcommands.cpp +++ b/tests/baseline/shared/paintcommands.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "paintcommands.h" #include <qdir.h> @@ -200,6 +175,12 @@ const char *PaintCommands::imageFormatTable[] = { "RGBA32FPx4_Premultiplied", }; +const char *PaintCommands::renderHintTable[] = { + "Antialiasing", + "SmoothPixmapTransform", + "NonCosmeticBrushPatterns" +}; + int PaintCommands::translateEnum(const char *table[], const QString &pattern, int limit) { QByteArray p = pattern.toLatin1().toLower(); @@ -338,7 +319,7 @@ void PaintCommands::staticInit() "pen_setCosmetic true"); DECL_PAINTCOMMAND("setRenderHint", command_setRenderHint, "^setRenderHint\\s+([\\w_0-9]*)\\s*(\\w*)$", - "setRenderHint <Antialiasing|SmoothPixmapTransform> <true|false>", + "setRenderHint <hint> <true|false>", "setRenderHint Antialiasing true"); DECL_PAINTCOMMAND("clearRenderHint", command_clearRenderHint, "^clearRenderHint$", @@ -488,6 +469,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, @@ -564,8 +559,12 @@ void PaintCommands::staticInit() "setClipPath mypath ReplaceClip"); DECL_PAINTCOMMAND("setClipRect", command_setClipRect, "^setClipRect\\s+(-?\\w*)\\s+(-?\\w*)\\s+(-?\\w*)\\s+(-?\\w*)\\s*(\\w*)$", - "setClipRect <x1> <y1> <x2> <y2> <clip operation enum>", - "setClipRect 0.0 0.0 10.0 10.0 ReplaceClip"); + "setClipRect <x> <y> <w> <h> <clip operation enum>", + "setClipRect 0 0 10 10 ReplaceClip"); + DECL_PAINTCOMMAND("setClipRectF", command_setClipRectF, + "^setClipRectF\\s+(-?[.\\w]*)\\s+(-?[.\\w]*)\\s+(-?[.\\w]*)\\s+(-?[.\\w]*)\\s*(\\w.*)$", + "setClipRectF <x> <y> <w> <h> <clip operation enum>", + "setClipRectF 0.1 0.2 10.3 10.4 ReplaceClip"); DECL_PAINTCOMMAND("setClipping", command_setClipping, "^setClipping\\s+(\\w*)$", "setClipping <true|false>", @@ -686,6 +685,7 @@ void PaintCommands::staticInit() ADD_ENUMLIST("image formats", imageFormatTable); ADD_ENUMLIST("coordinate modes", coordinateMethodTable); ADD_ENUMLIST("size modes", sizeModeTable); + ADD_ENUMLIST("render hints", renderHintTable); } #undef DECL_PAINTCOMMAND @@ -745,8 +745,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); @@ -921,7 +921,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; @@ -939,7 +939,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(')'); @@ -949,10 +949,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); @@ -1466,6 +1466,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) { @@ -2082,6 +2169,25 @@ void PaintCommands::command_setClipRect(QRegularExpressionMatch re) } /***************************************************************************************************/ +void PaintCommands::command_setClipRectF(QRegularExpressionMatch re) +{ + QStringList caps = re.capturedTexts(); + double x = convertToDouble(caps.at(1)); + double y = convertToDouble(caps.at(2)); + double w = convertToDouble(caps.at(3)); + double h = convertToDouble(caps.at(4)); + + int combine = translateEnum(clipOperationTable, caps.at(5), Qt::IntersectClip + 1); + if (combine == -1) + combine = Qt::ReplaceClip; + + if (m_verboseMode) + printf(" -(lance) setClipRectF(%f, %f, %f, %f), %s\n", x, y, w, h, clipOperationTable[combine]); + + m_painter->setClipRect(QRectF(x, y, w, h), Qt::ClipOperation(combine)); +} + +/***************************************************************************************************/ void PaintCommands::command_setClipPath(QRegularExpressionMatch re) { int combine = translateEnum(clipOperationTable, re.captured(2), Qt::IntersectClip + 1); @@ -2121,19 +2227,27 @@ void PaintCommands::command_setFont(QRegularExpressionMatch re) { QStringList caps = re.capturedTexts(); QString family = caps.at(1); - int size = convertToInt(caps.at(2)); - - int weight = translateEnum(fontWeightTable, re.captured(3).toLower(), 5); - if (weight != -1) { - switch (weight) { - case 0: weight = QFont::Light; break; - case 1: weight = QFont::Normal; break; - case 2: weight = QFont::DemiBold; break; - case 3: weight = QFont::Bold; break; - case 4: weight = QFont::Black; break; - } - } else { - weight = convertToInt(re.captured(3)); + + int size = -1; // Default + QString sizeArg = caps.at(2); + if (!sizeArg.isEmpty()) + size = convertToInt(caps.at(2)); + + int weight = -1; // Default + QString weightArg = caps.at(3); + if (!weightArg.isEmpty()) { + weight = translateEnum(fontWeightTable, weightArg.toLower(), 5); + if (weight != -1) { + switch (weight) { + case 0: weight = QFont::Light; break; + case 1: weight = QFont::Normal; break; + case 2: weight = QFont::DemiBold; break; + case 3: weight = QFont::Bold; break; + case 4: weight = QFont::Black; break; + } + } else { + weight = convertToInt(weightArg); + } } bool italic = caps.at(4).toLower() == "true" || caps.at(4).toLower() == "italic"; @@ -2234,18 +2348,27 @@ void PaintCommands::command_setPen2(QRegularExpressionMatch re) void PaintCommands::command_setRenderHint(QRegularExpressionMatch re) { QString hintString = re.captured(1).toLower(); - bool on = re.captured(2).isEmpty() || re.captured(2).toLower() == "true"; - if (hintString.contains("antialiasing")) { - if (m_verboseMode) - printf(" -(lance) setRenderHint Antialiasing\n"); + QString setting = re.captured(2).toLower(); - m_painter->setRenderHint(QPainter::Antialiasing, on); + bool on = setting.isEmpty() || setting == "true" || setting == "on"; + QPainter::RenderHint hint; + int hintIdx = -1; + if (hintString.contains("antialiasing")) { + hintIdx = 0; + hint = QPainter::Antialiasing; } else if (hintString.contains("smoothpixmaptransform")) { + hintIdx = 1; + hint = QPainter::SmoothPixmapTransform; + } else if (hintString.contains("noncosmeticbrushpatterns")) { + hintIdx = 2; + hint = QPainter::NonCosmeticBrushPatterns; + } + if (hintIdx >= 0) { if (m_verboseMode) - printf(" -(lance) setRenderHint SmoothPixmapTransform\n"); - m_painter->setRenderHint(QPainter::SmoothPixmapTransform, on); + printf(" -(lance) setRenderHint %s %s\n", renderHintTable[hintIdx], on ? "true" : "false"); + m_painter->setRenderHint(hint, on); } else { - fprintf(stderr, "ERROR(setRenderHint): unknown hint '%s'\n", qPrintable(hintString)); + fprintf(stderr, "ERROR(setRenderHint): unknown hint '%s'\n", qPrintable(re.captured(1))); } } @@ -2254,6 +2377,7 @@ void PaintCommands::command_clearRenderHint(QRegularExpressionMatch /*re*/) { m_painter->setRenderHint(QPainter::Antialiasing, false); m_painter->setRenderHint(QPainter::SmoothPixmapTransform, false); + m_painter->setRenderHint(QPainter::NonCosmeticBrushPatterns, false); if (m_verboseMode) printf(" -(lance) clearRenderHint\n"); } |