14.3 round 1: print sizes tie to even; one trim of Foundation's .whitespaces, U+200B included, for New Canvas, validDimension and hex

This commit is contained in:
ZacharyZhang-NY committed 2026-10-11 03:12:40 -04:00
1 parent f8c1332c29
commit bb9b5c959e
8 files changed
+38 -26

No files matched your search

+2
View File
@@ -57,6 +57,8 @@ void ColorPickerTests::hexParsesFullShorthandAndRejectsInvalid()
// Swift trims tabs and wide spaces, never line breaks.
QCOMPARE(PaletteColor::fromHex(QStringLiteral("\t#abc") + QChar(0x00A0)), std::optional(PaletteColor{170.0 / 255, 187.0 / 255, 204.0 / 255}));
QVERIFY(!PaletteColor::fromHex(QStringLiteral("\n00ff00")));
// Foundation's .whitespaces holds U+200B too.
QCOMPARE(PaletteColor::fromHex(QChar(0x200B) + QStringLiteral("0f0") + QChar(0x200B)), std::optional(PaletteColor{0, 1, 0}));
// Its UInt32 takes signs, minus for zero only; no 0x.
QCOMPARE(PaletteColor::fromHex(QStringLiteral("+0F800")), std::optional(PaletteColor{0, 248.0 / 255, 0}));
QCOMPARE(PaletteColor::fromHex(QStringLiteral("-00000")), std::optional(PaletteColor::black()));
+1
View File
@@ -27,6 +27,7 @@ void CompositorTests::dimensionValidation()
QCOMPARE(CanvasDocument::validDimension(" 1920 "), std::optional<int>(1920));
QCOMPARE(CanvasDocument::validDimension("30000"), std::optional<int>(30000));
QCOMPARE(CanvasDocument::validDimension("\t+64\u00a0"), std::optional<int>(64));
QCOMPARE(CanvasDocument::validDimension(QChar(0x200B) + QString("64") + QChar(0x200B)), std::optional<int>(64));
QCOMPARE(CanvasDocument::validDimension("1920\n"), std::nullopt);
QCOMPARE(CanvasDocument::validDimension(QString::fromUtf8("1920\0px", 7)), std::nullopt);
QCOMPARE(CanvasDocument::validDimension("19 20"), std::nullopt);
+7
View File
@@ -28,6 +28,9 @@ void NewCanvasUnitTests::printSizesBecomePixelsAtTheDPI()
QCOMPARE(pixels(NewCanvasUnit::inches, "0.0016", 300), std::nullopt);
QCOMPARE(pixels(NewCanvasUnit::inches, " 1\t", 72), std::optional(72));
QCOMPARE(pixels(NewCanvasUnit::inches, "\t\u00a01", 72), std::optional(72));
// Foundation's .whitespaces holds U+200B; a line break is none.
QCOMPARE(pixels(NewCanvasUnit::inches, "\u200b1\u200b", 72), std::optional(72));
QCOMPARE(pixels(NewCanvasUnit::inches, "1\n", 72), std::nullopt);
// Infinity and NaN fail the range and the whole number.
QCOMPARE(pixels(NewCanvasUnit::inches, "inf", 72), std::nullopt);
QCOMPARE(pixels(NewCanvasUnit::pixels, "nan", 72), std::nullopt);
@@ -42,6 +45,10 @@ void NewCanvasUnitTests::unitsRoundTripAndCycle()
QCOMPARE(text(NewCanvasUnit::inches, 3000, 300), QString("10"));
QCOMPARE(text(NewCanvasUnit::millimeters, 2480, 300), QString("209.97"));
QCOMPARE(text(NewCanvasUnit::centimeters, 30000, 72), QString("1058.33"));
// Exact halves go to the even digit, as Foundation rounds.
QCOMPARE(text(NewCanvasUnit::inches, 153, 72), QString("2.12"));
QCOMPARE(text(NewCanvasUnit::inches, 9, 72), QString("0.12"));
QCOMPARE(text(NewCanvasUnit::inches, 27, 72), QString("0.38"));
QCOMPARE(text(NewCanvasUnit::pixels, 30000, 72), QString("30000"));
for (NewCanvasUnit unit : {NewCanvasUnit::inches, NewCanvasUnit::centimeters, NewCanvasUnit::millimeters})
QCOMPARE(pixels(unit, text(unit, 2550, 300), 300), std::optional(2550));