Bug 381631 - Cannot print pages in Landscape mode. r=pavlov, sr=roc.
authorkherron@fmailbox.com
Sun, 24 Jun 2007 04:20:34 -0700
changeset 2728 2668a2676293333ec4ad2c149a2efb39e5539527
parent 2727 81093307a37bc49823d10fb6c6d78fbd43cbb100
child 2729 9cbe781d3b7651519dcff15a74b2d50adec15a67
push idunknown
push userunknown
push dateunknown
reviewerspavlov, roc
bugs381631
milestone1.9a6pre
Bug 381631 - Cannot print pages in Landscape mode. r=pavlov, sr=roc.
layout/base/nsDocumentViewer.cpp
widget/public/nsIPrintSettings.idl
widget/src/beos/nsDeviceContextSpecB.cpp
widget/src/beos/nsDeviceContextSpecB.h
widget/src/gtk2/nsDeviceContextSpecG.cpp
widget/src/gtk2/nsDeviceContextSpecG.h
widget/src/windows/nsDeviceContextSpecWin.cpp
widget/src/xpwidgets/nsPrintSettingsImpl.cpp
--- a/layout/base/nsDocumentViewer.cpp
+++ b/layout/base/nsDocumentViewer.cpp
@@ -840,19 +840,19 @@ DocumentViewerImpl::InitInternal(nsIWidg
         NS_ENSURE_SUCCESS(rv, rv);
         rv = devctx->InitForPrinting(devspec);
         NS_ENSURE_SUCCESS(rv, rv);
         // XXX I'm breaking this code; I'm not sure I really want to mess with
         // the document viewer at the moment to get the right device context
         // (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)));
         mPresContext->SetIsRootPaginatedDocument(PR_TRUE);
         mPresContext->SetPageScale(1.0f);
       }
 #endif
     }
--- a/widget/public/nsIPrintSettings.idl
+++ b/widget/public/nsIPrintSettings.idl
@@ -53,17 +53,17 @@
   
 interface nsIPrintSession;
 
 /**
  * Simplified graphics interface for JS rendering.
  *
  * @status UNDER_REVIEW
  */
-[scriptable, uuid(f1094df6-ce0e-42c9-9847-2f663172c38d)]
+[scriptable, uuid(89c06ccb-6d41-4846-a8e2-63bfa7bd3157)]
 
 interface nsIPrintSettings : nsISupports
 {
   /**
    * PrintSettings to be Saved Navigation Constants
    */
   const unsigned long kInitSaveOddEvenPages   = 0x00000001;
   const unsigned long kInitSaveHeaderLeft     = 0x00000002;
@@ -173,19 +173,20 @@ interface nsIPrintSettings : nsISupports
   PRBool GetPrintOptions(in PRInt32 aType);
 
   /**
    * Set PrintOptions Bit field
    */
   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
    */
     nsIPrintSettings clone();
 
   /**
    * Assigns the internal values from the "in" arg to the current object
--- a/widget/src/beos/nsDeviceContextSpecB.cpp
+++ b/widget/src/beos/nsDeviceContextSpecB.cpp
@@ -397,21 +397,16 @@ NS_IMETHODIMP nsDeviceContextSpecBeOS ::
  * Closes the printmanager if it is open.
  *  @update   dc 2/15/98
  */
 NS_IMETHODIMP nsDeviceContextSpecBeOS :: ClosePrintManager()
 {
   return NS_OK;
 }  
 
-NS_IMETHODIMP nsDeviceContextSpecBeOS::GetPageSizeInTwips(PRInt32 *aWidth, PRInt32 *aHeight)
-{
-  return mPrintSettings->GetPageSizeInTwips(aWidth, aHeight);
-}
-
 //  Printer Enumerator
 nsPrinterEnumeratorBeOS::nsPrinterEnumeratorBeOS()
 {
 }
 
 NS_IMPL_ISUPPORTS1(nsPrinterEnumeratorBeOS, nsIPrinterEnumerator)
 
 NS_IMETHODIMP nsPrinterEnumeratorBeOS::GetPrinterNameList(nsIStringEnumerator **aPrinterNameList)
--- a/widget/src/beos/nsDeviceContextSpecB.h
+++ b/widget/src/beos/nsDeviceContextSpecB.h
@@ -80,18 +80,16 @@ public:
   
 /**
  * Closes the printmanager if it is open.
  * @update   dc 2/13/98
  * @return error status
  */
   NS_IMETHOD ClosePrintManager();
   
-  NS_IMETHOD GetPageSizeInTwips(PRInt32 *aWidth, PRInt32 *aHeight);
-
   NS_IMETHOD GetToPrinter( PRBool &aToPrinter ); 
 
   NS_IMETHOD GetPrinterName ( const char **aPrinter );
 
   NS_IMETHOD GetCopies ( int &aCopies ); 
 
   NS_IMETHOD GetFirstPageFirst ( PRBool &aFpf );     
  
--- a/widget/src/gtk2/nsDeviceContextSpecG.cpp
+++ b/widget/src/gtk2/nsDeviceContextSpecG.cpp
@@ -398,43 +398,42 @@ NS_IMPL_ISUPPORTS1(nsDeviceContextSpecGT
 #include "gfxPDFSurface.h"
 #include "gfxPSSurface.h"
 #include "nsUnitConversion.h"
 NS_IMETHODIMP nsDeviceContextSpecGTK::GetSurfaceForPrinter(gfxASurface **aSurface)
 {
   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))
     return rv;
 
   nsCOMPtr<nsILocalFile> file;
   rv = mPrintJob->GetSpoolFile(getter_AddRefs(file));
   if (NS_FAILED(rv))
     return rv;
 
   nsCOMPtr<nsIFileOutputStream> stream = do_CreateInstance("@mozilla.org/network/file-output-stream;1");
   rv = stream->Init(file, -1, -1, 0);
   if (NS_FAILED(rv))
     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);
   
   *aSurface = surface;
   NS_ADDREF(*aSurface);
 
   return NS_OK;
 }
