From 17802f01e7e19fff711f4bf2b0e8e144723bc88c Mon Sep 17 00:00:00 2001 From: "kjh-5727%comcast.net" Date: Sat, 6 Mar 2004 21:49:44 +0000 Subject: [PATCH] Bug 175879. Display ISO paper sizes in mm & remove extraneous 1/4-inch margin from printouts. r=tor, sr=roc --- gfx/src/Makefile.in | 9 ++ gfx/src/gtk/nsDeviceContextSpecG.cpp | 60 ++++----- gfx/src/ps/nsPaperPS.cpp | 72 +++++++++++ gfx/src/ps/nsPaperPS.h | 126 +++++++++++++++++++ gfx/src/ps/nsPostScriptObj.cpp | 147 +++++------------------ gfx/src/ps/nsPostScriptObj.h | 72 +---------- gfx/src/xlib/nsDeviceContextSpecXlib.cpp | 59 ++++----- 7 files changed, 281 insertions(+), 264 deletions(-) create mode 100644 gfx/src/ps/nsPaperPS.cpp create mode 100644 gfx/src/ps/nsPaperPS.h diff --git a/gfx/src/Makefile.in b/gfx/src/Makefile.in index b56a69b8bf4f..899d7310d123 100644 --- a/gfx/src/Makefile.in +++ b/gfx/src/Makefile.in @@ -131,6 +131,15 @@ EXPORTS += \ $(NULL) endif +ifdef MOZ_ENABLE_POSTSCRIPT +CPPSRCS += \ + ps/nsPaperPS.cpp \ + $(NULL) +EXPORTS += \ + ps/nsPaperPS.h \ + $(NULL) +endif + EXTRA_DSO_LDOPTS = \ $(DIST)/lib/$(LIB_PREFIX)mozutil_s.$(LIB_SUFFIX) \ $(MOZ_UNICHARUTIL_LIBS) \ diff --git a/gfx/src/gtk/nsDeviceContextSpecG.cpp b/gfx/src/gtk/nsDeviceContextSpecG.cpp index a4b39866ac20..ea6cd06ba1c8 100644 --- a/gfx/src/gtk/nsDeviceContextSpecG.cpp +++ b/gfx/src/gtk/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 */ } diff --git a/gfx/src/ps/nsPaperPS.cpp b/gfx/src/ps/nsPaperPS.cpp new file mode 100644 index 000000000000..4f5d29d4ee39 --- /dev/null +++ b/gfx/src/ps/nsPaperPS.cpp @@ -0,0 +1,72 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ex: set tabstop=8 softtabstop=4 shiftwidth=4 expandtab: */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is developed for mozilla. The tables of paper sizes + * and paper orientations are based on tables from nsPostScriptObj.h. + * + * The Initial Developer of the Original Code is + * Kenneth Herron . + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + + +#include "nsPaperPS.h" +#include "plstr.h" + +#define COUNTOF(x) (sizeof(x) / sizeof((x)[0])) + +const nsPaperSizePS_ nsPaperSizePS::mList[] = +{ +#define SIZE_MM(x) (x) +#define SIZE_INCH(x) ((x) * 25.4) + { "A5", SIZE_MM(148), SIZE_MM(210), PR_TRUE }, + { "A4", SIZE_MM(210), SIZE_MM(297), PR_TRUE }, + { "A3", SIZE_MM(297), SIZE_MM(420), PR_TRUE }, + { "Letter", SIZE_INCH(8.5), SIZE_INCH(11), PR_FALSE }, + { "Legal", SIZE_INCH(8.5), SIZE_INCH(14), PR_FALSE }, + { "Executive", SIZE_INCH(7.5), SIZE_INCH(10), PR_FALSE }, +#undef SIZE_INCH +#undef SIZE_MM +}; + +const unsigned int nsPaperSizePS::mCount = COUNTOF(mList); + +PRBool +nsPaperSizePS::Find(const char *aName) +{ + for (int i = mCount; i--; ) { + if (!PL_strcasecmp(aName, mList[i].name)) { + mCurrent = i; + return PR_TRUE; + } + } + return PR_FALSE; +} diff --git a/gfx/src/ps/nsPaperPS.h b/gfx/src/ps/nsPaperPS.h new file mode 100644 index 000000000000..2d5e79c48314 --- /dev/null +++ b/gfx/src/ps/nsPaperPS.h @@ -0,0 +1,126 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ex: set tabstop=8 softtabstop=4 shiftwidth=4 expandtab: */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is developed for mozilla. + * + * The Initial Developer of the Original Code is + * Kenneth Herron . + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + + +#ifndef _PAPERPS_H_ +#define _PAPERPS_H_ + +#include "prtypes.h" +#include "nsDebug.h" + +struct nsPaperSizePS_ { + const char *name; + float width_mm; + float height_mm; + PRBool isMetric; // Present to the user in metric, if possible +}; + +class nsPaperSizePS { + public: + /** --------------------------------------------------- + * Constructor + */ + nsPaperSizePS() { mCurrent = 0; } + + /** --------------------------------------------------- + * @return PR_TRUE if the cursor points past the last item. + */ + PRBool AtEnd() { return mCurrent >= mCount; } + + /** --------------------------------------------------- + * Position the cursor at the beginning of the paper size list. + * @return VOID + */ + void First() { mCurrent = 0; } + + /** --------------------------------------------------- + * Advance the cursor to the next item. + * @return VOID + */ + void Next() { + NS_WARN_IF_FALSE(!AtEnd(), "Invalid current item"); + mCurrent++; + } + + /** --------------------------------------------------- + * Point the cursor to the entry with the given paper name. + * @return PR_TRUE if pointing to a valid entry. + */ + PRBool Find(const char *aName); + + /** --------------------------------------------------- + * @return a pointer to the name of the current paper size + */ + const char *Name() { + NS_PRECONDITION(!AtEnd(), "Invalid current item"); + return mList[mCurrent].name; + } + + /** --------------------------------------------------- + * @return the width of the page in millimeters + */ + float Width_mm() { + NS_PRECONDITION(!AtEnd(), "Invalid current item"); + return mList[mCurrent].width_mm; + } + + /** --------------------------------------------------- + * @return the height of the page in millimeters + */ + float Height_mm() { + NS_PRECONDITION(!AtEnd(), "Invalid current item"); + return mList[mCurrent].height_mm; + } + + /** --------------------------------------------------- + * @return PR_TRUE if the paper should be presented to + * the user in metric units. + */ + PRBool IsMetric() { + NS_PRECONDITION(!AtEnd(), "Invalid current item"); + return mList[mCurrent].isMetric; + } + + private: + unsigned int mCurrent; + static const nsPaperSizePS_ mList[]; + static const unsigned int mCount; +}; + +#endif + diff --git a/gfx/src/ps/nsPostScriptObj.cpp b/gfx/src/ps/nsPostScriptObj.cpp index 0540fabae4bc..5c0d1c47ba4f 100644 --- a/gfx/src/ps/nsPostScriptObj.cpp +++ b/gfx/src/ps/nsPostScriptObj.cpp @@ -19,6 +19,7 @@ * * Contributor(s): * Roland Mainz + * Ken Herron * * This Original Code has been modified by IBM Corporation. Modifications made by IBM * described herein are Copyright (c) International Business Machines Corporation, 2000. @@ -54,6 +55,7 @@ #include "nsIPersistentProperties2.h" #include "nsCRT.h" #include "nsFontMetricsPS.h" +#include "nsPaperPS.h" #ifndef NS_BUILD_ID #include "nsBuildID.h" @@ -261,25 +263,9 @@ nsPostScriptObj::settitle(PRUnichar * aTitle) } } -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 - * @update 2/1/99 dwc + * @update 2/20/2004 kherron */ nsresult nsPostScriptObj::Init( nsIDeviceContextSpecPS *aSpec ) @@ -288,7 +274,6 @@ nsPostScriptObj::Init( nsIDeviceContextSpecPS *aSpec ) isAPrinter, isFirstPageFirst; int landscape; - float fwidth, fheight; const char *printername; nsresult rv; @@ -313,14 +298,6 @@ nsPostScriptObj::Init( nsIDeviceContextSpecPS *aSpec ) if ( isFirstPageFirst == PR_FALSE ) mPrintSetup->reverse = 1; - /* Find PS paper size record by name */ - const char *paper_name = nsnull; - aSpec->GetPaperName(&paper_name); - mPrintSetup->paper_size = paper_name_to_PSPaperSizeRec(paper_name); - - if (!mPrintSetup->paper_size) - return NS_ERROR_GFX_PRINTER_PAPER_SIZE_NOT_SUPPORTED; - // Clean up tempfile remnants of any previous print job if (mDocProlog) mDocProlog->Remove(PR_FALSE); @@ -425,34 +402,26 @@ nsPostScriptObj::Init( nsIDeviceContextSpecPS *aSpec ) memset(mPrintContext, 0, sizeof(struct PSContext_)); memset(pi, 0, sizeof(struct PrintInfo_)); - mPrintSetup->dpi = 72.0f; // dpi for externally sized items + /* Find PS paper size record by name */ + aSpec->GetPaperName(&(mPrintSetup->paper_name)); + nsPaperSizePS paper; + if (!paper.Find(mPrintSetup->paper_name)) + return NS_ERROR_GFX_PRINTER_PAPER_SIZE_NOT_SUPPORTED; + aSpec->GetLandscape( landscape ); - fwidth = mPrintSetup->paper_size->width; - fheight = mPrintSetup->paper_size->height; + mPrintSetup->width = NS_MILLIMETERS_TO_TWIPS(paper.Width_mm()); + mPrintSetup->height = NS_MILLIMETERS_TO_TWIPS(paper.Height_mm()); if (landscape) { - float temp; - temp = fwidth; - fwidth = fheight; - fheight = temp; + nscoord temp = mPrintSetup->width; + mPrintSetup->width = mPrintSetup->height; + mPrintSetup->height = temp; } - mPrintSetup->left = NSToCoordRound(mPrintSetup->paper_size->left - * mPrintSetup->dpi * TWIPS_PER_POINT_FLOAT); - mPrintSetup->top = NSToCoordRound(mPrintSetup->paper_size->top - * mPrintSetup->dpi * TWIPS_PER_POINT_FLOAT); - mPrintSetup->bottom = NSToCoordRound(mPrintSetup->paper_size->bottom - * mPrintSetup->dpi * TWIPS_PER_POINT_FLOAT); - mPrintSetup->right = NSToCoordRound(mPrintSetup->paper_size->right - * mPrintSetup->dpi * TWIPS_PER_POINT_FLOAT); - - mPrintSetup->width = NSToCoordRound(fwidth - * mPrintSetup->dpi * TWIPS_PER_POINT_FLOAT); - mPrintSetup->height = NSToCoordRound(fheight - * mPrintSetup->dpi * TWIPS_PER_POINT_FLOAT); #ifdef DEBUG - printf("\nPreWidth = %f PreHeight = %f\n",fwidth,fheight); - printf("\nWidth = %d Height = %d\n",mPrintSetup->width,mPrintSetup->height); + printf("\nPaper Width = %d twips (%gmm) Height = %d twips (%gmm)\n", + mPrintSetup->width, paper.Width_mm(), + mPrintSetup->height, paper.Height_mm()); #endif mPrintSetup->header = "header"; mPrintSetup->footer = "footer"; @@ -464,10 +433,7 @@ nsPostScriptObj::Init( nsIDeviceContextSpecPS *aSpec ) mPrintSetup->underline = PR_TRUE; // underline links mPrintSetup->scale_images = PR_TRUE; // Scale unsized images which are too big mPrintSetup->scale_pre = PR_FALSE; // do the pre-scaling thing - // scale margins (specified in inches) to dots. - PR_LOG(nsPostScriptObjLM, PR_LOG_DEBUG, ("dpi %g top %d bottom %d left %d right %d\n", - mPrintSetup->dpi, mPrintSetup->top, mPrintSetup->bottom, mPrintSetup->left, mPrintSetup->right)); mPrintSetup->rules = 1.0f; // Scale factor for rulers mPrintSetup->n_up = 0; // cool page combining @@ -487,23 +453,9 @@ nsPostScriptObj::Init( nsIDeviceContextSpecPS *aSpec ) mPrintSetup->carg = nsnull; // Data saved for completion routine mPrintSetup->status = 0; // Status of URL on completion - pi->page_height = mPrintSetup->height; // Size of printable area on page - pi->page_width = mPrintSetup->width; // Size of printable area on page - pi->page_break = 0; // Current page bottom - pi->page_topy = 0; // Current page top - pi->phase = 0; - - - pi->pages = nsnull; // Contains extents of each page - - pi->pt_size = 0; // Size of above table - pi->n_pages = 0; // # of valid entries in above table - mTitle = nsnull; pi->doc_title = mTitle; - pi->doc_width = 0; // Total document width - pi->doc_height = 0; // Total document height mPrintContext->prInfo = pi; @@ -553,10 +505,8 @@ nsPostScriptObj::begin_document() int i; FILE *f; - nscoord paper_width = mPrintContext->prSetup->left - + mPrintContext->prSetup->width + mPrintContext->prSetup->right; - nscoord paper_height = mPrintContext->prSetup->bottom - + mPrintContext->prSetup->height + mPrintContext->prSetup->top; + nscoord paper_width = mPrintContext->prSetup->width; + nscoord paper_height = mPrintContext->prSetup->height; const char *orientation; if (paper_height < paper_width) { @@ -573,16 +523,14 @@ FILE *f; f = mPrintContext->prSetup->out; fprintf(f, "%%!PS-Adobe-3.0\n"); - fprintf(f, "%%%%BoundingBox: %s %s %s %s\n", - fpCString(NSTwipsToFloatPoints(mPrintContext->prSetup->left)).get(), - fpCString(NSTwipsToFloatPoints(mPrintContext->prSetup->bottom)).get(), - fpCString(NSTwipsToFloatPoints(paper_width - mPrintContext->prSetup->right)).get(), - fpCString(NSTwipsToFloatPoints(paper_height - mPrintContext->prSetup->top)).get()); + fprintf(f, "%%%%BoundingBox: 0 0 %s %s\n", + fpCString(NSTwipsToFloatPoints(paper_width)).get(), + fpCString(NSTwipsToFloatPoints(paper_height)).get()); fprintf(f, "%%%%Creator: Mozilla PostScript module (%s/%lu)\n", "rv:" MOZILLA_VERSION, (unsigned long)NS_BUILD_ID); fprintf(f, "%%%%DocumentData: Clean8Bit\n"); - fprintf(f, "%%%%DocumentPaperSizes: %s\n", mPrintSetup->paper_size->name); + fprintf(f, "%%%%DocumentPaperSizes: %s\n", mPrintSetup->paper_name); fprintf(f, "%%%%Orientation: %s\n", orientation); // hmm, n_pages is always zero so don't use it @@ -621,17 +569,12 @@ FILE *f; // Tell the printer what size paper it should use fprintf(f, "/setpagedevice where\n" // Test for the feature - "{ pop 2 dict\n" // Set up a dictionary + "{ pop 1 dict\n" // Set up a dictionary " dup /PageSize [ %s %s ] put\n" // Paper dimensions - " dup /ImagingBBox [ %s %s %s %s ] put\n" // Bounding box " setpagedevice\n" // Install settings "} if\n", fpCString(NSTwipsToFloatPoints(paper_width)).get(), - fpCString(NSTwipsToFloatPoints(paper_height)).get(), - fpCString(NSTwipsToFloatPoints(mPrintContext->prSetup->left)).get(), - fpCString(NSTwipsToFloatPoints(mPrintContext->prSetup->bottom)).get(), - fpCString(NSTwipsToFloatPoints(paper_width - mPrintContext->prSetup->right)).get(), - fpCString(NSTwipsToFloatPoints(paper_height - mPrintContext->prSetup->top)).get()); + fpCString(NSTwipsToFloatPoints(paper_height)).get()); fprintf(f, "["); for (i = 0; i < 256; i++){ @@ -2003,26 +1946,14 @@ FILE *f; fprintf(f,"/pagelevel save def\n"); // Rescale the coordinate system from points to twips. scale(1.0 / TWIPS_PER_POINT_FLOAT, 1.0 / TWIPS_PER_POINT_FLOAT); - // Move the origin to the bottom left of the printable region. + // Rotate and shift the coordinate system for landscape if (mPrintContext->prSetup->landscape){ - fprintf(f, "90 rotate %d -%d translate\n", - mPrintContext->prSetup->left, - mPrintContext->prSetup->height + mPrintContext->prSetup->top); - } - else { - fprintf(f, "%d %d translate\n", - mPrintContext->prSetup->left, - mPrintContext->prSetup->bottom); + fprintf(f, "90 rotate 0 -%d translate\n", mPrintContext->prSetup->height); } + // Try to turn on automatic stroke adjust fputs("true Msetstrokeadjust\n", f); fprintf(f, "%%%%EndPageSetup\n"); -#if 0 - annotate_page( mPrintContext->prSetup->header, 0, -1, pn); -#endif - // Set up a clipping rectangle around the printable area. - fprintf(f, "0 0 %d %d Mrect closepath clip newpath\n", - mPrintContext->prInfo->page_width, mPrintContext->prInfo->page_height); // need to reset all U2Ntable gLangGroups->Enumerate(ResetU2Ntable, nsnull); @@ -2035,18 +1966,7 @@ FILE *f; void nsPostScriptObj::end_page() { -#if 0 - annotate_page( mPrintContext->prSetup->footer, - mPrintContext->prSetup->height-mPrintContext->prSetup->bottom-mPrintContext->prSetup->top, - 1, pn); - fprintf(mPrintContext->prSetup->out, "pagelevel restore\nshowpage\n"); -#endif - fprintf(mPrintContext->prSetup->tmpBody, "pagelevel restore\n"); - annotate_page(mPrintContext->prSetup->header, mPrintContext->prSetup->top/2, -1, mPageNumber); - annotate_page( mPrintContext->prSetup->footer, - mPrintContext->prSetup->height - mPrintContext->prSetup->bottom/2, - 1, mPageNumber); fprintf(mPrintContext->prSetup->tmpBody, "showpage\n"); mPageNumber++; } @@ -2163,17 +2083,6 @@ nsPostScriptObj::end_document() return rv; } -/** --------------------------------------------------- - * See documentation in nsPostScriptObj.h - * @update 2/1/99 dwc - */ -void -nsPostScriptObj::annotate_page(const char *aTemplate, - int y, int delta_dir, int pn) -{ - -} - /** --------------------------------------------------- * See documentation in nsPostScriptObj.h * @update 2/1/99 dwc. Updated 3/22/2000 to deal with only non-Unicode chars. yueheng.xu@intel.com diff --git a/gfx/src/ps/nsPostScriptObj.h b/gfx/src/ps/nsPostScriptObj.h index 8d00c83b5b33..4f63564ee360 100644 --- a/gfx/src/ps/nsPostScriptObj.h +++ b/gfx/src/ps/nsPostScriptObj.h @@ -21,6 +21,7 @@ * * Contributor(s): * Roland Mainz + * Ken Herron * * * Alternatively, the contents of this file may be used under the terms of @@ -67,46 +68,6 @@ class nsIImage; typedef int XP_Bool; -typedef struct { - const char *name; - float left, - top, - right, - bottom, - width, - height; -} PSPaperSizeRec; - - -static const -PSPaperSizeRec postscript_module_paper_sizes[] = -{ - { "A5", 0.25f, 0.25f, 0.25f, 0.25f, 5.33f, 7.77f }, /* 148mm X 210mm ( 5.83in X 8.27in) */ - { "A4", 0.25f, 0.25f, 0.25f, 0.25f, 7.77f, 11.19f }, /* 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) */ - { "Letter", 0.25f, 0.25f, 0.25f, 0.25f, 8.00f, 10.50f }, /* 8.50in X 11.0in */ - { "Legal", 0.25f, 0.25f, 0.25f, 0.25f, 8.00f, 13.50f }, /* 8.50in X 14.0in */ - { "Executive", 0.25f, 0.25f, 0.25f, 0.25f, 7.00f, 9.50f }, /* 7.50in X 10.0in */ - { 0, 0.25f, 0.25f, 0.25f, 0.25f, 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 struct page_breaks { @@ -127,21 +88,7 @@ typedef struct LineRecord_struct LineRecord; ** Used to store state needed while translation is in progress */ struct PrintInfo_ { - /* for table printing */ - int32 page_height; /* Size of printable area on page */ - int32 page_width; /* Size of printable area on page */ - int32 page_break; /* Current page bottom */ - int32 page_topy; /* Current page top */ - int phase; - - PageBreaks *pages; /* Contains extents of each page */ - - int pt_size; /* Size of above table */ - int n_pages; /* # of valid entries in above table */ - const char *doc_title; /* best guess at title */ - int32 doc_width; /* Total document width */ - int32 doc_height; /* Total document height */ #ifdef LATER THIS IS GOING TO BE DELETED XXXXX @@ -168,16 +115,12 @@ typedef struct PrintInfo_ PrintInfo; ** Used to pass info into text and/or postscript translation */ struct PrintSetup_ { - nscoord top; /* Margins -- distance from the edge */ - nscoord bottom; /* of the printable region to the */ - nscoord left; /* edge of the paper. Measured in twips. */ - nscoord right; - - nscoord width; /* Paper size, in twips. */ - nscoord height; + nscoord width; /* Page size, in twips, as oriented for */ + nscoord height; /* this print job. */ const char* header; const char* footer; + const char* paper_name; int *sizes; XP_Bool reverse; /* Output order */ @@ -187,11 +130,9 @@ struct PrintSetup_ { XP_Bool underline; /* underline links */ XP_Bool scale_images; /* Scale unsized images which are too big */ XP_Bool scale_pre; /* do the pre-scaling thing */ - float dpi; /* dpi for externally sized items */ float rules; /* Scale factor for rulers */ int n_up; /* cool page combining */ int bigger; /* Used to init sizes if sizesin NULL */ - const PSPaperSizeRec *paper_size; /* Paper size record */ const char* prefix; /* For text xlate, prepended to each line */ const char* eol; /* For text translation, line terminator */ const char* bullet; /* What char to use for bullets */ @@ -373,11 +314,6 @@ public: * @update 2/1/99 dwc */ void finalize_translation(); - /** --------------------------------------------------- - * ??? - * @update 2/1/99 dwc - */ - void annotate_page( const char*, int, int, int); /** --------------------------------------------------- * Output postscript to scale the current coordinate system * @param aX X scale factor diff --git a/gfx/src/xlib/nsDeviceContextSpecXlib.cpp b/gfx/src/xlib/nsDeviceContextSpecXlib.cpp index 77a0fd61935f..918a060a1ea3 100644 --- a/gfx/src/xlib/nsDeviceContextSpecXlib.cpp +++ b/gfx/src/xlib/nsDeviceContextSpecXlib.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 nsPrinterEnumeratorXlib::InitPrintSettingsFromPrinter(const PRUnic } #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,32 @@ NS_IMETHODIMP nsPrinterEnumeratorXlib::InitPrintSettingsFromPrinter(const PRUnic #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; + nsPaperSizePS paper; - 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))); + 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->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()); + 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 */ }