diff options
author | Eirik Aavitsland <eirik.aavitsland@qt.io> | 2023-11-23 12:10:24 +0100 |
---|---|---|
committer | Eirik Aavitsland <eirik.aavitsland@qt.io> | 2023-11-28 19:47:56 +0100 |
commit | 7706c2a28ea5995f828144e39b8d1662aa263aa2 (patch) | |
tree | 6cb60f555eeccd50e6d8cef0db16b42be8593942 /src/gui/painting/qcosmeticstroker.cpp | |
parent | c39844c78ea79960c9181ddea50a1c65b5283a73 (diff) |
Raster painting: Correct the coordinate rounding in drawPoints()
When using the cosmetic stroker (i.e. plain pens with effective line
width of 1), drawing points with fractional coordinates >= 0.5 would
fill the wrong pixel.
This is a long-standing bug where the drawPoints() code in the
cosmetic stroker code was missed during the painting coordinate system
shift for Qt 5.0. Prior to that, coordinates were interpreted as the
upper left corner of a pixel, so rounding fractional coordinates to
the closest integer would be the correct way to determine the pixel to
be filled. From Qt 5 onwards however, coordinates instead designate
the center point of the primitive to be stroked. In order to determine
which pixel is most covered by the unit square centered in the given
coordinates, fractional coordinates must be rounded downwards
(floored).
This fix makes the behavior consistent between the cosmetic and
non-cosmetic stroker, so that drawPoints() with e.g. penwidths 1 and
1.01 in practice fills the same pixels.
Pick-to: 6.6
Fixes: QTBUG-119306
Change-Id: I39cb7ad55229553dda098e6fbc9ee449b1fd9664
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
Diffstat (limited to 'src/gui/painting/qcosmeticstroker.cpp')
-rw-r--r-- | src/gui/painting/qcosmeticstroker.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/gui/painting/qcosmeticstroker.cpp b/src/gui/painting/qcosmeticstroker.cpp index f555b56adb..a0eddf65d9 100644 --- a/src/gui/painting/qcosmeticstroker.cpp +++ b/src/gui/painting/qcosmeticstroker.cpp @@ -364,7 +364,7 @@ void QCosmeticStroker::drawPoints(const QPoint *points, int num) const QPoint *end = points + num; while (points < end) { QPointF p = QPointF(*points) * state->matrix; - drawPixel(this, qRound(p.x()), qRound(p.y()), 255); + drawPixel(this, std::floor(p.x()), std::floor(p.y()), 255); ++points; } @@ -377,7 +377,7 @@ void QCosmeticStroker::drawPoints(const QPointF *points, int num) const QPointF *end = points + num; while (points < end) { QPointF p = (*points) * state->matrix; - drawPixel(this, qRound(p.x()), qRound(p.y()), 255); + drawPixel(this, std::floor(p.x()), std::floor(p.y()), 255); ++points; } |