Bug 1401069 - Part 6. Fine tune ComputeScaleFactor. draft
authorcku <cku@mozilla.com>
Mon, 18 Sep 2017 23:40:05 +0800
changeset 668140 5fc419fb381e412f17e1fb5f6aa31db892fd4921
parent 668139 be26488180377be845111cbac6bcd1929cd7e6dc
child 668141 d62efd8e9a54d10e14ab93ec7312c4a132cc6f59
push id80936
push usercku@mozilla.com
push dateThu, 21 Sep 2017 04:54:21 +0000
bugs1401069
milestone57.0a1
Bug 1401069 - Part 6. Fine tune ComputeScaleFactor. Make the implementation of it moew consice. MozReview-Commit-ID: J7v98HBLhT
widget/windows/PDFViaEMFPrintHelper.cpp
--- a/widget/windows/PDFViaEMFPrintHelper.cpp
+++ b/widget/windows/PDFViaEMFPrintHelper.cpp
@@ -6,32 +6,26 @@
 #include "PDFViaEMFPrintHelper.h"
 #include "nsIFileStreams.h"
 #include "WindowsEMF.h"
 #include "nsFileStreams.h"
 #include "mozilla/UniquePtrExtensions.h"
 #include "mozilla/dom/File.h"
 #include "mozilla/Unused.h"
 
+/* Scale DC by keeping aspect ratio */
 static
 float ComputeScaleFactor(int aDCWidth, int aDCHeight,
                          int aPageWidth, int aPageHeight)
 {
   MOZ_ASSERT(aPageWidth !=0 && aPageWidth != 0);
 
-  float scaleFactor = 1.0;
-  // If page fits DC - no scaling needed.
-  if (aDCWidth < aPageWidth || aDCHeight < aPageHeight) {
-    float xFactor =
-      static_cast<float>(aDCWidth) / static_cast <float>(aPageWidth);
-    float yFactor =
-      static_cast<float>(aDCHeight) / static_cast <float>(aPageHeight);
-    scaleFactor = std::min(xFactor, yFactor);
-  }
-  return scaleFactor;
+  return (aDCWidth >= aPageWidth && aDCHeight >= aPageHeight)
+    ? 1.0 /* If page fits DC - no scaling needed. */
+    : std::min(static_cast<float>(aDCWidth) / static_cast<float>(aPageWidth),         static_cast<float>(aDCHeight) / static_cast<float>(aPageHeight));
 }
 
 PDFViaEMFPrintHelper::PDFViaEMFPrintHelper()
   : mPDFDoc(nullptr)
 {
 }
 
 PDFViaEMFPrintHelper::~PDFViaEMFPrintHelper()