[gs-cvs] rev 9373 - in trunk/gs: base doc

ken at ghostscript.com ken at ghostscript.com
Mon Jan 19 01:47:56 PST 2009


Author: ken
Date: 2009-01-19 01:47:56 -0800 (Mon, 19 Jan 2009)
New Revision: 9373

Modified:
   trunk/gs/base/gdevpdfb.h
   trunk/gs/base/gdevpdfp.c
   trunk/gs/base/gdevpdfu.c
   trunk/gs/base/gdevpdfx.h
   trunk/gs/base/gdevpsu.c
   trunk/gs/doc/Ps2ps2.htm
Log:
Fix (pswrite): %%BoundingBox comment geenration
   (ps2write): media selection and %%BoundingBox generation

Details:
bug #690236 "Ghostscript is not able to convert PDF to PostScript 
maintaining the input document's page sizes"

The pswrite bug is actually in the consuming applications, which are unable to 
process the media selection requests in the pswrite output and instead use DSC
comments to select the media. pswrite attempts to use the bbox deice to generate a
%%BoundingBox comment, but because this is a high-level device, no marks are made, so 
the BoundingBox is 0 0 0 0. 

Fixed by using the media size instead if this case is detected.


ps2write did not generate a %%BoundingBox, or any other DSC comment at all, because it
does not produce DSC PostScript (there is a request to address this already #690064).
Also the media selection in the ps2write output is disabled by default, forcing users
to find some means to set particular keys in userdict on the target device.

Fixed by emitting a %%BoundingBox equal to the media size of the first page (NB as
this is not DSC, other pages will be selected incorrectly if this is all the
application uses). Also allow the use of the /SetPageSize, /RotatePages and /FitPages
keys during ps2write processing to emit a PostScript file with these keys already
set, thus allowing media selection to take place without further user intervention.

Expected Differences
None


Modified: trunk/gs/base/gdevpdfb.h
===================================================================
--- trunk/gs/base/gdevpdfb.h	2009-01-18 19:57:58 UTC (rev 9372)
+++ trunk/gs/base/gdevpdfb.h	2009-01-19 09:47:56 UTC (rev 9373)
@@ -242,6 +242,9 @@
  0,				/* OPDFRead_procset_length */
  0,				/* find_resource_param */
  0,				/* last_charpath_op */
- 0				/* type3charpath */
+ 0,				/* type3charpath */
+ 0,				/* SetPageSize */
+ 0,				/* RotatePages */
+ 0				/* Fit Pages */
 };
 

Modified: trunk/gs/base/gdevpdfp.c
===================================================================
--- trunk/gs/base/gdevpdfp.c	2009-01-18 19:57:58 UTC (rev 9372)
+++ trunk/gs/base/gdevpdfp.c	2009-01-19 09:47:56 UTC (rev 9373)
@@ -104,6 +104,11 @@
     pi("PDFXTrimBoxToMediaBoxOffset", gs_param_type_float_array, PDFXTrimBoxToMediaBoxOffset),
     pi("PDFXSetBleedBoxToMediaBox", gs_param_type_bool, PDFXSetBleedBoxToMediaBox),
     pi("PDFXBleedBoxToTrimBoxOffset", gs_param_type_float_array, PDFXBleedBoxToTrimBoxOffset),
+
+    /* media selection parameters */
+    pi("SetPageSize", gs_param_type_bool, SetPageSize),
+    pi("RotatePages", gs_param_type_bool, RotatePages),
+    pi("FitPages", gs_param_type_bool, FitPages),
 #undef pi
     gs_param_item_end
 };

