Bug 1401069 - Part 6. Fine tune ComputeScaleFactor.
Make the implementation of it moew consice.
MozReview-Commit-ID: J7v98HBLhT
--- 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()