diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-07-04 17:24:04 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-07-05 12:35:26 +0000 |
commit | d866617ea68534c11d4983486609bc01e4d78e33 (patch) | |
tree | 2e8d5d159197ecec728c8fa031123d85ff2798ec /tests/auto/gui | |
parent | 03b4838cb51513bd5d2edf76dccc4bc4a1181681 (diff) |
Fix polygon stroking with cosmetic pen
Fix a number of issues that caused polygons to not always be drawn
fully connected.
Ensures the original lastPixel is set when drawing closed polygons,
ensure we don't round away from the original starting point, and add
handling of edges that need to be rounded half a pixel sideways to line
up with endpoints.
Task-number: QTBUG-27053
Change-Id: Ib51ee5623a629996af51a0967096383f04e91e2f
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
Diffstat (limited to 'tests/auto/gui')
-rw-r--r-- | tests/auto/gui/painting/qpainter/tst_qpainter.cpp | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/tests/auto/gui/painting/qpainter/tst_qpainter.cpp b/tests/auto/gui/painting/qpainter/tst_qpainter.cpp index 8db4489ec1..6b6869c2ba 100644 --- a/tests/auto/gui/painting/qpainter/tst_qpainter.cpp +++ b/tests/auto/gui/painting/qpainter/tst_qpainter.cpp @@ -303,6 +303,8 @@ private slots: void blendNullRGB32(); void toRGB64(); + void fillPolygon(); + private: void fillData(); void setPenColor(QPainter& p); @@ -5191,6 +5193,112 @@ void tst_QPainter::toRGB64() } } +void tst_QPainter::fillPolygon() +{ + QImage image(50, 50, QImage::Format_RGB32); + image.fill(Qt::white); + + QPainter painter(&image); + QBrush brush(Qt::black, Qt::SolidPattern); + painter.setBrush(brush); + + QPen pen(Qt::red, 0, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin); + painter.setPen(pen); + + const QPoint diamondpoints[5] = { + QPoint(-15, 0), + QPoint(0, -15), + QPoint(15, 0), + QPoint(0, 15), + QPoint(-15, 0) + }; + enum { Outside1, Border1, Inside, Border2, Outside2 } state; + + for (int i = 0; i < 16 ; i++) + { + for (int j = 0; j < 16 ; j++) + { + image.fill(Qt::white); + painter.resetTransform(); + painter.translate(25 + i/16., 25 + j/16.); + painter.drawPolygon(diamondpoints, 5); + + for (int x = 0; x < 50; x++) { + state = Outside1; + for (int y = 0; y < 50; y++) { + QRgb c = image.pixel(x, y); + switch (state) { + case Outside1: + if (c == QColor(Qt::red).rgb()) + state = Border1; + else + QCOMPARE(c, QColor(Qt::white).rgb()); + break; + case Border1: + if (c == QColor(Qt::black).rgb()) + state = Inside; + else if (c == QColor(Qt::white).rgb()) + state = Outside2; + else + QCOMPARE(c, QColor(Qt::red).rgb()); + break; + case Inside: + if (c == QColor(Qt::red).rgb()) + state = Border2; + else + QCOMPARE(c, QColor(Qt::black).rgb()); + break; + case Border2: + if (c == QColor(Qt::white).rgb()) + state = Outside2; + else + QCOMPARE(c, QColor(Qt::red).rgb()); + break; + case Outside2: + QCOMPARE(c, QColor(Qt::white).rgb()); + } + } + } + for (int y = 0; y < 50; y++) { + state = Outside1; + for (int x = 0; x < 50; x++) { + QRgb c = image.pixel(x, y); + switch (state) { + case Outside1: + if (c == QColor(Qt::red).rgb()) + state = Border1; + else + QCOMPARE(c, QColor(Qt::white).rgb()); + break; + case Border1: + if (c == QColor(Qt::black).rgb()) + state = Inside; + else if (c == QColor(Qt::white).rgb()) + state = Outside2; + else + QCOMPARE(c, QColor(Qt::red).rgb()); + break; + case Inside: + if (c == QColor(Qt::red).rgb()) + state = Border2; + else + QCOMPARE(c, QColor(Qt::black).rgb()); + break; + case Border2: + if (c == QColor(Qt::white).rgb()) + state = Outside2; + else + QCOMPARE(c, QColor(Qt::red).rgb()); + break; + case Outside2: + QCOMPARE(c, QColor(Qt::white).rgb()); + } + } + } + } + } +} + QTEST_MAIN(tst_QPainter) #include "tst_qpainter.moc" |