Bug 1271348: Only use LOGPIXELSY for calculating internal printing surface size on Windows. r=jimm a=lizzard
authorBob Owen <bobowencode@gmail.com>
Tue, 10 May 2016 15:17:56 +0100
changeset 332869 01daa1cb8a99db9cd98afead29de3cb5a980aece
parent 332868 8f49523be5c17c3eacf207e411b37855bb932983
child 332870 64c29da64cb8e9b0e4efde3394d63603f6a4216d
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjimm, lizzard
bugs1271348
milestone48.0a2
Bug 1271348: Only use LOGPIXELSY for calculating internal printing surface size on Windows. r=jimm a=lizzard MozReview-Commit-ID: 9KUVyI0Oy07
gfx/thebes/gfxWindowsSurface.cpp
widget/windows/nsPrintSettingsWin.cpp
--- a/gfx/thebes/gfxWindowsSurface.cpp
+++ b/gfx/thebes/gfxWindowsSurface.cpp
@@ -307,20 +307,23 @@ gfxWindowsSurface::EndPage()
 #endif
 }
 
 const mozilla::gfx::IntSize
 gfxWindowsSurface::GetSize() const
 {
     if (mForPrinting) {
         // On Windows we need to use the printable area of the page.
+        // Note: we only scale the printing using the LOGPIXELSY, so we use that
+        // when calculating the surface width as well as the height.
+        int32_t heightDPI = ::GetDeviceCaps(mDC, LOGPIXELSY);
         float width = (::GetDeviceCaps(mDC, HORZRES) * POINTS_PER_INCH_FLOAT)
-                      / ::GetDeviceCaps(mDC, LOGPIXELSX);
+                      / heightDPI;
         float height = (::GetDeviceCaps(mDC, VERTRES) * POINTS_PER_INCH_FLOAT)
-                       / ::GetDeviceCaps(mDC, LOGPIXELSY);
+                       / heightDPI;
         return mozilla::gfx::IntSize(width, height);
     }
 
     if (!mSurfaceValid) {
         NS_WARNING ("GetImageSurface on an invalid (null) surface; who's calling this without checking for surface errors?");
         return mozilla::gfx::IntSize(-1, -1);
     }
 
--- a/widget/windows/nsPrintSettingsWin.cpp
+++ b/widget/windows/nsPrintSettingsWin.cpp
@@ -204,32 +204,33 @@ nsPrintSettingsWin::CopyFromNative(HDC a
   } else {
     mPaperWidth = -1l;
   }
 
   // On Windows we currently create a surface using the printable area of the
   // page and don't set the unwriteable [sic] margins. Using the unwriteable
   // margins doesn't appear to work on Windows, but I am not sure if this is a
   // bug elsewhere in our code or a Windows quirk.
+  // Note: we only scale the printing using the LOGPIXELSY, so we use that
+  // when calculating the surface width as well as the height.
   int32_t printableWidthInDots = GetDeviceCaps(aHdc, HORZRES);
   int32_t printableHeightInDots = GetDeviceCaps(aHdc, VERTRES);
-  int32_t widthDPI = GetDeviceCaps(aHdc, LOGPIXELSX);
   int32_t heightDPI = GetDeviceCaps(aHdc, LOGPIXELSY);
 
   // Keep these values in portrait format, so we can reflect our own changes
   // to mOrientation.
   if (mOrientation == kPortraitOrientation) {
-    mPrintableWidthInInches = double(printableWidthInDots) / widthDPI;
+    mPrintableWidthInInches = double(printableWidthInDots) / heightDPI;
     mPrintableHeightInInches = double(printableHeightInDots) / heightDPI;
   } else {
-    mPrintableHeightInInches = double(printableWidthInDots) / widthDPI;
+    mPrintableHeightInInches = double(printableWidthInDots) / heightDPI;
     mPrintableWidthInInches = double(printableHeightInDots) / heightDPI;
   }
 
-  // Using Y to match existing code, X DPI should be the same for printing.
+  // Using Y to match existing code for print scaling calculations.
   mResolution = heightDPI;
 }
 
 void
 nsPrintSettingsWin::CopyToNative(DEVMODEW* aDevMode)
 {
   MOZ_ASSERT(aDevMode);
 
@@ -392,9 +393,9 @@ Tester::Tester()
 
     nsCOMPtr<nsIPrintSettings> psClone;
     ps2->Clone(getter_AddRefs(psClone));
 
   }
 
 }
 Tester gTester;
-#endif
\ No newline at end of file
+#endif