Bug 1399787 - Part 11.d. Using PrintTargetEMF on windows if skia-pdf is enable. draft
authorcku <cku@mozilla.com>
Tue, 14 Nov 2017 13:57:11 +0800
changeset 709059 cbbcef476eaedd6f01ba81facf74477a83c53732
parent 709058 5db82860ef86d91bb293b6d2d49e7492676302bb
child 709060 5e248d356b4dfe5686e219f8b7977e17a8eb950c
push id92525
push usercku@mozilla.com
push dateThu, 07 Dec 2017 14:36:53 +0000
bugs1399787
milestone59.0a1
Bug 1399787 - Part 11.d. Using PrintTargetEMF on windows if skia-pdf is enable. MozReview-Commit-ID: Hx94fqGJFz6
widget/windows/nsDeviceContextSpecWin.cpp
--- a/widget/windows/nsDeviceContextSpecWin.cpp
+++ b/widget/windows/nsDeviceContextSpecWin.cpp
@@ -31,16 +31,17 @@
 #include "nsIDOMWindow.h"
 #include "mozilla/Services.h"
 #include "nsWindowsHelpers.h"
 
 #include "mozilla/gfx/Logging.h"
 
 #ifdef MOZ_ENABLE_SKIA_PDF
 #include "mozilla/gfx/PrintTargetSkPDF.h"
+#include "mozilla/gfx/PrintTargetEMF.h"
 #include "nsIUUIDGenerator.h"
 #include "nsDirectoryServiceDefs.h"
 #include "nsPrintfCString.h"
 #include "nsThreadUtils.h"
 #endif
 
 static mozilla::LazyLogModule kWidgetPrintingLogMod("printing-widget");
 #define PR_PL(_p1)  MOZ_LOG(kWidgetPrintingLogMod, mozilla::LogLevel::Debug, _p1)
@@ -222,17 +223,24 @@ already_AddRefed<PrintTarget> nsDeviceCo
       mPrintSettings->GetToFileName(filename);
 
       nsAutoCString printFile(NS_ConvertUTF16toUTF8(filename).get());
       auto skStream = MakeUnique<SkFILEWStream>(printFile.get());
       return PrintTargetSkPDF::CreateOrNull(Move(skStream), size);
     }
 
     if (mDevMode) {
-      // TBD: Implement a new PrintTarget to serve EMF OOP.
+      NS_WARNING_ASSERTION(!mDriverName.IsEmpty(), "No driver!");
+      HDC dc = ::CreateDCW(mDriverName.get(), mDeviceName.get(), nullptr, mDevMode);
+      if (!dc) {
+        gfxCriticalError(gfxCriticalError::DefaultOptions(false))
+          << "Failed to create device context in GetSurfaceForPrinter";
+        return nullptr;
+      }
+      return PrintTargetEMF::CreateOrNull(dc, size);
     }
   }
 #endif
 
   if (mOutputFormat == nsIPrintSettings::kOutputFormatPDF) {
     nsString filename;
     mPrintSettings->GetToFileName(filename);