From fde9a7c3c64ae429d919cd20f76638597b6a59bd Mon Sep 17 00:00:00 2001 From: "erik%netscape.com" Date: Wed, 28 Apr 1999 04:35:34 +0000 Subject: [PATCH] Fix related to bug 5599. We now look at the "browser.screen_resolution" pref for the dpi value. If it is not set, we use the default of 96. If it is set to zero (0), we use the X server's dpi value. Otherwise, we use whatever dpi value was set in the pref. git-svn-id: svn://10.0.0.236/trunk@29677 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/gfx/src/gtk/nsDeviceContextGTK.cpp | 39 +++++++++++++++++----- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/mozilla/gfx/src/gtk/nsDeviceContextGTK.cpp b/mozilla/gfx/src/gtk/nsDeviceContextGTK.cpp index 47f3ecbc93a..83cf6c9e22c 100644 --- a/mozilla/gfx/src/gtk/nsDeviceContextGTK.cpp +++ b/mozilla/gfx/src/gtk/nsDeviceContextGTK.cpp @@ -19,6 +19,8 @@ #include #include "nspr.h" +#include "nsIPref.h" +#include "nsIServiceManager.h" #include "il_util.h" #include "nsDeviceContextGTK.h" @@ -58,6 +60,9 @@ NS_IMPL_QUERY_INTERFACE(nsDeviceContextGTK, kDeviceContextIID) NS_IMPL_ADDREF(nsDeviceContextGTK) NS_IMPL_RELEASE(nsDeviceContextGTK) +static NS_DEFINE_CID(kPrefCID, NS_PREF_CID); +static NS_DEFINE_IID(kIPrefIID, NS_IPREF_IID); + NS_IMETHODIMP nsDeviceContextGTK::Init(nsNativeWidget aNativeWidget) { GdkVisual *vis; @@ -66,20 +71,36 @@ NS_IMETHODIMP nsDeviceContextGTK::Init(nsNativeWidget aNativeWidget) mWidget = aNativeWidget; -#define IGNORE_X_SERVER_DPI -#ifdef IGNORE_X_SERVER_DPI - nscoord dpi = 96; -#else /* IGNORE_X_SERVER_DPI */ - // Compute dpi of display - float screenWidth = float(::gdk_screen_width()); - float screenWidthIn = float(::gdk_screen_width_mm()) / 25.4f; - nscoord dpi = nscoord(screenWidth / screenWidthIn); + static nscoord dpi = 96; + static int initialized = 0; + if (!initialized) { + initialized = 1; + nsIPref* prefs = nsnull; + nsresult res = nsServiceManager::GetService(kPrefCID, kIPrefIID, + (nsISupports**) &prefs); + if (NS_SUCCEEDED(res) && prefs) { + PRInt32 intVal = 96; + res = prefs->GetIntPref("browser.screen_resolution", &intVal); + if (NS_SUCCEEDED(res)) { + if (intVal) { + dpi = intVal; + } + else { + // Compute dpi of display + float screenWidth = float(::gdk_screen_width()); + float screenWidthIn = float(::gdk_screen_width_mm()) / 25.4f; + dpi = nscoord(screenWidth / screenWidthIn); + } + } + } + } +#if 0 // Now for some wacky heuristics. if (dpi < 84) dpi = 72; else if (dpi < 108) dpi = 96; else if (dpi < 132) dpi = 120; -#endif /* IGNORE_X_SERVER_DPI */ +#endif mTwipsToPixels = float(dpi) / float(NSIntPointsToTwips(72)); mPixelsToTwips = 1.0f / mTwipsToPixels;