Herbert, 

I'm happy with the idea behind your "Bounding Box relative to the original" 
patch, but not with the execution. I think that the BoundingBox stored in 
GraphicsParams should be relative to the original. That way, we remove 
duplication of code in other graphics loaders and, more importantly, can set 
it to empty() if the bounds are obviously wrong.

Here's my reworking. Could you check it with your rose.eps (I think!) file.

Regards,
Angus
Index: src/frontends/xforms/xformsGImage.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/xforms/xformsGImage.C,v
retrieving revision 1.4
diff -u -p -r1.4 xformsGImage.C
--- src/frontends/xforms/xformsGImage.C	4 Apr 2002 14:49:54 -0000	1.4
+++ src/frontends/xforms/xformsGImage.C	8 Apr 2002 15:22:51 -0000
@@ -251,8 +251,9 @@ void xformsGImage::clip(GParams const & 
 	int const new_width  = params.bb.xr - params.bb.xl;
 	int const new_height = params.bb.yt - params.bb.yb;
 
-	if (new_width  <= 0 || new_width > image_->w ||
-	    new_height <= 0 || new_height > image_->h)
+	// No need to check if the width, height are > 0 because the
+	// Bounding Box would be empty() in this case.
+	if (new_width > image_->w || new_height > image_->h)
 		// Bounds are invalid.
 		return;
 
Index: src/graphics/ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/graphics/ChangeLog,v
retrieving revision 1.47
diff -u -p -r1.47 ChangeLog
--- src/graphics/ChangeLog	4 Apr 2002 14:49:54 -0000	1.47
+++ src/graphics/ChangeLog	8 Apr 2002 15:22:51 -0000
@@ -1,3 +1,9 @@
+2002-04-08  Angus Leeming  <[EMAIL PROTECTED]>
+
+	* GraphicsParams.C (c-tor): if clipping, then check the Bounding Box of
+	the EPS file too, to ensure that the flipped Bounding Box is relative
+	to the original. (From Herbert.)
+
 2002-04-04  Angus Leeming  <[EMAIL PROTECTED]>
 
 	* GraphicsParams.C (BoundingBox c-tor): ensure that the member
Index: src/graphics/GraphicsParams.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/graphics/GraphicsParams.C,v
retrieving revision 1.8
diff -u -p -r1.8 GraphicsParams.C
--- src/graphics/GraphicsParams.C	4 Apr 2002 14:49:54 -0000	1.8
+++ src/graphics/GraphicsParams.C	8 Apr 2002 15:22:51 -0000
@@ -32,9 +32,32 @@ GParams::GParams(InsetGraphicsParams con
 		filename = MakeAbsPath(filename, filepath);
 	}
 
-	if (iparams.clip)
+	if (iparams.clip) {
 		bb = iparams.bb;
 
+		// Get the original Bounding Box from the file
+		string const bb_orig_str = readBB_from_PSFile(filename);
+		if (!bb_orig_str.empty()) {
+			BoundingBox bb_orig = bb_orig_str;
+
+			bb.xl -= bb_orig.xl;
+			bb.xr -= bb_orig.xl;
+			bb.yb -= bb_orig.yb;
+			bb.yt -= bb_orig.yt;
+		}
+
+		// Paranoia check.
+		int const width  = bb.xr - bb.xl;
+		int const height = bb.yt - bb.yb;
+
+		if (width  < 0 || height < 0) {
+			bb.xl = 0;
+			bb.xr = 0;
+			bb.yb = 0;
+			bb.yt = 0;
+		}
+	}
+	
 	if (iparams.rotate)
 		angle = int(iparams.rotateAngle);
 
Index: src/graphics/GraphicsParams.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/graphics/GraphicsParams.h,v
retrieving revision 1.5
diff -u -p -r1.5 GraphicsParams.h
--- src/graphics/GraphicsParams.h	26 Mar 2002 12:43:21 -0000	1.5
+++ src/graphics/GraphicsParams.h	8 Apr 2002 15:22:51 -0000
@@ -65,6 +65,10 @@ struct GParams
 	/// The image filename.
 	string filename;
 
+	/** Note that the BoundingBox is always relative to the BoundingBox
+	 *  as stored in the EPS file.
+	 *  Ie, bb.xl and bb.yb == 0 if that corner is not moved.
+	 */
 	BoundingBox bb;
 
 	/** The size of the view inside lyx in pixels or the scaling of the

Reply via email to