]> git.lyx.org Git - features.git/commitdiff
Store BoundingBox relative to original.
authorAngus Leeming <leeming@lyx.org>
Mon, 8 Apr 2002 16:51:46 +0000 (16:51 +0000)
committerAngus Leeming <leeming@lyx.org>
Mon, 8 Apr 2002 16:51:46 +0000 (16:51 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3948 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/xforms/ChangeLog
src/frontends/xforms/xformsGImage.C
src/graphics/ChangeLog
src/graphics/GraphicsParams.C
src/graphics/GraphicsParams.h

index 4e2d62ee5f62472a4ced0440b65938df559f0ef5..ab79ceca86a51dc80ffb28cdfa07e2032ad7ceac 100644 (file)
@@ -1,3 +1,8 @@
+2002-04-08  Angus Leeming  <a.leeming@ic.ac.uk>
+
+       * xformsGImage.C (clip): no need to check if the width, height are > 0
+       because the BoundingBox would be empty() in this case.
+
 2002-04-08  Lars Gullik Bjønnes  <larsbj@birdstep.com>
 
        * forms/Makefile.am (SUFFIXES): instead of .SUFFIXES
index 57069e8cfefbc33461f035f73fae6008439ab8ac..fadefb4c6fa69fc88f6cfd1e2b6d116eb982a68a 100644 (file)
@@ -251,8 +251,9 @@ void xformsGImage::clip(GParams const & params)
        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 1608094dd935db6b6666ef9beeef44f55962fd3a..67be3c9a291ed784a25cadbdaca9673f0f4d3119 100644 (file)
@@ -1,3 +1,9 @@
+2002-04-08  Angus Leeming  <a.leeming@ic.ac.uk>
+
+       * GraphicsParams.C (c-tor): if clipping, then check the Bounding Box of
+       the EPS file too, to ensure that the clipped Bounding Box is relative
+       to the original. (From Herbert.)
+
 2002-04-04  Angus Leeming  <a.leeming@ic.ac.uk>
 
        * GraphicsParams.C (BoundingBox c-tor): ensure that the member
index 5a84963f0dc668ffb6e31ad042df1a076f81950f..b130623134be184e9627d0372f50fde920f5b03b 100644 (file)
@@ -32,9 +32,36 @@ GParams::GParams(InsetGraphicsParams const & iparams, string const & filepath)
                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.xl = strToInt(token(bb_orig_str, ' ', 0));
+                       bb_orig.yb = strToInt(token(bb_orig_str, ' ', 1));
+                       bb_orig.xr = strToInt(token(bb_orig_str, ' ', 2));
+                       bb_orig.yt = strToInt(token(bb_orig_str, ' ', 3));
+
+                       bb.xl -= bb_orig.xl;
+                       bb.xr -= bb_orig.xl;
+                       bb.yb -= bb_orig.yb;
+                       bb.yt -= bb_orig.yb;
+               }
+
+               // 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);
 
@@ -131,14 +158,10 @@ BoundingBox::BoundingBox(string const & bb)
        // want the bounding box in Postscript pixels.
        // Note further that there are 72 Postscript pixels per inch.
        double const scaling_factor = 7200.0 / (lyxrc.dpi * lyxrc.zoom);
-       unsigned int const xl_tmp =
-               uint(scaling_factor * length_xl.inPixels(1, 1));
-       unsigned int const yb_tmp =
-               uint(scaling_factor * length_yb.inPixels(1, 1));
-       unsigned int const xr_tmp =
-               uint(scaling_factor * length_xr.inPixels(1, 1));
-       unsigned int const yt_tmp =
-               uint(scaling_factor * length_yt.inPixels(1, 1));
+       int const xl_tmp = int(scaling_factor * length_xl.inPixels(1, 1));
+       int const yb_tmp = int(scaling_factor * length_yb.inPixels(1, 1));
+       int const xr_tmp = int(scaling_factor * length_xr.inPixels(1, 1));
+       int const yt_tmp = int(scaling_factor * length_yt.inPixels(1, 1));
 
        if (xr_tmp <= xl_tmp || yt_tmp <= yb_tmp)
                return;
index 28335a9b5519c7c75d31430683b39d5d4a2670d2..04080f7d95f50443639bba2fab918c93be96e7ed 100644 (file)
@@ -38,10 +38,10 @@ struct BoundingBox {
        /// 0 0 0 0 is empty!
        bool empty() const;
 
-       unsigned int xl;
-       unsigned int yb;
-       unsigned int xr;
-       unsigned int yt;
+       int xl;
+       int yb;
+       int xr;
+       int yt;
 };
 
 bool operator==(BoundingBox const &, BoundingBox const &);
@@ -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