]> git.lyx.org Git - features.git/commitdiff
Store InsetGraphics bounding box in parsed form
authorGeorg Baum <baum@lyx.org>
Sat, 18 Jul 2015 15:02:54 +0000 (17:02 +0200)
committerGeorg Baum <baum@lyx.org>
Sat, 18 Jul 2015 15:02:54 +0000 (17:02 +0200)
This is like InsetExternal does it, avoids some string parsing, reduces the
amount of code and makes it more robust.

src/frontends/qt4/GuiGraphics.cpp
src/insets/InsetGraphics.cpp
src/insets/InsetGraphicsParams.cpp
src/insets/InsetGraphicsParams.h

index 979cd2774e5c5f8ef81de455d4c66f7985a26e80..05ee2137c25e11a2dde94dde425f51c965f16131 100644 (file)
@@ -525,7 +525,7 @@ void GuiGraphics::paramsToDialog(InsetGraphicsParams const & igp)
        filename->setText(toqstr(name));
 
        // set the bounding box values
-       if (igp.bb.empty()) {
+       if (igp.bbox.empty()) {
                string const bb = readBoundingBox(igp.filename.absFileName());
                // the values from the file always have the bigpoint-unit bp
                doubleToWidget(lbX, token(bb, ' ', 0));
@@ -539,39 +539,18 @@ void GuiGraphics::paramsToDialog(InsetGraphicsParams const & igp)
                bbChanged = false;
        } else {
                // get the values from the inset
-               Length anyLength;
-               string const xl = token(igp.bb, ' ', 0);
-               string const yl = token(igp.bb, ' ', 1);
-               string const xr = token(igp.bb, ' ', 2);
-               string const yr = token(igp.bb, ' ', 3);
-               if (isValidLength(xl, &anyLength)) {
-                       doubleToWidget(lbX, anyLength.value());
-                       string const unit = unit_name[anyLength.unit()];
-                       lbXunit->setCurrentIndex(lbXunit->findData(toqstr(unit)));
-               } else {
-                       lbX->setText(toqstr(xl));
-               }
-               if (isValidLength(yl, &anyLength)) {
-                       doubleToWidget(lbY, anyLength.value());
-                       string const unit = unit_name[anyLength.unit()];
-                       lbYunit->setCurrentIndex(lbYunit->findData(toqstr(unit)));
-               } else {
-                       lbY->setText(toqstr(xl));
-               }
-               if (isValidLength(xr, &anyLength)) {
-                       doubleToWidget(rtX, anyLength.value());
-                       string const unit = unit_name[anyLength.unit()];
-                       rtXunit->setCurrentIndex(rtXunit->findData(toqstr(unit)));
-               } else {
-                       rtX->setText(toqstr(xl));
-               }
-               if (isValidLength(yr, &anyLength)) {
-                       doubleToWidget(rtY, anyLength.value());
-                       string const unit = unit_name[anyLength.unit()];
-                       rtYunit->setCurrentIndex(rtYunit->findData(toqstr(unit)));
-               } else {
-                       rtY->setText(toqstr(xl));
-               }
+               doubleToWidget(lbX, igp.bbox.xl.value());
+               string unit = unit_name[igp.bbox.xl.unit()];
+               lbXunit->setCurrentIndex(lbXunit->findData(toqstr(unit)));
+               doubleToWidget(lbY, igp.bbox.yb.value());
+               unit = unit_name[igp.bbox.yb.unit()];
+               lbYunit->setCurrentIndex(lbYunit->findData(toqstr(unit)));
+               doubleToWidget(rtX, igp.bbox.xr.value());
+               unit = unit_name[igp.bbox.xr.unit()];
+               rtXunit->setCurrentIndex(rtXunit->findData(toqstr(unit)));
+               doubleToWidget(rtY, igp.bbox.yt.value());
+               unit = unit_name[igp.bbox.yt.unit()];
+               rtYunit->setCurrentIndex(rtYunit->findData(toqstr(unit)));
                bbChanged = true;
        }
 
@@ -673,7 +652,7 @@ void GuiGraphics::applyView()
        igp.filename.set(fromqstr(filename->text()), fromqstr(bufferFilePath()));
 
        // the bb section
-       igp.bb.erase();
+       igp.bbox = graphics::BoundingBox();
        if (bbChanged) {
                string bb;
                string lbXs = widgetToDoubleStr(lbX);
@@ -685,22 +664,17 @@ void GuiGraphics::applyView()
                        convert<int>(rtXs) + convert<int>(rtXs);
                if (bb_sum) {
                        if (lbXs.empty())
-                               bb = "0 ";
-                       else
-                               bb = lbXs + fromqstr(lbXunit->currentText()) + ' ';
+                               lbXs = "0";
+                       igp.bbox.xl = Length(lbXs + fromqstr(lbXunit->currentText()));
                        if (lbYs.empty())
-                               bb += "0 ";
-                       else
-                               bb += (lbYs + fromqstr(lbYunit->currentText()) + ' ');
+                               lbYs = "0";
+                       igp.bbox.yb = Length(lbYs + fromqstr(lbYunit->currentText()));
                        if (rtXs.empty())
-                               bb += "0 ";
-                       else
-                               bb += (rtXs + fromqstr(rtXunit->currentText()) + ' ');
+                               rtXs = "0";
+                       igp.bbox.xr = Length(rtXs + fromqstr(rtXunit->currentText()));
                        if (rtYs.empty())
-                               bb += '0';
-                       else
-                               bb += (rtYs + fromqstr(rtYunit->currentText()));
-                       igp.bb = bb;
+                               rtYs = "0";
+                       igp.bbox.yt = Length(rtYs + fromqstr(rtYunit->currentText()));
                }
        }
 
index b3293ce37c8c48312a210a1bf2371e71577518b6..ac9d0809d83f0a73203245a25b5cf108f0e64cec 100644 (file)
@@ -310,8 +310,11 @@ string InsetGraphics::createLatexOptions() const
        // stream since we might have a trailing comma that we would like to remove
        // before writing it to the output stream.
        ostringstream options;
-       if (!params().bb.empty())
-           options << "bb=" << rtrim(params().bb) << ',';
+       if (!params().bbox.empty())
+               options << "bb=" << params().bbox.xl.asLatexString() << ' '
+                       << params().bbox.yb.asLatexString() << ' '
+                       << params().bbox.xr.asLatexString() << ' '
+                       << params().bbox.yt.asLatexString() << ',';
        if (params().draft)
            options << "draft,";
        if (params().clip)
@@ -734,7 +737,7 @@ void InsetGraphics::latex(otexstream & os,
                        && params().filename.isReadableFile();
        string message;
        if (!file_exists) {
-               if (params().bb.empty())
+               if (params().bbox.empty())
                    message = "bb = 0 0 200 100";
                if (!params().draft) {
                        if (!message.empty())
index 85e25d2f13d8abf61aa8bfd42c732010b0a06927..15d6cad7a4a1324173a414e0ce4a71df4e9d8c0b 100644 (file)
@@ -19,7 +19,6 @@
 #include "LyXRC.h"
 
 #include "graphics/epstools.h"
-#include "graphics/GraphicsParams.h"
 #include "graphics/GraphicsTypes.h"
 
 #include "support/convert.h"
@@ -72,7 +71,7 @@ void InsetGraphicsParams::init()
        draft = false;                  // draft mode
        scaleBeforeRotation = false;    // scale image before rotating
 
-       bb = string();                  // bounding box
+       bbox = graphics::BoundingBox(); // bounding box
        clip = false;                   // clip image
 
        rotateAngle = "0";              // angle of rotation in degrees
@@ -94,7 +93,7 @@ void InsetGraphicsParams::copy(InsetGraphicsParams const & igp)
        draft = igp.draft;
        scaleBeforeRotation = igp.scaleBeforeRotation;
 
-       bb = igp.bb;
+       bbox = igp.bbox;
        clip = igp.clip;
 
        rotateAngle = igp.rotateAngle;
@@ -117,7 +116,7 @@ bool operator==(InsetGraphicsParams const & left,
            left.draft == right.draft &&
            left.scaleBeforeRotation == right.scaleBeforeRotation &&
 
-           left.bb == right.bb &&
+           left.bbox == right.bbox &&
            left.clip == right.clip &&
 
            left.rotateAngle == right.rotateAngle &&
@@ -160,8 +159,8 @@ void InsetGraphicsParams::Write(ostream & os, Buffer const & buffer) const
        if (scaleBeforeRotation)
                os << "\tscaleBeforeRotation\n";
 
-       if (!bb.empty())                // bounding box
-               os << "\tBoundingBox " << bb << '\n';
+       if (!bbox.empty())              // bounding box
+               os << "\tBoundingBox " << bbox << '\n';
        if (clip)                       // clip image
                os << "\tclip\n";
 
@@ -207,13 +206,14 @@ bool InsetGraphicsParams::Read(Lexer & lex, string const & token, string const &
        } else if (token == "scaleBeforeRotation") {
                scaleBeforeRotation = true;
        } else if (token == "BoundingBox") {
-               bb.erase();
-               for (int i = 0; i < 4; ++i) {
-                       if (i != 0)
-                               bb += ' ';
-                       lex.next();
-                       bb += lex.getString();
-               }
+               lex.next();
+               bbox.xl = Length(lex.getString());
+               lex.next();
+               bbox.yb = Length(lex.getString());
+               lex.next();
+               bbox.xr = Length(lex.getString());
+               lex.next();
+               bbox.yt = Length(lex.getString());
        } else if (token == "clip") {
                clip = true;
        } else if (token == "rotateAngle") {
@@ -252,7 +252,7 @@ graphics::Params InsetGraphicsParams::as_grfxParams() const
        pars.angle = convert<double>(rotateAngle);
 
        if (clip) {
-               pars.bb = bb;
+               pars.bb = bbox;
 
                // Get the original Bounding Box from the file
                string const tmp = graphics::readBB_from_PSFile(filename);
index 4e40dd703f9aae374562b411e9f5607c340c003f..78d2ebf4107c52c1324d03607adb81ddd13aca4c 100644 (file)
@@ -14,7 +14,7 @@
 #define INSETGRAPHICSPARAMS_H
 
 
-#include "Length.h"
+#include "graphics/GraphicsParams.h"
 
 #include "support/FileName.h"
 
@@ -51,8 +51,8 @@ public:
        /// scale image before rotating
        bool scaleBeforeRotation;
 
-       /// The bounding box with "xLB yLB yRT yRT ", divided by a space!
-       std::string bb;
+       /// The bounding box
+       graphics::BoundingBox bbox;
        /// clip image
        bool clip;