@@ -658,21 +657,16 @@ NS_IMETHODIMP nsDeviceContextSpecGTK::Ge
 }
 
 NS_IMETHODIMP nsDeviceContextSpecGTK::GetDownloadFonts(PRBool &aDownloadFonts)      
 {
   aDownloadFonts = mDownloadFonts;
   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);
 }
 
 /* static !! */
 nsresult nsDeviceContextSpecGTK::GetPrintMethod(const char *aPrinter, PrintMethod &aMethod)
 {
--- a/widget/src/gtk2/nsDeviceContextSpecG.h
+++ b/widget/src/gtk2/nsDeviceContextSpecG.h
@@ -84,17 +84,16 @@ public:
   NS_IMETHOD GetLeftMargin(float &value); 
   NS_IMETHOD GetRightMargin(float &value); 
   NS_IMETHOD GetCommand(const char **aCommand);   
   NS_IMETHOD GetPath (const char **aPath);    
   NS_IMETHOD GetLandscape (PRBool &aLandscape);
   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);
   NS_IMETHOD GetColorspace(const char **aColorspace);
   NS_IMETHOD GetDownloadFonts(PRBool &aDownloadFonts);   
   virtual ~nsDeviceContextSpecGTK();
   
 protected:
--- a/widget/src/windows/nsDeviceContextSpecWin.cpp
+++ b/widget/src/windows/nsDeviceContextSpecWin.cpp
@@ -525,33 +525,32 @@ NS_IMETHODIMP nsDeviceContextSpecWin::Ge
   PRInt16 outputFormat;
   mPrintSettings->GetOutputFormat(&outputFormat);
 
   if (outputFormat == nsIPrintSettings::kOutputFormatPDF) {
     nsXPIDLString filename;
     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<nsILocalFile> file = do_CreateInstance("@mozilla.org/file/local;1");
     nsresult rv = file->InitWithPath(filename);
     if (NS_FAILED(rv))
       return rv;
 
     nsCOMPtr<nsIFileOutputStream> stream = do_CreateInstance("@mozilla.org/network/file-output-stream;1");
     rv = stream->Init(file, -1, -1, 0);
     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);
 
       // have this surface take over ownership of this DC
       newSurface = new gfxWindowsSurface(dc, PR_TRUE);
     }
   }
--- a/widget/src/xpwidgets/nsPrintSettingsImpl.cpp
+++ b/widget/src/xpwidgets/nsPrintSettingsImpl.cpp
@@ -915,28 +915,32 @@ NS_IMETHODIMP
 nsPrintSettings::GetMarginInTwips(nsMargin& aMargin)
 {
   aMargin = mMargin;
   return NS_OK;
 }
 
 /** ---------------------------------------------------
  *  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));
     *aHeight = NS_INCHES_TO_TWIPS(float(mPaperHeight));
   } else {
     *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;
 }
 
 nsresult 
 nsPrintSettings::_Clone(nsIPrintSettings **_retval)
 {
   nsPrintSettings* printSettings = new nsPrintSettings(*this);
   return printSettings->QueryInterface(NS_GET_IID(nsIPrintSettings), (void**)_retval); // ref counts