clipping on original bounding boxes like 29 39 200 300
is wrong, because LyX takes the first two values
(lower left) in relation to (0,0) and crops the image
with wrong values.

This was first mentioned by Rob.

The attached patch fixes this, so that lyx-view
and latex view are the same..

Herbert



-- 
http://www.lyx.org/help/
Index: src/frontends/controllers/ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/controllers/ChangeLog,v
retrieving revision 1.154
diff -u -r1.154 ChangeLog
--- src/frontends/controllers/ChangeLog 5 Apr 2002 09:18:25 -0000       1.154
+++ src/frontends/controllers/ChangeLog 7 Apr 2002 16:16:56 -0000
@@ -1,3 +1,7 @@
+2002-04-07  Herbert Voss  <[EMAIL PROTECTED]>
+
+       * ControlGraphics.[C]: move readBB as readBB_from_PSFile into filetools
+
 2002-04-05  Angus Leeming  <[EMAIL PROTECTED]>
 
        * ControlGraphics.C (readBB): sigh. Make sure that the correct path is
Index: src/frontends/controllers/ControlGraphics.C
===================================================================
RCS file: 
/usr/local/lyx/cvsroot/lyx-devel/src/frontends/controllers/ControlGraphics.C,v
retrieving revision 1.29
diff -u -r1.29 ControlGraphics.C
--- src/frontends/controllers/ControlGraphics.C 5 Apr 2002 09:18:25 -0000       1.29
+++ src/frontends/controllers/ControlGraphics.C 7 Apr 2002 16:16:56 -0000
@@ -36,12 +36,12 @@
 #include "support/FileInfo.h"  // for FileInfo
 #include "helper_funcs.h"
 #include "support/lstrings.h"
-#include "support/filetools.h" // for AddName, zippedFile
+#include "support/filetools.h" // for AddName, zippedFile, readBB_from_PSFile
 
 using std::pair;
 using std::make_pair;
 using std::ifstream;
-
+ 
 ControlGraphics::ControlGraphics(LyXView & lv, Dialogs & d)
        : ControlInset<InsetGraphics, InsetGraphicsParams>(lv, d)
 {
@@ -104,37 +104,7 @@
 
 string const ControlGraphics::readBB(string const & file)
 {
-       // in a file it's an entry like %%BoundingBox:23 45 321 345
-       // The first number can following without a space, so we have
-       // to be a little careful.
-       // On the other hand some plot programs write the bb at the
-       // end of the file. Than we have in the header:
-       // %%BoundingBox: (atend)
-       // In this case we must check the end.
-       string file_ = MakeAbsPath(file, lv_.buffer()->filePath());
-       if (zippedFile(file_))
-               file_ = unzipFile(file_);
-
-       string const format = getExtFromContents(file_);
-       if (format != "eps" && format != "ps")
-               return string();
-
-       std::ifstream is(file_.c_str());
-       while (is) {
-               string s;
-               is >> s;
-               if (contains(s,"%%BoundingBox:")) {
-                       string a, b, c, d;
-                       is >> a >> b >> c >> d;
-                       if (is && !contains(a,"atend")) { // bb at the end?
-                               if (s != "%%BoundingBox:")
-                                   return (s.substr(14)+" "+a+" "+b+" "+c+" ");
-                               else
-                                   return (a+" "+b+" "+c+" "+d+" ");
-                       }
-               }
-       }
-       return string();
+       return readBB_from_PSFile(MakeAbsPath(file, lv_.buffer()->filePath()));
 }
 
 
Index: src/frontends/xforms/ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/xforms/ChangeLog,v
retrieving revision 1.345
diff -u -r1.345 ChangeLog
--- src/frontends/xforms/ChangeLog      6 Apr 2002 13:15:10 -0000       1.345
+++ src/frontends/xforms/ChangeLog      7 Apr 2002 16:16:57 -0000
@@ -1,3 +1,8 @@
+2002-04-07  Herbert Voss  <[EMAIL PROTECTED]>
+
+       * xformsGImage.C: use correct values for the bounding box when
+       clipping the image
+
 2002-04-06  Lars Gullik Bjønnes  <[EMAIL PROTECTED]>
 
        * forms/.cvsignore: add Makefile.in
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 -r1.4 xformsGImage.C
--- src/frontends/xforms/xformsGImage.C 4 Apr 2002 14:49:54 -0000       1.4
+++ src/frontends/xforms/xformsGImage.C 7 Apr 2002 16:16:57 -0000
@@ -20,6 +20,7 @@
 #include "frontends/GUIRunTime.h"   // x11Display, x11Screen
 #include "support/LAssert.h"
 #include "support/lyxfunctional.h"  // compare_memfun
+#include "support/filetools.h"      // readBB_from_PSFile
 
 using std::find_if;
 
@@ -248,6 +249,12 @@
                // No clipping is necessary.
                return;
 
+       //get the original bb from the file
+       string const bb_orig = readBB_from_PSFile(params.filename);
+       lyxerr[Debug::GRAPHICS] << "xFormsGImage::readBB: " << bb_orig << endl;
+       // we need only the lower left values
+       int const xl_orig = strToInt(token(bb_orig,' ',0));
+       int const yb_orig = strToInt(token(bb_orig,' ',1));
        int const new_width  = params.bb.xr - params.bb.xl;
        int const new_height = params.bb.yt - params.bb.yb;
 
@@ -260,10 +267,19 @@
                // Bounds are unchanged.
                return;
 
-       int const xoffset_l = params.bb.xl;
-       int const xoffset_r = image_->w - params.bb.xr;
-       int const yoffset_t = image_->h - params.bb.yt;
-       int const yoffset_b = params.bb.yb;
+       // correct the lower left if the original bb
+       // doesn't has a lower left(0,0)
+       int dummy = params.bb.xl - xl_orig;
+       int const xoffset_l = (dummy < 0) ? 0 : dummy;
+
+       dummy = image_->w - (params.bb.xr - xl_orig);
+       int const xoffset_r = (dummy < 0) ? 0 : dummy;
+
+       dummy = image_->h - (params.bb.yt - yb_orig);
+       int const yoffset_t = (dummy < 0) ? 0 : dummy;
+
+       dummy = params.bb.yb - yb_orig;
+       int const yoffset_b = (dummy < 0) ? 0 : dummy;
 
        flimage_crop(image_, xoffset_l, yoffset_t, xoffset_r, yoffset_b);
 }
