]> git.lyx.org Git - lyx.git/commitdiff
Herbert's and my fixes to the graphics inset.
authorAngus Leeming <leeming@lyx.org>
Thu, 4 Apr 2002 14:49:54 +0000 (14:49 +0000)
committerAngus Leeming <leeming@lyx.org>
Thu, 4 Apr 2002 14:49:54 +0000 (14:49 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3906 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/controllers/ChangeLog
src/frontends/controllers/ControlGraphics.C
src/frontends/xforms/ChangeLog
src/frontends/xforms/FormGraphics.C
src/frontends/xforms/FormGraphics.h
src/frontends/xforms/xformsGImage.C
src/graphics/ChangeLog
src/graphics/GraphicsParams.C

index 9a54d53b04b9c2ebd844a712dbd1b2095f929a48..da02712894abafb80c1d2145e981c9bfcb4f13c9 100644 (file)
@@ -1,3 +1,9 @@
+2002-04-04  Angus Leeming  <a.leeming@ic.ac.uk>
+
+       * ControlGraphics.C (readBB): Don't open the ifstrem and then
+       check the format from the contents (and open a second ifstream in the
+       process. One at a time please.
+
 2002-03-26  Angus Leeming  <a.leeming@ic.ac.uk>
 
        * ControlRef.C (getBufferNum): squash warning message.
index e5df87deb3806f495bfeb5e2c5e1e5fd4f7b27e1..6c1454fc13d7ed72ec6b2c3f48e9765af7217489 100644 (file)
@@ -104,19 +104,22 @@ string const ControlGraphics::Browse(string const & in_name)
 
 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 check a bit more.
-// on the other hand some plot programs write the bb at the
-// end of the file. Than we have in the header a
-//     %%BoundingBox: (atend)
-// In this case we must check until the end.
+       // 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_ = file;
        if (zippedFile(file_))
            file_ = unzipFile(file_);
+
+       string const format = getExtFromContents(file_);
+       if (format != "eps" && format != "ps")
+               return string();
+
        std::ifstream is(file_.c_str());
-       if (!contains(getExtFromContents(file_),"ps"))  // bb exists?
-           return string();
        while (is) {
                string s;
                is >> s;
index 66580a885f8f2aa02cf749a83b866a018933af3b..07bbd9ed814c63c6eb788aa603fd5c4d2d0a8134 100644 (file)
@@ -1,3 +1,13 @@
+2002-04-04  Angus Leeming  <a.leeming@ic.ac.uk>
+
+       * xformsGImage.C (clip): ensure that the clipped image has sensible
+       dimensions.
+
+2002-04-04  Herbert Voss  <voss@lyx.org>
+
+       * FormGraphics.C (updateBB):  new method to read the BBox when reading
+       a new file or changing an existing one.
+
 2002-04-03  Lars Gullik Bjønnes  <larsbj@birdstep.com>
 
        * FormCharacter.C (findPos): add a missing typename
index abe5add5bccffd7b2313d2ae8dbe7e9d637c4bd4..52713df6b88251a852ca2213a4aef7221bb4ab1e 100644 (file)
@@ -417,50 +417,68 @@ void FormGraphics::update() {
        // the bb section
        // set the bounding box values, if exists. First we need the whole
        // path, because the controller knows nothing about the doc-dir
+       updateBB(igp.filename, igp.bb);
+       fl_set_button(bbox_->check_clip, igp.clip);
+
+       // the special section
+       fl_set_input(special_->input_special, igp.special.c_str());
+}
+
+
+void FormGraphics::updateBB(string const & filename, string const & bb_inset)
+{
+       // Update dialog with details from inset
+       // set the bounding box values, if exists. First we need the whole
+       // path, because the controller knows nothing about the doc-dir
        controller().bbChanged = false;
-       if (igp.bb.empty()) {
+       if (bb_inset.empty()) {
                lyxerr[Debug::GRAPHICS] << "update:: no BoundingBox" << endl;
                string const fileWithAbsPath =
-                       MakeAbsPath(igp.filename, OnlyPath(igp.filename));
+                       MakeAbsPath(filename, OnlyPath(filename));
                string const bb = controller().readBB(fileWithAbsPath);
                if (!bb.empty()) {
                        // get the values from the file
                        // in this case we always have the point-unit
-                       fl_set_input(bbox_->input_bb_x0, token(bb,' ',0).c_str());
-                       fl_set_input(bbox_->input_bb_y0, token(bb,' ',1).c_str());
-                       fl_set_input(bbox_->input_bb_x1, token(bb,' ',2).c_str());
-                       fl_set_input(bbox_->input_bb_y1, token(bb,' ',3).c_str());
-               } else {                // no bb from file
+                       fl_set_input(bbox_->input_bb_x0,
+                                    token(bb,' ',0).c_str());
+                       fl_set_input(bbox_->input_bb_y0,
+                                    token(bb,' ',1).c_str());
+                       fl_set_input(bbox_->input_bb_x1,
+                                    token(bb,' ',2).c_str());
+                       fl_set_input(bbox_->input_bb_y1,
+                                    token(bb,' ',3).c_str());
+
+               } else {
+                       // no bb from file
                        fl_set_input(bbox_->input_bb_x0, bb.c_str());
                        fl_set_input(bbox_->input_bb_y0, bb.c_str());
                        fl_set_input(bbox_->input_bb_x1, bb.c_str());
                        fl_set_input(bbox_->input_bb_y1, bb.c_str());
                }
-               fl_set_choice(bbox_->choice_bb_units, 1);       // "pt"
-       } else {                                // get the values from the inset
-               lyxerr[Debug::GRAPHICS] << "update:: igp has BoundingBox" << endl;
+               // "pt"
+               fl_set_choice(bbox_->choice_bb_units, 1);
+
+       } else {
+               // get the values from the inset
+               lyxerr[Debug::GRAPHICS] << "update:: igp has BoundingBox"
+                                       << endl;
                controller().bbChanged = true;
                LyXLength anyLength;
-               anyLength = LyXLength(token(igp.bb,' ',0));
+               anyLength = LyXLength(token(bb_inset,' ',0));
                updateWidgetsFromLength(bbox_->input_bb_x0,
                                        bbox_->choice_bb_units,anyLength,"pt");
-               anyLength = LyXLength(token(igp.bb,' ',1));
+               anyLength = LyXLength(token(bb_inset,' ',1));
                updateWidgetsFromLength(bbox_->input_bb_y0,
                                        bbox_->choice_bb_units,anyLength,"pt");
-               anyLength = LyXLength(token(igp.bb,' ',2));
+               anyLength = LyXLength(token(bb_inset,' ',2));
                updateWidgetsFromLength(bbox_->input_bb_x1,
                                        bbox_->choice_bb_units,anyLength,"pt");
-               anyLength = LyXLength(token(igp.bb,' ',3));
+               anyLength = LyXLength(token(bb_inset,' ',3));
                updateWidgetsFromLength(bbox_->input_bb_y1,
                                        bbox_->choice_bb_units,anyLength,"pt");
        }
-       fl_set_button(bbox_->check_clip, igp.clip);
-
-       // the special section
-       fl_set_input(special_->input_special, igp.special.c_str());
 }
 
-
 namespace {
 
 bool isValid(FL_OBJECT * ob)
@@ -480,16 +498,12 @@ ButtonPolicy::SMInput FormGraphics::input(FL_OBJECT * ob, long)
                // Get the filename from the dialog
                string const in_name = getStringFromInput(file_->input_filename);
                string const out_name = controller().Browse(in_name);
+               lyxerr[Debug::GRAPHICS] << "[FormGraphics]out_name: " << out_name << endl;
                if (out_name != in_name && !out_name.empty()) {
                        fl_set_input(file_->input_filename, out_name.c_str());
                }
-//             if (!controller().isFilenameValid(out_name))
-//                     return ButtonPolicy::SMI_INVALID;
-
-//     } else if (ob == file_->input_filename) {
-//             string name = getStringFromInput(file_->input_filename);
-//             if (!controller().isFilenameValid(name))
-//                     return ButtonPolicy::SMI_INVALID;
+               if (controller().isFilenameValid(out_name))
+                       updateBB(out_name, string());
 
        } else if (ob == file_->check_subcaption) {
                setEnabled(file_->input_subcaption,
index 20e7c3440e87b687302573085069dc91606703da..db5fccd4b320e7f36f800700d040e68594360cd8 100644 (file)
@@ -46,6 +46,8 @@ private:
        virtual void build();
        /// Update dialog before/whilst showing it.
        virtual void update();
+       /// Update the BoundingBox info.
+       void updateBB(string const & filename, string const & bb_inset); 
        /// Filter the inputs on callback from xforms
        virtual ButtonPolicy::SMInput input(FL_OBJECT *, long);
 
index 257c1fd61d04c94791c3d3e369a9be15d138e484..57069e8cfefbc33461f035f73fae6008439ab8ac 100644 (file)
@@ -251,7 +251,8 @@ 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 > image_->w || new_height > image_->h)
+       if (new_width  <= 0 || new_width > image_->w ||
+           new_height <= 0 || new_height > image_->h)
                // Bounds are invalid.
                return;
 
index da3dc91d622f104be303acc94a1a116bd01abf1f..1608094dd935db6b6666ef9beeef44f55962fd3a 100644 (file)
@@ -1,7 +1,8 @@
 2002-04-04  Angus Leeming  <a.leeming@ic.ac.uk>
 
-       * GraphicsParams.C (c-tor): ensure that the member variables are
-       initialised.
+       * GraphicsParams.C (BoundingBox c-tor): ensure that the member
+       variables are initialised. Clean-up parsing of the string (with thanks
+       to Herbert.)
 
 2002-03-26  Angus Leeming  <a.leeming@ic.ac.uk>
 
index 0ddcff4ba67e42fe02f7d5055da31afaebab872e..5a84963f0dc668ffb6e31ad042df1a076f81950f 100644 (file)
@@ -114,25 +114,16 @@ BoundingBox::BoundingBox(string const & bb)
        if (bb.empty())
                return;
 
-       string tmp1;
-       string tmp2 = split(bb, tmp1, ' ');
-       if (!isValidLength(tmp1))
-               return;
-
-       LyXLength const length_xl(tmp1);
-
-       tmp2 = split(tmp2, tmp1, ' ');
-       if (!isValidLength(tmp1))
-               return;
-
-       LyXLength const length_yb(tmp1);
-
-       tmp2 = split(tmp2, tmp1, ' ');
-       if (!isValidLength(tmp1) || !isValidLength(tmp2))
-               return;
+       std::istringstream is(bb.c_str());
+       string a, b, c, d;
+       is >> a >> b >> c >> d;
 
-       LyXLength const length_xr(tmp1);
-       LyXLength const length_yt(tmp2);
+       // Don't need to check that the strings are valid LyXLength's
+       // because this is done in the LyXLength c-tor.
+       LyXLength const length_xl(a);
+       LyXLength const length_yb(b);
+       LyXLength const length_xr(c);
+       LyXLength const length_yt(d);
 
        // inPixels returns the length in inches, scaled by
        // lyxrc.dpi and lyxrc.zoom.
@@ -149,7 +140,7 @@ BoundingBox::BoundingBox(string const & bb)
        unsigned int const yt_tmp =
                uint(scaling_factor * length_yt.inPixels(1, 1));
 
-       if (xr <= xl || yt <= yb)
+       if (xr_tmp <= xl_tmp || yt_tmp <= yb_tmp)
                return;
 
        xl = xl_tmp;