From 5cf291106d1ff14ebee8b18c0783ce2ad9e578d4 Mon Sep 17 00:00:00 2001 From: "syd%netscape.com" Date: Tue, 14 Dec 1999 02:16:17 +0000 Subject: [PATCH] Partial fix for 18083. Grab page size preference from user and use it to compute page size for layout. Previously, it was assumed that page was 8x10, ignoring user choice made in the printer dialog. r=dcone, a=chofmann. --- gfx/src/gtk/nsDeviceContextSpecG.cpp | 19 +++++++++++++++++++ gfx/src/gtk/nsDeviceContextSpecG.h | 2 ++ gfx/src/ps/nsDeviceContextPS.cpp | 17 +++++++++++++---- gfx/src/ps/nsDeviceContextPS.h | 2 -- gfx/src/ps/nsIDeviceContextSpecPS.h | 8 ++++++++ gfx/src/ps/nsPostScriptObj.cpp | 15 +++++++-------- gfx/src/ps/nsPostScriptObj.h | 2 -- widget/src/gtk2/nsDeviceContextSpecG.cpp | 19 +++++++++++++++++++ widget/src/gtk2/nsDeviceContextSpecG.h | 2 ++ 9 files changed, 70 insertions(+), 16 deletions(-) diff --git a/gfx/src/gtk/nsDeviceContextSpecG.cpp b/gfx/src/gtk/nsDeviceContextSpecG.cpp index 2475a5e412e9..a0eb1364b9ce 100644 --- a/gfx/src/gtk/nsDeviceContextSpecG.cpp +++ b/gfx/src/gtk/nsDeviceContextSpecG.cpp @@ -155,6 +155,25 @@ NS_IMETHODIMP nsDeviceContextSpecGTK :: GetSize ( int &aSize ) return NS_OK; } +NS_IMETHODIMP nsDeviceContextSpecGTK :: GetPageDimensions ( float &aWidth, float &aHeight ) +{ + if ( mPrData.size == NS_LETTER_SIZE ) { + aWidth = 8.5; + aHeight = 11.0; + } else if ( mPrData.size == NS_LEGAL_SIZE ) { + aWidth = 8.5; + aHeight = 14.0; + } else if ( mPrData.size == NS_EXECUTIVE_SIZE ) { + aWidth = 7.5; + aHeight = 10.0; + } else if ( mPrData.size == NS_A4_SIZE ) { + // 210mm X 297mm == 8.27in X 11.69in + aWidth = 8.27; + aHeight = 11.69; + } + return NS_OK; +} + NS_IMETHODIMP nsDeviceContextSpecGTK :: GetTopMargin ( float &value ) { value = mPrData.top; diff --git a/gfx/src/gtk/nsDeviceContextSpecG.h b/gfx/src/gtk/nsDeviceContextSpecG.h index e7fd0691047b..b6faa10345be 100644 --- a/gfx/src/gtk/nsDeviceContextSpecG.h +++ b/gfx/src/gtk/nsDeviceContextSpecG.h @@ -83,6 +83,8 @@ public: NS_IMETHOD GetPath ( char **aPath ); + NS_IMETHOD GetPageDimensions (float &aWidth, float &aHeight ); + NS_IMETHOD GetUserCancelled( PRBool &aCancel ); protected: diff --git a/gfx/src/ps/nsDeviceContextPS.cpp b/gfx/src/ps/nsDeviceContextPS.cpp index 7a77a4713796..898c8c651122 100644 --- a/gfx/src/ps/nsDeviceContextPS.cpp +++ b/gfx/src/ps/nsDeviceContextPS.cpp @@ -248,11 +248,20 @@ NS_IMETHODIMP nsDeviceContextPS :: GetSystemAttribute(nsSystemAttrID anID, Syste */ NS_IMETHODIMP nsDeviceContextPS::GetDeviceSurfaceDimensions(PRInt32 &aWidth, PRInt32 &aHeight) { + nsIDeviceContextSpecPS *psSpec; + nsresult res; + float width, height; - aWidth = NSToIntRound((72.0f*8.0f) * mDevUnitsToAppUnits); - aHeight = NSToIntRound((72.0f*10.0f) * mDevUnitsToAppUnits); - - return NS_OK; + if ( nsnull != mSpec ) { + res = mSpec->QueryInterface(kIDeviceContextSpecPSIID, (void **) &psSpec); + if ( res == NS_OK ) { + psSpec->GetPageDimensions( width, height ); + aWidth = NSToIntRound((72.0f*width) * mDevUnitsToAppUnits); + aHeight = NSToIntRound((72.0f*height) * mDevUnitsToAppUnits); + return NS_OK; + } + } + return NS_ERROR_FAILURE; } /** --------------------------------------------------- diff --git a/gfx/src/ps/nsDeviceContextPS.h b/gfx/src/ps/nsDeviceContextPS.h index b41a63bd45e9..71250126242b 100644 --- a/gfx/src/ps/nsDeviceContextPS.h +++ b/gfx/src/ps/nsDeviceContextPS.h @@ -72,8 +72,6 @@ public: NS_IMETHOD GetDeviceContextFor(nsIDeviceContextSpec *aDevice,nsIDeviceContext *&aContext); NS_IMETHOD GetSystemAttribute(nsSystemAttrID anID, SystemAttrStruct * aInfo) const; - - NS_IMETHOD GetMetricsFor(const nsFont& aFont, nsIFontMetrics*& aMetrics); NS_IMETHOD GetMetricsFor(const nsFont& aFont, nsIAtom* aLangGroup, nsIFontMetrics*& aMetrics); NS_IMETHOD BeginDocument(void); diff --git a/gfx/src/ps/nsIDeviceContextSpecPS.h b/gfx/src/ps/nsIDeviceContextSpecPS.h index 2f878f0fffd1..f95613421d1f 100644 --- a/gfx/src/ps/nsIDeviceContextSpecPS.h +++ b/gfx/src/ps/nsIDeviceContextSpecPS.h @@ -103,6 +103,14 @@ public: **/ NS_IMETHOD GetCommand ( char **aCommand ) = 0; + /* + * Get width and height based on user page size choice, e.g., 8.5 x 11.0 + * @update + * @param aWidth, aHeight + * @return + **/ + NS_IMETHOD GetPageDimensions ( float &aWidth, float &aHeight ) = 0; + /* * If toPrinter = PR_FALSE, dest file * @update diff --git a/gfx/src/ps/nsPostScriptObj.cpp b/gfx/src/ps/nsPostScriptObj.cpp index 1d59061ac22a..ff1faea5f69c 100644 --- a/gfx/src/ps/nsPostScriptObj.cpp +++ b/gfx/src/ps/nsPostScriptObj.cpp @@ -94,7 +94,6 @@ nsPostScriptObj::~nsPostScriptObj() if (nsnull != mPrintSetup) delete mPrintSetup; - } /** --------------------------------------------------- @@ -106,7 +105,7 @@ nsPostScriptObj::Init( nsIDeviceContextSpecPS *aSpec ) { PRBool isGray, isAPrinter, isFirstPageFirst; int printSize; - float top, bottom, left, right; + float top, bottom, left, right, fwidth, fheight; char *buf; PrintInfo* pi = new PrintInfo(); @@ -165,8 +164,10 @@ printf( "top %f bottom %f left %f right %f\n", top, bottom, left, right ); memset(mPrintContext, 0, sizeof(struct PSContext_)); memset(pi, 0, sizeof(struct PrintInfo_)); - mPrintSetup->width = PAGE_WIDTH; // Paper size, # of cols for text xlate - mPrintSetup->height = PAGE_HEIGHT; + mPrintSetup->dpi = 72.0f; // dpi for externally sized items + aSpec->GetPageDimensions( fwidth, fheight ); + mPrintSetup->width = (int)(fwidth * mPrintSetup->dpi); + mPrintSetup->height = (int)(fheight * mPrintSetup->dpi); mPrintSetup->header = "header"; mPrintSetup->footer = "footer"; mPrintSetup->sizes = NULL; @@ -174,7 +175,6 @@ printf( "top %f bottom %f left %f right %f\n", top, bottom, left, right ); mPrintSetup->underline = TRUE; // underline links mPrintSetup->scale_images = TRUE; // Scale unsized images which are too big mPrintSetup->scale_pre = FALSE; // do the pre-scaling thing - mPrintSetup->dpi = 72.0f; // dpi for externally sized items // scale margins (specified in inches) to dots. mPrintSetup->top = (int) (top * mPrintSetup->dpi); @@ -202,9 +202,8 @@ printf( "dpi %f top %d bottom %d left %d right %d\n", mPrintSetup->dpi, mPrintSe // font info parsed from "other" afm file mPrintSetup->otherFontCharSetID = 0; // charset ID of "other" font //mPrintSetup->cx = NULL; // original context, if available - - pi->page_height=PAGE_HEIGHT * 10; // Size of printable area on page - pi->page_width = PAGE_WIDTH * 10; // Size of printable area on page + pi->page_height = mPrintSetup->height * 10; // Size of printable area on page + pi->page_width = mPrintSetup->width * 10; // Size of printable area on page pi->page_break = 0; // Current page bottom pi->page_topy = 0; // Current page top pi->phase = 0; diff --git a/gfx/src/ps/nsPostScriptObj.h b/gfx/src/ps/nsPostScriptObj.h index a869921f9380..9345dcd5c37a 100644 --- a/gfx/src/ps/nsPostScriptObj.h +++ b/gfx/src/ps/nsPostScriptObj.h @@ -43,8 +43,6 @@ class nsIImage; #define NS_EXECUTIVE_SIZE 2 #define NS_A4_SIZE 3 -#define PAGE_WIDTH 612 // Points -#define PAGE_HEIGHT 792 //Points #define N_FONTS 8 #define INCH_TO_PAGE(f) ((int) (.5 + (f)*720)) #define PAGE_TO_POINT_I(f) ((int) ((f) / 10.0)) diff --git a/widget/src/gtk2/nsDeviceContextSpecG.cpp b/widget/src/gtk2/nsDeviceContextSpecG.cpp index 2475a5e412e9..a0eb1364b9ce 100644 --- a/widget/src/gtk2/nsDeviceContextSpecG.cpp +++ b/widget/src/gtk2/nsDeviceContextSpecG.cpp @@ -155,6 +155,25 @@ NS_IMETHODIMP nsDeviceContextSpecGTK :: GetSize ( int &aSize ) return NS_OK; } +NS_IMETHODIMP nsDeviceContextSpecGTK :: GetPageDimensions ( float &aWidth, float &aHeight ) +{ + if ( mPrData.size == NS_LETTER_SIZE ) { + aWidth = 8.5; + aHeight = 11.0; + } else if ( mPrData.size == NS_LEGAL_SIZE ) { + aWidth = 8.5; + aHeight = 14.0; + } else if ( mPrData.size == NS_EXECUTIVE_SIZE ) { + aWidth = 7.5; + aHeight = 10.0; + } else if ( mPrData.size == NS_A4_SIZE ) { + // 210mm X 297mm == 8.27in X 11.69in + aWidth = 8.27; + aHeight = 11.69; + } + return NS_OK; +} + NS_IMETHODIMP nsDeviceContextSpecGTK :: GetTopMargin ( float &value ) { value = mPrData.top; diff --git a/widget/src/gtk2/nsDeviceContextSpecG.h b/widget/src/gtk2/nsDeviceContextSpecG.h index e7fd0691047b..b6faa10345be 100644 --- a/widget/src/gtk2/nsDeviceContextSpecG.h +++ b/widget/src/gtk2/nsDeviceContextSpecG.h @@ -83,6 +83,8 @@ public: NS_IMETHOD GetPath ( char **aPath ); + NS_IMETHOD GetPageDimensions (float &aWidth, float &aHeight ); + NS_IMETHOD GetUserCancelled( PRBool &aCancel ); protected: