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 710610 abb8a6394ed9e4abe140e07ae7893bc146c94e79
parent 710609 4c5759e18b3f28f49e4298c0831b84a6def382e6
child 710611 85e65df8ddb48b66b9dff482c34aebdf4c51ea25
push id92855
push usercku@mozilla.com
push dateMon, 11 Dec 2017 02:44:26 +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);