14.18 round 2: size fields read Swift's Int field, the mask and a tall page tested

This commit is contained in:
ZacharyZhang-NY committed 2026-10-11 09:58:21 -04:00
1 parent cd31454815
commit b66ef3c8ea
5 files changed
+55 -16

No files matched your search

+17
View File
@@ -345,6 +345,23 @@ void ExportAsSheetTests::theSizeKeepsTheProportionsWithinTheLimits()
// The surface's limit caps a growth: 312.5 times here.
type(width, "100000");
QVERIFY(width.text() == "20000" && height.text() == "10000");
// Swift's Int field: past Int32, exponents, fractions truncated.
const auto both = [&](QLineEdit &field, const char *typed) {
type(field, QString::fromLatin1(typed));
return width.text() + QLatin1Char('x') + height.text();
};
QCOMPARE(both(width, "1e3"), QString("1000x500"));
QCOMPARE(both(height, "2147483648"), QString("20000x10000"));
QCOMPARE(both(width, " 12.7 "), QString("12x6"));
QCOMPARE(both(width, "1E2"), QString("100x50"));
QCOMPARE(both(height, "-12.7"), QString("1x1"));
QCOMPARE(both(width, "9223372036854775807"), QString("20000x10000"));
QCOMPARE(both(width, "64"), QString("64x32"));
// Past Int64, or grouped, Swift reads nothing here.
QCOMPARE(both(width, "9223372036854775808"), QString("64x32"));
QCOMPARE(both(width, "1e19"), QString("64x32"));
QCOMPARE(both(width, "-1e19"), QString("64x32"));
QCOMPARE(both(width, "1,000"), QString("64x32"));
// The menu's steps.
QStringList steps;
for (QAction *each : scale.menu()->actions())
+5 -7
View File
@@ -1,6 +1,5 @@
#include "AddressSpaceLimit.h"
#include "IO/ImageExporter.h"
#include <QThreadPool>
#include <QtEndian>
#include <QtTest>
#include <malloc.h>
@@ -30,7 +29,7 @@ QList<QByteArray> inflated(const QByteArray &pdf)
void ExportPDFFailureTests::aStarvedPDFThrowsOrIsWhole()
{
// Noise, so the compressed streams stay near their size.
QImage noise(1000, 1000, QImage::Format_RGBA8888_Premultiplied);
QImage noise(360, 360, QImage::Format_RGBA8888_Premultiplied);
quint32 seed = 7;
for (int y = 0; y < noise.height(); ++y) {
auto *row = reinterpret_cast<quint32 *>(noise.scanLine(y));
@@ -38,14 +37,13 @@ void ExportPDFFailureTests::aStarvedPDFThrowsOrIsWhole()
row[x] = (seed = seed * 1664525u + 1013904223u) | 0xff000000u;
}
const ExportRaster raster{noise, 72};
// Qt converts on pool threads: start them before any limit.
QThreadPool::globalInstance()->setExpiryTimeout(-1);
// Under 2^17 pixels Qt converts on this thread alone.
ImageExporter::pdfData(raster);
int refused = 0, whole = 0;
for (qint64 megabytes = 2; megabytes <= 48; ++megabytes) {
for (qint64 kilobytes = 64; kilobytes <= 4096; kilobytes += 32) {
QByteArray pdf;
try {
const AddressSpaceLimit limit(megabytes << 20);
const AddressSpaceLimit limit(kilobytes << 10);
pdf = ImageExporter::pdfData(raster);
} catch (const ExportError &error) {
QCOMPARE(error.kind, ExportError::Kind::render);
@@ -54,7 +52,7 @@ void ExportPDFFailureTests::aStarvedPDFThrowsOrIsWhole()
}
const QList<QByteArray> streams = inflated(pdf);
QCOMPARE(streams.size(), qsizetype(2));
QVERIFY2(streams[0].size() == 1000 * 1000 * 3 && streams[1].size() == 1000 * 1000, qPrintable(QString::number(megabytes)));
QVERIFY2(streams[0].size() == 360 * 360 * 3 && streams[1].size() == 360 * 360, qPrintable(QString::number(kilobytes)));
++whole;
}
// The sweep reaches both sides of the limit.
+10
View File
@@ -87,6 +87,16 @@ void ExportPDFTests::pdfIsOnePageAtThePrintedSizeWithLosslessPixels()
const QByteArray rows = ImageExporter::pdfData(ExportRaster{grid, 72});
QCOMPARE(streamOf(object(rows, 5)), QByteArray("\x0a\x64\xc8\x1e\x5a\xcd\x32\x82\x96\x46\x78\x9b\x5a\xa0\x64\x6e\x96\x69", 18));
QVERIFY(object(rows, 5).contains("/Width 2 /Height 3"));
// A tall page draws its image tall: 2 by 3.
QVERIFY(object(rows, 3).contains("/MediaBox [0 0 2.0000 3.0000]"));
QCOMPARE(streamOf(object(rows, 4)), QByteArray("q\n2.0000 0 0 3.0000 0 0 cm /Im0 Do\nQ"));
// The mask's rows and columns where the pixels are.
QImage clear = BrushRaster::context(2, 3, false);
clear.setPixel(1, 0, qRgba(0, 0, 255, 255));
clear.setPixel(0, 2, qRgba(0, 64, 0, 64));
const QByteArray masked = ImageExporter::pdfData(ExportRaster{clear, 72});
QCOMPARE(streamOf(object(masked, 6)), QByteArray("\x00\xff\x00\x00\x40\x00", 6));
QCOMPARE(streamOf(object(masked, 5)), QByteArray("\x00\x00\x00\x00\x00\xff\x00\x00\x00\x00\x00\x00\x00\xff\x00\x00\x00\x00", 18));
// A soft edge goes straight: colour whole, alpha apart.
QImage soft = BrushRaster::context(1, 1, false);
soft.setPixelColor(0, 0, QColor(255, 0, 0, 128));