summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/gui/painting/qrasterizer.cpp41
-rw-r--r--tests/auto/qpainter/tst_qpainter.cpp22
2 files changed, 39 insertions, 24 deletions
diff --git a/src/gui/painting/qrasterizer.cpp b/src/gui/painting/qrasterizer.cpp
index f8f8afb..61ed12e 100644
--- a/src/gui/painting/qrasterizer.cpp
+++ b/src/gui/painting/qrasterizer.cpp
@@ -718,17 +718,21 @@ void QRasterizer::rasterizeLine(const QPointF &a, const QPointF &b, qreal width,
QPointF pa = a;
QPointF pb = b;
- QPointF offs = QPointF(qAbs(b.y() - a.y()), qAbs(b.x() - a.x())) * width * 0.5;
- if (squareCap)
- offs += QPointF(offs.y(), offs.x());
+ if (squareCap) {
+ QPointF delta = pb - pa;
+ pa -= (0.5f * width) * delta;
+ pb += (0.5f * width) * delta;
+ }
+
+ QPointF offs = QPointF(qAbs(b.y() - a.y()), qAbs(b.x() - a.x())) * width * 0.5;
const QRectF clip(d->clipRect.topLeft() - offs, d->clipRect.bottomRight() + QPoint(1, 1) + offs);
- if (!clip.contains(a) || !clip.contains(b)) {
+ if (!clip.contains(pa) || !clip.contains(pb)) {
qreal t1 = 0;
qreal t2 = 1;
- const qreal o[2] = { a.x(), a.y() };
- const qreal d[2] = { b.x() - a.x(), b.y() - a.y() };
+ const qreal o[2] = { pa.x(), pa.y() };
+ const qreal d[2] = { pb.x() - pa.x(), pb.y() - pa.y() };
const qreal low[2] = { clip.left(), clip.top() };
const qreal high[2] = { clip.right(), clip.bottom() };
@@ -751,8 +755,12 @@ void QRasterizer::rasterizeLine(const QPointF &a, const QPointF &b, qreal width,
if (t1 >= t2)
return;
}
- pa = a + (b - a) * t1;
- pb = a + (b - a) * t2;
+
+ QPointF npa = pa + (pb - pa) * t1;
+ QPointF npb = pa + (pb - pa) * t2;
+
+ pa = npa;
+ pb = npb;
}
if (!d->antialiased) {
@@ -799,12 +807,7 @@ void QRasterizer::rasterizeLine(const QPointF &a, const QPointF &b, qreal width,
pa = QPointF(x, y - dy);
pb = QPointF(x, y + dy);
- if (squareCap)
- width = 1 / width + 1.0f;
- else
- width = 1 / width;
-
- squareCap = false;
+ width = 1 / width;
}
if (q16Dot16Compare(pa.x(), pb.x())) {
@@ -814,11 +817,6 @@ void QRasterizer::rasterizeLine(const QPointF &a, const QPointF &b, qreal width,
const qreal dy = pb.y() - pa.y();
const qreal halfWidth = 0.5f * width * dy;
- if (squareCap) {
- pa.ry() -= halfWidth;
- pb.ry() += halfWidth;
- }
-
qreal left = pa.x() - halfWidth;
qreal right = pa.x() + halfWidth;
@@ -899,11 +897,6 @@ void QRasterizer::rasterizeLine(const QPointF &a, const QPointF &b, qreal width,
delta *= 0.5f * width;
const QPointF perp(delta.y(), -delta.x());
- if (squareCap) {
- pa -= delta;
- pb += delta;
- }
-
QPointF top;
QPointF left;
QPointF right;
diff --git a/tests/auto/qpainter/tst_qpainter.cpp b/tests/auto/qpainter/tst_qpainter.cpp
index f358681..a94c300 100644
--- a/tests/auto/qpainter/tst_qpainter.cpp
+++ b/tests/auto/qpainter/tst_qpainter.cpp
@@ -252,6 +252,8 @@ private slots:
void QTBUG5939_attachPainterPrivate();
+ void drawPointScaled();
+
private:
void fillData();
void setPenColor(QPainter& p);
@@ -4522,6 +4524,26 @@ void tst_QPainter::QTBUG5939_attachPainterPrivate()
QCOMPARE(widget->deviceTransform, proxy->deviceTransform);
}
+void tst_QPainter::drawPointScaled()
+{
+ QImage image(32, 32, QImage::Format_RGB32);
+ image.fill(0xffffffff);
+
+ QPainter p(&image);
+
+ p.scale(0.1, 0.1);
+
+ QPen pen;
+ pen.setWidth(1000);
+ pen.setColor(Qt::red);
+
+ p.setPen(pen);
+ p.drawPoint(0, 0);
+ p.end();
+
+ QCOMPARE(image.pixel(16, 16), 0xffff0000);
+}
+
QTEST_MAIN(tst_QPainter)
#include "tst_qpainter.moc"