From 87fc9a9a6fa74973a5812fb495615edb4df10e27 Mon Sep 17 00:00:00 2001 From: Suneel BS Date: Fri, 8 May 2009 10:03:53 +0530 Subject: Fixed path bug in the SVG module. In path, if 'moveto' is followed by multiple pairs of coordinates, those pairs shall be treated as 'lineto'. Autotest added by Kim. Reviewed-by: Kim --- src/svg/qsvghandler.cpp | 10 ++++++ tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp | 54 ++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/src/svg/qsvghandler.cpp b/src/svg/qsvghandler.cpp index 8185fc6..9486512 100644 --- a/src/svg/qsvghandler.cpp +++ b/src/svg/qsvghandler.cpp @@ -1377,6 +1377,11 @@ static bool parsePathDataFast(const QStringRef &dataStr, QPainterPath &path) y = y0 = arg[1] + offsetY; path.moveTo(x0, y0); arg.pop_front(); arg.pop_front(); + + // As per 1.2 spec 8.3.2 The "moveto" commands + // If a 'moveto' is followed by multiple pairs of coordinates without explicit commands, + // the subsequent pairs shall be treated as implicit 'lineto' commands. + pathElem = QLatin1Char('l'); } break; case 'M': { @@ -1389,6 +1394,11 @@ static bool parsePathDataFast(const QStringRef &dataStr, QPainterPath &path) path.moveTo(x0, y0); arg.pop_front(); arg.pop_front(); + + // As per 1.2 spec 8.3.2 The "moveto" commands + // If a 'moveto' is followed by multiple pairs of coordinates without explicit commands, + // the subsequent pairs shall be treated as implicit 'lineto' commands. + pathElem = QLatin1Char('L'); } break; case 'z': diff --git a/tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp b/tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp index d1c11ed..c7bfee8 100644 --- a/tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp +++ b/tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp @@ -77,6 +77,7 @@ private slots: void gradientStops() const; void fillRule(); void opacity(); + void paths(); #ifndef QT_NO_COMPRESS void testGzLoading(); @@ -788,6 +789,59 @@ void tst_QSvgRenderer::opacity() */ } +void tst_QSvgRenderer::paths() +{ + static const char *svgs[] = { + // Absolute coordinates, explicit commands. + "" + " " + " " + "", + // Absolute coordinates, implicit commands. + "" + " " + " " + "", + // Relative coordinates, explicit commands. + "" + " " + " " + "", + // Relative coordinates, implicit commands. + "" + " " + " " + "", + // Absolute coordinates, explicit commands, minimal whitespace. + "" + " " + " " + "", + // Absolute coordinates, explicit commands, extra whitespace. + "" + " " + " " + "" + }; + + const int COUNT = sizeof(svgs) / sizeof(svgs[0]); + QImage images[COUNT]; + QPainter p; + + for (int i = 0; i < COUNT; ++i) { + QByteArray data(svgs[i]); + QSvgRenderer renderer(data); + QVERIFY(renderer.isValid()); + images[i] = QImage(50, 50, QImage::Format_ARGB32_Premultiplied); + images[i].fill(0); + p.begin(&images[i]); + renderer.render(&p); + p.end(); + if (i != 0) { + QCOMPARE(images[i], images[0]); + } + } +} QTEST_MAIN(tst_QSvgRenderer) #include "tst_qsvgrenderer.moc" -- cgit v0.12