bug 132563 ("Print job options dialog should use paper name instead of paper size to set/get the selected paper size"), r=rods, sr=attinasi, a=asa

patch by Roland.Mainz@informatik.med.uni-giessen.de
This commit is contained in:
cbiesinger%web.de 2002-03-25 23:57:40 +00:00
Родитель 3460c97c56
Коммит e41446ba72
14 изменённых файлов: 975 добавлений и 432 удалений

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

@ -71,6 +71,9 @@
#include "nsPostScriptObj.h" #include "nsPostScriptObj.h"
#endif /* USE_POSTSCRIPT */ #endif /* USE_POSTSCRIPT */
/* Ensure that the result is always equal to either PR_TRUE or PR_FALSE */
#define MAKE_PR_BOOL(val) ((val)?(PR_TRUE):(PR_FALSE))
#ifdef PR_LOGGING #ifdef PR_LOGGING
static PRLogModuleInfo *DeviceContextSpecGTKLM = PR_NewLogModule("DeviceContextSpecGTK"); static PRLogModuleInfo *DeviceContextSpecGTKLM = PR_NewLogModule("DeviceContextSpecGTK");
#endif /* PR_LOGGING */ #endif /* PR_LOGGING */
@ -104,6 +107,111 @@ protected:
static int mGlobalNumPrinters; static int mGlobalNumPrinters;
}; };
#ifdef SET_PRINTER_FEATURES_VIA_PREFS
/* "Prototype" for the new nsPrinterFeatures service */
class nsPrinterFeatures {
public:
nsPrinterFeatures( const char *printername );
~nsPrinterFeatures() {};
/* Does this device allow to set/change the paper size ? */
void SetCanChangePaperSize( PRBool aCanSetPaperSize );
/* Set number of paper size records and the records itself */
void SetNumPaperSizeRecords( PRInt32 aCount );
void SetPaperRecord( PRInt32 aIndex, const char *aName, PRInt32 aWidthMM, PRInt32 aHeightMM, PRBool aIsInch );
/* Does this device allow to set/change the content orientation ? */
void SetCanChangeOrientation( PRBool aCanSetOrientation );
/* Set number of orientation records and the records itself */
void SetNumOrientationRecords( PRInt32 aCount );
void SetOrientationRecord( PRInt32 aIndex, const char *aName );
/* Does this device allow to set/change the spooler command ? */
void SetCanChangeSpoolerCommand( PRBool aCanSetSpoolerCommand );
/* Does this device allow to set/change number of copies for an document ? */
void SetCanChangeNumCopies( PRBool aCanSetNumCopies );
private:
/* private helper methods */
void SetBoolValue( const char *tagname, PRBool value );
void SetIntValue( const char *tagname, PRInt32 value );
void SetCharValue( const char *tagname, const char *value );
nsXPIDLCString mPrinterName;
nsCOMPtr<nsIPref> mPrefs;
};
void nsPrinterFeatures::SetBoolValue( const char *tagname, PRBool value )
{
mPrefs->SetBoolPref(nsPrintfCString(256, PRINTERFEATURES_PREF ".%s.%s", mPrinterName.get(), tagname).get(), value);
}
void nsPrinterFeatures::SetIntValue( const char *tagname, PRInt32 value )
{
mPrefs->SetIntPref(nsPrintfCString(256, PRINTERFEATURES_PREF ".%s.%s", mPrinterName.get(), tagname).get(), value);
}
void nsPrinterFeatures::SetCharValue( const char *tagname, const char *value )
{
mPrefs->SetCharPref(nsPrintfCString(256, PRINTERFEATURES_PREF ".%s.%s", mPrinterName.get(), tagname).get(), value);
}
nsPrinterFeatures::nsPrinterFeatures( const char *printername )
{
DO_PR_DEBUG_LOG(("nsPrinterFeatures::nsPrinterFeatures('%s')\n", printername));
mPrinterName.Assign(printername);
mPrefs = do_GetService(NS_PREF_CONTRACTID);
SetBoolValue("has_special_printerfeatures", PR_TRUE);
}
void nsPrinterFeatures::SetCanChangePaperSize( PRBool aCanSetPaperSize )
{
SetBoolValue("can_change_paper_size", aCanSetPaperSize);
}
/* Set number of paper size records and the records itself */
void nsPrinterFeatures::SetNumPaperSizeRecords( PRInt32 aCount )
{
SetIntValue("paper.count", aCount);
}
void nsPrinterFeatures::SetPaperRecord(PRInt32 aIndex, const char *aPaperName, PRInt32 aWidthMM, PRInt32 aHeightMM, PRBool aIsInch)
{
SetCharValue(nsPrintfCString(256, "paper.%d.name", aIndex).get(), aPaperName);
SetIntValue( nsPrintfCString(256, "paper.%d.width_mm", aIndex).get(), aWidthMM);
SetIntValue( nsPrintfCString(256, "paper.%d.height_mm", aIndex).get(), aHeightMM);
SetBoolValue(nsPrintfCString(256, "paper.%d.is_inch", aIndex).get(), aIsInch);
}
void nsPrinterFeatures::SetCanChangeOrientation( PRBool aCanSetOrientation )
{
SetBoolValue("can_change_orientation", aCanSetOrientation);
}
void nsPrinterFeatures::SetNumOrientationRecords( PRInt32 aCount )
{
SetIntValue("orientation.count", aCount);
}
void nsPrinterFeatures::SetOrientationRecord( PRInt32 aIndex, const char *aOrientationName )
{
SetCharValue(nsPrintfCString(256, "orientation.%d.name", aIndex).get(), aOrientationName);
}
void nsPrinterFeatures::SetCanChangeSpoolerCommand( PRBool aCanSetSpoolerCommand )
{
SetBoolValue("can_change_spoolercommand", aCanSetSpoolerCommand);
}
void nsPrinterFeatures::SetCanChangeNumCopies( PRBool aCanSetNumCopies )
{
SetBoolValue("can_change_num_copies", aCanSetNumCopies);
}
#endif /* SET_PRINTER_FEATURES_VIA_PREFS */
//--------------- //---------------
// static members // static members
GlobalPrinters GlobalPrinters::mGlobalPrinters; GlobalPrinters GlobalPrinters::mGlobalPrinters;
@ -216,9 +324,9 @@ static nsresult DisplayXPDialog(nsIPrintSettings* aPS,
* - GTK+-toolkit: * - GTK+-toolkit:
* file: mozilla/gfx/src/gtk/nsDeviceContextSpecG.cpp * file: mozilla/gfx/src/gtk/nsDeviceContextSpecG.cpp
* function: NS_IMETHODIMP nsDeviceContextSpecGTK::Init(PRBool aQuiet) * function: NS_IMETHODIMP nsDeviceContextSpecGTK::Init(PRBool aQuiet)
* - Xlib-toolkit: * - GTK-toolkit:
* file: mozilla/gfx/src/xlib/nsDeviceContextSpecXlib.cpp * file: mozilla/gfx/src/xlib/nsDeviceContextSpecGTK.cpp
* function: NS_IMETHODIMP nsDeviceContextSpecXlib::Init(PRBool aQuiet) * function: NS_IMETHODIMP nsDeviceContextSpecGTK::Init(PRBool aQuiet)
* - Qt-toolkit: * - Qt-toolkit:
* file: mozilla/gfx/src/qt/nsDeviceContextSpecQT.cpp * file: mozilla/gfx/src/qt/nsDeviceContextSpecQT.cpp
* function: NS_IMETHODIMP nsDeviceContextSpecQT::Init(PRBool aQuiet) * function: NS_IMETHODIMP nsDeviceContextSpecQT::Init(PRBool aQuiet)
@ -271,6 +379,7 @@ NS_IMETHODIMP nsDeviceContextSpecGTK::Init(nsIPrintSettings *aPS, PRBool aQuiet)
PRUnichar *command = nsnull; PRUnichar *command = nsnull;
PRInt32 copies = 1; PRInt32 copies = 1;
PRUnichar *printer = nsnull; PRUnichar *printer = nsnull;
PRUnichar *papername = nsnull;
PRUnichar *printfile = nsnull; PRUnichar *printfile = nsnull;
double dleft = 0.5; double dleft = 0.5;
double dright = 0.5; double dright = 0.5;
@ -280,6 +389,7 @@ NS_IMETHODIMP nsDeviceContextSpecGTK::Init(nsIPrintSettings *aPS, PRBool aQuiet)
aPS->GetPrinterName(&printer); aPS->GetPrinterName(&printer);
aPS->GetPrintReversed(&reversed); aPS->GetPrintReversed(&reversed);
aPS->GetPrintInColor(&color); aPS->GetPrintInColor(&color);
aPS->GetPaperName(&papername);
aPS->GetOrientation(&orientation); aPS->GetOrientation(&orientation);
aPS->GetPrintCommand(&command); aPS->GetPrintCommand(&command);
aPS->GetPrintRange(&printRange); aPS->GetPrintRange(&printRange);
@ -299,6 +409,8 @@ NS_IMETHODIMP nsDeviceContextSpecGTK::Init(nsIPrintSettings *aPS, PRBool aQuiet)
strcpy(mCommand, NS_ConvertUCS2toUTF8(command).get()); strcpy(mCommand, NS_ConvertUCS2toUTF8(command).get());
if (printer) if (printer)
strcpy(mPrinter, NS_ConvertUCS2toUTF8(printer).get()); strcpy(mPrinter, NS_ConvertUCS2toUTF8(printer).get());
if (papername)
strcpy(mPaperName, NS_ConvertUCS2toUTF8(papername).get());
DO_PR_DEBUG_LOG(("margins: %5.2f,%5.2f,%5.2f,%5.2f\n", dtop, dleft, dbottom, dright)); DO_PR_DEBUG_LOG(("margins: %5.2f,%5.2f,%5.2f,%5.2f\n", dtop, dleft, dbottom, dright));
DO_PR_DEBUG_LOG(("printRange %d\n", printRange)); DO_PR_DEBUG_LOG(("printRange %d\n", printRange));
@ -308,6 +420,7 @@ NS_IMETHODIMP nsDeviceContextSpecGTK::Init(nsIPrintSettings *aPS, PRBool aQuiet)
DO_PR_DEBUG_LOG(("printfile '%s'\n", printfile? NS_ConvertUCS2toUTF8(printfile).get():"<NULL>")); DO_PR_DEBUG_LOG(("printfile '%s'\n", printfile? NS_ConvertUCS2toUTF8(printfile).get():"<NULL>"));
DO_PR_DEBUG_LOG(("command '%s'\n", command? NS_ConvertUCS2toUTF8(command).get():"<NULL>")); DO_PR_DEBUG_LOG(("command '%s'\n", command? NS_ConvertUCS2toUTF8(command).get():"<NULL>"));
DO_PR_DEBUG_LOG(("printer '%s'\n", printer? NS_ConvertUCS2toUTF8(printer).get():"<NULL>")); DO_PR_DEBUG_LOG(("printer '%s'\n", printer? NS_ConvertUCS2toUTF8(printer).get():"<NULL>"));
DO_PR_DEBUG_LOG(("papername '%s'\n", papername? NS_ConvertUCS2toUTF8(papername).get():"<NULL>"));
mTop = dtop; mTop = dtop;
mBottom = dbottom; mBottom = dbottom;
@ -402,6 +515,12 @@ NS_IMETHODIMP nsDeviceContextSpecGTK::GetUserCancelled(PRBool &aCancel)
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP nsDeviceContextSpecGTK::GetPaperName( const char **aPaperName )
{
*aPaperName = mPaperName;
return NS_OK;
}
NS_IMETHODIMP nsDeviceContextSpecGTK::GetPageSizeInTwips(PRInt32 *aWidth, PRInt32 *aHeight) NS_IMETHODIMP nsDeviceContextSpecGTK::GetPageSizeInTwips(PRInt32 *aWidth, PRInt32 *aHeight)
{ {
return mPrintSettings->GetPageSizeInTwips(aWidth, aHeight); return mPrintSettings->GetPageSizeInTwips(aWidth, aHeight);
@ -582,20 +701,17 @@ NS_IMETHODIMP nsPrinterEnumeratorGTK::InitPrintSettingsFromPrinter(const PRUnich
NS_ENSURE_ARG_POINTER(aPrinterName); NS_ENSURE_ARG_POINTER(aPrinterName);
NS_ENSURE_ARG_POINTER(aPrintSettings); NS_ENSURE_ARG_POINTER(aPrintSettings);
if (!*aPrinterName) {
return NS_ERROR_FAILURE;
}
if (aPrintSettings == nsnull) { NS_ENSURE_TRUE(*aPrinterName, NS_ERROR_FAILURE);
return NS_ERROR_FAILURE; NS_ENSURE_TRUE(aPrintSettings, NS_ERROR_FAILURE);
}
nsCOMPtr<nsIPref> pPrefs = do_GetService(NS_PREF_CONTRACTID, &rv); nsCOMPtr<nsIPref> pPrefs = do_GetService(NS_PREF_CONTRACTID, &rv);
if (NS_FAILED(rv)) if (NS_FAILED(rv))
return rv; return rv;
nsXPIDLCString printerName; nsXPIDLCString fullPrinterName, /* Full name of printer incl. driver-specific prefix */
printerName; /* "Stripped" name of printer */
fullPrinterName.Assign(NS_ConvertUCS2toUTF8(aPrinterName));
printerName.Assign(NS_ConvertUCS2toUTF8(aPrinterName)); printerName.Assign(NS_ConvertUCS2toUTF8(aPrinterName));
DO_PR_DEBUG_LOG(("printerName='%s'\n", printerName.get())); DO_PR_DEBUG_LOG(("printerName='%s'\n", printerName.get()));
@ -615,33 +731,25 @@ NS_IMETHODIMP nsPrinterEnumeratorGTK::InitPrintSettingsFromPrinter(const PRUnich
#ifdef SET_PRINTER_FEATURES_VIA_PREFS #ifdef SET_PRINTER_FEATURES_VIA_PREFS
/* Defaults to FALSE */ /* Defaults to FALSE */
pPrefs->SetBoolPref(nsPrintfCString(256, PRINTERFEATURES_PREF ".%s.has_special_printerfeatures", printerName.get()).get(), PR_FALSE); pPrefs->SetBoolPref(nsPrintfCString(256, PRINTERFEATURES_PREF ".%s.has_special_printerfeatures", fullPrinterName.get()).get(), PR_FALSE);
#endif /* SET_PRINTER_FEATURES_VIA_PREFS */ #endif /* SET_PRINTER_FEATURES_VIA_PREFS */
/* These switches may be dynamic in the future... */
PRBool doingFilename = PR_TRUE; /* Set filename */
PRBool doingNumCopies = PR_TRUE; nsXPIDLCString filename;
PRBool doingOrientation = PR_TRUE; if (NS_FAILED(CopyPrinterCharPref(pPrefs, nsnull, printerName, "filename", getter_Copies(filename)))) {
PRBool doingPaperSize = PR_TRUE; const char *path;
PRBool doingCommand = PR_TRUE;
if (!(path = PR_GetEnv("PWD")))
if (doingFilename) { path = PR_GetEnv("HOME");
nsXPIDLCString filename;
if (NS_FAILED(CopyPrinterCharPref(pPrefs, nsnull, printerName, "filename", getter_Copies(filename)))) { if (path)
const char *path; filename = nsPrintfCString(PATH_MAX, "%s/mozilla.ps", path);
else
if (!(path = PR_GetEnv("PWD"))) filename.Assign("mozilla.ps");
path = PR_GetEnv("HOME"); }
DO_PR_DEBUG_LOG(("Setting default filename to '%s'\n", filename.get()));
if (path) aPrintSettings->SetToFileName(NS_ConvertUTF8toUCS2(filename).get());
filename = nsPrintfCString(PATH_MAX, "%s/mozilla.ps", path);
else
filename.Assign("mozilla.ps");
}
DO_PR_DEBUG_LOG(("Setting default filename to '%s'\n", filename.get()));
aPrintSettings->SetToFileName(NS_ConvertUTF8toUCS2(filename).get());
}
#ifdef USE_XPRINT #ifdef USE_XPRINT
if (type == pmXprint) { if (type == pmXprint) {
@ -651,78 +759,127 @@ NS_IMETHODIMP nsPrinterEnumeratorGTK::InitPrintSettingsFromPrinter(const PRUnich
XPContext pcontext; XPContext pcontext;
if (XpuGetPrinter(printerName, &pdpy, &pcontext) != 1) if (XpuGetPrinter(printerName, &pdpy, &pcontext) != 1)
return NS_ERROR_GFX_PRINTER_NAME_NOT_FOUND; return NS_ERROR_GFX_PRINTER_NAME_NOT_FOUND;
if (doingOrientation) {
XpuOrientationList olist;
int ocount;
XpuOrientationRec *default_orientation;
/* Get list of supported orientations */ XpuSupportedFlags supported_doc_attrs = XpuGetSupportedDocAttributes(pdpy, pcontext);
olist = XpuGetOrientationList(pdpy, pcontext, &ocount);
if (olist) {
default_orientation = &olist[0]; /* First entry is the default one */
if (!PL_strcasecmp(default_orientation->orientation, "portrait")) {
DO_PR_DEBUG_LOG(("setting default orientation to 'portrait'\n"));
aPrintSettings->SetOrientation(nsIPrintSettings::kPortraitOrientation);
}
else if (!PL_strcasecmp(default_orientation->orientation, "landscape")) {
DO_PR_DEBUG_LOG(("setting default orientation to 'landscape'\n"));
aPrintSettings->SetOrientation(nsIPrintSettings::kLandscapeOrientation);
}
else {
DO_PR_DEBUG_LOG(("Unknown default orientation '%s'\n", default_orientation->orientation));
}
XpuFreeOrientationList(olist);
}
}
/* Setup Number of Copies */
if (doingNumCopies) {
#ifdef NOT_IMPLEMENTED_YET
aPrintSettings->SetNumCopies(PRInt32(aDevMode->dmCopies));
#endif /* NOT_IMPLEMENTED_YET */
}
if (doingPaperSize) {
XpuMediumSourceSizeList mlist;
int mcount;
XpuMediumSourceSizeRec *default_medium;
mlist = XpuGetMediumSourceSizeList(pdpy, pcontext, &mcount);
if (mlist) {
default_medium = &mlist[0]; /* First entry is the default one */
double total_width = default_medium->ma1 + default_medium->ma2,
total_height = default_medium->ma3 + default_medium->ma4;
DO_PR_DEBUG_LOG(("setting default paper size to %g/%g mm\n", total_width, total_height));
aPrintSettings->SetPaperSizeType(nsIPrintSettings::kPaperSizeDefined);
aPrintSettings->SetPaperSizeUnit(nsIPrintSettings::kPaperSizeMillimeters);
aPrintSettings->SetPaperWidth(total_width);
aPrintSettings->SetPaperHeight(total_height);
#ifdef SET_PRINTER_FEATURES_VIA_PREFS #ifdef SET_PRINTER_FEATURES_VIA_PREFS
pPrefs->SetBoolPref(nsPrintfCString(256, PRINTERFEATURES_PREF ".%s.has_special_printerfeatures", printerName.get()).get(), PR_TRUE); nsPrinterFeatures printerFeatures(fullPrinterName);
int i;
for( i = 0 ; i < mcount ; i++ )
{
XpuMediumSourceSizeRec *curr = &mlist[i];
double total_width = curr->ma1 + curr->ma2,
total_height = curr->ma3 + curr->ma4;
pPrefs->SetCharPref(nsPrintfCString(256, PRINTERFEATURES_PREF ".%s.paper.%d.name", printerName.get(), i).get(), curr->medium_name);
pPrefs->SetIntPref( nsPrintfCString(256, PRINTERFEATURES_PREF ".%s.paper.%d.width_mm", printerName.get(), i).get(), PRInt32(total_width));
pPrefs->SetIntPref( nsPrintfCString(256, PRINTERFEATURES_PREF ".%s.paper.%d.height_mm", printerName.get(), i).get(), PRInt32(total_height));
pPrefs->SetBoolPref(nsPrintfCString(256, PRINTERFEATURES_PREF ".%s.paper.%d.is_inch", printerName.get(), i).get(), PR_FALSE);
}
pPrefs->SetIntPref(nsPrintfCString(256, PRINTERFEATURES_PREF ".%s.paper.count", printerName.get(), i).get(), (PRInt32)mcount);
#endif /* SET_PRINTER_FEATURES_VIA_PREFS */ #endif /* SET_PRINTER_FEATURES_VIA_PREFS */
XpuFreeMediumSourceSizeList(mlist); /* Setup orientation stuff */
XpuOrientationList olist;
int ocount;
XpuOrientationRec *default_orientation;
#ifdef SET_PRINTER_FEATURES_VIA_PREFS
PRBool canSetOrientation = MAKE_PR_BOOL(supported_doc_attrs & XPUATTRIBUTESUPPORTED_CONTENT_ORIENTATION);
printerFeatures.SetCanChangeOrientation(canSetOrientation);
#endif /* SET_PRINTER_FEATURES_VIA_PREFS */
/* Get list of supported orientations */
olist = XpuGetOrientationList(pdpy, pcontext, &ocount);
if (olist) {
default_orientation = &olist[0]; /* First entry is the default one */
if (!PL_strcasecmp(default_orientation->orientation, "portrait")) {
DO_PR_DEBUG_LOG(("setting default orientation to 'portrait'\n"));
aPrintSettings->SetOrientation(nsIPrintSettings::kPortraitOrientation);
}
else if (!PL_strcasecmp(default_orientation->orientation, "landscape")) {
DO_PR_DEBUG_LOG(("setting default orientation to 'landscape'\n"));
aPrintSettings->SetOrientation(nsIPrintSettings::kLandscapeOrientation);
} }
else {
DO_PR_DEBUG_LOG(("Unknown default orientation '%s'\n", default_orientation->orientation));
}
#ifdef SET_PRINTER_FEATURES_VIA_PREFS
int i;
for( i = 0 ; i < ocount ; i++ )
{
XpuOrientationRec *curr = &olist[i];
printerFeatures.SetOrientationRecord(i, curr->orientation);
}
printerFeatures.SetNumOrientationRecords(ocount);
#endif /* SET_PRINTER_FEATURES_VIA_PREFS */
XpuFreeOrientationList(olist);
}
/* Setup Number of Copies */
#ifdef SET_PRINTER_FEATURES_VIA_PREFS
PRBool canSetNumCopies = MAKE_PR_BOOL(supported_doc_attrs & XPUATTRIBUTESUPPORTED_COPY_COUNT);
printerFeatures.SetCanChangeNumCopies(canSetNumCopies);
#endif /* SET_PRINTER_FEATURES_VIA_PREFS */
long numCopies;
if( XpuGetOneLongAttribute(pdpy, pcontext, XPDocAttr, "copy-count", &numCopies) != 1 )
{
/* Fallback on failure */
numCopies = 1;
} }
aPrintSettings->SetNumCopies(numCopies);
/* Setup paper size stuff */
XpuMediumSourceSizeList mlist;
int mcount;
XpuMediumSourceSizeRec *default_medium;
#ifdef SET_PRINTER_FEATURES_VIA_PREFS
PRBool canSetPaperSize = MAKE_PR_BOOL(supported_doc_attrs & XPUATTRIBUTESUPPORTED_DEFAULT_MEDIUM);
printerFeatures.SetCanChangePaperSize(canSetPaperSize);
#endif /* SET_PRINTER_FEATURES_VIA_PREFS */
mlist = XpuGetMediumSourceSizeList(pdpy, pcontext, &mcount);
if (mlist) {
nsXPIDLCString papername;
default_medium = &mlist[0]; /* First entry is the default one */
double total_width = default_medium->ma1 + default_medium->ma2,
total_height = default_medium->ma3 + default_medium->ma4;
/* Either "paper" or "tray/paper" */
if (default_medium->tray_name) {
papername = nsPrintfCString(256, "%s/%s", default_medium->tray_name, default_medium->medium_name);
}
else {
papername.Assign(default_medium->medium_name);
}
DO_PR_DEBUG_LOG(("setting default paper size to '%s' (%g/%g mm)\n", papername.get(), total_width, total_height));
aPrintSettings->SetPaperSizeType(nsIPrintSettings::kPaperSizeDefined);
aPrintSettings->SetPaperSizeUnit(nsIPrintSettings::kPaperSizeMillimeters);
aPrintSettings->SetPaperWidth(total_width);
aPrintSettings->SetPaperHeight(total_height);
aPrintSettings->SetPaperName(NS_ConvertUTF8toUCS2(papername).get());
#ifdef SET_PRINTER_FEATURES_VIA_PREFS
int i;
for( i = 0 ; i < mcount ; i++ )
{
XpuMediumSourceSizeRec *curr = &mlist[i];
double total_width = curr->ma1 + curr->ma2,
total_height = curr->ma3 + curr->ma4;
if (curr->tray_name) {
papername = nsPrintfCString(256, "%s/%s", curr->tray_name, curr->medium_name);
}
else {
papername.Assign(curr->medium_name);
}
printerFeatures.SetPaperRecord(i, papername, PRInt32(total_width), PRInt32(total_height), PR_FALSE);
}
printerFeatures.SetNumPaperSizeRecords(mcount);
#endif /* SET_PRINTER_FEATURES_VIA_PREFS */
XpuFreeMediumSourceSizeList(mlist);
}
#ifdef SET_PRINTER_FEATURES_VIA_PREFS
/* Xprint does not allow the client to set a spooler command.
* Job spooling is the job of the server side (=Xprt) */
printerFeatures.SetCanChangeSpoolerCommand(PR_FALSE);
#endif /* SET_PRINTER_FEATURES_VIA_PREFS */
XpuClosePrinterDisplay(pdpy, pcontext); XpuClosePrinterDisplay(pdpy, pcontext);
return NS_OK; return NS_OK;
@ -733,68 +890,100 @@ NS_IMETHODIMP nsPrinterEnumeratorGTK::InitPrintSettingsFromPrinter(const PRUnich
#ifdef USE_POSTSCRIPT #ifdef USE_POSTSCRIPT
if (type == pmPostScript) { if (type == pmPostScript) {
DO_PR_DEBUG_LOG(("InitPrintSettingsFromPrinter() for PostScript printer\n")); DO_PR_DEBUG_LOG(("InitPrintSettingsFromPrinter() for PostScript printer\n"));
#ifdef SET_PRINTER_FEATURES_VIA_PREFS
nsPrinterFeatures printerFeatures(fullPrinterName);
#endif /* SET_PRINTER_FEATURES_VIA_PREFS */
if (doingNumCopies) { #ifdef SET_PRINTER_FEATURES_VIA_PREFS
/* Not implemented yet */ printerFeatures.SetCanChangeOrientation(PR_TRUE);
#endif /* SET_PRINTER_FEATURES_VIA_PREFS */
nsXPIDLCString orientation;
if (NS_SUCCEEDED(CopyPrinterCharPref(pPrefs, "postscript", printerName, "orientation", getter_Copies(orientation)))) {
if (!PL_strcasecmp(orientation, "portrait")) {
DO_PR_DEBUG_LOG(("setting default orientation to 'portrait'\n"));
aPrintSettings->SetOrientation(nsIPrintSettings::kPortraitOrientation);
}
else if (!PL_strcasecmp(orientation, "landscape")) {
DO_PR_DEBUG_LOG(("setting default orientation to 'landscape'\n"));
aPrintSettings->SetOrientation(nsIPrintSettings::kLandscapeOrientation);
}
else {
DO_PR_DEBUG_LOG(("Unknown default orientation '%s'\n", orientation.get()));
}
}
#ifdef SET_PRINTER_FEATURES_VIA_PREFS
int i;
for( i = 0 ; postscript_module_orientations[i].orientation != nsnull ; i++ )
{
const PSOrientationRec *curr = &postscript_module_orientations[i];
printerFeatures.SetOrientationRecord(i, curr->orientation);
}
printerFeatures.SetNumOrientationRecords(i);
#endif /* SET_PRINTER_FEATURES_VIA_PREFS */
#ifdef SET_PRINTER_FEATURES_VIA_PREFS
printerFeatures.SetCanChangePaperSize(PR_TRUE);
#endif /* SET_PRINTER_FEATURES_VIA_PREFS */
nsXPIDLCString papername;
if (NS_SUCCEEDED(CopyPrinterCharPref(pPrefs, "postscript", printerName, "paper_size", getter_Copies(papername)))) {
int i;
const PSPaperSizeRec *default_paper = nsnull;
for( i = 0 ; postscript_module_paper_sizes[i].name != nsnull ; i++ )
{
const PSPaperSizeRec *curr = &postscript_module_paper_sizes[i];
if (!PL_strcasecmp(papername, curr->name)) {
default_paper = curr;
break;
}
}
if (default_paper) {
DO_PR_DEBUG_LOG(("setting default paper size to '%s' (%g inch/%g inch)\n",
default_paper->name,
PSPaperSizeRec_FullPaperWidth(default_paper),
PSPaperSizeRec_FullPaperHeight(default_paper)));
aPrintSettings->SetPaperSizeType(nsIPrintSettings::kPaperSizeDefined);
aPrintSettings->SetPaperSizeUnit(nsIPrintSettings::kPaperSizeInches);
aPrintSettings->SetPaperWidth(PSPaperSizeRec_FullPaperWidth(default_paper));
aPrintSettings->SetPaperHeight(PSPaperSizeRec_FullPaperHeight(default_paper));
aPrintSettings->SetPaperName(NS_ConvertUTF8toUCS2(default_paper->name).get());
}
else {
DO_PR_DEBUG_LOG(("Unknown paper size '%s' given.\n", papername.get()));
}
#ifdef SET_PRINTER_FEATURES_VIA_PREFS
for( i = 0 ; postscript_module_paper_sizes[i].name != nsnull ; i++ )
{
const PSPaperSizeRec *curr = &postscript_module_paper_sizes[i];
#define CONVERT_INCH_TO_MILLIMETERS(inch) ((inch) * 25.4)
double total_width = CONVERT_INCH_TO_MILLIMETERS(PSPaperSizeRec_FullPaperWidth(curr)),
total_height = CONVERT_INCH_TO_MILLIMETERS(PSPaperSizeRec_FullPaperHeight(curr));
printerFeatures.SetPaperRecord(i, curr->name, PRInt32(total_width), PRInt32(total_height), PR_TRUE);
}
printerFeatures.SetNumPaperSizeRecords(i);
#endif /* SET_PRINTER_FEATURES_VIA_PREFS */
}
#ifdef SET_PRINTER_FEATURES_VIA_PREFS
printerFeatures.SetCanChangeSpoolerCommand(PR_TRUE);
#endif /* SET_PRINTER_FEATURES_VIA_PREFS */
nsXPIDLCString command;
if (NS_SUCCEEDED(CopyPrinterCharPref(pPrefs, "postscript", printerName, "print_command", getter_Copies(command)))) {
DO_PR_DEBUG_LOG(("setting default print command to '%s'\n", command.get()));
aPrintSettings->SetPrintCommand(NS_ConvertUTF8toUCS2(command).get());
} }
if (doingOrientation) { #ifdef SET_PRINTER_FEATURES_VIA_PREFS
nsXPIDLCString orientation; printerFeatures.SetCanChangeNumCopies(PR_TRUE);
if (NS_SUCCEEDED(CopyPrinterCharPref(pPrefs, "postscript", printerName, "orientation", getter_Copies(orientation)))) { #endif /* SET_PRINTER_FEATURES_VIA_PREFS */
if (!PL_strcasecmp(orientation, "portrait")) {
DO_PR_DEBUG_LOG(("setting default orientation to 'portrait'\n"));
aPrintSettings->SetOrientation(nsIPrintSettings::kPortraitOrientation);
}
else if (!PL_strcasecmp(orientation, "landscape")) {
DO_PR_DEBUG_LOG(("setting default orientation to 'landscape'\n"));
aPrintSettings->SetOrientation(nsIPrintSettings::kLandscapeOrientation);
}
else {
DO_PR_DEBUG_LOG(("Unknown default orientation '%s'\n", orientation.get()));
}
}
}
if (doingPaperSize) {
/* Not implemented yet */
nsXPIDLCString papername;
if (NS_SUCCEEDED(CopyPrinterCharPref(pPrefs, "postscript", printerName, "paper_size", getter_Copies(papername)))) {
int i;
double width = 0.,
height = 0.;
for( i = 0 ; postscript_module_paper_sizes[i].name != nsnull ; i++ )
{
const PSPaperSizeRec *curr = &postscript_module_paper_sizes[i];
if (!PL_strcasecmp(papername, curr->name)) {
width = curr->width;
height = curr->height;
break;
}
}
if (width!=0.0 && height!=0.0) {
DO_PR_DEBUG_LOG(("setting default paper size to %g/%g inch\n", width, height));
aPrintSettings->SetPaperSizeType(nsIPrintSettings::kPaperSizeDefined);
aPrintSettings->SetPaperSizeUnit(nsIPrintSettings::kPaperSizeInches);
aPrintSettings->SetPaperWidth(width);
aPrintSettings->SetPaperHeight(height);
}
else {
DO_PR_DEBUG_LOG(("Unknown paper size '%s' given.\n", papername));
}
}
}
if (doingCommand) {
nsXPIDLCString command;
if (NS_SUCCEEDED(CopyPrinterCharPref(pPrefs, "postscript", printerName, "print_command", getter_Copies(command)))) {
DO_PR_DEBUG_LOG(("setting default print command to '%s'\n", command.get()));
aPrintSettings->SetPrintCommand(NS_ConvertUTF8toUCS2(command).get());
}
}
return NS_OK; return NS_OK;
} }
#endif /* USE_POSTSCRIPT */ #endif /* USE_POSTSCRIPT */

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

@ -93,6 +93,7 @@ public:
NS_IMETHOD GetPrintMethod(PrintMethod &aMethod); NS_IMETHOD GetPrintMethod(PrintMethod &aMethod);
static nsresult GetPrintMethod(const char *aPrinter, PrintMethod &aMethod); static nsresult GetPrintMethod(const char *aPrinter, PrintMethod &aMethod);
NS_IMETHOD GetPageSizeInTwips(PRInt32 *aWidth, PRInt32 *aHeight); NS_IMETHOD GetPageSizeInTwips(PRInt32 *aWidth, PRInt32 *aHeight);
NS_IMETHOD GetPaperName(const char **aPaperName);
virtual ~nsDeviceContextSpecGTK(); virtual ~nsDeviceContextSpecGTK();
protected: protected:
@ -104,6 +105,7 @@ protected:
char mCommand[PATH_MAX]; /* Print command e.g., lpr */ char mCommand[PATH_MAX]; /* Print command e.g., lpr */
char mPath[PATH_MAX]; /* If toPrinter = PR_FALSE, dest file */ char mPath[PATH_MAX]; /* If toPrinter = PR_FALSE, dest file */
char mPrinter[256]; /* Printer name */ char mPrinter[256]; /* Printer name */
char mPaperName[256]; /* Printer name */
int mCopies; /* number of copies */ int mCopies; /* number of copies */
PRBool mCancel; /* If PR_TRUE, user cancelled */ PRBool mCancel; /* If PR_TRUE, user cancelled */
float mLeft; /* left margin */ float mLeft; /* left margin */

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

@ -151,6 +151,14 @@ public:
**/ **/
NS_IMETHOD GetUserCancelled( PRBool &aCancel ) = 0; NS_IMETHOD GetUserCancelled( PRBool &aCancel ) = 0;
/*
* Paper name e.g., "din-a4" or "manual/din-a4"
* @update
* @param aPaperName --
* @return
**/
NS_IMETHOD GetPaperName ( const char **aPaperName ) = 0;
/* /*
* Returns W/H in Twips from Paper Size H/W * Returns W/H in Twips from Paper Size H/W
*/ */

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

@ -64,6 +64,9 @@
#include "prprf.h" #include "prprf.h"
#endif #endif
/* This is deprecated but we still need it until all platforms set the paper name in nsIPrintSettings... */
#define PS_FIND_PAPER_BY_SIZE 1
#ifdef PR_LOGGING #ifdef PR_LOGGING
static PRLogModuleInfo *nsPostScriptObjLM = PR_NewLogModule("nsPostScriptObj"); static PRLogModuleInfo *nsPostScriptObjLM = PR_NewLogModule("nsPostScriptObj");
#endif /* PR_LOGGING */ #endif /* PR_LOGGING */
@ -79,7 +82,7 @@ extern "C" PS_FontInfo *PSFE_MaskToFI[N_FONTS]; // need fontmetrics.c
#define NS_PS_RED(x) (((float)(NS_GET_R(x))) / 255.0) #define NS_PS_RED(x) (((float)(NS_GET_R(x))) / 255.0)
#define NS_PS_GREEN(x) (((float)(NS_GET_G(x))) / 255.0) #define NS_PS_GREEN(x) (((float)(NS_GET_G(x))) / 255.0)
#define NS_PS_BLUE(x) (((float)(NS_GET_B(x))) / 255.0) #define NS_PS_BLUE(x) (((float)(NS_GET_B(x))) / 255.0)
#define NS_TWIPS_TO_POINTS(x) ((x / 20)) #define NS_TWIPS_TO_POINTS(x) (((x) / 20))
#define NS_IS_BOLD(x) (((x) >= 401) ? 1 : 0) #define NS_IS_BOLD(x) (((x) >= 401) ? 1 : 0)
static NS_DEFINE_CID(kPrefCID, NS_PREF_CID); static NS_DEFINE_CID(kPrefCID, NS_PREF_CID);
@ -242,8 +245,9 @@ nsPostScriptObj::settitle(PRUnichar * aTitle)
} }
} }
#ifdef PS_FIND_PAPER_BY_SIZE
static static
const char *paper_size_to_paper_name(float width_in_inch, float height_in_inch) const PSPaperSizeRec *paper_size_to_PSPaperSizeRec(float width_in_inch, float height_in_inch)
{ {
#define MORE_OR_LESS_EQUAL(a, b, tolerance) (PR_ABS((a) - (b)) <= (tolerance)) #define MORE_OR_LESS_EQUAL(a, b, tolerance) (PR_ABS((a) - (b)) <= (tolerance))
#define MATCH_PAGE(width, height, paper_width, paper_height) \ #define MATCH_PAGE(width, height, paper_width, paper_height) \
@ -255,14 +259,31 @@ const char *paper_size_to_paper_name(float width_in_inch, float height_in_inch)
{ {
const PSPaperSizeRec *curr = &postscript_module_paper_sizes[i]; const PSPaperSizeRec *curr = &postscript_module_paper_sizes[i];
if (MATCH_PAGE(width_in_inch, height_in_inch, curr->width, curr->height)) if (MATCH_PAGE(width_in_inch, height_in_inch, PSPaperSizeRec_FullPaperWidth(curr), PSPaperSizeRec_FullPaperHeight(curr)))
return curr->name; return curr;
} }
#undef MATCH_PAGE #undef MATCH_PAGE
#undef MORE_OR_LESS_EQUAL #undef MORE_OR_LESS_EQUAL
return nsnull; return nsnull;
} }
#endif /* PS_FIND_PAPER_BY_SIZE */
static
const PSPaperSizeRec *paper_name_to_PSPaperSizeRec(const char *paper_name)
{
int i;
for( i = 0 ; postscript_module_paper_sizes[i].name != nsnull ; i++ )
{
const PSPaperSizeRec *curr = &postscript_module_paper_sizes[i];
if (!PL_strcasecmp(paper_name, curr->name))
return curr;
}
return nsnull;
}
/** --------------------------------------------------- /** ---------------------------------------------------
* See documentation in nsPostScriptObj.h * See documentation in nsPostScriptObj.h
@ -283,7 +304,7 @@ nsPostScriptObj::Init( nsIDeviceContextSpecPS *aSpec )
if( (nsnull!=pi) && (nsnull!=mPrintSetup) ){ if( (nsnull!=pi) && (nsnull!=mPrintSetup) ){
memset(mPrintSetup, 0, sizeof(struct PrintSetup_)); memset(mPrintSetup, 0, sizeof(struct PrintSetup_));
mPrintSetup->color = PR_TRUE; // Image output mPrintSetup->color = PR_TRUE; // Image output
mPrintSetup->deep_color = PR_TRUE; // 24 bit color output mPrintSetup->deep_color = PR_TRUE; // 24 bit color output
mPrintSetup->reverse = 0; // Output order, 0 is acsending mPrintSetup->reverse = 0; // Output order, 0 is acsending
@ -297,16 +318,25 @@ nsPostScriptObj::Init( nsIDeviceContextSpecPS *aSpec )
aSpec->GetFirstPageFirst( isFirstPageFirst ); aSpec->GetFirstPageFirst( isFirstPageFirst );
if ( isFirstPageFirst == PR_FALSE ) if ( isFirstPageFirst == PR_FALSE )
mPrintSetup->reverse = 1; mPrintSetup->reverse = 1;
PRInt32 paper_width_in_twips,
paper_height_in_twips;
aSpec->GetPageSizeInTwips(&paper_width_in_twips, &paper_height_in_twips);
mPrintSetup->paper_width_in_inch = NS_TWIPS_TO_INCHES(paper_width_in_twips);
mPrintSetup->paper_height_in_inch = NS_TWIPS_TO_INCHES(paper_height_in_twips);
/* Chceck if we have a name for this paper size... */ /* Find PS paper size record by name */
if (!paper_size_to_paper_name(mPrintSetup->paper_width_in_inch, mPrintSetup->paper_height_in_inch)) const char *paper_name = nsnull;
aSpec->GetPaperName(&paper_name);
mPrintSetup->paper_size = paper_name_to_PSPaperSizeRec(paper_name);
#ifdef PS_FIND_PAPER_BY_SIZE
if (!mPrintSetup->paper_size) {
PR_LOG(nsPostScriptObjLM, PR_LOG_DEBUG, ("No paper matched by name '%s' - trying deprecated match-by-size way...\n", paper_name));
PRInt32 paper_width_in_twips,
paper_height_in_twips;
aSpec->GetPageSizeInTwips(&paper_width_in_twips, &paper_height_in_twips);
mPrintSetup->paper_size = paper_size_to_PSPaperSizeRec(NS_TWIPS_TO_INCHES(paper_width_in_twips), NS_TWIPS_TO_INCHES(paper_height_in_twips));
}
#endif /* PS_FIND_PAPER_BY_SIZE */
if (!mPrintSetup->paper_size)
return NS_ERROR_GFX_PRINTER_PAPER_SIZE_NOT_SUPPORTED; return NS_ERROR_GFX_PRINTER_PAPER_SIZE_NOT_SUPPORTED;
aSpec->GetToPrinter( isAPrinter ); aSpec->GetToPrinter( isAPrinter );
if (isAPrinter) { if (isAPrinter) {
/* Define the destination printer (queue). /* Define the destination printer (queue).
@ -375,8 +405,8 @@ nsPostScriptObj::Init( nsIDeviceContextSpecPS *aSpec )
mPrintSetup->dpi = 72.0f; // dpi for externally sized items mPrintSetup->dpi = 72.0f; // dpi for externally sized items
aSpec->GetLandscape( landscape ); aSpec->GetLandscape( landscape );
fwidth = mPrintSetup->paper_width_in_inch; fwidth = mPrintSetup->paper_size->width;
fheight = mPrintSetup->paper_height_in_inch; fheight = mPrintSetup->paper_size->height;
if (landscape) { if (landscape) {
float temp; float temp;
@ -385,7 +415,12 @@ nsPostScriptObj::Init( nsIDeviceContextSpecPS *aSpec )
fheight = temp; fheight = temp;
} }
mPrintSetup->width = (int)(fwidth * mPrintSetup->dpi); mPrintSetup->left = (int)(mPrintSetup->paper_size->left * mPrintSetup->dpi);
mPrintSetup->top = (int)(mPrintSetup->paper_size->top * mPrintSetup->dpi);
mPrintSetup->bottom = (int)(mPrintSetup->paper_size->bottom * mPrintSetup->dpi);
mPrintSetup->right = (int)(mPrintSetup->paper_size->right * mPrintSetup->dpi);
mPrintSetup->width = (int)(fwidth * mPrintSetup->dpi);
mPrintSetup->height = (int)(fheight * mPrintSetup->dpi); mPrintSetup->height = (int)(fheight * mPrintSetup->dpi);
#ifdef DEBUG #ifdef DEBUG
printf("\nPreWidth = %f PreHeight = %f\n",fwidth,fheight); printf("\nPreWidth = %f PreHeight = %f\n",fwidth,fheight);
@ -403,13 +438,9 @@ nsPostScriptObj::Init( nsIDeviceContextSpecPS *aSpec )
mPrintSetup->scale_pre = PR_FALSE; // do the pre-scaling thing mPrintSetup->scale_pre = PR_FALSE; // do the pre-scaling thing
// scale margins (specified in inches) to dots. // scale margins (specified in inches) to dots.
mPrintSetup->top = (int) 0; PR_LOG(nsPostScriptObjLM, PR_LOG_DEBUG, ("dpi %g top %d bottom %d left %d right %d\n",
mPrintSetup->bottom = (int) 0; mPrintSetup->dpi, mPrintSetup->top, mPrintSetup->bottom, mPrintSetup->left, mPrintSetup->right));
mPrintSetup->left = (int) 0;
mPrintSetup->right = (int) 0;
#ifdef DEBUG
printf( "dpi %f top %d bottom %d left %d right %d\n", mPrintSetup->dpi, mPrintSetup->top, mPrintSetup->bottom, mPrintSetup->left, mPrintSetup->right );
#endif
mPrintSetup->rules = 1.0f; // Scale factor for rulers mPrintSetup->rules = 1.0f; // Scale factor for rulers
mPrintSetup->n_up = 0; // cool page combining mPrintSetup->n_up = 0; // cool page combining
mPrintSetup->bigger = 1; // Used to init sizes if sizesin NULL mPrintSetup->bigger = 1; // Used to init sizes if sizesin NULL
@ -526,8 +557,7 @@ FILE *f;
gPrefs->CopyCharPref("general.useragent.misc", getter_Copies(useragent)); gPrefs->CopyCharPref("general.useragent.misc", getter_Copies(useragent));
fprintf(f, "%%%%Creator: Mozilla PostScript module (%s/%lu)\n", useragent.get(), (unsigned long)NS_BUILD_ID); fprintf(f, "%%%%Creator: Mozilla PostScript module (%s/%lu)\n", useragent.get(), (unsigned long)NS_BUILD_ID);
fprintf(f, "%%%%DocumentData: Clean8Bit\n"); fprintf(f, "%%%%DocumentData: Clean8Bit\n");
fprintf(f, "%%%%DocumentPaperSizes: %s\n", fprintf(f, "%%%%DocumentPaperSizes: %s\n", mPrintSetup->paper_size->name);
paper_size_to_paper_name(mPrintSetup->paper_width_in_inch, mPrintSetup->paper_height_in_inch));
fprintf(f, "%%%%Orientation: %s\n", fprintf(f, "%%%%Orientation: %s\n",
(mPrintContext->prSetup->width < mPrintContext->prSetup->height) ? "Portrait" : "Landscape"); (mPrintContext->prSetup->width < mPrintContext->prSetup->height) ? "Portrait" : "Landscape");
@ -1970,7 +2000,7 @@ FILE *f;
fprintf(f, "%d 0 translate 90 rotate\n",PAGE_TO_POINT_I(mPrintContext->prSetup->height)); fprintf(f, "%d 0 translate 90 rotate\n",PAGE_TO_POINT_I(mPrintContext->prSetup->height));
} }
fprintf(f, "%d 0 translate\n", PAGE_TO_POINT_I(mPrintContext->prSetup->left)); fprintf(f, "%d 0 translate\n", PAGE_TO_POINT_I(mPrintContext->prSetup->left));
fprintf(f, "0 %d translate\n", -PAGE_TO_POINT_I(mPrintContext->prSetup->top)); fprintf(f, "0 %d translate\n", PAGE_TO_POINT_I(mPrintContext->prSetup->top));
fprintf(f, "%%%%EndPageSetup\n"); fprintf(f, "%%%%EndPageSetup\n");
#if 0 #if 0
annotate_page( mPrintContext->prSetup->header, 0, -1, pn); annotate_page( mPrintContext->prSetup->header, 0, -1, pn);

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

@ -67,23 +67,42 @@ class nsIImage;
typedef struct { typedef struct {
const char *name; const char *name;
float width, float left,
top,
right,
bottom,
width,
height; height;
} PSPaperSizeRec; } PSPaperSizeRec;
static const static const
PSPaperSizeRec postscript_module_paper_sizes[] = PSPaperSizeRec postscript_module_paper_sizes[] =
{ {
/* 148mm X 210mm == 5.83in X 8.27in */ { "A5", 0.25f, 0.25f, 0.25f, 0.25f, 5.33f, 7.77f }, /* 148mm X 210mm ( 5.83in X 8.27in) */
{ "A5", 5.83f, 8.27f }, { "A4", 0.25f, 0.25f, 0.25f, 0.25f, 7.77f, 11.19f }, /* 210mm X 297mm ( 8.27in X 11.69in) */
/* 210mm X 297mm == 8.27in X 11.69in */ { "A3", 0.25f, 0.25f, 0.25f, 0.25f, 11.19f, 16.03f }, /* 297mm X 420mm (11.69in X 16.53in) */
{ "A4", 8.27f, 11.69f }, { "Letter", 0.25f, 0.25f, 0.25f, 0.25f, 8.00f, 10.50f }, /* 8.50in X 11.0in */
/* 297mm X 420mm == 11.69in X 16.53in */ { "Legal", 0.25f, 0.25f, 0.25f, 0.25f, 8.00f, 13.50f }, /* 8.50in X 14.0in */
{ "A3", 11.69f, 16.53f }, { "Executive", 0.25f, 0.25f, 0.25f, 0.25f, 7.00f, 9.50f }, /* 7.50in X 10.0in */
{ "Letter", 8.50f, 11.0f }, { NULL, 0.25f, 0.25f, 0.25f, 0.25f, 0.00f, 0.0f }
{ "Legal", 8.50f, 14.0f }, };
{ "Executive", 7.50f, 10.0f },
{ NULL, 0.00f, 0.0f } #define PSPaperSizeRec_FullPaperWidth(rec) ((rec)->left + (rec)->right + (rec)->width)
#define PSPaperSizeRec_FullPaperHeight(rec) ((rec)->top + (rec)->bottom + (rec)->height)
/* This will be extended some day... */
typedef struct {
const char *orientation;
} PSOrientationRec;
/* This will be extended some day... */
static const
PSOrientationRec postscript_module_orientations[] =
{
{ "portrait" },
{ "landscape" },
{ NULL }
}; };
typedef void (*XL_CompletionRoutine)(void*); typedef void (*XL_CompletionRoutine)(void*);
@ -187,9 +206,7 @@ struct PrintSetup_ {
float rules; /* Scale factor for rulers */ float rules; /* Scale factor for rulers */
int n_up; /* cool page combining */ int n_up; /* cool page combining */
int bigger; /* Used to init sizes if sizesin NULL */ int bigger; /* Used to init sizes if sizesin NULL */
int paper_size; /* Paper Size(letter,legal,exec,a4,a3) */ const PSPaperSizeRec *paper_size; /* Paper size record */
float paper_width_in_inch, /* paper width in inch */
paper_height_in_inch; /* paper height in inch */
const char* prefix; /* For text xlate, prepended to each line */ const char* prefix; /* For text xlate, prepended to each line */
const char* eol; /* For text translation, line terminator */ const char* eol; /* For text translation, line terminator */
const char* bullet; /* What char to use for bullets */ const char* bullet; /* What char to use for bullets */

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

@ -71,6 +71,9 @@
#include "nsPostScriptObj.h" #include "nsPostScriptObj.h"
#endif /* USE_POSTSCRIPT */ #endif /* USE_POSTSCRIPT */
/* Ensure that the result is always equal to either PR_TRUE or PR_FALSE */
#define MAKE_PR_BOOL(val) ((val)?(PR_TRUE):(PR_FALSE))
#ifdef PR_LOGGING #ifdef PR_LOGGING
static PRLogModuleInfo *DeviceContextSpecXlibLM = PR_NewLogModule("DeviceContextSpecXlib"); static PRLogModuleInfo *DeviceContextSpecXlibLM = PR_NewLogModule("DeviceContextSpecXlib");
#endif /* PR_LOGGING */ #endif /* PR_LOGGING */
@ -104,6 +107,111 @@ protected:
static int mGlobalNumPrinters; static int mGlobalNumPrinters;
}; };
#ifdef SET_PRINTER_FEATURES_VIA_PREFS
/* "Prototype" for the new nsPrinterFeatures service */
class nsPrinterFeatures {
public:
nsPrinterFeatures( const char *printername );
~nsPrinterFeatures() {};
/* Does this device allow to set/change the paper size ? */
void SetCanChangePaperSize( PRBool aCanSetPaperSize );
/* Set number of paper size records and the records itself */
void SetNumPaperSizeRecords( PRInt32 aCount );
void SetPaperRecord( PRInt32 aIndex, const char *aName, PRInt32 aWidthMM, PRInt32 aHeightMM, PRBool aIsInch );
/* Does this device allow to set/change the content orientation ? */
void SetCanChangeOrientation( PRBool aCanSetOrientation );
/* Set number of orientation records and the records itself */
void SetNumOrientationRecords( PRInt32 aCount );
void SetOrientationRecord( PRInt32 aIndex, const char *aName );
/* Does this device allow to set/change the spooler command ? */
void SetCanChangeSpoolerCommand( PRBool aCanSetSpoolerCommand );
/* Does this device allow to set/change number of copies for an document ? */
void SetCanChangeNumCopies( PRBool aCanSetNumCopies );
private:
/* private helper methods */
void SetBoolValue( const char *tagname, PRBool value );
void SetIntValue( const char *tagname, PRInt32 value );
void SetCharValue( const char *tagname, const char *value );
nsXPIDLCString mPrinterName;
nsCOMPtr<nsIPref> mPrefs;
};
void nsPrinterFeatures::SetBoolValue( const char *tagname, PRBool value )
{
mPrefs->SetBoolPref(nsPrintfCString(256, PRINTERFEATURES_PREF ".%s.%s", mPrinterName.get(), tagname).get(), value);
}
void nsPrinterFeatures::SetIntValue( const char *tagname, PRInt32 value )
{
mPrefs->SetIntPref(nsPrintfCString(256, PRINTERFEATURES_PREF ".%s.%s", mPrinterName.get(), tagname).get(), value);
}
void nsPrinterFeatures::SetCharValue( const char *tagname, const char *value )
{
mPrefs->SetCharPref(nsPrintfCString(256, PRINTERFEATURES_PREF ".%s.%s", mPrinterName.get(), tagname).get(), value);
}
nsPrinterFeatures::nsPrinterFeatures( const char *printername )
{
DO_PR_DEBUG_LOG(("nsPrinterFeatures::nsPrinterFeatures('%s')\n", printername));
mPrinterName.Assign(printername);
mPrefs = do_GetService(NS_PREF_CONTRACTID);
SetBoolValue("has_special_printerfeatures", PR_TRUE);
}
void nsPrinterFeatures::SetCanChangePaperSize( PRBool aCanSetPaperSize )
{
SetBoolValue("can_change_paper_size", aCanSetPaperSize);
}
/* Set number of paper size records and the records itself */
void nsPrinterFeatures::SetNumPaperSizeRecords( PRInt32 aCount )
{
SetIntValue("paper.count", aCount);
}
void nsPrinterFeatures::SetPaperRecord(PRInt32 aIndex, const char *aPaperName, PRInt32 aWidthMM, PRInt32 aHeightMM, PRBool aIsInch)
{
SetCharValue(nsPrintfCString(256, "paper.%d.name", aIndex).get(), aPaperName);
SetIntValue( nsPrintfCString(256, "paper.%d.width_mm", aIndex).get(), aWidthMM);
SetIntValue( nsPrintfCString(256, "paper.%d.height_mm", aIndex).get(), aHeightMM);
SetBoolValue(nsPrintfCString(256, "paper.%d.is_inch", aIndex).get(), aIsInch);
}
void nsPrinterFeatures::SetCanChangeOrientation( PRBool aCanSetOrientation )
{
SetBoolValue("can_change_orientation", aCanSetOrientation);
}
void nsPrinterFeatures::SetNumOrientationRecords( PRInt32 aCount )
{
SetIntValue("orientation.count", aCount);
}
void nsPrinterFeatures::SetOrientationRecord( PRInt32 aIndex, const char *aOrientationName )
{
SetCharValue(nsPrintfCString(256, "orientation.%d.name", aIndex).get(), aOrientationName);
}
void nsPrinterFeatures::SetCanChangeSpoolerCommand( PRBool aCanSetSpoolerCommand )
{
SetBoolValue("can_change_spoolercommand", aCanSetSpoolerCommand);
}
void nsPrinterFeatures::SetCanChangeNumCopies( PRBool aCanSetNumCopies )
{
SetBoolValue("can_change_num_copies", aCanSetNumCopies);
}
#endif /* SET_PRINTER_FEATURES_VIA_PREFS */
//--------------- //---------------
// static members // static members
GlobalPrinters GlobalPrinters::mGlobalPrinters; GlobalPrinters GlobalPrinters::mGlobalPrinters;
@ -271,6 +379,7 @@ NS_IMETHODIMP nsDeviceContextSpecXlib::Init(nsIPrintSettings *aPS, PRBool aQuiet
PRUnichar *command = nsnull; PRUnichar *command = nsnull;
PRInt32 copies = 1; PRInt32 copies = 1;
PRUnichar *printer = nsnull; PRUnichar *printer = nsnull;
PRUnichar *papername = nsnull;
PRUnichar *printfile = nsnull; PRUnichar *printfile = nsnull;
double dleft = 0.5; double dleft = 0.5;
double dright = 0.5; double dright = 0.5;
@ -280,6 +389,7 @@ NS_IMETHODIMP nsDeviceContextSpecXlib::Init(nsIPrintSettings *aPS, PRBool aQuiet
aPS->GetPrinterName(&printer); aPS->GetPrinterName(&printer);
aPS->GetPrintReversed(&reversed); aPS->GetPrintReversed(&reversed);
aPS->GetPrintInColor(&color); aPS->GetPrintInColor(&color);
aPS->GetPaperName(&papername);
aPS->GetOrientation(&orientation); aPS->GetOrientation(&orientation);
aPS->GetPrintCommand(&command); aPS->GetPrintCommand(&command);
aPS->GetPrintRange(&printRange); aPS->GetPrintRange(&printRange);
@ -299,6 +409,8 @@ NS_IMETHODIMP nsDeviceContextSpecXlib::Init(nsIPrintSettings *aPS, PRBool aQuiet
strcpy(mCommand, NS_ConvertUCS2toUTF8(command).get()); strcpy(mCommand, NS_ConvertUCS2toUTF8(command).get());
if (printer) if (printer)
strcpy(mPrinter, NS_ConvertUCS2toUTF8(printer).get()); strcpy(mPrinter, NS_ConvertUCS2toUTF8(printer).get());
if (papername)
strcpy(mPaperName, NS_ConvertUCS2toUTF8(papername).get());
DO_PR_DEBUG_LOG(("margins: %5.2f,%5.2f,%5.2f,%5.2f\n", dtop, dleft, dbottom, dright)); DO_PR_DEBUG_LOG(("margins: %5.2f,%5.2f,%5.2f,%5.2f\n", dtop, dleft, dbottom, dright));
DO_PR_DEBUG_LOG(("printRange %d\n", printRange)); DO_PR_DEBUG_LOG(("printRange %d\n", printRange));
@ -308,6 +420,7 @@ NS_IMETHODIMP nsDeviceContextSpecXlib::Init(nsIPrintSettings *aPS, PRBool aQuiet
DO_PR_DEBUG_LOG(("printfile '%s'\n", printfile? NS_ConvertUCS2toUTF8(printfile).get():"<NULL>")); DO_PR_DEBUG_LOG(("printfile '%s'\n", printfile? NS_ConvertUCS2toUTF8(printfile).get():"<NULL>"));
DO_PR_DEBUG_LOG(("command '%s'\n", command? NS_ConvertUCS2toUTF8(command).get():"<NULL>")); DO_PR_DEBUG_LOG(("command '%s'\n", command? NS_ConvertUCS2toUTF8(command).get():"<NULL>"));
DO_PR_DEBUG_LOG(("printer '%s'\n", printer? NS_ConvertUCS2toUTF8(printer).get():"<NULL>")); DO_PR_DEBUG_LOG(("printer '%s'\n", printer? NS_ConvertUCS2toUTF8(printer).get():"<NULL>"));
DO_PR_DEBUG_LOG(("papername '%s'\n", papername? NS_ConvertUCS2toUTF8(papername).get():"<NULL>"));
mTop = dtop; mTop = dtop;
mBottom = dbottom; mBottom = dbottom;
@ -402,6 +515,12 @@ NS_IMETHODIMP nsDeviceContextSpecXlib::GetUserCancelled(PRBool &aCancel)
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP nsDeviceContextSpecXlib::GetPaperName( const char **aPaperName )
{
*aPaperName = mPaperName;
return NS_OK;
}
NS_IMETHODIMP nsDeviceContextSpecXlib::GetPageSizeInTwips(PRInt32 *aWidth, PRInt32 *aHeight) NS_IMETHODIMP nsDeviceContextSpecXlib::GetPageSizeInTwips(PRInt32 *aWidth, PRInt32 *aHeight)
{ {
return mPrintSettings->GetPageSizeInTwips(aWidth, aHeight); return mPrintSettings->GetPageSizeInTwips(aWidth, aHeight);
@ -582,20 +701,17 @@ NS_IMETHODIMP nsPrinterEnumeratorXlib::InitPrintSettingsFromPrinter(const PRUnic
NS_ENSURE_ARG_POINTER(aPrinterName); NS_ENSURE_ARG_POINTER(aPrinterName);
NS_ENSURE_ARG_POINTER(aPrintSettings); NS_ENSURE_ARG_POINTER(aPrintSettings);
if (!*aPrinterName) {
return NS_ERROR_FAILURE;
}
if (aPrintSettings == nsnull) { NS_ENSURE_TRUE(*aPrinterName, NS_ERROR_FAILURE);
return NS_ERROR_FAILURE; NS_ENSURE_TRUE(aPrintSettings, NS_ERROR_FAILURE);
}
nsCOMPtr<nsIPref> pPrefs = do_GetService(NS_PREF_CONTRACTID, &rv); nsCOMPtr<nsIPref> pPrefs = do_GetService(NS_PREF_CONTRACTID, &rv);
if (NS_FAILED(rv)) if (NS_FAILED(rv))
return rv; return rv;
nsXPIDLCString printerName; nsXPIDLCString fullPrinterName, /* Full name of printer incl. driver-specific prefix */
printerName; /* "Stripped" name of printer */
fullPrinterName.Assign(NS_ConvertUCS2toUTF8(aPrinterName));
printerName.Assign(NS_ConvertUCS2toUTF8(aPrinterName)); printerName.Assign(NS_ConvertUCS2toUTF8(aPrinterName));
DO_PR_DEBUG_LOG(("printerName='%s'\n", printerName.get())); DO_PR_DEBUG_LOG(("printerName='%s'\n", printerName.get()));
@ -615,33 +731,25 @@ NS_IMETHODIMP nsPrinterEnumeratorXlib::InitPrintSettingsFromPrinter(const PRUnic
#ifdef SET_PRINTER_FEATURES_VIA_PREFS #ifdef SET_PRINTER_FEATURES_VIA_PREFS
/* Defaults to FALSE */ /* Defaults to FALSE */
pPrefs->SetBoolPref(nsPrintfCString(256, PRINTERFEATURES_PREF ".%s.has_special_printerfeatures", printerName.get()).get(), PR_FALSE); pPrefs->SetBoolPref(nsPrintfCString(256, PRINTERFEATURES_PREF ".%s.has_special_printerfeatures", fullPrinterName.get()).get(), PR_FALSE);
#endif /* SET_PRINTER_FEATURES_VIA_PREFS */ #endif /* SET_PRINTER_FEATURES_VIA_PREFS */
/* These switches may be dynamic in the future... */
PRBool doingFilename = PR_TRUE; /* Set filename */
PRBool doingNumCopies = PR_TRUE; nsXPIDLCString filename;
PRBool doingOrientation = PR_TRUE; if (NS_FAILED(CopyPrinterCharPref(pPrefs, nsnull, printerName, "filename", getter_Copies(filename)))) {
PRBool doingPaperSize = PR_TRUE; const char *path;
PRBool doingCommand = PR_TRUE;
if (!(path = PR_GetEnv("PWD")))
if (doingFilename) { path = PR_GetEnv("HOME");
nsXPIDLCString filename;
if (NS_FAILED(CopyPrinterCharPref(pPrefs, nsnull, printerName, "filename", getter_Copies(filename)))) { if (path)
const char *path; filename = nsPrintfCString(PATH_MAX, "%s/mozilla.ps", path);
else
if (!(path = PR_GetEnv("PWD"))) filename.Assign("mozilla.ps");
path = PR_GetEnv("HOME"); }
DO_PR_DEBUG_LOG(("Setting default filename to '%s'\n", filename.get()));
if (path) aPrintSettings->SetToFileName(NS_ConvertUTF8toUCS2(filename).get());
filename = nsPrintfCString(PATH_MAX, "%s/mozilla.ps", path);
else
filename.Assign("mozilla.ps");
}
DO_PR_DEBUG_LOG(("Setting default filename to '%s'\n", filename.get()));
aPrintSettings->SetToFileName(NS_ConvertUTF8toUCS2(filename).get());
}
#ifdef USE_XPRINT #ifdef USE_XPRINT
if (type == pmXprint) { if (type == pmXprint) {
@ -651,78 +759,127 @@ NS_IMETHODIMP nsPrinterEnumeratorXlib::InitPrintSettingsFromPrinter(const PRUnic
XPContext pcontext; XPContext pcontext;
if (XpuGetPrinter(printerName, &pdpy, &pcontext) != 1) if (XpuGetPrinter(printerName, &pdpy, &pcontext) != 1)
return NS_ERROR_GFX_PRINTER_NAME_NOT_FOUND; return NS_ERROR_GFX_PRINTER_NAME_NOT_FOUND;
if (doingOrientation) {
XpuOrientationList olist;
int ocount;
XpuOrientationRec *default_orientation;
/* Get list of supported orientations */ XpuSupportedFlags supported_doc_attrs = XpuGetSupportedDocAttributes(pdpy, pcontext);
olist = XpuGetOrientationList(pdpy, pcontext, &ocount);
if (olist) {
default_orientation = &olist[0]; /* First entry is the default one */
if (!strcasecmp(default_orientation->orientation, "portrait")) {
DO_PR_DEBUG_LOG(("setting default orientation to 'portrait'\n"));
aPrintSettings->SetOrientation(nsIPrintSettings::kPortraitOrientation);
}
else if (!strcasecmp(default_orientation->orientation, "landscape")) {
DO_PR_DEBUG_LOG(("setting default orientation to 'landscape'\n"));
aPrintSettings->SetOrientation(nsIPrintSettings::kLandscapeOrientation);
}
else {
DO_PR_DEBUG_LOG(("Unknown default orientation '%s'\n", default_orientation->orientation));
}
XpuFreeOrientationList(olist);
}
}
/* Setup Number of Copies */
if (doingNumCopies) {
#ifdef NOT_IMPLEMENTED_YET
aPrintSettings->SetNumCopies(PRInt32(aDevMode->dmCopies));
#endif /* NOT_IMPLEMENTED_YET */
}
if (doingPaperSize) {
XpuMediumSourceSizeList mlist;
int mcount;
XpuMediumSourceSizeRec *default_medium;
mlist = XpuGetMediumSourceSizeList(pdpy, pcontext, &mcount);
if (mlist) {
default_medium = &mlist[0]; /* First entry is the default one */
double total_width = default_medium->ma1 + default_medium->ma2,
total_height = default_medium->ma3 + default_medium->ma4;
DO_PR_DEBUG_LOG(("setting default paper size to %g/%g mm\n", total_width, total_height));
aPrintSettings->SetPaperSizeType(nsIPrintSettings::kPaperSizeDefined);
aPrintSettings->SetPaperSizeUnit(nsIPrintSettings::kPaperSizeMillimeters);
aPrintSettings->SetPaperWidth(total_width);
aPrintSettings->SetPaperHeight(total_height);
#ifdef SET_PRINTER_FEATURES_VIA_PREFS #ifdef SET_PRINTER_FEATURES_VIA_PREFS
pPrefs->SetBoolPref(nsPrintfCString(256, PRINTERFEATURES_PREF ".%s.has_special_printerfeatures", printerName.get()).get(), PR_TRUE); nsPrinterFeatures printerFeatures(fullPrinterName);
int i;
for( i = 0 ; i < mcount ; i++ )
{
XpuMediumSourceSizeRec *curr = &mlist[i];
double total_width = curr->ma1 + curr->ma2,
total_height = curr->ma3 + curr->ma4;
pPrefs->SetCharPref(nsPrintfCString(256, PRINTERFEATURES_PREF ".%s.paper.%d.name", printerName.get(), i).get(), curr->medium_name);
pPrefs->SetIntPref( nsPrintfCString(256, PRINTERFEATURES_PREF ".%s.paper.%d.width_mm", printerName.get(), i).get(), PRInt32(total_width));
pPrefs->SetIntPref( nsPrintfCString(256, PRINTERFEATURES_PREF ".%s.paper.%d.height_mm", printerName.get(), i).get(), PRInt32(total_height));
pPrefs->SetBoolPref(nsPrintfCString(256, PRINTERFEATURES_PREF ".%s.paper.%d.is_inch", printerName.get(), i).get(), PR_FALSE);
}
pPrefs->SetIntPref(nsPrintfCString(256, PRINTERFEATURES_PREF ".%s.paper.count", printerName.get(), i).get(), (PRInt32)mcount);
#endif /* SET_PRINTER_FEATURES_VIA_PREFS */ #endif /* SET_PRINTER_FEATURES_VIA_PREFS */
XpuFreeMediumSourceSizeList(mlist); /* Setup orientation stuff */
XpuOrientationList olist;
int ocount;
XpuOrientationRec *default_orientation;
#ifdef SET_PRINTER_FEATURES_VIA_PREFS
PRBool canSetOrientation = MAKE_PR_BOOL(supported_doc_attrs & XPUATTRIBUTESUPPORTED_CONTENT_ORIENTATION);
printerFeatures.SetCanChangeOrientation(canSetOrientation);
#endif /* SET_PRINTER_FEATURES_VIA_PREFS */
/* Get list of supported orientations */
olist = XpuGetOrientationList(pdpy, pcontext, &ocount);
if (olist) {
default_orientation = &olist[0]; /* First entry is the default one */
if (!PL_strcasecmp(default_orientation->orientation, "portrait")) {
DO_PR_DEBUG_LOG(("setting default orientation to 'portrait'\n"));
aPrintSettings->SetOrientation(nsIPrintSettings::kPortraitOrientation);
}
else if (!PL_strcasecmp(default_orientation->orientation, "landscape")) {
DO_PR_DEBUG_LOG(("setting default orientation to 'landscape'\n"));
aPrintSettings->SetOrientation(nsIPrintSettings::kLandscapeOrientation);
} }
else {
DO_PR_DEBUG_LOG(("Unknown default orientation '%s'\n", default_orientation->orientation));
}
#ifdef SET_PRINTER_FEATURES_VIA_PREFS
int i;
for( i = 0 ; i < ocount ; i++ )
{
XpuOrientationRec *curr = &olist[i];
printerFeatures.SetOrientationRecord(i, curr->orientation);
}
printerFeatures.SetNumOrientationRecords(ocount);
#endif /* SET_PRINTER_FEATURES_VIA_PREFS */
XpuFreeOrientationList(olist);
}
/* Setup Number of Copies */
#ifdef SET_PRINTER_FEATURES_VIA_PREFS
PRBool canSetNumCopies = MAKE_PR_BOOL(supported_doc_attrs & XPUATTRIBUTESUPPORTED_COPY_COUNT);
printerFeatures.SetCanChangeNumCopies(canSetNumCopies);
#endif /* SET_PRINTER_FEATURES_VIA_PREFS */
long numCopies;
if( XpuGetOneLongAttribute(pdpy, pcontext, XPDocAttr, "copy-count", &numCopies) != 1 )
{
/* Fallback on failure */
numCopies = 1;
} }
aPrintSettings->SetNumCopies(numCopies);
/* Setup paper size stuff */
XpuMediumSourceSizeList mlist;
int mcount;
XpuMediumSourceSizeRec *default_medium;
#ifdef SET_PRINTER_FEATURES_VIA_PREFS
PRBool canSetPaperSize = MAKE_PR_BOOL(supported_doc_attrs & XPUATTRIBUTESUPPORTED_DEFAULT_MEDIUM);
printerFeatures.SetCanChangePaperSize(canSetPaperSize);
#endif /* SET_PRINTER_FEATURES_VIA_PREFS */
mlist = XpuGetMediumSourceSizeList(pdpy, pcontext, &mcount);
if (mlist) {
nsXPIDLCString papername;
default_medium = &mlist[0]; /* First entry is the default one */
double total_width = default_medium->ma1 + default_medium->ma2,
total_height = default_medium->ma3 + default_medium->ma4;
/* Either "paper" or "tray/paper" */
if (default_medium->tray_name) {
papername = nsPrintfCString(256, "%s/%s", default_medium->tray_name, default_medium->medium_name);
}
else {
papername.Assign(default_medium->medium_name);
}
DO_PR_DEBUG_LOG(("setting default paper size to '%s' (%g/%g mm)\n", papername.get(), total_width, total_height));
aPrintSettings->SetPaperSizeType(nsIPrintSettings::kPaperSizeDefined);
aPrintSettings->SetPaperSizeUnit(nsIPrintSettings::kPaperSizeMillimeters);
aPrintSettings->SetPaperWidth(total_width);
aPrintSettings->SetPaperHeight(total_height);
aPrintSettings->SetPaperName(NS_ConvertUTF8toUCS2(papername).get());
#ifdef SET_PRINTER_FEATURES_VIA_PREFS
int i;
for( i = 0 ; i < mcount ; i++ )
{
XpuMediumSourceSizeRec *curr = &mlist[i];
double total_width = curr->ma1 + curr->ma2,
total_height = curr->ma3 + curr->ma4;
if (curr->tray_name) {
papername = nsPrintfCString(256, "%s/%s", curr->tray_name, curr->medium_name);
}
else {
papername.Assign(curr->medium_name);
}
printerFeatures.SetPaperRecord(i, papername, PRInt32(total_width), PRInt32(total_height), PR_FALSE);
}
printerFeatures.SetNumPaperSizeRecords(mcount);
#endif /* SET_PRINTER_FEATURES_VIA_PREFS */
XpuFreeMediumSourceSizeList(mlist);
}
#ifdef SET_PRINTER_FEATURES_VIA_PREFS
/* Xprint does not allow the client to set a spooler command.
* Job spooling is the job of the server side (=Xprt) */
printerFeatures.SetCanChangeSpoolerCommand(PR_FALSE);
#endif /* SET_PRINTER_FEATURES_VIA_PREFS */
XpuClosePrinterDisplay(pdpy, pcontext); XpuClosePrinterDisplay(pdpy, pcontext);
return NS_OK; return NS_OK;
@ -733,68 +890,100 @@ NS_IMETHODIMP nsPrinterEnumeratorXlib::InitPrintSettingsFromPrinter(const PRUnic
#ifdef USE_POSTSCRIPT #ifdef USE_POSTSCRIPT
if (type == pmPostScript) { if (type == pmPostScript) {
DO_PR_DEBUG_LOG(("InitPrintSettingsFromPrinter() for PostScript printer\n")); DO_PR_DEBUG_LOG(("InitPrintSettingsFromPrinter() for PostScript printer\n"));
#ifdef SET_PRINTER_FEATURES_VIA_PREFS
nsPrinterFeatures printerFeatures(fullPrinterName);
#endif /* SET_PRINTER_FEATURES_VIA_PREFS */
if (doingNumCopies) { #ifdef SET_PRINTER_FEATURES_VIA_PREFS
/* Not implemented yet */ printerFeatures.SetCanChangeOrientation(PR_TRUE);
#endif /* SET_PRINTER_FEATURES_VIA_PREFS */
nsXPIDLCString orientation;
if (NS_SUCCEEDED(CopyPrinterCharPref(pPrefs, "postscript", printerName, "orientation", getter_Copies(orientation)))) {
if (!PL_strcasecmp(orientation, "portrait")) {
DO_PR_DEBUG_LOG(("setting default orientation to 'portrait'\n"));
aPrintSettings->SetOrientation(nsIPrintSettings::kPortraitOrientation);
}
else if (!PL_strcasecmp(orientation, "landscape")) {
DO_PR_DEBUG_LOG(("setting default orientation to 'landscape'\n"));
aPrintSettings->SetOrientation(nsIPrintSettings::kLandscapeOrientation);
}
else {
DO_PR_DEBUG_LOG(("Unknown default orientation '%s'\n", orientation.get()));
}
}
#ifdef SET_PRINTER_FEATURES_VIA_PREFS
int i;
for( i = 0 ; postscript_module_orientations[i].orientation != nsnull ; i++ )
{
const PSOrientationRec *curr = &postscript_module_orientations[i];
printerFeatures.SetOrientationRecord(i, curr->orientation);
}
printerFeatures.SetNumOrientationRecords(i);
#endif /* SET_PRINTER_FEATURES_VIA_PREFS */
#ifdef SET_PRINTER_FEATURES_VIA_PREFS
printerFeatures.SetCanChangePaperSize(PR_TRUE);
#endif /* SET_PRINTER_FEATURES_VIA_PREFS */
nsXPIDLCString papername;
if (NS_SUCCEEDED(CopyPrinterCharPref(pPrefs, "postscript", printerName, "paper_size", getter_Copies(papername)))) {
int i;
const PSPaperSizeRec *default_paper = nsnull;
for( i = 0 ; postscript_module_paper_sizes[i].name != nsnull ; i++ )
{
const PSPaperSizeRec *curr = &postscript_module_paper_sizes[i];
if (!PL_strcasecmp(papername, curr->name)) {
default_paper = curr;
break;
}
}
if (default_paper) {
DO_PR_DEBUG_LOG(("setting default paper size to '%s' (%g inch/%g inch)\n",
default_paper->name,
PSPaperSizeRec_FullPaperWidth(default_paper),
PSPaperSizeRec_FullPaperHeight(default_paper)));
aPrintSettings->SetPaperSizeType(nsIPrintSettings::kPaperSizeDefined);
aPrintSettings->SetPaperSizeUnit(nsIPrintSettings::kPaperSizeInches);
aPrintSettings->SetPaperWidth(PSPaperSizeRec_FullPaperWidth(default_paper));
aPrintSettings->SetPaperHeight(PSPaperSizeRec_FullPaperHeight(default_paper));
aPrintSettings->SetPaperName(NS_ConvertUTF8toUCS2(default_paper->name).get());
}
else {
DO_PR_DEBUG_LOG(("Unknown paper size '%s' given.\n", papername.get()));
}
#ifdef SET_PRINTER_FEATURES_VIA_PREFS
for( i = 0 ; postscript_module_paper_sizes[i].name != nsnull ; i++ )
{
const PSPaperSizeRec *curr = &postscript_module_paper_sizes[i];
#define CONVERT_INCH_TO_MILLIMETERS(inch) ((inch) * 25.4)
double total_width = CONVERT_INCH_TO_MILLIMETERS(PSPaperSizeRec_FullPaperWidth(curr)),
total_height = CONVERT_INCH_TO_MILLIMETERS(PSPaperSizeRec_FullPaperHeight(curr));
printerFeatures.SetPaperRecord(i, curr->name, PRInt32(total_width), PRInt32(total_height), PR_TRUE);
}
printerFeatures.SetNumPaperSizeRecords(i);
#endif /* SET_PRINTER_FEATURES_VIA_PREFS */
}
#ifdef SET_PRINTER_FEATURES_VIA_PREFS
printerFeatures.SetCanChangeSpoolerCommand(PR_TRUE);
#endif /* SET_PRINTER_FEATURES_VIA_PREFS */
nsXPIDLCString command;
if (NS_SUCCEEDED(CopyPrinterCharPref(pPrefs, "postscript", printerName, "print_command", getter_Copies(command)))) {
DO_PR_DEBUG_LOG(("setting default print command to '%s'\n", command.get()));
aPrintSettings->SetPrintCommand(NS_ConvertUTF8toUCS2(command).get());
} }
if (doingOrientation) { #ifdef SET_PRINTER_FEATURES_VIA_PREFS
nsXPIDLCString orientation; printerFeatures.SetCanChangeNumCopies(PR_TRUE);
if (NS_SUCCEEDED(CopyPrinterCharPref(pPrefs, "postscript", printerName, "orientation", getter_Copies(orientation)))) { #endif /* SET_PRINTER_FEATURES_VIA_PREFS */
if (!strcasecmp(orientation, "portrait")) {
DO_PR_DEBUG_LOG(("setting default orientation to 'portrait'\n"));
aPrintSettings->SetOrientation(nsIPrintSettings::kPortraitOrientation);
}
else if (!strcasecmp(orientation, "landscape")) {
DO_PR_DEBUG_LOG(("setting default orientation to 'landscape'\n"));
aPrintSettings->SetOrientation(nsIPrintSettings::kLandscapeOrientation);
}
else {
DO_PR_DEBUG_LOG(("Unknown default orientation '%s'\n", orientation.get()));
}
}
}
if (doingPaperSize) {
/* Not implemented yet */
nsXPIDLCString papername;
if (NS_SUCCEEDED(CopyPrinterCharPref(pPrefs, "postscript", printerName, "paper_size", getter_Copies(papername)))) {
int i;
double width = 0.,
height = 0.;
for( i = 0 ; postscript_module_paper_sizes[i].name != nsnull ; i++ )
{
const PSPaperSizeRec *curr = &postscript_module_paper_sizes[i];
if (!strcasecmp(papername, curr->name)) {
width = curr->width;
height = curr->height;
break;
}
}
if (width!=0.0 && height!=0.0) {
DO_PR_DEBUG_LOG(("setting default paper size to %g/%g inch\n", width, height));
aPrintSettings->SetPaperSizeType(nsIPrintSettings::kPaperSizeDefined);
aPrintSettings->SetPaperSizeUnit(nsIPrintSettings::kPaperSizeInches);
aPrintSettings->SetPaperWidth(width);
aPrintSettings->SetPaperHeight(height);
}
else {
DO_PR_DEBUG_LOG(("Unknown paper size '%s' given.\n", papername));
}
}
}
if (doingCommand) {
nsXPIDLCString command;
if (NS_SUCCEEDED(CopyPrinterCharPref(pPrefs, "postscript", printerName, "print_command", getter_Copies(command)))) {
DO_PR_DEBUG_LOG(("setting default print command to '%s'\n", command.get()));
aPrintSettings->SetPrintCommand(NS_ConvertUTF8toUCS2(command).get());
}
}
return NS_OK; return NS_OK;
} }
#endif /* USE_POSTSCRIPT */ #endif /* USE_POSTSCRIPT */

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

@ -93,6 +93,7 @@ public:
NS_IMETHOD GetPrintMethod(PrintMethod &aMethod); NS_IMETHOD GetPrintMethod(PrintMethod &aMethod);
static nsresult GetPrintMethod(const char *aPrinter, PrintMethod &aMethod); static nsresult GetPrintMethod(const char *aPrinter, PrintMethod &aMethod);
NS_IMETHOD GetPageSizeInTwips(PRInt32 *aWidth, PRInt32 *aHeight); NS_IMETHOD GetPageSizeInTwips(PRInt32 *aWidth, PRInt32 *aHeight);
NS_IMETHOD GetPaperName(const char **aPaperName);
virtual ~nsDeviceContextSpecXlib(); virtual ~nsDeviceContextSpecXlib();
protected: protected:
@ -104,6 +105,7 @@ protected:
char mCommand[PATH_MAX]; /* Print command e.g., lpr */ char mCommand[PATH_MAX]; /* Print command e.g., lpr */
char mPath[PATH_MAX]; /* If toPrinter = PR_FALSE, dest file */ char mPath[PATH_MAX]; /* If toPrinter = PR_FALSE, dest file */
char mPrinter[256]; /* Printer name */ char mPrinter[256]; /* Printer name */
char mPaperName[256]; /* Printer name */
int mCopies; /* number of copies */ int mCopies; /* number of copies */
PRBool mCancel; /* If PR_TRUE, user cancelled */ PRBool mCancel; /* If PR_TRUE, user cancelled */
float mLeft; /* left margin */ float mLeft; /* left margin */

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

@ -138,10 +138,13 @@ public:
**/ **/
NS_IMETHOD GetUserCancelled( PRBool &aCancel ) = 0; NS_IMETHOD GetUserCancelled( PRBool &aCancel ) = 0;
/* /*
* Returns W/H in Twips from Paper Size H/W * Paper name e.g., "din-a4" or "manual/din-a4"
*/ * @update
NS_IMETHOD GetPageSizeInTwips(PRInt32 *aWidth, PRInt32 *aHeight) = 0; * @param aPaperName --
* @return
**/
NS_IMETHOD GetPaperName ( const char **aPaperName ) = 0;
/* /*
* Return number of copies to print * Return number of copies to print

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

@ -353,15 +353,19 @@ nsXPrintContext::SetupWindow(int x, int y, int width, int height)
} }
nsresult nsXPrintContext::SetPageSize(float page_width_mm, float page_height_mm) nsresult nsXPrintContext::SetMediumSize(const char *aPaperName)
{ {
nsresult rv = NS_ERROR_GFX_PRINTER_PAPER_SIZE_NOT_SUPPORTED; nsresult rv = NS_ERROR_GFX_PRINTER_PAPER_SIZE_NOT_SUPPORTED;
XpuMediumSourceSizeList mlist; XpuMediumSourceSizeList mlist;
int mlist_count; int mlist_count;
int i; int i;
char *paper_name,
*alloc_paper_name; /* for free() ... */
paper_name = alloc_paper_name = strdup(aPaperName);
if (!paper_name)
return NS_ERROR_OUT_OF_MEMORY;
PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG, ("SetPageSize: Requested page width_mm=%f, page height_mm=%f\n", PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG, ("SetMediumSize: Requested page '%s'\n", paper_name));
(double)page_width_mm, (double)page_height_mm));
mlist = XpuGetMediumSourceSizeList(mPDisplay, mPContext, &mlist_count); mlist = XpuGetMediumSourceSizeList(mPDisplay, mPContext, &mlist_count);
if( !mlist ) if( !mlist )
@ -382,29 +386,38 @@ nsresult nsXPrintContext::SetPageSize(float page_width_mm, float page_height_mm)
} }
#endif /* PR_LOGGING */ #endif /* PR_LOGGING */
/* Tolerate +/- 2mm due conversion/rounding errors and different notations */ char *s;
match = XpuFindMediumSourceSizeBySize(mlist, mlist_count, page_width_mm, page_height_mm, 2.0f);
/* Did we get a tray name and paper name (e.g. "manual/din-a4") ? */
/* No match ? if (s = strchr(paper_name, '/'))
* The "try again" with a tolerance if +/- 10mm
*/
if (!match)
{ {
PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG, const char *tray_name;
("No match found in first attempt, trying again with 10mm tolerance...\n")); *s = '\0';
match = XpuFindMediumSourceSizeBySize(mlist, mlist_count, page_width_mm, page_height_mm, 10.0f); tray_name = paper_name;
} paper_name = s+1;
PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG, ("SetMediumSize: searching for '%s'/'%s'\n", tray_name, paper_name));
match = XpuFindMediumSourceSizeByName(mlist, mlist_count, tray_name, paper_name);
}
else
{
PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG, ("SetMediumSize: searching for '%s'\n", paper_name));
match = XpuFindMediumSourceSizeByName(mlist, mlist_count, nsnull, paper_name);
}
/* Found a match ? */ /* Found a match ? */
if (match) if (match)
{ {
PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG, PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG,
("match %s/%s !\n", XPU_NULLXSTR(match->tray_name), match->medium_name)); ("match '%s'/'%s' !\n", XPU_NULLXSTR(match->tray_name), match->medium_name));
/* Set document's paper size */
if( XpuSetDocMediumSourceSize(mPDisplay, mPContext, match) == 1 ) if( XpuSetDocMediumSourceSize(mPDisplay, mPContext, match) == 1 )
rv = NS_OK; rv = NS_OK;
} }
XpuFreeMediumSourceSizeList(mlist); XpuFreeMediumSourceSizeList(mlist);
free(alloc_paper_name);
return rv; return rv;
} }
@ -554,13 +567,10 @@ nsXPrintContext::SetupPrintContext(nsIDeviceContextSpecXp *aSpec)
dumpXpAttributes(mPDisplay, mPContext); dumpXpAttributes(mPDisplay, mPContext);
#endif /* XPRINT_DEBUG_SOMETIMES_USEFULL */ #endif /* XPRINT_DEBUG_SOMETIMES_USEFULL */
PRInt32 page_width_in_twips, const char *paper_name = nsnull;
page_height_in_twips; aSpec->GetPaperName(&paper_name);
aSpec->GetPageSizeInTwips(&page_width_in_twips, &page_height_in_twips);
if (NS_FAILED(XPU_TRACE(rv = SetPageSize(NS_TWIPS_TO_MILLIMETERS(page_width_in_twips), if (NS_FAILED(XPU_TRACE(rv = SetMediumSize(paper_name))))
NS_TWIPS_TO_MILLIMETERS(page_height_in_twips)))))
return rv; return rv;
if (NS_FAILED(XPU_TRACE(rv = SetOrientation(landscape)))) if (NS_FAILED(XPU_TRACE(rv = SetOrientation(landscape))))

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

@ -133,7 +133,7 @@ private:
nsresult SetupWindow(int x, int y, int width, int height); nsresult SetupWindow(int x, int y, int width, int height);
nsresult SetupPrintContext(nsIDeviceContextSpecXp *aSpec); nsresult SetupPrintContext(nsIDeviceContextSpecXp *aSpec);
nsresult SetPageSize(float page_width_mm, float page_height_mm); nsresult SetMediumSize(const char *paper_name);
nsresult SetOrientation(int landscape); nsresult SetOrientation(int landscape);
nsresult SetResolution(void); nsresult SetResolution(void);
}; };

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

@ -284,7 +284,10 @@ void XpuSetOneLongAttribute( Display *pdpy, XPContext pcontext,
} }
} }
/* check if attribute value is supported or not */ /* Check if attribute value is supported or not
* Use this function _only_ if XpuGetSupported{Job,Doc,Page}Attributes()
* does not help you...
*/
int XpuCheckSupported( Display *pdpy, XPContext pcontext, XPAttributes type, const char *attribute_name, const char *query ) int XpuCheckSupported( Display *pdpy, XPContext pcontext, XPAttributes type, const char *attribute_name, const char *query )
{ {
char *value; char *value;
@ -325,14 +328,14 @@ int XpuCheckSupported( Display *pdpy, XPContext pcontext, XPAttributes type, con
int XpuSetJobTitle( Display *pdpy, XPContext pcontext, const char *title ) int XpuSetJobTitle( Display *pdpy, XPContext pcontext, const char *title )
{ {
if( XpuCheckSupported(pdpy, pcontext, XPPrinterAttr, "job-attributes-supported", "job-name") ) if( XpuGetSupportedJobAttributes(pdpy, pcontext) & XPUATTRIBUTESUPPORTED_JOB_NAME )
{ {
XpuSetOneAttribute(pdpy, pcontext, XPJobAttr, "*job-name", title, XPAttrMerge); XpuSetOneAttribute(pdpy, pcontext, XPJobAttr, "*job-name", title, XPAttrMerge);
return(1); return(1);
} }
else else
{ {
XPU_DEBUG_ONLY(printf("XpuSetJobTitle: XpuCheckSupported failed for '%s'\n", XPU_NULLXSTR(title))); XPU_DEBUG_ONLY(printf("XpuSetJobTitle: XPUATTRIBUTESUPPORTED_JOB_NAME not supported ('%s')\n", XPU_NULLXSTR(title)));
return(0); return(0);
} }
} }
@ -890,14 +893,14 @@ void XpuFreePrinterList( XPPrinterList list )
/* Set number of copies to print from this document */ /* Set number of copies to print from this document */
int XpuSetDocumentCopies( Display *pdpy, XPContext pcontext, long num_copies ) int XpuSetDocumentCopies( Display *pdpy, XPContext pcontext, long num_copies )
{ {
if( XpuCheckSupported(pdpy, pcontext, XPPrinterAttr, "document-attributes-supported", "copy-count") ) if( XpuGetSupportedDocAttributes(pdpy, pcontext) & XPUATTRIBUTESUPPORTED_COPY_COUNT)
{ {
XpuSetOneLongAttribute(pdpy, pcontext, XPDocAttr, "*copy-count", num_copies, XPAttrMerge); XpuSetOneLongAttribute(pdpy, pcontext, XPDocAttr, "*copy-count", num_copies, XPAttrMerge);
return(1); return(1);
} }
else else
{ {
XPU_DEBUG_ONLY(printf("XpuSetContentOrientation: XpuCheckSupported failed for 'copy-count'\n")); XPU_DEBUG_ONLY(printf("XpuSetContentOrientation: XPUATTRIBUTESUPPORTED_COPY_COUNT not supported\n"));
/* Failure... */ /* Failure... */
return(0); return(0);
@ -1032,12 +1035,16 @@ int XpuSetMediumSourceSize( Display *pdpy, XPContext pcontext, XPAttributes type
/* Set document medium size */ /* Set document medium size */
int XpuSetDocMediumSourceSize( Display *pdpy, XPContext pcontext, XpuMediumSourceSizeRec *medium_spec ) int XpuSetDocMediumSourceSize( Display *pdpy, XPContext pcontext, XpuMediumSourceSizeRec *medium_spec )
{ {
if( XpuCheckSupported(pdpy, pcontext, XPPrinterAttr, "document-attributes-supported", "default-medium") == 0 ) XpuSupportedFlags doc_supported_flags;
doc_supported_flags = XpuGetSupportedDocAttributes(pdpy, pcontext);
if( (doc_supported_flags & XPUATTRIBUTESUPPORTED_DEFAULT_MEDIUM) == 0 )
return( 0 ); return( 0 );
if (medium_spec->tray_name) if (medium_spec->tray_name)
{ {
if( XpuCheckSupported(pdpy, pcontext, XPPrinterAttr, "document-attributes-supported", "default-input-tray") == 0 ) if( (doc_supported_flags & XPUATTRIBUTESUPPORTED_DEFAULT_INPUT_TRAY) == 0 )
return( 0 ); return( 0 );
} }
@ -1047,12 +1054,16 @@ int XpuSetDocMediumSourceSize( Display *pdpy, XPContext pcontext, XpuMediumSourc
/* Set page medium size */ /* Set page medium size */
int XpuSetPageMediumSourceSize( Display *pdpy, XPContext pcontext, XpuMediumSourceSizeRec *medium_spec ) int XpuSetPageMediumSourceSize( Display *pdpy, XPContext pcontext, XpuMediumSourceSizeRec *medium_spec )
{ {
if( XpuCheckSupported(pdpy, pcontext, XPPrinterAttr, "xp-page-attributes-supported", "default-medium") == 0 ) XpuSupportedFlags page_supported_flags;
page_supported_flags = XpuGetSupportedPageAttributes(pdpy, pcontext);
if( (page_supported_flags & XPUATTRIBUTESUPPORTED_DEFAULT_MEDIUM) == 0 )
return( 0 ); return( 0 );
if (medium_spec->tray_name) if (medium_spec->tray_name)
{ {
if( XpuCheckSupported(pdpy, pcontext, XPPrinterAttr, "xp-page-attributes-supported", "default-input-tray") == 0 ) if( (page_supported_flags & XPUATTRIBUTESUPPORTED_DEFAULT_INPUT_TRAY) == 0 )
return( 0 ); return( 0 );
} }
@ -1300,7 +1311,7 @@ int XpuSetResolution( Display *pdpy, XPContext pcontext, XPAttributes type, XpuR
*/ */
int XpuSetDocResolution( Display *pdpy, XPContext pcontext, XpuResolutionRec *rec ) int XpuSetDocResolution( Display *pdpy, XPContext pcontext, XpuResolutionRec *rec )
{ {
if( XpuCheckSupported(pdpy, pcontext, XPPrinterAttr, "document-attributes-supported", "default-printer-resolution") == 0 ) if( (XpuGetSupportedDocAttributes(pdpy, pcontext) & XPUATTRIBUTESUPPORTED_DEFAULT_PRINTER_RESOLUTION) == 0 )
return( 0 ); return( 0 );
return XpuSetResolution(pdpy, pcontext, XPDocAttr, rec); return XpuSetResolution(pdpy, pcontext, XPDocAttr, rec);
@ -1312,7 +1323,7 @@ int XpuSetDocResolution( Display *pdpy, XPContext pcontext, XpuResolutionRec *re
*/ */
int XpuSetPageResolution( Display *pdpy, XPContext pcontext, XpuResolutionRec *rec ) int XpuSetPageResolution( Display *pdpy, XPContext pcontext, XpuResolutionRec *rec )
{ {
if( XpuCheckSupported(pdpy, pcontext, XPPrinterAttr, "xp-page-attributes-supported", "default-printer-resolution") == 0 ) if( (XpuGetSupportedPageAttributes(pdpy, pcontext) & XPUATTRIBUTESUPPORTED_DEFAULT_PRINTER_RESOLUTION) == 0 )
return( 0 ); return( 0 );
return XpuSetResolution(pdpy, pcontext, XPPageAttr, rec); return XpuSetResolution(pdpy, pcontext, XPPageAttr, rec);
@ -1436,7 +1447,7 @@ int XpuSetOrientation( Display *pdpy, XPContext pcontext, XPAttributes type, Xpu
*/ */
int XpuSetDocOrientation( Display *pdpy, XPContext pcontext, XpuOrientationRec *rec ) int XpuSetDocOrientation( Display *pdpy, XPContext pcontext, XpuOrientationRec *rec )
{ {
if( XpuCheckSupported(pdpy, pcontext, XPPrinterAttr, "document-attributes-supported", "content-orientation") == 0 ) if( (XpuGetSupportedDocAttributes(pdpy, pcontext) & XPUATTRIBUTESUPPORTED_CONTENT_ORIENTATION) == 0 )
return( 0 ); return( 0 );
return XpuSetOrientation(pdpy, pcontext, XPDocAttr, rec); return XpuSetOrientation(pdpy, pcontext, XPDocAttr, rec);
@ -1448,7 +1459,7 @@ int XpuSetDocOrientation( Display *pdpy, XPContext pcontext, XpuOrientationRec *
*/ */
int XpuSetPageOrientation( Display *pdpy, XPContext pcontext, XpuOrientationRec *rec ) int XpuSetPageOrientation( Display *pdpy, XPContext pcontext, XpuOrientationRec *rec )
{ {
if( XpuCheckSupported(pdpy, pcontext, XPPrinterAttr, "xp-page-attributes-supported", "content-orientation") == 0 ) if( (XpuGetSupportedPageAttributes(pdpy, pcontext) & XPUATTRIBUTESUPPORTED_CONTENT_ORIENTATION) == 0 )
return( 0 ); return( 0 );
return XpuSetOrientation(pdpy, pcontext, XPPageAttr, rec); return XpuSetOrientation(pdpy, pcontext, XPPageAttr, rec);
@ -1572,7 +1583,7 @@ int XpuSetContentPlex( Display *pdpy, XPContext pcontext, XPAttributes type, Xpu
*/ */
int XpuSetDocPlex( Display *pdpy, XPContext pcontext, XpuPlexRec *rec ) int XpuSetDocPlex( Display *pdpy, XPContext pcontext, XpuPlexRec *rec )
{ {
if( XpuCheckSupported(pdpy, pcontext, XPPrinterAttr, "document-attributes-supported", "plex") == 0 ) if( (XpuGetSupportedDocAttributes(pdpy, pcontext) & XPUATTRIBUTESUPPORTED_PLEX) == 0 )
return( 0 ); return( 0 );
return XpuSetContentPlex(pdpy, pcontext, XPDocAttr, rec); return XpuSetContentPlex(pdpy, pcontext, XPDocAttr, rec);
@ -1584,10 +1595,67 @@ int XpuSetDocPlex( Display *pdpy, XPContext pcontext, XpuPlexRec *rec )
*/ */
int XpuSetPagePlex( Display *pdpy, XPContext pcontext, XpuPlexRec *rec ) int XpuSetPagePlex( Display *pdpy, XPContext pcontext, XpuPlexRec *rec )
{ {
if( XpuCheckSupported(pdpy, pcontext, XPPrinterAttr, "xp-page-attributes-supported", "plex") == 0 ) if( (XpuGetSupportedPageAttributes(pdpy, pcontext) & XPUATTRIBUTESUPPORTED_PLEX) == 0 )
return( 0 ); return( 0 );
return XpuSetContentPlex(pdpy, pcontext, XPPageAttr, rec); return XpuSetContentPlex(pdpy, pcontext, XPPageAttr, rec);
} }
/* Return flags to indicate which attributes are supported and which not... */
static
XpuSupportedFlags XpuGetSupportedAttributes( Display *pdpy, XPContext pcontext, XPAttributes type, const char *attribute_name )
{
char *value;
void *tok_lasts;
XpuSupportedFlags flags = 0;
MAKE_STRING_WRITABLE(attribute_name);
if( attribute_name == NULL )
return(0);
value = XpGetOneAttribute(pdpy, pcontext, type, STRING_AS_WRITABLE(attribute_name));
FREE_WRITABLE_STRING(attribute_name);
if( value != NULL )
{
const char *s;
for( s = XpuEnumerateXpAttributeValue(value, &tok_lasts) ; s != NULL ; s = XpuEnumerateXpAttributeValue(NULL, &tok_lasts) )
{
if( !strcmp(s, "job-name") ) flags |= XPUATTRIBUTESUPPORTED_JOB_NAME;
else if( !strcmp(s, "job-owner") ) flags |= XPUATTRIBUTESUPPORTED_JOB_OWNER;
else if( !strcmp(s, "notification-profile") ) flags |= XPUATTRIBUTESUPPORTED_NOTIFICATION_PROFILE;
else if( !strcmp(s, "copy-count") ) flags |= XPUATTRIBUTESUPPORTED_COPY_COUNT;
else if( !strcmp(s, "document-format") ) flags |= XPUATTRIBUTESUPPORTED_DOCUMENT_FORMAT;
else if( !strcmp(s, "content-orientation") ) flags |= XPUATTRIBUTESUPPORTED_CONTENT_ORIENTATION;
else if( !strcmp(s, "default-printer-resolution") ) flags |= XPUATTRIBUTESUPPORTED_DEFAULT_PRINTER_RESOLUTION;
else if( !strcmp(s, "default-input-tray") ) flags |= XPUATTRIBUTESUPPORTED_DEFAULT_INPUT_TRAY;
else if( !strcmp(s, "default-medium") ) flags |= XPUATTRIBUTESUPPORTED_DEFAULT_MEDIUM;
else if( !strcmp(s, "plex") ) flags |= XPUATTRIBUTESUPPORTED_PLEX;
}
XpuDisposeEnumerateXpAttributeValue(&tok_lasts);
XFree(value);
}
return(flags);
}
XpuSupportedFlags XpuGetSupportedJobAttributes(Display *pdpy, XPContext pcontext)
{
return XpuGetSupportedAttributes(pdpy, pcontext, XPPrinterAttr, "job-attributes-supported");
}
XpuSupportedFlags XpuGetSupportedDocAttributes(Display *pdpy, XPContext pcontext)
{
return XpuGetSupportedAttributes(pdpy, pcontext, XPPrinterAttr, "document-attributes-supported");
}
XpuSupportedFlags XpuGetSupportedPageAttributes(Display *pdpy, XPContext pcontext)
{
return XpuGetSupportedAttributes(pdpy, pcontext, XPPrinterAttr, "xp-page-attributes-supported");
}
/* EOF. */ /* EOF. */

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

@ -109,6 +109,24 @@ typedef struct {
const char *plex; const char *plex;
} XpuPlexRec, *XpuPlexList; } XpuPlexRec, *XpuPlexList;
/* XPUATTRIBUTESUPPORTED_*:
* Flags which indicate whether it is allowed to set/change a specific attribute
*/
typedef long XpuSupportedFlags;
/* Job attributes */
#define XPUATTRIBUTESUPPORTED_JOB_NAME (1L<<0)
#define XPUATTRIBUTESUPPORTED_JOB_OWNER (1L<<1)
#define XPUATTRIBUTESUPPORTED_NOTIFICATION_PROFILE (1L<<2)
/* Document/Page attributes */
#define XPUATTRIBUTESUPPORTED_COPY_COUNT (1L<<3)
#define XPUATTRIBUTESUPPORTED_DOCUMENT_FORMAT (1L<<4)
#define XPUATTRIBUTESUPPORTED_CONTENT_ORIENTATION (1L<<5)
#define XPUATTRIBUTESUPPORTED_DEFAULT_PRINTER_RESOLUTION (1L<<6)
#define XPUATTRIBUTESUPPORTED_DEFAULT_INPUT_TRAY (1L<<7)
#define XPUATTRIBUTESUPPORTED_DEFAULT_MEDIUM (1L<<8)
#define XPUATTRIBUTESUPPORTED_PLEX (1L<<9)
/* prototypes */ /* prototypes */
_XFUNCPROTOBEGIN _XFUNCPROTOBEGIN
@ -181,6 +199,11 @@ void XpuStartJobToSpooler(Display *pdpy);
void *XpuStartJobToFile( Display *pdpy, XPContext pcontext, const char *filename ); void *XpuStartJobToFile( Display *pdpy, XPContext pcontext, const char *filename );
XPGetDocStatus XpuWaitForPrintFileChild( void *handle ); XPGetDocStatus XpuWaitForPrintFileChild( void *handle );
/* Get flags which indicate whether it is allowed to set/change a specific attribute */
XpuSupportedFlags XpuGetSupportedJobAttributes(Display *pdpy, XPContext pcontext);
XpuSupportedFlags XpuGetSupportedDocAttributes(Display *pdpy, XPContext pcontext);
XpuSupportedFlags XpuGetSupportedPageAttributes(Display *pdpy, XPContext pcontext);
_XFUNCPROTOEND _XFUNCPROTOEND
#define XpuGetJobAttributes( pdpy, pcontext ) XpGetAttributes( (pdpy), (pcontext), XPJobAttr ) #define XpuGetJobAttributes( pdpy, pcontext ) XpGetAttributes( (pdpy), (pcontext), XPJobAttr )

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

@ -204,6 +204,7 @@ function setPrinterDefaultsForSelectedPrinter()
var flags = gPrintSetInterface.kInitSavePaperSizeType | gPrintSetInterface.kInitSavePaperSizeUnit | var flags = gPrintSetInterface.kInitSavePaperSizeType | gPrintSetInterface.kInitSavePaperSizeUnit |
gPrintSetInterface.kInitSavePaperWidth | gPrintSetInterface.kInitSavePaperHeight | gPrintSetInterface.kInitSavePaperWidth | gPrintSetInterface.kInitSavePaperHeight |
gPrintSetInterface.kInitSavePaperName |
gPrintSetInterface.kInitSavePrintCommand; gPrintSetInterface.kInitSavePrintCommand;
// now augment them with any values from last time // now augment them with any values from last time
@ -460,6 +461,7 @@ function onAccept()
if (saveToPrefs && gWebBrowserPrint != null) { if (saveToPrefs && gWebBrowserPrint != null) {
var flags = gPrintSetInterface.kInitSavePaperSizeType | gPrintSetInterface.kInitSavePaperSizeUnit | var flags = gPrintSetInterface.kInitSavePaperSizeType | gPrintSetInterface.kInitSavePaperSizeUnit |
gPrintSetInterface.kInitSavePaperWidth | gPrintSetInterface.kInitSavePaperHeight | gPrintSetInterface.kInitSavePaperWidth | gPrintSetInterface.kInitSavePaperHeight |
gPrintSetInterface.kInitSavePaperName |
gPrintSetInterface.kInitSavePrintCommand; gPrintSetInterface.kInitSavePrintCommand;
gWebBrowserPrint.savePrintSettingsToPrefs(gPrintSettings, true, flags); gWebBrowserPrint.savePrintSettingsToPrefs(gPrintSettings, true, flags);
} }

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

@ -96,6 +96,13 @@ function initDialog()
dialog.rightInput = document.getElementById("rightInput"); dialog.rightInput = document.getElementById("rightInput");
} }
//---------------------------------------------------
function round10(val)
{
return Math.round(val * 10) / 10;
}
//--------------------------------------------------- //---------------------------------------------------
function listElement(aListElement) function listElement(aListElement)
{ {
@ -126,7 +133,7 @@ listElement.prototype =
/* No name in string bundle ? Then build one manually (this /* No name in string bundle ? Then build one manually (this
* usually happens when gPaperArray was build by createPaperArrayFromPrinterFeatures() ...) */ * usually happens when gPaperArray was build by createPaperArrayFromPrinterFeatures() ...) */
if (paperObj.inches) { if (paperObj.inches) {
label = paperObj.name + " (" + paperObj.width + "x" + paperObj.height + " in.)"; label = paperObj.name + " (" + round10(paperObj.width) + "x" + round10(paperObj.height) + " inch)";
} }
else { else {
label = paperObj.name + " (" + paperObj.width + "x" + paperObj.height + " mm)"; label = paperObj.name + " (" + paperObj.width + "x" + paperObj.height + " mm)";
@ -259,8 +266,7 @@ function loadDialog()
var print_paper_unit = 0; var print_paper_unit = 0;
var print_paper_width = 0.0; var print_paper_width = 0.0;
var print_paper_height = 0.0; var print_paper_height = 0.0;
var print_paper_width_mm = 0.0; var print_paper_name = "";
var print_paper_height_mm = 0.0;
var print_color = true; var print_color = true;
var print_command = default_command; var print_command = default_command;
@ -271,20 +277,9 @@ function loadDialog()
print_paper_unit = gPrintSettings.paperSizeUnit; print_paper_unit = gPrintSettings.paperSizeUnit;
print_paper_width = gPrintSettings.paperWidth; print_paper_width = gPrintSettings.paperWidth;
print_paper_height = gPrintSettings.paperHeight; print_paper_height = gPrintSettings.paperHeight;
print_paper_name = gPrintSettings.paperName;
print_color = gPrintSettings.printInColor; print_color = gPrintSettings.printInColor;
print_command = gPrintSettings.printCommand; print_command = gPrintSettings.printCommand;
if (print_paper_unit == gPrintSettingsInterface.kPaperSizeInches) {
print_paper_width_mm = gPrintSettings.paperWidth * 25.4;
print_paper_height_mm = gPrintSettings.paperHeight * 25.4;
}
else if (print_paper_unit == gPrintSettingsInterface.kPaperSizeMillimeters) {
print_paper_width_mm = gPrintSettings.paperWidth;
print_paper_height_mm = gPrintSettings.paperHeight;
}
else {
dump("Unknown value in gPrintSettings.paperSizeUnit");
}
} }
if (doDebug) { if (doDebug) {
@ -292,6 +287,7 @@ function loadDialog()
dump("paperSizeType "+print_paper_unit+"\n"); dump("paperSizeType "+print_paper_unit+"\n");
dump("paperWidth "+print_paper_width+"\n"); dump("paperWidth "+print_paper_width+"\n");
dump("paperHeight "+print_paper_height+"\n"); dump("paperHeight "+print_paper_height+"\n");
dump("paperName "+print_paper_name+"\n");
dump("printInColor "+print_color+"\n"); dump("printInColor "+print_color+"\n");
dump("printCommand "+print_command+"\n"); dump("printCommand "+print_command+"\n");
} }
@ -299,11 +295,8 @@ function loadDialog()
createPaperArray(); createPaperArray();
var selectedInx = 0; var selectedInx = 0;
var tolerance = 10.0; // 4 is usually enougth except for large papers like DIN-A3
for (var i=0;i<gPaperArray.length;i++) { for (var i=0;i<gPaperArray.length;i++) {
// Weak match. Allow errors up to +/- 5mm due rounding errors if (print_paper_name == gPaperArray[i].name) {
if ((Math.abs(print_paper_width_mm - gPaperArray[i].width_mm) <= tolerance) &&
(Math.abs(print_paper_height_mm - gPaperArray[i].height_mm) <= tolerance)) {
selectedInx = i; selectedInx = i;
break; break;
} }
@ -312,6 +305,8 @@ function loadDialog()
if (doDebug) { if (doDebug) {
if (i == gPaperArray.length) if (i == gPaperArray.length)
dump("loadDialog: No paper found.\n"); dump("loadDialog: No paper found.\n");
else
dump("loadDialog: found paper '"+gPaperArray[selectedInx].name+"'.\n");
} }
createPaperSizeList(selectedInx); createPaperSizeList(selectedInx);
@ -328,25 +323,26 @@ function loadDialog()
dialog.cmdInput.value = print_command; dialog.cmdInput.value = print_command;
/* First initalize with the hardcoded defaults... */
dialog.topInput.value = "0.04";
dialog.bottomInput.value = "0.04";
dialog.leftInput.value = "0.04";
dialog.rightInput.value = "0.04";
try { try {
// first get the generic settings /* ... then try to get the generic settings ... */
dialog.topInput.value = gPrefs.getIntPref("print.print_edge_top") / 100.0; dialog.topInput.value = gPrefs.getIntPref("print.print_edge_top") / 100.0;
dialog.bottomInput.value = gPrefs.getIntPref("print.print_edge_left") / 100.0; dialog.bottomInput.value = gPrefs.getIntPref("print.print_edge_left") / 100.0;
dialog.leftInput.value = gPrefs.getIntPref("print.print_edge_right") / 100.0; dialog.leftInput.value = gPrefs.getIntPref("print.print_edge_right") / 100.0;
dialog.rightInput.value = gPrefs.getIntPref("print.print_edge_bottom") / 100.0; dialog.rightInput.value = gPrefs.getIntPref("print.print_edge_bottom") / 100.0;
// then the printer specific settings /* ... and then the printer specific settings. */
var printername = gPrintSettings.printerName; var printername = gPrintSettings.printerName;
dialog.topInput.value = gPrefs.getIntPref("print."+printername+"print_edge_top") / 100.0; dialog.topInput.value = gPrefs.getIntPref("print.printer_"+printername+".print_edge_top") / 100.0;
dialog.bottomInput.value = gPrefs.getIntPref("print."+printername+"print_edge_left") / 100.0; dialog.bottomInput.value = gPrefs.getIntPref("print.printer_"+printername+".print_edge_left") / 100.0;
dialog.leftInput.value = gPrefs.getIntPref("print."+printername+"print_edge_right") / 100.0; dialog.leftInput.value = gPrefs.getIntPref("print.printer_"+printername+".print_edge_right") / 100.0;
dialog.rightInput.value = gPrefs.getIntPref("print."+printername+"print_edge_bottom") / 100.0; dialog.rightInput.value = gPrefs.getIntPref("print.printer_"+printername+".print_edge_bottom") / 100.0;
} catch (e) { } catch (e) { }
dialog.topInput.value = "0.04";
dialog.bottomInput.value = "0.04";
dialog.leftInput.value = "0.04";
dialog.rightInput.value = "0.04";
}
} }
//--------------------------------------------------- //---------------------------------------------------
@ -378,8 +374,9 @@ function onAccept()
{ {
var print_paper_type = gPrintSettingsInterface.kPaperSizeDefined; var print_paper_type = gPrintSettingsInterface.kPaperSizeDefined;
var print_paper_unit = gPrintSettingsInterface.kPaperSizeInches; var print_paper_unit = gPrintSettingsInterface.kPaperSizeInches;
var print_paper_width = 8.5; var print_paper_width = 0.0;
var print_paper_height = 11.0; var print_paper_height = 0.0;
var print_paper_name = "";
if (gPrintSettings != null) { if (gPrintSettings != null) {
var selectedInx = dialog.paperList.selectedIndex; var selectedInx = dialog.paperList.selectedIndex;
@ -390,12 +387,14 @@ function onAccept()
} }
print_paper_width = gPaperArray[selectedInx].width; print_paper_width = gPaperArray[selectedInx].width;
print_paper_height = gPaperArray[selectedInx].height; print_paper_height = gPaperArray[selectedInx].height;
print_paper_name = gPaperArray[selectedInx].name;
gPrintSettings.paperSize = gPaperArray[selectedInx].paperSize; // deprecated gPrintSettings.paperSize = gPaperArray[selectedInx].paperSize; // deprecated
gPrintSettings.paperSizeType = print_paper_type; gPrintSettings.paperSizeType = print_paper_type;
gPrintSettings.paperSizeUnit = print_paper_unit; gPrintSettings.paperSizeUnit = print_paper_unit;
gPrintSettings.paperWidth = print_paper_width; gPrintSettings.paperWidth = print_paper_width;
gPrintSettings.paperHeight = print_paper_height; gPrintSettings.paperHeight = print_paper_height;
gPrintSettings.paperName = print_paper_name;
// save these out so they can be picked up by the device spec // save these out so they can be picked up by the device spec
gPrintSettings.printInColor = dialog.colorRadio.selected; gPrintSettings.printInColor = dialog.colorRadio.selected;
@ -405,16 +404,16 @@ function onAccept()
try { try {
var printerName = gPrintSettings.printerName; var printerName = gPrintSettings.printerName;
var i = dialog.topInput.value * 100; var i = dialog.topInput.value * 100;
gPrefs.setIntPref("print."+printerName+"print_edge_top", i); gPrefs.setIntPref("print.printer_"+printerName+".print_edge_top", i);
i = dialog.bottomInput.value * 100; i = dialog.bottomInput.value * 100;
gPrefs.setIntPref("print."+printerName+"print_edge_left", i); gPrefs.setIntPref("print.printer_"+printerName+".print_edge_left", i);
i = dialog.leftInput.value * 100; i = dialog.leftInput.value * 100;
gPrefs.setIntPref("print."+printerName+"print_edge_right", i); gPrefs.setIntPref("print.printer_"+printerName+".print_edge_right", i);
i = dialog.rightInput.value * 100; i = dialog.rightInput.value * 100;
gPrefs.setIntPref("print."+printerName+"print_edge_bottom", i); gPrefs.setIntPref("print.printer_"+printerName+".print_edge_bottom", i);
} catch (e) { } catch (e) {
} }
@ -425,9 +424,10 @@ function onAccept()
dump("paperSizeUnit "+print_paper_unit+"\n"); dump("paperSizeUnit "+print_paper_unit+"\n");
dump("paperWidth "+print_paper_width+"\n"); dump("paperWidth "+print_paper_width+"\n");
dump("paperHeight "+print_paper_height+"\n"); dump("paperHeight "+print_paper_height+"\n");
dump("paperName '"+print_paper_name+"'\n");
dump("printInColor "+gPrintSettings.printInColor+"\n"); dump("printInColor "+gPrintSettings.printInColor+"\n");
dump("printCommand "+gPrintSettings.printCommand+"\n"); dump("printCommand '"+gPrintSettings.printCommand+"'\n");
} }
} else { } else {
dump("************ onAccept gPrintSettings: "+gPrintSettings+"\n"); dump("************ onAccept gPrintSettings: "+gPrintSettings+"\n");