[okular] [Bug 461996] displayed aspect ratio changes when switching monitors?

Laurent bugzilla_noreply at kde.org
Wed Mar 8 21:42:35 GMT 2023


https://bugs.kde.org/show_bug.cgi?id=461996

--- Comment #12 from Laurent <kde94a0183f4466752 at lpsink.fastmail.com> ---
Note that there is already a workaround in the code for dealing with Qt
returning bad DPI values:

https://invent.kde.org/graphics/okular/-/blob/master/core/utils.cpp#L54

> if (qAbs(res.width() - res.height()) / qMin(res.height(), res.width()) < 0.15) 

The code checks if the pixels are nonsquare by less than 15%. If not, it falls
back on a default of 72 DPI. If my computations are correct, lowering the
threshold to 10% would fix the problem for Eric.

The fallback could also be to force square pixels by discarding one axis,
instead of discarding all DPI information. Proposed patch:

diff --git a/core/utils.cpp b/core/utils.cpp
index 9f5f47244..fec40da94 100644
--- a/core/utils.cpp
+++ b/core/utils.cpp
@@ -51,10 +51,11 @@ QSizeF Utils::realDpi(const QWindow *windowOnScreen)
     if (screen) {
         const QSizeF res(screen->physicalDotsPerInchX(),
screen->physicalDotsPerInchY());
         if (res.width() > 0 && res.height() > 0) {
-            if (qAbs(res.width() - res.height()) / qMin(res.height(),
res.width()) < 0.15) {
+            if (qAbs(res.width() - res.height()) / qMin(res.height(),
res.width()) < 0.10) {
                 return res;
             } else {
                 qCDebug(OkularCoreDebug) << "QScreen calculation returned a
non square dpi." << res << ". Falling back";
+                return QSizeF(res.width(), res.width());
             }
         }
     }

-- 
You are receiving this mail because:
You are the assignee for the bug.


More information about the Okular-devel mailing list