summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorSuneel BS <suneel.b-s@nokia.com>2009-05-08 09:17:36 (GMT)
committerKim Motoyoshi Kalland <kim.kalland@nokia.com>2009-06-22 13:26:13 (GMT)
commit2dcb97ff789dd7a9b7534348ca49c96c09783055 (patch)
treec74ba42af8bd8d7a66d395978bf5e464f43b7a35 /tests
parent51aba60ca75f6f094951d3ffaea803072db75d29 (diff)
downloadQt-2dcb97ff789dd7a9b7534348ca49c96c09783055.zip
Qt-2dcb97ff789dd7a9b7534348ca49c96c09783055.tar.gz
Qt-2dcb97ff789dd7a9b7534348ca49c96c09783055.tar.bz2
Fixed fill-rule for polygon SVG element.
Polygon element should apply the fill rule which is specified in its fill-rule attribute. Default fill rule is 'WindingFill' (nonzero). Modified and autotest added by Kim. Reviewed-by: Kim
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp72
1 files changed, 58 insertions, 14 deletions
diff --git a/tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp b/tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp
index e8cb089..b148f8c 100644
--- a/tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp
+++ b/tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp
@@ -331,7 +331,7 @@ void tst_QSvgRenderer::nestedQXmlStreamReader() const
QCOMPARE(reader.readNext(), QXmlStreamReader::StartDocument);
QCOMPARE(reader.readNext(), QXmlStreamReader::StartElement);
QCOMPARE(reader.name().toString(), QLatin1String("bar"));
-
+
QPicture picture;
QPainter painter(&picture);
QSvgRenderer renderer(&reader);
@@ -653,22 +653,66 @@ void tst_QSvgRenderer::testGzHelper()
void tst_QSvgRenderer::fillRule()
{
- QByteArray data(
+ static const char *svgs[] = {
+ // Paths
+ // Default fill-rule (nonzero)
"<svg>"
- "<rect x=\"0\" y=\"0\" height=\"300\" width=\"400\" fill=\"blue\" />"
- "<path d=\"M100 200 L300 200 L300 100 L100 100 M100 200 L300 200 L300 100 L100 100 Z\" fill=\"red\" stroke=\"black\" />"
- "</svg>");
-
- QSvgRenderer renderer(data);
-
- QImage image(128, 128, QImage::Format_ARGB32_Premultiplied);
- image.fill(0);
+ " <rect x=\"0\" y=\"0\" height=\"30\" width=\"30\" fill=\"blue\" />"
+ " <path d=\"M10 0 L30 0 L30 30 L0 30 L0 10 L20 10 L20 20 L10 20 Z\" fill=\"red\" />"
+ "</svg>",
+ // nonzero
+ "<svg>"
+ " <rect x=\"0\" y=\"0\" height=\"30\" width=\"30\" fill=\"blue\" />"
+ " <path d=\"M10 0 L30 0 L30 30 L0 30 L0 10 L20 10 L20 20 L10 20 Z\" fill=\"red\" fill-rule=\"nonzero\" />"
+ "</svg>",
+ // evenodd
+ "<svg>"
+ " <rect x=\"0\" y=\"0\" height=\"30\" width=\"30\" fill=\"blue\" />"
+ " <path d=\"M10 0 L30 0 L30 30 L0 30 L0 10 L20 10 L20 20 L10 20 Z\" fill=\"red\" fill-rule=\"evenodd\" />"
+ "</svg>",
- QPainter painter(&image);
- renderer.render(&painter);
- painter.end();
+ // Polygons
+ // Default fill-rule (nonzero)
+ "<svg>"
+ " <rect x=\"0\" y=\"0\" height=\"30\" width=\"30\" fill=\"blue\" />"
+ " <polygon points=\"10 0 30 0 30 30 0 30 0 10 20 10 20 20 10 20\" fill=\"red\" />"
+ "</svg>",
+ // nonzero
+ "<svg>"
+ " <rect x=\"0\" y=\"0\" height=\"30\" width=\"30\" fill=\"blue\" />"
+ " <polygon points=\"10 0 30 0 30 30 0 30 0 10 20 10 20 20 10 20\" fill=\"red\" fill-rule=\"nonzero\" />"
+ "</svg>",
+ // evenodd
+ "<svg>"
+ " <rect x=\"0\" y=\"0\" height=\"30\" width=\"30\" fill=\"blue\" />"
+ " <polygon points=\"10 0 30 0 30 30 0 30 0 10 20 10 20 20 10 20\" fill=\"red\" fill-rule=\"evenodd\" />"
+ "</svg>"
+ };
- QCOMPARE(image.pixel(64, 64), QColor(Qt::red).rgba());
+ const int COUNT = sizeof(svgs) / sizeof(svgs[0]);
+ QImage refImageNonZero(30, 30, QImage::Format_ARGB32_Premultiplied);
+ QImage refImageEvenOdd(30, 30, QImage::Format_ARGB32_Premultiplied);
+ refImageNonZero.fill(0xffff0000);
+ refImageEvenOdd.fill(0xffff0000);
+ QPainter p;
+ p.begin(&refImageNonZero);
+ p.fillRect(QRectF(0, 0, 10, 10), Qt::blue);
+ p.end();
+ p.begin(&refImageEvenOdd);
+ p.fillRect(QRectF(0, 0, 10, 10), Qt::blue);
+ p.fillRect(QRectF(10, 10, 10, 10), Qt::blue);
+ p.end();
+
+ for (int i = 0; i < COUNT; ++i) {
+ QByteArray data(svgs[i]);
+ QSvgRenderer renderer(data);
+ QImage image(30, 30, QImage::Format_ARGB32_Premultiplied);
+ image.fill(0);
+ p.begin(&image);
+ renderer.render(&p);
+ p.end();
+ QCOMPARE(image, i % 3 == 2 ? refImageEvenOdd : refImageNonZero);
+ }
}
QTEST_MAIN(tst_QSvgRenderer)