From 0806d9799a74a4d71699ea1499b24a18e264c329 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Thu, 7 Apr 2022 18:11:48 +0200 Subject: [PATCH] Fix misuses of 0.9999 constant Replace it with floor and round. It appears the old behavior was to work around combining ceil with inaccurate FP, but it doesn't appear this hacky ceil is needed. Change-Id: I5c16ec0fa4916e17198a733c46937fde53f2ddb5 Reviewed-by: Eirik Aavitsland --- src/gui/image/qimage.cpp | 9 ++------- src/gui/text/windows/qwindowsfontengine.cpp | 4 ++-- .../platforms/xcb/nativepainting/qpixmap_x11.cpp | 12 +++--------- 3 files changed, 7 insertions(+), 18 deletions(-) diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp index 11de984438..a9f9a98c2c 100644 --- a/src/gui/image/qimage.cpp +++ b/src/gui/image/qimage.cpp @@ -4783,13 +4783,8 @@ QImage QImage::transformed(const QTransform &matrix, Qt::TransformationMode mode else if (mat.m11() == -1. && mat.m22() == -1.) return rotated180(*this); - if (mode == Qt::FastTransformation) { - hd = qRound(qAbs(mat.m22()) * hs); - wd = qRound(qAbs(mat.m11()) * ws); - } else { - hd = int(qAbs(mat.m22()) * hs + 0.9999); - wd = int(qAbs(mat.m11()) * ws + 0.9999); - } + hd = qRound(qAbs(mat.m22()) * hs); + wd = qRound(qAbs(mat.m11()) * ws); scale_xform = true; // The paint-based scaling is only bilinear, and has problems // with scaling smoothly more than 2x down. diff --git a/src/gui/text/windows/qwindowsfontengine.cpp b/src/gui/text/windows/qwindowsfontengine.cpp index 06c21d930b..545b5459e2 100644 --- a/src/gui/text/windows/qwindowsfontengine.cpp +++ b/src/gui/text/windows/qwindowsfontengine.cpp @@ -626,8 +626,8 @@ qreal QWindowsFontEngine::minRightBearing() const fmr = qMin(fmr,abc[i].abcfC); } } - ml = int(fml - 0.9999); - mr = int(fmr - 0.9999); + ml = qFloor(fml); + mr = qFloor(fmr); delete [] abc; } lbearing = ml; diff --git a/src/plugins/platforms/xcb/nativepainting/qpixmap_x11.cpp b/src/plugins/platforms/xcb/nativepainting/qpixmap_x11.cpp index 2a84431cde..186a3cf9d7 100644 --- a/src/plugins/platforms/xcb/nativepainting/qpixmap_x11.cpp +++ b/src/plugins/platforms/xcb/nativepainting/qpixmap_x11.cpp @@ -1437,22 +1437,16 @@ QPixmap QX11PlatformPixmap::transformed(const QTransform &transform, Qt::Transfo transform.m21(), transform.m22(), transform.m23(), 0., 0., 1); bool complex_xform = false; - qreal scaledWidth; - qreal scaledHeight; if (mat.type() <= QTransform::TxScale) { - scaledHeight = qAbs(mat.m22()) * hs + 0.9999; - scaledWidth = qAbs(mat.m11()) * ws + 0.9999; - h = qAbs(int(scaledHeight)); - w = qAbs(int(scaledWidth)); + h = qRound(qAbs(mat.m22()) * hs); + w = qRound(qAbs(mat.m11()) * ws); } else { // rotation or shearing QPolygonF a(QRectF(0, 0, ws, hs)); a = mat.map(a); QRect r = a.boundingRect().toAlignedRect(); w = r.width(); h = r.height(); - scaledWidth = w; - scaledHeight = h; complex_xform = true; } mat = QPixmap::trueMatrix(mat, ws, hs); // true matrix @@ -1461,7 +1455,7 @@ QPixmap QX11PlatformPixmap::transformed(const QTransform &transform, Qt::Transfo mat = mat.inverted(&invertible); // invert matrix if (h == 0 || w == 0 || !invertible - || qAbs(scaledWidth) >= 32768 || qAbs(scaledHeight) >= 32768 ) + || qAbs(h) >= 32768 || qAbs(w) >= 32768 ) // error, return null pixmap return QPixmap();