summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamuel Rødal <samuel.rodal@digia.com>2012-09-20 13:30:24 (GMT)
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-09-25 13:35:09 (GMT)
commit87cd2d3530dfd3d7dc78b7dab50aefde87ca3b16 (patch)
tree929cdf900ec7087ead0b0fad1ce0d3870fbfb73c
parentf6bd9714a956000b18045576f648431ea569f9e8 (diff)
downloadQt-87cd2d3530dfd3d7dc78b7dab50aefde87ca3b16.zip
Qt-87cd2d3530dfd3d7dc78b7dab50aefde87ca3b16.tar.gz
Qt-87cd2d3530dfd3d7dc78b7dab50aefde87ca3b16.tar.bz2
Fixed inconsistent rounding of square cap pens.
A horizontal line should round up at the same time as a vertical line with square cap, when rendering at subpixel coordinates. Thus, the special casing in the cosmetic stroker of offsetting by half a pixel should be for flat caps instead of for square caps. Task-number: QTBUG-26013 (cherry picked from commit 72aaba336c7afe6d79d59995bfb31a8effca4e9e) Change-Id: If7e7c6b6e37c5b1ce4685012a11fd29ff0b1df5a Reviewed-by: Lars Knoll <lars.knoll@digia.com>
-rw-r--r--src/gui/painting/qcosmeticstroker.cpp20
-rw-r--r--tests/auto/qpainter/tst_qpainter.cpp30
2 files changed, 40 insertions, 10 deletions
diff --git a/src/gui/painting/qcosmeticstroker.cpp b/src/gui/painting/qcosmeticstroker.cpp
index 7517cc8..9ed8e85 100644
--- a/src/gui/painting/qcosmeticstroker.cpp
+++ b/src/gui/painting/qcosmeticstroker.cpp
@@ -409,7 +409,7 @@ void QCosmeticStroker::calculateLastPoint(qreal rx1, qreal ry1, qreal rx2, qreal
if (clipLine(rx1, ry1, rx2, ry2))
return;
- const int half = 32;
+ const int half = 31;
int x1 = toF26Dot6(rx1) + half;
int y1 = toF26Dot6(ry1) + half;
int x2 = toF26Dot6(rx2) + half;
@@ -429,8 +429,8 @@ void QCosmeticStroker::calculateLastPoint(qreal rx1, qreal ry1, qreal rx2, qreal
int xinc = F16Dot16FixedDiv(x2 - x1, y2 - y1);
int x = x1 << 10;
- int y = y1 >> 6;
- int ys = y2 >> 6;
+ int y = (y1 + 32) >> 6;
+ int ys = (y2 + 32) >> 6;
if (y != ys) {
x += ( ((((y << 6) + 32 - y1))) * xinc ) >> 6;
@@ -460,8 +460,8 @@ void QCosmeticStroker::calculateLastPoint(qreal rx1, qreal ry1, qreal rx2, qreal
int yinc = F16Dot16FixedDiv(y2 - y1, x2 - x1);
int y = y1 << 10;
- int x = x1 >> 6;
- int xs = x2 >> 6;
+ int x = (x1 + 32) >> 6;
+ int xs = (x2 + 32) >> 6;
if (x != xs) {
y += ( ((((x << 6) + 32 - x1))) * yinc ) >> 6;
@@ -703,7 +703,7 @@ static void drawLine(QCosmeticStroker *stroker, qreal rx1, qreal ry1, qreal rx2,
if (stroker->clipLine(rx1, ry1, rx2, ry2))
return;
- static const int half = 32;
+ static const int half = 31;
int x1 = toF26Dot6(rx1) + half;
int y1 = toF26Dot6(ry1) + half;
int x2 = toF26Dot6(rx2) + half;
@@ -736,8 +736,8 @@ static void drawLine(QCosmeticStroker *stroker, qreal rx1, qreal ry1, qreal rx2,
capAdjust(caps, y1, y2, x, xinc);
- int y = y1 >> 6;
- int ys = y2 >> 6;
+ int y = (y1 + 32) >> 6;
+ int ys = (y2 + 32) >> 6;
if (y != ys) {
x += ( ((((y << 6) + 32 - y1))) * xinc ) >> 6;
@@ -811,8 +811,8 @@ static void drawLine(QCosmeticStroker *stroker, qreal rx1, qreal ry1, qreal rx2,
capAdjust(caps, x1, x2, y, yinc);
- int x = x1 >> 6;
- int xs = x2 >> 6;
+ int x = (x1 + 32) >> 6;
+ int xs = (x2 + 32) >> 6;
if (x != xs) {
y += ( ((((x << 6) + 32 - x1))) * yinc ) >> 6;
diff --git a/tests/auto/qpainter/tst_qpainter.cpp b/tests/auto/qpainter/tst_qpainter.cpp
index 9e98013..5d5f9c6 100644
--- a/tests/auto/qpainter/tst_qpainter.cpp
+++ b/tests/auto/qpainter/tst_qpainter.cpp
@@ -269,6 +269,8 @@ private slots:
void drawTextOutsideGuiThread();
+ void QTBUG26013_squareCapStroke();
+
private:
void fillData();
void setPenColor(QPainter& p);
@@ -4780,6 +4782,34 @@ void tst_QPainter::drawTextOutsideGuiThread()
QCOMPARE(referenceRendering, t.rendering);
}
+void tst_QPainter::QTBUG26013_squareCapStroke()
+{
+ QImage image(4, 4, QImage::Format_RGB32);
+
+ QPainter p(&image);
+ p.setPen(QPen(Qt::black, 0, Qt::SolidLine, Qt::SquareCap));
+
+ for (int i = 0; i < 3; ++i) {
+ qreal d = i / 3.0;
+
+ image.fill(0xffffffff);
+
+ p.drawLine(QLineF(0, d, 0, d + 2));
+ p.drawLine(QLineF(1, d, 3, d));
+
+ // ensure that a horizontal line and a vertical line with square cap round up (downwards) at the same time
+ QCOMPARE(image.pixel(0, 0), image.pixel(1, 0));
+
+ image.fill(0xffffffff);
+
+ p.drawLine(QLineF(d, 0, d + 2, 0));
+ p.drawLine(QLineF(d, 1, d, 3));
+
+ // ensure that a vertical line and a horizontal line with square cap round up (to the right) at the same time
+ QCOMPARE(image.pixel(0, 0), image.pixel(0, 1));
+ }
+}
+
QTEST_MAIN(tst_QPainter)
#include "tst_qpainter.moc"