From db724a0ad5b623cef6edd0197e2a790a11e2ef23 Mon Sep 17 00:00:00 2001 From: "kipp%netscape.com" Date: Thu, 18 Mar 1999 21:18:40 +0000 Subject: [PATCH] Fudge the dpi into something that makes for more rational scaling to twips --- gfx/src/gtk/nsDeviceContextGTK.cpp | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/gfx/src/gtk/nsDeviceContextGTK.cpp b/gfx/src/gtk/nsDeviceContextGTK.cpp index 1104907678d9..eaaa033c2ca8 100644 --- a/gfx/src/gtk/nsDeviceContextGTK.cpp +++ b/gfx/src/gtk/nsDeviceContextGTK.cpp @@ -64,12 +64,34 @@ NS_IMETHODIMP nsDeviceContextGTK::Init(nsNativeWidget aNativeWidget) mWidget = aNativeWidget; -// this is used for something odd. who knows - mTwipsToPixels = (((float)::gdk_screen_width()) / - ((float)::gdk_screen_width_mm()) * 25.4) / + // Compute dpi of display + float screenWidth = float(::gdk_screen_width()); + float screenWidthIn = float(::gdk_screen_width_mm()) / 25.4f; + nscoord dpi = nscoord(screenWidth / screenWidthIn); + + // Now for some wacky heuristics. + if (dpi < 84) dpi = 72; + else if (dpi < 108) dpi = 96; + else if (dpi < 132) dpi = 120; + + mTwipsToPixels = float(dpi) / float(NSIntPointsToTwips(72)); + mPixelsToTwips = 1.0f / mTwipsToPixels; + +#ifdef DEBUG + static PRBool once = PR_TRUE; + if (once) { + printf("GFX: dpi=%d t2p=%g p2t=%g\n", dpi, mTwipsToPixels, mPixelsToTwips); + once = PR_FALSE; + } +#endif + +#if 0 + mTwipsToPixels = ( ((float)::gdk_screen_width()) / + ((float)::gdk_screen_width_mm()) * 25.4) / (float)NSIntPointsToTwips(72); mPixelsToTwips = 1.0f / mTwipsToPixels; +#endif vis = gdk_rgb_get_visual(); mDepth = vis->depth;