Modified: trunk/gs/base/gdevpdfu.c
===================================================================
--- trunk/gs/base/gdevpdfu.c	2009-01-18 19:57:58 UTC (rev 9372)
+++ trunk/gs/base/gdevpdfu.c	2009-01-19 09:47:56 UTC (rev 9373)
@@ -300,8 +300,19 @@
 	pdev->binary_ok = !pdev->params.ASCII85EncodePages;
 	if (pdev->ForOPDFRead && pdev->OPDFReadProcsetPath.size) {
 	    int code, status;
+	    char BBox[256];
+	    int width = (int)(pdev->width * 72.0 / pdev->HWResolution[0] + 0.5);
+	    int height = (int)(pdev->height * 72.0 / pdev->HWResolution[1] + 0.5);
 	    
 	    stream_write(s, (byte *)"%!PS-Adobe-2.0\r", 15);
+	    sprintf(BBox, "%%%%BoundingBox: 0 0 %d %d\r", width, height);
+	    stream_write(s, (byte *)BBox, strlen(BBox));
+	    if(pdev->SetPageSize)
+		stream_puts(s, "/SetPageSize true def\n");
+	    if(pdev->RotatePages)
+		stream_puts(s, "/RotatePages true def\n");
+	    if(pdev->FitPages)
+		stream_puts(s, "/FitPages true def\n");
 	    if (pdev->params.CompressPages || pdev->CompressEntireFile) {
 		/*  When CompressEntireFile is true and ASCII85EncodePages is false,
 		    the ASCII85Encode filter is applied, rather one may expect the opposite.

Modified: trunk/gs/base/gdevpdfx.h
===================================================================
--- trunk/gs/base/gdevpdfx.h	2009-01-18 19:57:58 UTC (rev 9372)
+++ trunk/gs/base/gdevpdfx.h	2009-01-19 09:47:56 UTC (rev 9373)
@@ -650,6 +650,9 @@
     void *find_resource_param; /* WARNING : not visible for garbager. */
     int last_charpath_op; /* true or false state of last charpath */
     bool type3charpath;
+    bool SetPageSize;
+    bool RotatePages;
+    bool FitPages;
 };
 
 #define is_in_page(pdev)\

Modified: trunk/gs/base/gdevpsu.c
===================================================================
--- trunk/gs/base/gdevpsu.c	2009-01-18 19:57:58 UTC (rev 9372)
+++ trunk/gs/base/gdevpsu.c	2009-01-19 09:47:56 UTC (rev 9373)
@@ -239,7 +239,23 @@
 	    long save_pos = ftell(f);
 
 	    fseek(f, pdpc->bbox_position, SEEK_SET);
-	    psw_print_bbox(f, pbbox);
+	    /* Theoretically the bbox device should fill in the bounding box
+	     * but this does nothing because we don't write on the page.
+	     * So if bbox = 0 0 0 0, replace with the device page size.
+	     */
+	    if(pbbox->p.x == 0 && pbbox->p.y == 0 
+		&& pbbox->q.x == 0 && pbbox->q.y == 0) {
+		gs_rect bbox;
+		int width = (int)(dev->width * 72.0 / dev->HWResolution[0] + 0.5);
+		int height = (int)(dev->height * 72.0 / dev->HWResolution[1] + 0.5);
+
+		bbox.p.x = 0;
+		bbox.p.y = 0;
+		bbox.q.x = width;
+		bbox.q.y = height;
+		psw_print_bbox(f, &bbox);
+	    } else 
+		psw_print_bbox(f, pbbox);
             fputc('%', f);
             if (ferror(f))
                 return_error(gs_error_ioerror);

Modified: trunk/gs/doc/Ps2ps2.htm
===================================================================
--- trunk/gs/doc/Ps2ps2.htm	2009-01-18 19:57:58 UTC (rev 9372)
+++ trunk/gs/doc/Ps2ps2.htm	2009-01-19 09:47:56 UTC (rev 9373)
@@ -208,10 +208,14 @@
 executing a job generated with <code>ps2ps2</code>.
 
 <p>
-Currently Ghostscript does not provide a method for 
-incorporating these in a print job.
-Users should refer to the printer's documentation.
+These keys can be set when executing ps2ps2 (or using the ps2write device), 
+this 'fixes' the resulting behaviour according to which key has been set. 
+If these keys are not defined during conversion, the resulting PostScript 
+will not attempt any form of media selection. 
 
+In this case the behaviour can then be modified by setting the keys, either by modifying the resulting 
+PostScript or setting the values in some other manner on the target device.
+
 <hr>
 
 



More information about the gs-cvs mailing list