From 39de55eebf0641bd32fd0af9be7e2f50a9e2bbbc Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Sun, 20 Jul 2014 22:30:49 +0200 Subject: [PATCH] If the dpi calculations don't give a reasonably square pixel fallback to other methods BUGS: 336018 FIXED-IN: 4.14.0 --- core/utils.cpp | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/core/utils.cpp b/core/utils.cpp index 7f1a7eac8..a3558b066 100644 --- a/core/utils.cpp +++ b/core/utils.cpp @@ -150,7 +150,11 @@ QSizeF Utils::realDpi(QWidget* widgetOnScreen) kDebug() << "Output is vertical, transposing DPI rect"; res.transpose(); } - return res; + if (qAbs(res.width() - res.height()) / qMin(res.height(), res.width()) < 0.05) { + return res; + } else { + kDebug() << "KScreen calculation returned a non square dpi." << res << ". Falling back"; + } } } else @@ -166,7 +170,22 @@ QSizeF Utils::realDpi(QWidget* widgetOnScreen) } // this is also fallback for LibKScreen branch if KScreen::Output // for particular widget was not found - return QSizeF(realDpiX(), realDpiY()); + QSizeF res = QSizeF(realDpiX(), realDpiY()); + if (qAbs(res.width() - res.height()) / qMin(res.height(), res.width()) < 0.05) { + return res; + } else { + kDebug() << "QDesktopWidget calculation returned a non square dpi." << res << ". Falling back"; + } + + res = QSizeF(dpiX(), dpiY()); + if (qAbs(res.width() - res.height()) / qMin(res.height(), res.width()) < 0.05) { + return res; + } else { + kDebug() << "QX11Info returned a non square dpi." << res << ". Falling back"; + } + + res = QSizeF(72, 72); + return res; } #elif defined(Q_WS_MAC)