Implement printing of Landscape in Unix.
Contact me at kai.engert@gmx.de
This commit is contained in:
kaie%netscape.com 2001-09-05 14:30:16 +00:00
Родитель c9cdb95d9a
Коммит 8f9d189880
21 изменённых файлов: 181 добавлений и 56 удалений

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

@ -74,6 +74,12 @@ interface nsIPrintOptions : nsISupports
const short kA4PaperSize = 3;
const short kA3PaperSize = 4;
/**
* Orientation Constants
*/
const short kPortraitOrientation = 0;
const short kLandscapeOrientation = 1;
/**
* Print Frame Constants
*/
@ -143,6 +149,7 @@ interface nsIPrintOptions : nsISupports
attribute boolean printReversed;
attribute boolean printInColor; /* a false means grayscale */
attribute long paperSize; /* see page size consts */
attribute long orientation; /* see orientation consts */
attribute wstring printCommand;
attribute boolean printToFile;
attribute wstring toFileName;

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

@ -113,6 +113,7 @@ NS_IMETHODIMP nsDeviceContextSpecBeOS :: Init(PRBool aQuiet)
PRBool reversed = PR_FALSE, color = PR_FALSE, landscape = PR_FALSE;
PRBool tofile = PR_FALSE;
PRInt32 paper_size = NS_LETTER_SIZE;
PRInt32 orientation = NS_PORTRAIT;
int ileft = 500, iright = 0, itop = 500, ibottom = 0;
char *command;
char *printfile = nsnull;
@ -155,6 +156,7 @@ NS_IMETHODIMP nsDeviceContextSpecBeOS :: Init(PRBool aQuiet)
(void) pPrefs->GetBoolPref("print.print_color", &color);
(void) pPrefs->GetBoolPref("print.print_landscape", &landscape);
(void) pPrefs->GetIntPref("print.print_paper_size", &paper_size);
(void) pPrefs->GetIntPref("print.print_orientation", &orientation);
(void) pPrefs->CopyCharPref("print.print_command", (char **) &command);
(void) pPrefs->GetIntPref("print.print_margin_top", &itop);
(void) pPrefs->GetIntPref("print.print_margin_left", &ileft);
@ -181,6 +183,7 @@ sprintf( mPrData.command, "lpr" );
mPrData.fpf = !reversed;
mPrData.grayscale = !color;
mPrData.size = paper_size;
mPrData.orientation = orientation;
mPrData.toPrinter = !tofile;
// PWD, HOME, or fail
@ -246,9 +249,23 @@ NS_IMETHODIMP nsDeviceContextSpecBeOS :: GetPageDimensions ( float &aWidth, floa
aWidth = 11.69;
aHeight = 16.53;
}
if (mPrData.orientation == NS_LANDSCAPE) {
float temp;
temp = aWidth;
aWidth = aHeight;
aHeight = temp;
}
return NS_OK;
}
NS_IMETHODIMP nsDeviceContextSpecBeOS :: GetLandscape ( PRBool &landscape )
{
landscape = (mPrData.orientation == NS_LANDSCAPE);
return NS_OK;
}
NS_IMETHODIMP nsDeviceContextSpecBeOS :: GetTopMargin ( float &value )
{
value = mPrData.top;

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

@ -83,6 +83,8 @@ public:
NS_IMETHOD GetPageDimensions (float &aWidth, float &aHeight );
NS_IMETHOD GetLandscape (PRBool &aLandscape);
NS_IMETHOD GetUserCancelled( PRBool &aCancel );
protected:

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

@ -38,6 +38,9 @@ PR_BEGIN_EXTERN_C
#define NS_EXECUTIVE_SIZE 2
#define NS_A4_SIZE 3
#define NS_A3_SIZE 4
#define NS_PORTRAIT 0
#define NS_LANDSCAPE 1
#endif
#ifndef PATH_MAX

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

@ -159,6 +159,7 @@ NS_IMETHODIMP nsDeviceContextSpecGTK::Init(PRBool aQuiet)
PRBool tofile = PR_FALSE;
PRInt16 printRange = nsIPrintOptions::kRangeAllPages;
PRInt32 paper_size = NS_LETTER_SIZE;
PRInt32 orientation = NS_PORTRAIT;
PRInt32 fromPage = 1;
PRInt32 toPage = 1;
PRUnichar *command = nsnull;
@ -212,6 +213,7 @@ NS_IMETHODIMP nsDeviceContextSpecGTK::Init(PRBool aQuiet)
printService->GetPrintReversed(&reversed);
printService->GetPrintInColor(&color);
printService->GetPaperSize(&paper_size);
printService->GetOrientation(&orientation);
printService->GetPrintCommand(&command);
printService->GetPrintRange(&printRange);
printService->GetToFileName(&printfile);
@ -251,6 +253,7 @@ NS_IMETHODIMP nsDeviceContextSpecGTK::Init(PRBool aQuiet)
mPrData.fpf = !reversed;
mPrData.grayscale = !color;
mPrData.size = paper_size;
mPrData.orientation = orientation;
mPrData.toPrinter = !tofile;
// PWD, HOME, or fail
@ -321,9 +324,23 @@ NS_IMETHODIMP nsDeviceContextSpecGTK :: GetPageDimensions ( float &aWidth, float
// 297mm X 420mm == 11.69in X 16.53in
aWidth = 11.69;
aHeight = 16.53; }
if (mPrData.orientation == NS_LANDSCAPE) {
float temp;
temp = aWidth;
aWidth = aHeight;
aHeight = temp;
}
return NS_OK;
}
NS_IMETHODIMP nsDeviceContextSpecGTK :: GetLandscape ( PRBool &landscape )
{
landscape = (mPrData.orientation == NS_LANDSCAPE);
return NS_OK;
}
NS_IMETHODIMP nsDeviceContextSpecGTK :: GetTopMargin ( float &value )
{
value = mPrData.top;

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

@ -104,6 +104,8 @@ public:
NS_IMETHOD GetPageDimensions (float &aWidth, float &aHeight );
NS_IMETHOD GetLandscape (PRBool &aLandscape);
NS_IMETHOD GetUserCancelled( PRBool &aCancel );
NS_IMETHOD GetPrintMethod(PrintMethod &aMethod );

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

@ -38,6 +38,9 @@ PR_BEGIN_EXTERN_C
#define NS_EXECUTIVE_SIZE 2
#define NS_A4_SIZE 3
#define NS_A3_SIZE 4
#define NS_PORTRAIT 0
#define NS_LANDSCAPE 1
#endif
#ifndef PATH_MAX
@ -53,6 +56,7 @@ typedef struct unixprdata {
PRBool fpf; /* If PR_TRUE, first page first */
PRBool grayscale; /* If PR_TRUE, print grayscale */
int size; /* Paper size e.g., SizeLetter */
int orientation; /* Orientation e.g. Portrait */
char command[ PATH_MAX ]; /* Print command e.g., lpr */
char path[ PATH_MAX ]; /* If toPrinter = PR_FALSE, dest file */
PRBool cancel; /* If PR_TRUE, user cancelled */

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

@ -72,6 +72,7 @@ const char * kPrintDate = "print.print_date";
const char * kPrintReversed = "print.print_reversed";
const char * kPrintColor = "print.print_color";
const char * kPrintPaperSize = "print.print_paper_size";
const char * kPrintOrientation= "print.print_orientation";
const char * kPrintCommand = "print.print_command";
const char * kPrintFile = "print.print_file";
const char * kPrintToFile = "print.print_tofile";
@ -102,6 +103,7 @@ nsPrintOptions::nsPrintOptions() :
mPrintReversed(PR_FALSE),
mPrintInColor(PR_TRUE),
mPaperSize(kLetterPaperSize),
mOrientation(kPortraitOrientation),
mPrintToFile(PR_FALSE),
mPrintFrameType(kFramesAsIs),
mHowToEnableFrameUI(kFrameEnableNone),
@ -282,6 +284,7 @@ nsPrintOptions::ReadPrefs()
prefs->GetBoolPref(kPrintReversed, &mPrintReversed);
prefs->GetBoolPref(kPrintColor, &mPrintInColor);
prefs->GetIntPref(kPrintPaperSize, &mPaperSize);
prefs->GetIntPref(kPrintOrientation, &mOrientation);
ReadPrefString(prefs, kPrintCommand, mPrintCommand);
prefs->GetBoolPref(kPrintFile, &mPrintToFile);
ReadPrefString(prefs, kPrintToFile, mToFileName);
@ -320,6 +323,7 @@ nsPrintOptions::WritePrefs()
prefs->SetBoolPref(kPrintReversed, mPrintReversed);
prefs->SetBoolPref(kPrintColor, mPrintInColor);
prefs->SetIntPref(kPrintPaperSize, mPaperSize);
prefs->SetIntPref(kPrintOrientation, mOrientation);
WritePrefString(prefs, kPrintCommand, mPrintCommand);
prefs->SetBoolPref(kPrintFile, mPrintToFile);
WritePrefString(prefs, kPrintToFile, mToFileName);
@ -395,6 +399,19 @@ NS_IMETHODIMP nsPrintOptions::SetPaperSize(PRInt32 aPaperSize)
return NS_OK;
}
/* attribute short orientation; */
NS_IMETHODIMP nsPrintOptions::GetOrientation(PRInt32 *aOrientation)
{
//NS_ENSURE_ARG_POINTER(aOrientation);
*aOrientation = mOrientation;
return NS_OK;
}
NS_IMETHODIMP nsPrintOptions::SetOrientation(PRInt32 aOrientation)
{
mOrientation = aOrientation;
return NS_OK;
}
/* attribute wstring printCommand; */
NS_IMETHODIMP nsPrintOptions::GetPrintCommand(PRUnichar * *aPrintCommand)
{

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

@ -73,6 +73,7 @@ protected:
PRBool mPrintReversed;
PRBool mPrintInColor; // a false means grayscale
PRInt32 mPaperSize; // see page size consts
PRInt32 mOrientation; // see orientation consts
nsString mPrintCommand;
PRBool mPrintToFile;
nsString mToFileName;

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

@ -111,6 +111,14 @@ public:
**/
NS_IMETHOD GetPageDimensions ( float &aWidth, float &aHeight ) = 0;
/*
* If PR_TRUE, user chose Landscape
* @update
* @param aLandscape
* @return
**/
NS_IMETHOD GetLandscape ( PRBool &aLandscape ) = 0;
/*
* If toPrinter = PR_FALSE, dest file
* @update

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

@ -242,6 +242,7 @@ nsPostScriptObj::Init( nsIDeviceContextSpecPS *aSpec, PRUnichar * aTitle )
{
PRBool isGray, isAPrinter, isFirstPageFirst;
int printSize;
int landscape;
float fwidth, fheight;
char *buf;
@ -313,7 +314,11 @@ nsPostScriptObj::Init( nsIDeviceContextSpecPS *aSpec, PRUnichar * aTitle )
mPrintSetup->header = "header";
mPrintSetup->footer = "footer";
mPrintSetup->sizes = NULL;
mPrintSetup->landscape = PR_FALSE; // Rotated output
aSpec->GetLandscape( landscape );
mPrintSetup->landscape = (landscape) ? PR_TRUE : PR_FALSE; // Rotated output
//mPrintSetup->landscape = PR_FALSE;
mPrintSetup->underline = PR_TRUE; // underline links
mPrintSetup->scale_images = PR_TRUE; // Scale unsized images which are too big
mPrintSetup->scale_pre = PR_FALSE; // do the pre-scaling thing
@ -411,11 +416,15 @@ nsPostScriptObj::initialize_translation(PrintSetup* pi)
dup->left = POINT_TO_PAGE(dup->left);
dup->bottom = POINT_TO_PAGE(dup->bottom);
dup->right = POINT_TO_PAGE(dup->right);
/*
if (pi->landscape){
dup->height = POINT_TO_PAGE(pi->width);
dup->width = POINT_TO_PAGE(pi->height);
//XXX Should I swap the margins too ???
//XXX kaie: I don't think so... The user still sees the options
// named left margin etc.
}
*/
}
/** ---------------------------------------------------

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

@ -49,6 +49,9 @@ class nsIImage;
#define NS_A4_SIZE 3
#define NS_A3_SIZE 4
#define NS_PORTRAIT 0
#define NS_LANDSCAPE 1
#define N_FONTS 8
#define INCH_TO_PAGE(f) ((int) (.5 + (f)*720))
#define PAGE_TO_POINT_I(f) ((int) ((f) / 10.0))
@ -140,7 +143,7 @@ struct PrintSetup_ {
int width; /* Paper size, # of cols for text xlate */
int height;
char* header;
char* footer;

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

@ -146,6 +146,7 @@ NS_IMETHODIMP nsDeviceContextSpecXlib::Init(PRBool aQuiet)
PRBool tofile = PR_FALSE;
PRInt16 printRange = nsIPrintOptions::kRangeAllPages;
PRInt32 paper_size = NS_LETTER_SIZE;
PRInt32 orientation = NS_PORTRAIT;
PRInt32 fromPage = 1;
PRInt32 toPage = 1;
PRUnichar *command = nsnull;
@ -199,6 +200,7 @@ NS_IMETHODIMP nsDeviceContextSpecXlib::Init(PRBool aQuiet)
printService->GetPrintReversed(&reversed);
printService->GetPrintInColor(&color);
printService->GetPaperSize(&paper_size);
printService->GetOrientation(&orientation);
printService->GetPrintCommand(&command);
printService->GetPrintRange(&printRange);
printService->GetToFileName(&printfile);
@ -238,6 +240,7 @@ NS_IMETHODIMP nsDeviceContextSpecXlib::Init(PRBool aQuiet)
mPrData.fpf = !reversed;
mPrData.grayscale = !color;
mPrData.size = paper_size;
mPrData.orientation = orientation;
mPrData.toPrinter = !tofile;
// PWD, HOME, or fail
@ -309,10 +312,23 @@ NS_IMETHODIMP nsDeviceContextSpecXlib::GetPageDimensions(float &aWidth, float &a
aWidth = 11.69;
aHeight = 16.53;
}
if (mPrData.orientation == NS_LANDSCAPE) {
float temp;
temp = aWidth;
aWidth = aHeight;
aHeight = temp;
}
return NS_OK;
}
NS_IMETHODIMP nsDeviceContextSpecXlib::GetLandscape(PRBool &landscape)
{
landscape = (mPrData.orientation == NS_LANDSCAPE);
return NS_OK;
}
NS_IMETHODIMP nsDeviceContextSpecXlib::GetTopMargin(float &value)
{
value = mPrData.top;

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

@ -71,6 +71,7 @@ public:
NS_IMETHOD GetCommand(char **aCommand);
NS_IMETHOD GetPath (char **aPath);
NS_IMETHOD GetPageDimensions(float &aWidth, float &aHeight);
NS_IMETHOD GetLandscape (PRBool &aLandscape);
NS_IMETHOD GetUserCancelled(PRBool &aCancel);
NS_IMETHOD GetPrintMethod(PrintMethod &aMethod);
virtual ~nsDeviceContextSpecXlib();

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

@ -34,6 +34,9 @@ PR_BEGIN_EXTERN_C
#define NS_EXECUTIVE_SIZE 2
#define NS_A4_SIZE 3
#define NS_A3_SIZE 4
#define NS_PORTRAIT 0
#define NS_LANDSCAPE 1
#endif
#ifndef PATH_MAX
@ -49,6 +52,7 @@ typedef struct unixprdata {
PRBool fpf; /* If PR_TRUE, first page first */
PRBool grayscale; /* If PR_TRUE, print grayscale */
int size; /* Paper size e.g., SizeLetter */
int orientation; /* Orientation e.g. Portrait */
char command[PATH_MAX]; /* Print command e.g., lpr */
char path[PATH_MAX]; /* If toPrinter = PR_FALSE, dest file */
PRBool cancel; /* If PR_TRUE, user cancelled */

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

@ -115,6 +115,14 @@ public:
**/
NS_IMETHOD GetPageDimensions ( float &aWidth, float &aHeight ) = 0;
/*
* If PR_TRUE, user chose Landscape
* @update
* @param aLandscape
* @return
**/
NS_IMETHOD GetLandscape ( PRBool &aLandscape ) = 0;
/*
* If toPrinter = PR_FALSE, dest file
* @update

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

@ -217,6 +217,7 @@ nsXPrintContext::SetupPrintContext(nsIDeviceContextSpecXp *aSpec)
int printSize;
float top, bottom, left, right;
int landscape;
char *buf;
// Get the Attributes
@ -227,7 +228,8 @@ nsXPrintContext::SetupPrintContext(nsIDeviceContextSpecXp *aSpec)
aSpec->GetBottomMargin(bottom);
aSpec->GetLeftMargin(left);
aSpec->GetRightMargin(right);
aSpec->GetLandscape(landscape);
PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG,
("nsXPrintContext::SetupPrintContext: borders top=%f, bottom=%f, left=%f, right=%f\n",
top, bottom, left, right));
@ -269,11 +271,28 @@ nsXPrintContext::SetupPrintContext(nsIDeviceContextSpecXp *aSpec)
dumpXpAttributes(mPDisplay, mPContext);
#endif /* DEBUG */
// Set the Document Attributes
// XpSetAttributes(mPDisplay,mPContext, XPDocAttr,(char *)"*content-orientation: landscape",XPAttrMerge);
// or
// XpuSetContentOrientation(mPDisplay,mPContext, XPDocAttr, "landscape");
/* which orientation ? */
switch (landscape)
{
case 1 /* NS_LANDSCAPE */:
if (XpuSetContentOrientation(mPDisplay,mPContext, XPDocAttr, "landscape") != 1)
{
NS_WARNING("orientation 'landscape' not supported on this printer");
return NS_ERROR_FAILURE;
}
break;
case 0 /* NS_PORTRAIT */:
if (XpuSetContentOrientation(mPDisplay,mPContext, XPDocAttr, "portrait") != 1)
{
NS_WARNING("orientation 'portrait' not supported on this printer");
return NS_ERROR_FAILURE;
}
break;
default:
NS_WARNING("unsupported orientation");
return NS_ERROR_FAILURE;
}
/* set printer context
* WARNING: after this point it is no longer allows to change job attributes
* only after the XpSetContext() call the alllication is allowed to make

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

@ -132,6 +132,15 @@ PrintPreviewContext::GetPageDim(nsRect* aActualRect, nsRect* aAdjRect)
break;
} // switch
PRInt32 orientation = nsIPrintOptions::kPortraitOrientation;
printService->GetOrientation(&orientation);
if (orientation == nsIPrintOptions::kLandscapeOrientation) {
// swap
nscoord temp;
temp = aActualRect->width;
aActualRect->width = aActualRect->height;
aActualRect->height = temp;
}
}
#ifdef NS_DEBUG

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

@ -57,6 +57,9 @@ function initDialog()
dialog.letterRadio = document.getElementById("letterRadio");
dialog.legalRadio = document.getElementById("legalRadio");
dialog.exectiveRadio = document.getElementById("exectiveRadio");
dialog.portraitRadio = document.getElementById("portraitRadio");
dialog.landscapeRadio = document.getElementById("landscapeRadio");
dialog.allpagesRadio = document.getElementById("allpagesRadio");
dialog.rangeRadio = document.getElementById("rangeRadio");
@ -157,6 +160,7 @@ function loadDialog()
var print_reversed = false;
var print_color = true;
var print_paper_size = 0;
var print_orientation = 0;
var print_margin_top = 0.5;
var print_margin_left = 0.5;
var print_margin_bottom = 0.5;
@ -181,6 +185,7 @@ function loadDialog()
print_reversed = printService.printReversed;
print_color = printService.printInColor;
print_paper_size = printService.paperSize;
print_orientation = printService.orientation;
print_margin_top = printService.marginTop;
print_margin_left = printService.marginLeft;
@ -199,6 +204,7 @@ function loadDialog()
dump("printReversed "+print_reversed+"\n");
dump("printInColor "+print_color+"\n");
dump("paperSize "+print_paper_size+"\n");
dump("orientation "+print_orientation+"\n");
dump("printCommand "+print_command+"\n");
dump("toFileName "+print_file+"\n");
dump("printToFile "+print_tofile+"\n");
@ -254,6 +260,12 @@ function loadDialog()
dialog.a3Radio.checked = true;
}
if ( print_orientation == gPrintOptInterface.kPortraitOrientation ) {
dialog.portraitRadio.checked = true;
} else if ( print_orientation == gPrintOptInterface.kLandscapeOrientation ) {
dialog.landscapeRadio.checked = true;
}
dialog.allpagesRadio.checked = true;
if ( print_selection_radio_enabled) {
dialog.selectionRadio.removeAttribute("disabled");
@ -359,6 +371,13 @@ function onOK()
print_paper_size = gPrintOptInterface.kA3PaperSize;
}
printService.paperSize = print_paper_size;
if (dialog.portraitRadio.checked) {
print_orientation = gPrintOptInterface.kPortraitOrientation;
} else if (dialog.landscapeRadio.checked) {
print_orientation = gPrintOptInterface.kLandscapeOrientation;
}
printService.orientation = print_orientation;
// save these out so they can be picked up by the device spec
printService.marginTop = dialog.topInput.value;

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

@ -88,6 +88,13 @@ Contributor(s): Masaki Katakai <katakai@japan.sun.com>
<radio group = "paperGroup" id = "a3Radio" label = "&a3Radio.label;" />
</radiogroup>
</row>
<row>
<text class="label" value="&orientationGroup.label;" flex ="1"/>
<radiogroup id="orientationGroup" orient="horizontal">
<radio group = "orientationGroup" id = "portraitRadio" label = "&portraitRadio.label;" />
<radio group = "orientationGroup" id = "landscapeRadio" label = "&landscapeRadio.label;"/>
</radiogroup>
</row>
<row>
<text class="label" value="&printrangeGroup.label;" flex ="1"/>
<radiogroup id="printrangeGroup" orient="vertical">

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

@ -1,48 +0,0 @@
<!-- extracted from printdialog.xul -->
<!ENTITY printButton.label "Print">
<!ENTITY printDialog.title "Print">
<!ENTITY fpDialog.title "Save File">
<!ENTITY printTo.label "Print To:">
<!ENTITY printerRadio.label "Printer">
<!ENTITY fileRadio.label "File">
<!ENTITY cmdInput.label "Print Command:">
<!ENTITY fileInput.label "File:">
<!ENTITY chooseButton.label "Choose File...">
<!ENTITY reverseGroup.label "Print:">
<!ENTITY firstRadio.label "First Page First">
<!ENTITY lastRadio.label "Last Page First">
<!ENTITY colorGroup.label "Color:">
<!ENTITY grayRadio.label "GrayScale">
<!ENTITY colorRadio.label "Color">
<!ENTITY paperGroup.label "Paper Size:">
<!ENTITY letterRadio.label "Letter (8 1/2 x 11 in.)">
<!ENTITY legalRadio.label "Legal (8 1/2 x 14 in.)">
<!ENTITY exectiveRadio.label "Executive (7 1/2 x 10 in.)">
<!ENTITY a4Radio.label "A4 (210 x 297 mm)">
<!ENTITY a3Radio.label "A3 (297 x 420 mm)">
<!ENTITY printrangeGroup.label "Print Range:">
<!ENTITY allpagesRadio.label "All Pages">
<!ENTITY rangeRadio.label "Pages">
<!ENTITY frompageInput.label "from">
<!ENTITY topageInput.label "to">
<!ENTITY selectionRadio.label "Selection">
<!ENTITY printframeGroup.label "Print Frames:">
<!ENTITY aslaidoutRadio.label "As laid out on the screen">
<!ENTITY selectedframeRadio.label "The selected frame">
<!ENTITY eachframesepRadio.label "Each frame separately">
<!ENTITY marginInput.label "Margins(inches):">
<!ENTITY topInput.label "Top:">
<!ENTITY bottomInput.label "Bottom:">
<!ENTITY leftInput.label "Left:">
<!ENTITY rightInput.label "Right:">