Index: src/support/ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/support/ChangeLog,v
retrieving revision 1.94
diff -u -r1.94 ChangeLog
--- src/support/ChangeLog       7 Apr 2002 15:31:16 -0000       1.94
+++ src/support/ChangeLog       7 Apr 2002 16:16:58 -0000
@@ -1,5 +1,10 @@
 2002-04-07  Herbert Voss  <[EMAIL PROTECTED]>
 
+       * filetools.[Ch]: add readBB_from_PSFile() to make bb available
+       for the lyx-view in graphics (moved from ControlGraphics)
+
+2002-04-07  Herbert Voss  <[EMAIL PROTECTED]>
+
        * filetools.C: fix bug for eps. scans now a whole line
 
 2002-04-06  Lars Gullik Bjønnes  <[EMAIL PROTECTED]>
Index: src/support/filetools.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/support/filetools.C,v
retrieving revision 1.114
diff -u -r1.114 filetools.C
--- src/support/filetools.C     7 Apr 2002 15:31:16 -0000       1.114
+++ src/support/filetools.C     7 Apr 2002 16:16:58 -0000
@@ -1344,3 +1344,37 @@
                }
        }
 }
+
+
+string const readBB_from_PSFile(string const & file)
+{
+       // in a (e)ps-file it's an entry like %%BoundingBox:23 45 321 345
+       // The first number can following without a space, so we have
+       // to be a little careful.
+       // On the other hand some plot programs write the bb at the
+       // end of the file. Than we have in the header:
+       // %%BoundingBox: (atend)
+       // In this case we must check the end.
+       string const file_ = zippedFile(file) ? unzipFile(file) : file;
+       string const format = getExtFromContents(file_);
+       if (format != "eps" && format != "ps")
+               return string();
+
+       std::ifstream is(file_.c_str());
+       while (is) {
+               string s;
+               is >> s;
+               if (contains(s,"%%BoundingBox:")) {
+                       string a, b, c, d;
+                       is >> a >> b >> c >> d;
+                       if (is && !contains(a,"atend")) { // bb at the end?
+                               if (s != "%%BoundingBox:")
+                                   return (s.substr(14)+" "+a+" "+b+" "+c+" ");
+                               else
+                                   return (a+" "+b+" "+c+" "+d+" ");
+                       }
+               }
+       }
+       return string();
+}
+
Index: src/support/filetools.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/support/filetools.h,v
retrieving revision 1.33
diff -u -r1.33 filetools.h
--- src/support/filetools.h     27 Mar 2002 00:05:28 -0000      1.33
+++ src/support/filetools.h     7 Apr 2002 16:16:58 -0000
@@ -206,5 +206,8 @@
 /// remove the autosave-file and give a Message if it can't be done
 void removeAutosaveFile(string const & filename);
 
+/// read the BoundingBox entry from a ps/eps/pdf-file
+string const readBB_from_PSFile(string const & file);
+
 
 #endif

Reply via email to