Fix for 687410, 687478 in bbox device

Alex Cherepanov <[email protected]> Sun, 23 May 2004 21:10:42 -0400
Newsgroups gmane.comp.printing.ghostscript.patches
Organization Coscript Software
Message-ID <[email protected]>
Add /WhiteIsOpaque page device parameter to provide user interface
to the corresponding bbox device flag. Fix a bug introduced in
gdevbbox.c v.1.9 (for bug 645531) that left bdev->white and
bdev->black uninitialized, resulting in black objects skipped
as white.
Fix bugs 687410, 687478

_______________________________________________
gs-code-review mailing list
[email protected]
http://www.ghostscript.com/mailman/listinfo/gs-code-review
gdevbbox.diff (text/plain, 2.9 KB)
Index: gs/src/gdevbbox.c
===================================================================
RCS file: /cvs/ghostscript/gs/src/gdevbbox.c,v
retrieving revision 1.16
diff -b -u -r1.16 gdevbbox.c
--- a/gs/src/gdevbbox.c	14 Apr 2004 00:02:20 -0000	1.16
+++ b/gs/src/gdevbbox.c	24 May 2004 00:54:18 -0000
@@ -222,7 +222,7 @@
 
     if (tdev != 0)
 	gx_device_copy_params((gx_device *)bdev, tdev);
-    if (remap_colors && bdev->is_open) {
+    if (remap_colors) {
 	bdev->black = gx_device_black((gx_device *)bdev);
 	bdev->white = gx_device_white((gx_device *)bdev);
 	bdev->transparent =
@@ -522,7 +522,11 @@
     bbox[2] = fixed2float(fbox.q.x);
     bbox[3] = fixed2float(fbox.q.y);
     bba.data = bbox, bba.size = 4, bba.persistent = false;
-    return param_write_float_array(plist, "PageBoundingBox", &bba);
+    code = param_write_float_array(plist, "PageBoundingBox", &bba);
+    if (code < 0)
+        return code;
+    code = param_write_bool(plist, "WhiteIsOpaque", &bdev->white_is_opaque);
+    return code;
 }
 
 /* We implement put_params to ensure that we keep the important */
@@ -534,6 +538,7 @@
     gx_device_bbox *const bdev = (gx_device_bbox *) dev;
     int code;
     int ecode = 0;
+    bool white_is_opaque = bdev->white_is_opaque;
     gs_param_name param_name;
     gs_param_float_array bba;
 
@@ -553,15 +558,27 @@
 	    bba.data = 0;
     }
 
+    switch (code = param_read_bool(plist, (param_name = "WhiteIsOpaque"), &white_is_opaque)) {
+	default:
+	    ecode = code;
+	    param_signal_error(plist, param_name, ecode);
+	case 0:
+        case 1:
+	    break;
+    }
+
     code = gx_forward_put_params(dev, plist);
     if (ecode < 0)
 	code = ecode;
-    if (code >= 0 && bba.data != 0) {
+    if (code >= 0) {
+        if( bba.data != 0) {
 	BBOX_INIT_BOX(bdev);
 	BBOX_ADD_RECT(bdev, float2fixed(bba.data[0]), float2fixed(bba.data[1]),
 		      float2fixed(bba.data[2]), float2fixed(bba.data[3]));
     }
-    bbox_copy_params(bdev, true);
+        bdev->white_is_opaque = white_is_opaque;
+    }
+    bbox_copy_params(bdev, bdev->is_open);
     return code;
 }
 
Index: gs/doc/Devices.htm
===================================================================
RCS file: /cvs/ghostscript/gs/doc/Devices.htm,v
retrieving revision 1.73
diff -b -u -r1.73 Devices.htm
--- a/gs/doc/Devices.htm	23 Dec 2003 15:36:13 -0000	1.73
+++ b/gs/doc/Devices.htm	24 May 2004 00:54:18 -0000
@@ -1146,6 +1146,15 @@
 eventually, it should also recognize <b><tt>-sOutputFile=</tt></b>.
 
 <p>
+By default, white objects don't contribute to the bounding box because
+many files fill the whole page with white before drawing other objects.
+This can be changed by:
+
+<blockquote><tt><b>
+<< /WhiteIsOpaque true >> setpagedevice
+</b></tt></blockquote>
+
+<p>
 Note that this device, like other devices, has a resolution and a (maximum)
 page size.  As for other devices, the product (resolution x page size) is
 limited to approximately 500K pixels.  By default, the resolution is 4000