diff --git a/gfx/src/mac/nsDeviceContextMac.cpp b/gfx/src/mac/nsDeviceContextMac.cpp index a7e2100f773d..4438e9d41eb9 100644 --- a/gfx/src/mac/nsDeviceContextMac.cpp +++ b/gfx/src/mac/nsDeviceContextMac.cpp @@ -28,9 +28,11 @@ #include #include "il_util.h" #include +#include "nsIPref.h" +#include "nsIServiceManager.h" -const PRUint32 nsDeviceContextMac::kPixelsPerInch = 96; +PRUint32 nsDeviceContextMac::mPixelsPerInch = 96; static NS_DEFINE_IID(kDeviceContextIID, NS_IDEVICE_CONTEXT_IID); @@ -72,7 +74,7 @@ double pix_inch; thegd = ::GetMainDevice(); thepix = (**thegd).gdPMap; // dereferenced handle: don't move memory below! mDepth = (**thepix).pixelSize; - pix_inch = kPixelsPerInch; //Fix2X((**thepix).hRes); + pix_inch = GetScreenResolution(); //Fix2X((**thepix).hRes); mTwipsToPixels = pix_inch/(float)NSIntPointsToTwips(72); mPixelsToTwips = 1.0f/mTwipsToPixels; @@ -325,6 +327,7 @@ NS_IMETHODIMP nsDeviceContextMac::GetDeviceSurfaceDimensions(PRInt32 &aWidth, PR } +#pragma mark - //------------------------------------------------------------------------ NS_IMETHODIMP nsDeviceContextMac::GetDeviceContextFor(nsIDeviceContextSpec *aDevice,nsIDeviceContext *&aContext) @@ -561,3 +564,32 @@ nsresult nsDeviceContextMac::CreateFontAliasTable() } return result; } + +#pragma mark - + +//------------------------------------------------------------------------ +// +static NS_DEFINE_IID(kIPrefIID, NS_IPREF_IID); +static NS_DEFINE_CID(kPrefCID, NS_PREF_CID); + +PRUint32 nsDeviceContextMac::GetScreenResolution() +{ + static PRBool initialized = PR_FALSE; + if (initialized) + return mPixelsPerInch; + initialized = PR_TRUE; + + nsIPref* prefs; + nsresult rv = nsServiceManager::GetService(kPrefCID, kIPrefIID, (nsISupports**)&prefs); + if (NS_SUCCEEDED(rv) && prefs) { + PRInt32 intVal; + if (NS_SUCCEEDED(prefs->GetIntPref("browser.screen_resolution", &intVal))) { + mPixelsPerInch = intVal; + } + nsServiceManager::ReleaseService(kPrefCID, prefs); + } + + + return mPixelsPerInch; + +} diff --git a/gfx/src/mac/nsDeviceContextMac.h b/gfx/src/mac/nsDeviceContextMac.h index 4ba8fb82f7e3..d1ce9bd9422f 100644 --- a/gfx/src/mac/nsDeviceContextMac.h +++ b/gfx/src/mac/nsDeviceContextMac.h @@ -79,7 +79,10 @@ protected: public: static bool GetMacFontNumber(const nsString& aFontName, short &fontNum); - static const PRUint32 kPixelsPerInch; +private: + static PRUint32 mPixelsPerInch; +public: + static PRUint32 GetScreenResolution(); }; #endif /* nsDeviceContextMac_h___ */ diff --git a/gfx/src/mac/nsImageMac.cpp b/gfx/src/mac/nsImageMac.cpp index d05b22fd414e..fb078e7fe3c2 100644 --- a/gfx/src/mac/nsImageMac.cpp +++ b/gfx/src/mac/nsImageMac.cpp @@ -113,8 +113,8 @@ PRInt32 bufferdepth; mThePixelmap.pixelSize = bufferdepth; mThePixelmap.packType = 0; mThePixelmap.packSize = 0; - mThePixelmap.hRes = nsDeviceContextMac::kPixelsPerInch<<16; - mThePixelmap.vRes = nsDeviceContextMac::kPixelsPerInch<<16; + mThePixelmap.hRes = nsDeviceContextMac::GetScreenResolution()<<16; + mThePixelmap.vRes = nsDeviceContextMac::GetScreenResolution()<<16; mThePixelmap.planeBytes = 0; mThePixelmap.pmReserved = 0; mThePixelmap.pmVersion = 0; diff --git a/widget/src/mac/nsDeviceContextMac.cpp b/widget/src/mac/nsDeviceContextMac.cpp index a7e2100f773d..4438e9d41eb9 100644 --- a/widget/src/mac/nsDeviceContextMac.cpp +++ b/widget/src/mac/nsDeviceContextMac.cpp @@ -28,9 +28,11 @@ #include #include "il_util.h" #include +#include "nsIPref.h" +#include "nsIServiceManager.h" -const PRUint32 nsDeviceContextMac::kPixelsPerInch = 96; +PRUint32 nsDeviceContextMac::mPixelsPerInch = 96; static NS_DEFINE_IID(kDeviceContextIID, NS_IDEVICE_CONTEXT_IID); @@ -72,7 +74,7 @@ double pix_inch; thegd = ::GetMainDevice(); thepix = (**thegd).gdPMap; // dereferenced handle: don't move memory below! mDepth = (**thepix).pixelSize; - pix_inch = kPixelsPerInch; //Fix2X((**thepix).hRes); + pix_inch = GetScreenResolution(); //Fix2X((**thepix).hRes); mTwipsToPixels = pix_inch/(float)NSIntPointsToTwips(72); mPixelsToTwips = 1.0f/mTwipsToPixels; @@ -325,6 +327,7 @@ NS_IMETHODIMP nsDeviceContextMac::GetDeviceSurfaceDimensions(PRInt32 &aWidth, PR } +#pragma mark - //------------------------------------------------------------------------ NS_IMETHODIMP nsDeviceContextMac::GetDeviceContextFor(nsIDeviceContextSpec *aDevice,nsIDeviceContext *&aContext) @@ -561,3 +564,32 @@ nsresult nsDeviceContextMac::CreateFontAliasTable() } return result; } + +#pragma mark - + +//------------------------------------------------------------------------ +// +static NS_DEFINE_IID(kIPrefIID, NS_IPREF_IID); +static NS_DEFINE_CID(kPrefCID, NS_PREF_CID); + +PRUint32 nsDeviceContextMac::GetScreenResolution() +{ + static PRBool initialized = PR_FALSE; + if (initialized) + return mPixelsPerInch; + initialized = PR_TRUE; + + nsIPref* prefs; + nsresult rv = nsServiceManager::GetService(kPrefCID, kIPrefIID, (nsISupports**)&prefs); + if (NS_SUCCEEDED(rv) && prefs) { + PRInt32 intVal; + if (NS_SUCCEEDED(prefs->GetIntPref("browser.screen_resolution", &intVal))) { + mPixelsPerInch = intVal; + } + nsServiceManager::ReleaseService(kPrefCID, prefs); + } + + + return mPixelsPerInch; + +} diff --git a/widget/src/mac/nsDeviceContextMac.h b/widget/src/mac/nsDeviceContextMac.h index 4ba8fb82f7e3..d1ce9bd9422f 100644 --- a/widget/src/mac/nsDeviceContextMac.h +++ b/widget/src/mac/nsDeviceContextMac.h @@ -79,7 +79,10 @@ protected: public: static bool GetMacFontNumber(const nsString& aFontName, short &fontNum); - static const PRUint32 kPixelsPerInch; +private: + static PRUint32 mPixelsPerInch; +public: + static PRUint32 GetScreenResolution(); }; #endif /* nsDeviceContextMac_h___ */