From 399f64beeff51e94fc29f02f085788d883049034 Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Tue, 9 Jun 2009 00:45:02 +0000 Subject: [PATCH] Introduce realDpi{X,Y}(), that (on X11) can return the ral DPI values w/o any Xrdb setting. Otherwise, they return the same as dpi{X,Y}(). svn path=/trunk/KDE/kdegraphics/okular/; revision=979128 --- core/utils.cpp | 35 ++++++++++++++++++++++++++++++++++- core/utils.h | 20 ++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/core/utils.cpp b/core/utils.cpp index 93cf76446..5dd84484f 100644 --- a/core/utils.cpp +++ b/core/utils.cpp @@ -12,6 +12,8 @@ #include "utils_p.h" #include +#include +#include #include #include @@ -67,6 +69,18 @@ double Utils::dpiY() return QX11Info::appDpiY(); } +double Utils::realDpiX() +{ + const QDesktopWidget* w = QApplication::desktop(); + return (double(w->width()) * 25.4) / double(w->widthMM()); +} + +double Utils::realDpiY() +{ + const QDesktopWidget* w = QApplication::desktop(); + return (double(w->height()) * 25.4) / double(w->heightMM()); +} + #elif defined(Q_WS_MAC) /* * Code copied from http://developer.apple.com/qa/qa2001/qa1217.html @@ -140,8 +154,17 @@ double Utils::dpiY() return err == CGDisplayNoErr ? y : 72.0; } + +double Utils::realDpiX() +{ + return dpiX(); +} + +double Utils::realDpiY() +{ + return dpiY(); +} #else -#include double Utils::dpiX() { @@ -152,6 +175,16 @@ double Utils::dpiY() { return QDesktopWidget().physicalDpiY(); } + +double Utils::realDpiX() +{ + return dpiX(); +} + +double Utils::realDpiY() +{ + return dpiY(); +} #endif inline static bool isWhite( QRgb argb ) { diff --git a/core/utils.h b/core/utils.h index 9e125c9c0..7895a5421 100644 --- a/core/utils.h +++ b/core/utils.h @@ -43,6 +43,26 @@ class OKULAR_EXPORT Utils */ static double dpiY(); + /** + * Return the real horizontal DPI of the main display. + * + * On X11, it can indicate the real horizontal DPI value without any Xrdb + * setting. Otherwise, returns the same as dpiX(), + * + * since 0.9 (KDE 4.3) + */ + static double realDpiX(); + + /** + * Return the real vertical DPI of the main display + * + * On X11, it can indicate the real horizontal DPI value without any Xrdb + * setting. Otherwise, returns the same as dpiX(), + * + * since 0.9 (KDE 4.3) + */ + static double realDpiY(); + /** * Compute the smallest rectangle that contains all non-white pixels in image), * in normalized [0,1] coordinates.