[gs-cvs] gs/lib

Dan Coby dan at ghostscript.com
Fri Apr 8 16:55:15 PDT 2005


Update of /cvs/ghostscript/gs/lib
In directory casper2:/tmp/cvs-serv18193/lib

Modified Files:
	pdf_main.ps 
Log Message:
Fix for 688019  /configurationerror in --setpagedevice--.  The PDF
interpreter was incorrectly determining the size of the page.

DETAILS:

The test file specifies the following media box:

/MediaBox [ 0 1080 1620 0 ]

The PDF 1.6 specification says the following about media box rectangles:

"3.8.4 Rectangles
Rectangles are used to describe locations on a page and bounding boxes for a
variety of objects, such as fonts. A rectangle is written as an array of four 
numbers giving the coordinates of a pair of diagonally opposite corners. 
Typically, the array takes the form
[llx lly urx ury]
specifying the lower-left x, lower-left y, upper-right x, and upper-right 
coordinates of the rectangle, in that order. The other two corners of the 
rectangle are then assumed to have coordinates (llx, ury) and (urx, lly).

Note: Although rectangles are conventionally specified by their lower-left and 
upperright corners, it is acceptable to specify any two diagonally opposite 
corners. Applications that process PDF should be prepared to normalize such 
rectangles in situations where specific corners are required."


The PDF interpreter was assuming that the MediaBox and the CropBox were
in the 'typical' form.  This fix consists of creating a pair of procedures
for converting rectangles into the typical form and then using the
procedures.


Index: pdf_main.ps
===================================================================
RCS file: /cvs/ghostscript/gs/lib/pdf_main.ps,v
retrieving revision 1.95
retrieving revision 1.96
diff -u -d -r1.95 -r1.96
--- pdf_main.ps	16 Mar 2005 23:04:07 -0000	1.95
+++ pdf_main.ps	8 Apr 2005 23:55:13 -0000	1.96
@@ -130,7 +130,7 @@
    pdfdict begin
    pdfopen begin
    Trailer /Root oget /Pages oget /CropBox knownoget
-    { oforce_array mark /CropBox 3 -1 roll /PAGES pdfmark
+    { oforce_array normrect mark /CropBox 3 -1 roll /PAGES pdfmark
     }
    if
    /FirstPage where 
@@ -835,7 +835,22 @@
    ifelse
  } bind def
 
-% Display a given page.
+% Arrange the four elements that define a rectangle into a 'normal' order.
+/normrect_elems   % <x1> <y1> <x2> <y2> normrect_elems <llx> <lly> <urx> <ury>
+{
+    exch 4 1 roll			% <x2> <x1> <y1> <y2>
+    2 copy gt { exch } if		% <x2> <x1> <lly> <ury>
+    4 2 roll 2 copy lt { exch } if	% <lly> <ury> <urx> <llx>
+    4 1 roll exch			% <llx> <lly> <urx> <ury>
+} bind def
+
+% Arrange a rectangle into a 'normal' order.  I.e the lower left corner
+% followed by the upper right corner.
+/normrect 	% <rect> normrect <rect>
+{
+    aload pop normrect_elems 4 array astore
+} bind def
+
 /boxrect		% <llx> <lly> <urx> <ury> boxrect <x> <y> <w> <h>
  { exch 3 index sub exch 2 index sub
  } bind def
@@ -963,7 +978,7 @@
     dup /MediaBox pget pop	% There has to be a MediaBox
   } ifelse
   % stack: [<prevproc>] <pagedict> <Crop|Media Box>
-  exch pop oforce_array			% done with the pagedict
+  exch pop oforce_array normrect		% done with the pagedict
   systemdict /PDFFitPage known {
     PDFDEBUG { (Fiting PDF to imageable area of the page.) = flush } if
     currentpagedevice /.HWMargins get aload pop
@@ -997,12 +1012,13 @@
 	% Stack: pagedict currentpagedict
   1 index /CropBox pget dup {exch pop} if systemdict /UseCropBox known and {
 			% Set the page size.
-    1 index /CropBox pget pop oforce_elems
-    boxrect 2 array astore /PageSize exch def pop pop
+    1 index /CropBox pget pop oforce_elems normrect_elems boxrect
+    2 array astore /PageSize exch def pop pop
   } {
     1 index /MediaBox pget {
 			% Set the page size.
-      oforce_elems boxrect 2 array astore /PageSize exch def pop pop
+      oforce_elems normrect_elems boxrect
+      2 array astore /PageSize exch def pop pop
     } if
   } ifelse
   % Don't change the page size if we are going to fit the PDF to the page
@@ -1043,7 +1059,7 @@
 
 	% Copy the crop box.
     dup /CropBox knownoget {
-      oforce_array
+      oforce_array normrect
 
         % .pdfshowpage_Install translates the origin -
         % do same here with the CropBox.
@@ -1053,7 +1069,7 @@
       } {
         1 index /MediaBox pget pop	% There has to be a MediaBox
       } ifelse
-      oforce_array
+      oforce_array normrect
       dup 0 get exch 1 get   % [] tx ty
       2 index 0 get 2 index sub 3 index exch 0 exch put
       2 index 2 get 2 index sub 3 index exch 2 exch put
@@ -1091,7 +1107,8 @@
    /TRDefault currenttransfer def
   matrix currentmatrix 2 dict
   2 index /CropBox knownoget {
-    oforce_elems boxrect 4 array astore 1 index /ClipRect 3 -1 roll put
+    oforce_elems normrect_elems boxrect
+    4 array astore 1 index /ClipRect 3 -1 roll put
   } if
   dictbeginpage setmatrix
   /DefaultQstate qstate store
@@ -1109,7 +1126,7 @@
       dup /Group knownoget {
 	1 index /CropBox knownoget not {
 	  1 index /MediaBox pget pop
-	} if oforce_array .beginformgroup {
+	} if oforce_array normrect .beginformgroup {
 	  showpagecontents
 	} stopped {
 	  .discardtransparencygroup stop



More information about the gs-cvs mailing list