From d238a3e16a612cb384f7900cbb1acd34ac08b0d8 Mon Sep 17 00:00:00 2001 From: "kjh-5727%comcast.net" Date: Tue, 7 Feb 2006 01:14:44 +0000 Subject: [PATCH] Bug 175879. Display ISO paper sizes in mm & remove extraneous 1/4-inch margin from printouts. r=tor, sr=roc --- widget/src/gtk2/nsDeviceContextSpecG.cpp | 60 +++++++++--------------- 1 file changed, 21 insertions(+), 39 deletions(-) diff --git a/widget/src/gtk2/nsDeviceContextSpecG.cpp b/widget/src/gtk2/nsDeviceContextSpecG.cpp index a4b39866ac20..ea6cd06ba1c8 100644 --- a/widget/src/gtk2/nsDeviceContextSpecG.cpp +++ b/widget/src/gtk2/nsDeviceContextSpecG.cpp @@ -63,8 +63,7 @@ #endif /* USE_XPRINT */ #ifdef USE_POSTSCRIPT -/* Fetch |postscript_module_paper_sizes| */ -#include "nsPostScriptObj.h" +#include "nsPaperPS.h" /* Paper size list */ #endif /* USE_POSTSCRIPT */ /* Ensure that the result is always equal to either PR_TRUE or PR_FALSE */ @@ -948,13 +947,9 @@ NS_IMETHODIMP nsPrinterEnumeratorGTK::InitPrintSettingsFromPrinter(const PRUnich } #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); + printerFeatures.SetOrientationRecord(0, "portrait"); + printerFeatures.SetOrientationRecord(1, "landscape"); + printerFeatures.SetNumOrientationRecords(2); #endif /* SET_PRINTER_FEATURES_VIA_PREFS */ /* PostScript module does not support changing the plex mode... */ @@ -973,44 +968,31 @@ NS_IMETHODIMP nsPrinterEnumeratorGTK::InitPrintSettingsFromPrinter(const PRUnich #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]; + nsPaperSizePS paper; - 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()); + if (paper.Find(papername)) { + DO_PR_DEBUG_LOG(("setting default paper size to '%s' (%g mm/%g mm)\n", + paper.Name(), paper.Width_mm(), paper.Height_mm())); + aPrintSettings->SetPaperSizeUnit(paper.IsMetric() ? + (int)nsIPrintSettings::kPaperSizeMillimeters : + (int)nsIPrintSettings::kPaperSizeInches); + aPrintSettings->SetPaperWidth(paper.Width_mm()); + aPrintSettings->SetPaperHeight(paper.Height_mm()); + aPrintSettings->SetPaperName(NS_ConvertASCIItoUCS2(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++ ) + paper.First(); + int count = 0; + while (!paper.AtEnd()) { - 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.SetPaperRecord(count++, paper.Name(), + (int)paper.Width_mm(), (int)paper.Height_mm(), !paper.IsMetric()); + paper.Next(); } - printerFeatures.SetNumPaperSizeRecords(i); + printerFeatures.SetNumPaperSizeRecords(count); #endif /* SET_PRINTER_FEATURES_VIA_PREFS */ }