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.
This commit is contained in:
syd%netscape.com 1999-12-14 02:16:17 +00:00
Родитель 5c834d30d8
Коммит a1fd50730e
9 изменённых файлов: 70 добавлений и 16 удалений

Просмотреть файл

@ -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;

Просмотреть файл

@ -83,6 +83,8 @@ public:
NS_IMETHOD GetPath ( char **aPath );
NS_IMETHOD GetPageDimensions (float &aWidth, float &aHeight );
NS_IMETHOD GetUserCancelled( PRBool &aCancel );
protected:

Просмотреть файл

@ -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;
}
/** ---------------------------------------------------

Просмотреть файл

@ -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);

Просмотреть файл

@ -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

Просмотреть файл

@ -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;

Просмотреть файл

@ -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))

Просмотреть файл

@ -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;

Просмотреть файл

@ -83,6 +83,8 @@ public:
NS_IMETHOD GetPath ( char **aPath );
NS_IMETHOD GetPageDimensions (float &aWidth, float &aHeight );
NS_IMETHOD GetUserCancelled( PRBool &aCancel );
protected: