Skip to content

armgit / krita

Public Imported from GitHub
0

Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.

C++

Change the baseline tests from render tests to position tests.

Wolthera van Hövell tot Westerflier28d4511eac4a
diff --git a/libs/flake/tests/TestSvgText.cpp b/libs/flake/tests/TestSvgText.cpp
index b1a83f6849..4b97a9b8e4 100644
--- a/libs/flake/tests/TestSvgText.cpp
+++ b/libs/flake/tests/TestSvgText.cpp
@@ -585,14 +585,31 @@ void TestSvgText::testTextBaselineShift()
bool res = file.open(QIODevice::ReadOnly | QIODevice::Text);
QVERIFY2(res, QString("Cannot open test svg file.").toLatin1());
- SvgRenderTester t(file.readAll());
-
- t.setCheckQImagePremultiplied(true);
- t.test_standard("text_baseline_shift", QSize(180, 40), 72);
+ SvgTester t(file.readAll());
+ t.parser().setResolution(QRectF(0, 0, 180, 40) /* px */, 72 /* ppi */);
+ t.run();
KoSvgTextShape *baseShape = dynamic_cast<KoSvgTextShape*>(t.findShape("testRect"));
QVERIFY(baseShape);
+ QLineF caret;
+ QColor color;
+
+ baseShape->cursorForPos(0, caret, color);
+
+ QLine testCaret = QLine(QPoint(4,25),QPoint(4,10));
+ QVERIFY2(caret.toLine() == testCaret,
+ QString("Wrong caret for position 0, normal").toLatin1());
+
+ baseShape->cursorForPos(7, caret, color);
+ testCaret = QLine(QPoint(60,17),QPoint(60,2));
+ QVERIFY2(caret.toLine() == testCaret,
+ QString("Wrong caret for position 7, superscript").toLatin1());
+
+ baseShape->cursorForPos(17, caret, color);
+ testCaret = QLine(QPoint(141,27),QPoint(141,12));
+ QVERIFY2(caret.toLine() == testCaret,
+ QString("Wrong caret for position 17, subscript").toLatin1());
}
/**
* @brief TestSvgText::testTextSpacing
@@ -2454,9 +2471,10 @@ void TestSvgText::testTextWrap()
}
}
/**
- * Test baseline alignment. Within CSS text this is defined in CSS3-Inline,
- * however, it was originally part of SVG 1.1, and we implement that version
- * as it has the clearest implementation explanation.
+ * Test baseline alignment. Within CSS text this is defined in CSS3-Inline-3,
+ * and we now implement this version. The main difference between the two is that
+ * SVG 1.1/XSL 1.1 there is one baseline table over the whole paragraph, while in
+ * CSS-inline, the baseline-table is calculated per-span.
*
* This relies on different font-sizes, because otherwise all the baseline tables
* are exactly the same.
@@ -2467,9 +2485,36 @@ void TestSvgText::testTextBaselineAlignment()
bool res = file.open(QIODevice::ReadOnly | QIODevice::Text);
QVERIFY2(res, QString("Cannot open test svg file.").toLatin1());
- SvgRenderTester t(file.readAll());
- t.setFuzzyThreshold(5);
- t.test_standard("test-text-baseline-alignment", QSize(90, 51), 72.0);
+ SvgTester t(file.readAll());
+ t.parser().setResolution(QRectF(0, 0, 90, 51) /* px */, 72 /* ppi */);
+ t.run();
+
+ KoSvgTextShape *textShape = dynamic_cast<KoSvgTextShape*>(t.findShape("testRect"));
+
+ QVERIFY(textShape);
+
+ QLineF caret;
+ QColor color;
+ textShape->cursorForPos(0, caret, color);
+
+ QLine testCaret = QLine(QPoint(6,38),QPoint(6,23));
+ QVERIFY2(caret.toLine() == testCaret,
+ QString("Wrong caret for position 0").toLatin1());
+
+ textShape->cursorForPos(3, caret, color);
+ testCaret = QLine(QPoint(56,38),QPoint(56,8));
+ QVERIFY2(caret.toLine() == testCaret,
+ QString("Wrong caret for position 3").toLatin1());
+
+ textShape->cursorForPos(5, caret, color);
+ testCaret = QLine(QPoint(80,28),QPoint(80,23));
+ QVERIFY2(caret.toLine() == testCaret,
+ QString("Wrong caret for position 5").toLatin1());
+
+ textShape->cursorForPos(7, caret, color);
+ testCaret = QLine(QPoint(86,31),QPoint(86,26));
+ QVERIFY2(caret.toLine() == testCaret,
+ QString("Wrong caret for position 7").toLatin1());
}
void TestSvgText::testFontMetrics_data()
diff --git a/libs/flake/tests/data/fonts/textTestSvgs/test-text-baseline-alignment.svg b/libs/flake/tests/data/fonts/textTestSvgs/test-text-baseline-alignment.svg
index 998a0f93aa..24100eb70e 100644
--- a/libs/flake/tests/data/fonts/textTestSvgs/test-text-baseline-alignment.svg
+++ b/libs/flake/tests/data/fonts/textTestSvgs/test-text-baseline-alignment.svg
@@ -8,7 +8,7 @@
fill="none" stroke="red"/>
<text id="testRect" x="6" y="35"
- font-family="Baseline Test" font-size="15" fill="blue" >道道<tspan alignment-baseline="ideographic" font-size="30">LL</tspan><tspan alignment-baseline="text-top" font-size="5">LL</tspan>
+ font-family="Baseline Test" font-size="15" fill="blue" >道道<tspan alignment-baseline="ideographic" font-size="30">LL</tspan><tspan alignment-baseline="text-top" font-size="5">LL</tspan><tspan baseline-shift="super" font-size="5">LL</tspan>
</text>
</g>
diff --git a/libs/flake/tests/data/svg_render/load_test-text-baseline-alignment.png b/libs/flake/tests/data/svg_render/load_test-text-baseline-alignment.png
deleted file mode 100644
index dfff8a0f40..0000000000
Binary files a/libs/flake/tests/data/svg_render/load_test-text-baseline-alignment.png and /dev/null differ
diff --git a/libs/flake/tests/data/svg_render/load_text_baseline_shift.png b/libs/flake/tests/data/svg_render/load_text_baseline_shift.png
deleted file mode 100644
index 067d878d38..0000000000
Binary files a/libs/flake/tests/data/svg_render/load_text_baseline_shift.png and /dev/null differ