]> git.lyx.org Git - lyx.git/blobdiff - src/insets/ExternalTransforms.cpp
Use the same code for editable and non-editable buttons
[lyx.git] / src / insets / ExternalTransforms.cpp
index 8506d8e8d2c98c4b70e126b971c9d07c031aadc4..2381241b9a28441557833e456b32997f6eab7c2b 100644 (file)
 
 #include "ExternalTransforms.h"
 
+#include "support/convert.h"
 #include "support/debug.h"
-
 #include "support/lstrings.h"
 #include "support/lyxlib.h" // float_equal
-#include "support/convert.h"
 #include "support/Translator.h"
 
-#include <boost/regex.hpp>
+#include "support/regex.h"
 
-#include <cmath> // std::abs
+#include <cmath> // abs
 #include <sstream>
 
+using namespace std;
+using namespace lyx::support;
 
 namespace lyx {
 namespace external {
 
-using support::float_equal;
-using std::string;
-
 
 string const ExtraData::get(string const & id) const
 {
-       std::map<string, string>::const_iterator it = data_.find(id);
+       map<string, string>::const_iterator it = data_.find(id);
        return it == data_.end() ? string() : it->second;
 }
 
@@ -59,7 +57,7 @@ bool ResizeData::usingScale() const
 
 bool RotationData::no_rotation() const
 {
-       return (angle.empty() || std::abs(convert<double>(angle)) < 0.1);
+       return (angle.empty() || abs(convert<double>(angle)) < 0.1);
 }
 
 
@@ -67,7 +65,7 @@ string const RotationData::adjAngle() const
 {
        // Ensure that angle lies in the range -360 < angle < 360
        double rotAngle = convert<double>(angle);
-       if (std::abs(rotAngle) > 360.0) {
+       if (abs(rotAngle) > 360.0) {
                rotAngle -= 360.0 * floor(rotAngle / 360.0);
                return convert<string>(rotAngle);
        }
@@ -100,7 +98,7 @@ string const ResizeLatexCommand::front_impl() const
        if (data.no_resize())
                return string();
 
-       std::ostringstream os;
+       ostringstream os;
        if (data.usingScale()) {
                double const scl = convert<double>(data.scale) / 100.0;
                os << "\\scalebox{" << scl << "}[" << scl << "]{";
@@ -138,7 +136,7 @@ string const ResizeLatexCommand::back_impl() const
 
 namespace {
 
-std::ostream & operator<<(std::ostream & os, RotationData::OriginType type)
+ostream & operator<<(ostream & os, RotationData::OriginType type)
 {
        switch (type) {
        case RotationData::DEFAULT:
@@ -193,7 +191,7 @@ string const RotationLatexCommand::front_impl() const
        if (data.no_rotation())
                return string();
 
-       std::ostringstream os;
+       ostringstream os;
        os << "\\rotatebox";
 
        if (data.origin() != RotationData::DEFAULT)
@@ -218,9 +216,12 @@ string const  ClipLatexOption::option_impl() const
        if (!data.clip || data.bbox.empty())
                return string();
 
-       std::ostringstream os;
+       ostringstream os;
        if (!data.bbox.empty())
-               os << "bb=" << data.bbox << ',';
+               os << "bb=" << data.bbox.xl.asLatexString() << ' '
+                  << data.bbox.yb.asLatexString() << ' '
+                  << data.bbox.xr.asLatexString() << ' '
+                  << data.bbox.yt.asLatexString() << ',';
        if (data.clip)
                os << "clip,";
        return os.str();
@@ -232,7 +233,7 @@ string const ResizeLatexOption::option_impl() const
        if (data.no_resize())
                return string();
 
-       std::ostringstream os;
+       ostringstream os;
        if (data.usingScale()) {
                double const scl = convert<double>(data.scale);
                if (!float_equal(scl, 100.0, 0.05))
@@ -256,7 +257,7 @@ string const RotationLatexOption ::option_impl() const
        if (data.no_rotation())
                return string();
 
-       std::ostringstream os;
+       ostringstream os;
        os << "angle=" << data.angle << ',';
 
        if (data.origin() != RotationData::DEFAULT)
@@ -281,11 +282,10 @@ string const sanitizeLatexOption(string const & input)
        // Strip any leading commas
        // "[,,,,foo..." -> "foo..." ("foo..." may be empty)
        string output;
-       boost::smatch what;
-       static boost::regex const front("^( *[[],*)(.*)$");
+       lyx::smatch what;
+       static lyx::regex const front("^( *\\[,*)(.*)$");
 
-       regex_match(it, end, what, front, boost::match_partial);
-       if (!what[0].matched) {
+       if (!regex_match(it, end, what, front)) {
                lyxerr << "Unable to sanitize LaTeX \"Option\": "
                       << input << '\n';
                return string();
@@ -295,10 +295,9 @@ string const sanitizeLatexOption(string const & input)
        // Replace any consecutive commas with a single one
        // "foo,,,,bar" -> "foo,bar"
        // with iterator now pointing to 'b'
-       static boost::regex const commas("([^,]*)(,,*)(.*)$");
+       static lyx::regex const commas("([^,]*)(,,*)(.*)$");
        for (; it != end;) {
-               regex_match(it, end, what, commas, boost::match_partial);
-               if (!what[0].matched) {
+               if (!regex_match(it, end, what, commas)) {
                        output += string(it, end);
                        break;
                }
@@ -308,9 +307,8 @@ string const sanitizeLatexOption(string const & input)
 
        // Strip any trailing commas
        // "...foo,,,]" -> "...foo" ("...foo,,," may be empty)
-       static boost::regex const back("^(.*[^,])?,*[]] *$");
-       regex_match(output, what, back);
-       if (!what[0].matched) {
+       static lyx::regex const back("^(.*[^,])?,*\\] *$");
+       if (!regex_match(output, what, back)) {
                lyxerr << "Unable to sanitize LaTeX \"Option\": "
                       << output << '\n';
                return string();
@@ -318,7 +316,7 @@ string const sanitizeLatexOption(string const & input)
        output = what.str(1);
 
        // Remove any surrounding whitespace
-       output = support::trim(output);
+       output = trim(output);
 
        // If the thing is empty, leave it so, else wrap it in square brackets.
        return output.empty() ? output : "[" + output + "]";
@@ -335,7 +333,7 @@ void extractIt(boost::any const & any_factory,
                return;
 
        Factory factory = boost::any_cast<Factory>(any_factory);
-       if (!factory.empty())
+       if (factory)
                transformer = factory(data);
 }