diff --git a/embedding/components/printingui/ipc/PrintingParent.h b/embedding/components/printingui/ipc/PrintingParent.h index 79f7ce4e1a4..f3a37b7b5e0 100644 --- a/embedding/components/printingui/ipc/PrintingParent.h +++ b/embedding/components/printingui/ipc/PrintingParent.h @@ -14,9 +14,11 @@ class nsIDOMWindow; class PPrintProgressDialogParent; class PPrintSettingsDialogParent; -typedef mozilla::layout::PRemotePrintJobParent PRemotePrintJobParent; - namespace mozilla { +namespace layout { +class PRemotePrintJobParent; +} + namespace embedding { class PrintingParent final : public PPrintingParent diff --git a/embedding/components/printingui/ipc/nsPrintingProxy.cpp b/embedding/components/printingui/ipc/nsPrintingProxy.cpp index 7e13b502217..1f414feda7c 100644 --- a/embedding/components/printingui/ipc/nsPrintingProxy.cpp +++ b/embedding/components/printingui/ipc/nsPrintingProxy.cpp @@ -22,8 +22,7 @@ using namespace mozilla; using namespace mozilla::dom; using namespace mozilla::embedding; - -typedef mozilla::layout::RemotePrintJobChild RemotePrintJobChild; +using namespace mozilla::layout; static StaticRefPtr sPrintingProxyInstance; diff --git a/embedding/components/printingui/ipc/nsPrintingProxy.h b/embedding/components/printingui/ipc/nsPrintingProxy.h index c740fa636c0..6b4d9cf5ae9 100644 --- a/embedding/components/printingui/ipc/nsPrintingProxy.h +++ b/embedding/components/printingui/ipc/nsPrintingProxy.h @@ -9,7 +9,11 @@ #include "nsIPrintingPromptService.h" #include "mozilla/embedding/PPrintingChild.h" -typedef mozilla::layout::PRemotePrintJobChild PRemotePrintJobChild; +namespace mozilla { +namespace layout { +class PRemotePrintJobChild; +} +} class nsPrintingProxy: public nsIPrintingPromptService, public mozilla::embedding::PPrintingChild diff --git a/gfx/src/nsDeviceContext.cpp b/gfx/src/nsDeviceContext.cpp index e6e37f67d16..6c92ea472f2 100644 --- a/gfx/src/nsDeviceContext.cpp +++ b/gfx/src/nsDeviceContext.cpp @@ -314,30 +314,10 @@ nsDeviceContext::SetDPI() { float dpi = -1.0f; - // PostScript, PDF and Mac (when printing) all use 72 dpi - // Use a printing DC to determine the other dpi values - if (mPrintingSurface) { - switch (mPrintingSurface->GetType()) { - case gfxSurfaceType::PDF: - case gfxSurfaceType::PS: - case gfxSurfaceType::Quartz: - dpi = 72.0f; - break; -#ifdef XP_WIN - case gfxSurfaceType::Win32: - case gfxSurfaceType::Win32Printing: { - HDC dc = reinterpret_cast(mPrintingSurface.get())->GetDC(); - int32_t OSVal = GetDeviceCaps(dc, LOGPIXELSY); - dpi = 144.0f; - mPrintingScale = float(OSVal) / dpi; - break; - } -#endif - default: - NS_NOTREACHED("Unexpected printing surface type"); - break; - } - + // Use the printing DC to determine DPI values, if we have one. + if (mDeviceContextSpec) { + dpi = mDeviceContextSpec->GetDPI(); + mPrintingScale = mDeviceContextSpec->GetPrintingScale(); mAppUnitsPerDevPixelAtUnitFullZoom = NS_lround((AppUnitsPerCSSPixel() * 96) / dpi); } else { @@ -698,34 +678,7 @@ nsDeviceContext::CalcPrintingSize() gfxSize size(0, 0); switch (mPrintingSurface->GetType()) { - case gfxSurfaceType::Image: - inPoints = false; - size = reinterpret_cast(mPrintingSurface.get())->GetSize(); - break; - -#if defined(MOZ_PDF_PRINTING) - case gfxSurfaceType::PDF: - inPoints = true; - size = reinterpret_cast(mPrintingSurface.get())->GetSize(); - break; -#endif - -#ifdef MOZ_WIDGET_GTK - case gfxSurfaceType::PS: - inPoints = true; - size = reinterpret_cast(mPrintingSurface.get())->GetSize(); - break; -#endif - -#ifdef XP_MACOSX - case gfxSurfaceType::Quartz: - inPoints = true; // this is really only true when we're printing - size = reinterpret_cast(mPrintingSurface.get())->GetSize(); - break; -#endif - #ifdef XP_WIN - case gfxSurfaceType::Win32: case gfxSurfaceType::Win32Printing: { inPoints = false; @@ -740,10 +693,8 @@ nsDeviceContext::CalcPrintingSize() break; } #endif - default: - gfxCriticalError() << "Printing to unknown surface type " << (int)mPrintingSurface->GetType(); - NS_ERROR("trying to print to unknown surface type"); + size = mPrintingSurface->GetSize(); } if (inPoints) { diff --git a/widget/nsIDeviceContextSpec.h b/widget/nsIDeviceContextSpec.h index c91436a0362..4f232daaeb8 100644 --- a/widget/nsIDeviceContextSpec.h +++ b/widget/nsIDeviceContextSpec.h @@ -13,8 +13,8 @@ class nsIPrintSettings; class gfxASurface; #define NS_IDEVICE_CONTEXT_SPEC_IID \ -{ 0xb5548fb1, 0xf43e, 0x4921, \ - { 0x82, 0x19, 0xc3, 0x82, 0x06, 0xee, 0x74, 0x5c } } +{ 0xf407cfba, 0xbe28, 0x46c9, \ + { 0x8a, 0xba, 0x04, 0x2d, 0xae, 0xbb, 0x4f, 0x23 } } class nsIDeviceContextSpec : public nsISupports { @@ -34,6 +34,20 @@ public: NS_IMETHOD GetSurfaceForPrinter(gfxASurface **nativeSurface) = 0; + /** + * Override to return something other than the default. + * + * @return DPI for printing. + */ + virtual float GetDPI() { return 72.0f; } + + /** + * Override to return something other than the default. + * + * @return the printing scale to be applied to the context for printing. + */ + virtual float GetPrintingScale() { return 1.0f; } + NS_IMETHOD BeginDocument(const nsAString& aTitle, char16_t* aPrintToFileName, int32_t aStartPage, diff --git a/widget/windows/nsDeviceContextSpecWin.cpp b/widget/windows/nsDeviceContextSpecWin.cpp index 2d265d8d269..d3b48f9854a 100644 --- a/widget/windows/nsDeviceContextSpecWin.cpp +++ b/widget/windows/nsDeviceContextSpecWin.cpp @@ -270,6 +270,7 @@ NS_IMETHODIMP nsDeviceContextSpecWin::GetSurfaceForPrinter(gfxASurface **surface { NS_ASSERTION(mDevMode, "DevMode can't be NULL here"); + *surface = nullptr; RefPtr newSurface; int16_t outputFormat = 0; @@ -315,19 +316,24 @@ NS_IMETHODIMP nsDeviceContextSpecWin::GetSurfaceForPrinter(gfxASurface **surface newSurface = new gfxWindowsSurface(dc, gfxWindowsSurface::FLAG_TAKE_DC | gfxWindowsSurface::FLAG_FOR_PRINTING); if (newSurface->GetType() == (gfxSurfaceType)-1) { gfxCriticalError() << "Invalid windows surface from " << gfx::hexa(dc); - newSurface = nullptr; + return NS_ERROR_FAILURE; } } } - if (newSurface) { - *surface = newSurface; - NS_ADDREF(*surface); - return NS_OK; - } + mPrintingSurface = newSurface; + newSurface.forget(surface); + return NS_OK; +} - *surface = nullptr; - return NS_ERROR_FAILURE; +float +nsDeviceContextSpecWin::GetPrintingScale() +{ + MOZ_ASSERT(mPrintingSurface); + + HDC dc = reinterpret_cast(mPrintingSurface.get())->GetDC(); + int32_t OSVal = GetDeviceCaps(dc, LOGPIXELSY); + return float(OSVal) / GetDPI(); } //---------------------------------------------------------------------------------- diff --git a/widget/windows/nsDeviceContextSpecWin.h b/widget/windows/nsDeviceContextSpecWin.h index e0549bde56f..912bb16aa98 100644 --- a/widget/windows/nsDeviceContextSpecWin.h +++ b/widget/windows/nsDeviceContextSpecWin.h @@ -13,6 +13,7 @@ #include "nsISupportsPrimitives.h" #include #include "mozilla/Attributes.h" +#include "mozilla/RefPtr.h" class nsIWidget; @@ -34,6 +35,10 @@ public: NS_IMETHOD Init(nsIWidget* aWidget, nsIPrintSettings* aPS, bool aIsPrintPreview) override; + float GetDPI() final { return 144.0f; } + + float GetPrintingScale() final; + void GetDriverName(wchar_t *&aDriverName) const { aDriverName = mDriverName; } void GetDeviceName(wchar_t *&aDeviceName) const { aDeviceName = mDeviceName; } @@ -64,6 +69,7 @@ protected: LPDEVMODEW mDevMode; nsCOMPtr mPrintSettings; + RefPtr mPrintingSurface; };