From 0a5c57beee4f045b4f937f62704f66385209c3ec Mon Sep 17 00:00:00 2001 From: "kherron@fmailbox.com" Date: Sun, 24 Jun 2007 04:20:34 -0700 Subject: [PATCH] Bug 381631 - Cannot print pages in Landscape mode. r=pavlov, sr=roc. --- layout/base/nsDocumentViewer.cpp | 6 +++--- widget/public/nsIPrintSettings.idl | 7 ++++--- widget/src/beos/nsDeviceContextSpecB.cpp | 5 ----- widget/src/beos/nsDeviceContextSpecB.h | 2 -- widget/src/gtk2/nsDeviceContextSpecG.cpp | 20 +++++++------------ widget/src/gtk2/nsDeviceContextSpecG.h | 1 - widget/src/windows/nsDeviceContextSpecWin.cpp | 9 ++++----- widget/src/xpwidgets/nsPrintSettingsImpl.cpp | 8 ++++++-- 8 files changed, 24 insertions(+), 34 deletions(-) diff --git a/layout/base/nsDocumentViewer.cpp b/layout/base/nsDocumentViewer.cpp index 272f036534a..72bf2b1baf1 100644 --- a/layout/base/nsDocumentViewer.cpp +++ b/layout/base/nsDocumentViewer.cpp @@ -845,9 +845,9 @@ DocumentViewerImpl::InitInternal(nsIWidget* aParentWidget, // (this won't break anyone, since page layout mode was never really // usable) #endif - PRInt32 pageWidth = 0, pageHeight = 0; - mPresContext->GetPrintSettings()->GetPageSizeInTwips(&pageWidth, - &pageHeight); + double pageWidth = 0, pageHeight = 0; + mPresContext->GetPrintSettings()->GetEffectivePageSize(&pageWidth, + &pageHeight); mPresContext->SetPageSize( nsSize(mPresContext->TwipsToAppUnits(pageWidth), mPresContext->TwipsToAppUnits(pageHeight))); diff --git a/widget/public/nsIPrintSettings.idl b/widget/public/nsIPrintSettings.idl index 5593bd3bd75..4f76ecf1ae7 100644 --- a/widget/public/nsIPrintSettings.idl +++ b/widget/public/nsIPrintSettings.idl @@ -58,7 +58,7 @@ interface nsIPrintSession; * * @status UNDER_REVIEW */ -[scriptable, uuid(f1094df6-ce0e-42c9-9847-2f663172c38d)] +[scriptable, uuid(89c06ccb-6d41-4846-a8e2-63bfa7bd3157)] interface nsIPrintSettings : nsISupports { @@ -178,9 +178,10 @@ interface nsIPrintSettings : nsISupports PRInt32 GetPrintOptionsBits(); /** - * Returns W/H in Twips from Paper Size H/W + * Get the page size in twips, considering the + * orientation (portrait or landscape). */ - void GetPageSizeInTwips(out long aWidth, out long aHeight); + void GetEffectivePageSize(out double aWidth, out double aHeight); /** * Makes a new copy diff --git a/widget/src/beos/nsDeviceContextSpecB.cpp b/widget/src/beos/nsDeviceContextSpecB.cpp index 5008b1e35d5..262f09e6ae0 100644 --- a/widget/src/beos/nsDeviceContextSpecB.cpp +++ b/widget/src/beos/nsDeviceContextSpecB.cpp @@ -402,11 +402,6 @@ NS_IMETHODIMP nsDeviceContextSpecBeOS :: ClosePrintManager() return NS_OK; } -NS_IMETHODIMP nsDeviceContextSpecBeOS::GetPageSizeInTwips(PRInt32 *aWidth, PRInt32 *aHeight) -{ - return mPrintSettings->GetPageSizeInTwips(aWidth, aHeight); -} - // Printer Enumerator nsPrinterEnumeratorBeOS::nsPrinterEnumeratorBeOS() { diff --git a/widget/src/beos/nsDeviceContextSpecB.h b/widget/src/beos/nsDeviceContextSpecB.h index 35c251a5060..39c2bce8b26 100644 --- a/widget/src/beos/nsDeviceContextSpecB.h +++ b/widget/src/beos/nsDeviceContextSpecB.h @@ -85,8 +85,6 @@ public: */ NS_IMETHOD ClosePrintManager(); - NS_IMETHOD GetPageSizeInTwips(PRInt32 *aWidth, PRInt32 *aHeight); - NS_IMETHOD GetToPrinter( PRBool &aToPrinter ); NS_IMETHOD GetPrinterName ( const char **aPrinter ); diff --git a/widget/src/gtk2/nsDeviceContextSpecG.cpp b/widget/src/gtk2/nsDeviceContextSpecG.cpp index d0e5d4c018b..b1b464e2650 100644 --- a/widget/src/gtk2/nsDeviceContextSpecG.cpp +++ b/widget/src/gtk2/nsDeviceContextSpecG.cpp @@ -403,14 +403,13 @@ NS_IMETHODIMP nsDeviceContextSpecGTK::GetSurfaceForPrinter(gfxASurface **aSurfac const char *path; GetPath(&path); - PRInt32 width, height; - GetPageSizeInTwips(&width, &height); - double w, h; + double width, height; + mPrintSettings->GetEffectivePageSize(&width, &height); // convert twips to points - w = width/20; - h = height/20; + width /= 20; + height /= 20; - printf("\"%s\", %d, %d\n", path, width, height); + DO_PR_DEBUG_LOG(("\"%s\", %f, %f\n", path, width, height)); nsresult rv = nsPrintJobFactoryGTK::CreatePrintJob(this, mPrintJob); if (NS_FAILED(rv)) @@ -427,9 +426,9 @@ NS_IMETHODIMP nsDeviceContextSpecGTK::GetSurfaceForPrinter(gfxASurface **aSurfac return rv; #ifdef USE_PDF - gfxPDFSurface *surface = new gfxPDFSurface(stream, gfxSize(w, h)); + gfxPDFSurface *surface = new gfxPDFSurface(stream, gfxSize(width, height)); #else - gfxPSSurface *surface = new gfxPSSurface(stream, gfxSize(w, h)); + gfxPSSurface *surface = new gfxPSSurface(stream, gfxSize(width, height)); #endif // surface->SetDPI(600, 600); @@ -663,11 +662,6 @@ NS_IMETHODIMP nsDeviceContextSpecGTK::GetDownloadFonts(PRBool &aDownloadFonts) return NS_OK; } -NS_IMETHODIMP nsDeviceContextSpecGTK::GetPageSizeInTwips(PRInt32 *aWidth, PRInt32 *aHeight) -{ - return mPrintSettings->GetPageSizeInTwips(aWidth, aHeight); -} - NS_IMETHODIMP nsDeviceContextSpecGTK::GetPrintMethod(PrintMethod &aMethod) { return GetPrintMethod(mPrinter, aMethod); diff --git a/widget/src/gtk2/nsDeviceContextSpecG.h b/widget/src/gtk2/nsDeviceContextSpecG.h index 12ab1674a76..e453f92945b 100644 --- a/widget/src/gtk2/nsDeviceContextSpecG.h +++ b/widget/src/gtk2/nsDeviceContextSpecG.h @@ -89,7 +89,6 @@ public: NS_IMETHOD GetUserCancelled(PRBool &aCancel); NS_IMETHOD GetPrintMethod(PrintMethod &aMethod); static nsresult GetPrintMethod(const char *aPrinter, PrintMethod &aMethod); - NS_IMETHOD GetPageSizeInTwips(PRInt32 *aWidth, PRInt32 *aHeight); NS_IMETHOD GetPaperName(const char **aPaperName); NS_IMETHOD GetPlexName(const char **aPlexName); NS_IMETHOD GetResolutionName(const char **aResolutionName); diff --git a/widget/src/windows/nsDeviceContextSpecWin.cpp b/widget/src/windows/nsDeviceContextSpecWin.cpp index 509d7b35297..9b3860bb937 100644 --- a/widget/src/windows/nsDeviceContextSpecWin.cpp +++ b/widget/src/windows/nsDeviceContextSpecWin.cpp @@ -530,11 +530,10 @@ NS_IMETHODIMP nsDeviceContextSpecWin::GetSurfaceForPrinter(gfxASurface **surface mPrintSettings->GetToFileName(getter_Copies(filename)); PRInt32 width, height; - mPrintSettings->GetPageSizeInTwips(&width, &height); - double w, h; + mPrintSettings->GetEffectivePageSize(&width, &height); // convert twips to points - w = width/20; - h = height/20; + width /= 20; + height /= 20; nsCOMPtr file = do_CreateInstance("@mozilla.org/file/local;1"); nsresult rv = file->InitWithPath(filename); @@ -546,7 +545,7 @@ NS_IMETHODIMP nsDeviceContextSpecWin::GetSurfaceForPrinter(gfxASurface **surface if (NS_FAILED(rv)) return rv; - newSurface = new gfxPDFSurface(stream, gfxSize(w, h)); + newSurface = new gfxPDFSurface(stream, gfxSize(width, height)); } else { if (mDevMode) { HDC dc = ::CreateDC(mDriverName, mDeviceName, NULL, mDevMode); diff --git a/widget/src/xpwidgets/nsPrintSettingsImpl.cpp b/widget/src/xpwidgets/nsPrintSettingsImpl.cpp index 1b68fb8c513..42db40d20f5 100644 --- a/widget/src/xpwidgets/nsPrintSettingsImpl.cpp +++ b/widget/src/xpwidgets/nsPrintSettingsImpl.cpp @@ -920,10 +920,9 @@ nsPrintSettings::GetMarginInTwips(nsMargin& aMargin) /** --------------------------------------------------- * See documentation in nsPrintOptionsImpl.h - * @update 6/21/00 dwc */ NS_IMETHODIMP -nsPrintSettings::GetPageSizeInTwips(PRInt32 *aWidth, PRInt32 *aHeight) +nsPrintSettings::GetEffectivePageSize(double *aWidth, double *aHeight) { if (mPaperSizeUnit == kPaperSizeInches) { *aWidth = NS_INCHES_TO_TWIPS(float(mPaperWidth)); @@ -932,6 +931,11 @@ nsPrintSettings::GetPageSizeInTwips(PRInt32 *aWidth, PRInt32 *aHeight) *aWidth = NS_MILLIMETERS_TO_TWIPS(float(mPaperWidth)); *aHeight = NS_MILLIMETERS_TO_TWIPS(float(mPaperHeight)); } + if (kLandscapeOrientation == mOrientation) { + double temp = *aWidth; + *aWidth = *aHeight; + *aHeight = temp; + } return NS_OK; }