From 72cc2941569c387c3202fc2aca26a8bedd68f37f Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Wed, 14 Feb 2024 14:45:20 +0100 Subject: [PATCH] AppleIconEngine: fix aspect ratio adjustment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The requested icon might not be square, so fit the image we have correctly into the requested size. Fixes: QTBUG-121764 Change-Id: I877dedf5aa779cd82a75a1a49b26c08e3cea6163 Reviewed-by: Tor Arne Vestbø (cherry picked from commit 5b993fa8ede67871a8b2434505bc3c3d8bb906c6) Reviewed-by: Qt Cherry-pick Bot --- src/gui/platform/darwin/qappleiconengine.mm | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/gui/platform/darwin/qappleiconengine.mm b/src/gui/platform/darwin/qappleiconengine.mm index 154d3b79bb4..049bd827f96 100644 --- a/src/gui/platform/darwin/qappleiconengine.mm +++ b/src/gui/platform/darwin/qappleiconengine.mm @@ -185,18 +185,19 @@ QPixmap QAppleIconEngine::scaledPixmap(const QSize &size, QIcon::Mode mode, QIco } const auto *image = configuredImage(m_image, color); - // the size we want is typically square, but the icon might not be. So - // ask for a pixmap with the same aspect ratio as the icon, and then - // center that within a pixmap of the requested size. + // The size we want might have a different aspect ratio than the icon we have. + // So ask for a pixmap with the same aspect ratio as the icon, constrained to the + // size we want, and then center that within a pixmap of the requested size. QSizeF renderSize = size * scale; - const bool aspectRatioAdjusted = image.size.width != image.size.height; + const double inputAspectRatio = image.size.width / image.size.height; + const double outputAspectRatio = size.width() / size.height(); + const bool aspectRatioAdjusted = !qFuzzyCompare(inputAspectRatio, outputAspectRatio); if (aspectRatioAdjusted) { - double aspectRatio = image.size.width / image.size.height; // don't grow - if (aspectRatio < 1) - renderSize.rwidth() = renderSize.height() * aspectRatio; + if (outputAspectRatio > inputAspectRatio) + renderSize.rwidth() = renderSize.height() * inputAspectRatio; else - renderSize.rheight() = renderSize.width() / aspectRatio; + renderSize.rheight() = renderSize.width() / inputAspectRatio; } QPixmap iconPixmap = imageToPixmap(image, renderSize);