From d5c6335ff3f86616b49a8ca0cb6f4991ff5dfef9 Mon Sep 17 00:00:00 2001 From: Eirik Aavitsland Date: Thu, 19 Mar 2015 08:46:56 +0100 Subject: Fix rasterization errors in aliased cosmetic drawPolyLine If a cosmetic polyline contained a 1-pixel segment, the next segment would be drawn with wrong starting point. The original fix for QTBUG-26156 had some unwanted side effects (QTBUG-31579 and now QTBUG-42398). It tried to skip start-point update if stroke() did not actually draw anything (because the segment was too small). However, to determine that, it tested for a change in lastPixel. But that was not failsafe; in some cases (1-pixel segment), lastPixel could be unchanged even though the segment had been drawn. With this change, we instead test directly whether stroke() skipped the segment or not. Task-number: QTBUG-42398 Change-Id: Id751db69a18cd1af4f45070db9d5698aa532d22a Reviewed-by: Allan Sandfeld Jensen --- tests/auto/gui/painting/qpainter/tst_qpainter.cpp | 37 +++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'tests/auto/gui/painting') diff --git a/tests/auto/gui/painting/qpainter/tst_qpainter.cpp b/tests/auto/gui/painting/qpainter/tst_qpainter.cpp index 8a0705630d..bf19a04203 100644 --- a/tests/auto/gui/painting/qpainter/tst_qpainter.cpp +++ b/tests/auto/gui/painting/qpainter/tst_qpainter.cpp @@ -290,6 +290,10 @@ private slots: void RasterOp_NotDestination(); void drawTextNoHinting(); + + void drawPolyline_data(); + void drawPolyline(); + private: void fillData(); void setPenColor(QPainter& p); @@ -4828,6 +4832,39 @@ void tst_QPainter::drawTextNoHinting() QVERIFY(true); } +void tst_QPainter::drawPolyline_data() +{ + QTest::addColumn< QVector >("points"); + + QTest::newRow("basic") << (QVector() << QPointF(10, 10) << QPointF(20, 10) << QPointF(20, 20) << QPointF(10, 20)); + QTest::newRow("clipped") << (QVector() << QPoint(-10, 100) << QPoint(-1, 100) << QPoint(-1, -2) << QPoint(100, -2) << QPoint(100, 40)); // QTBUG-31579 + QTest::newRow("shortsegment") << (QVector() << QPoint(20, 100) << QPoint(20, 99) << QPoint(21, 99) << QPoint(21, 104)); // QTBUG-42398 +} + +void tst_QPainter::drawPolyline() +{ + QFETCH(QVector, points); + QImage images[2]; + + for (int r = 0; r < 2; r++) { + images[r] = QImage(150, 150, QImage::Format_ARGB32); + images[r].fill(Qt::transparent); + QPainter p(images + r); + QPen pen(Qt::red, 0, Qt::SolidLine, Qt::FlatCap); + p.setPen(pen); + QVERIFY(p.pen().isCosmetic()); + if (r) { + for (int i = 0; i < points.count()-1; i++) { + p.drawLine(points.at(i), points.at(i+1)); + } + } else { + p.drawPolyline(points); + } + } + + QCOMPARE(images[0], images[1]); +} + QTEST_MAIN(tst_QPainter) #include "tst_qpainter.moc" -- cgit v1.2.3