]> git.lyx.org Git - features.git/blobdiff - src/insets/ExternalTransforms.C
change "support/std_sstream.h" to <sstream>
[features.git] / src / insets / ExternalTransforms.C
index 79f2d16ebb5fda80d627d8f9327159eb805b3ffd..806943dbfb0611d2921dfefb216c8b367c6d6281 100644 (file)
@@ -19,8 +19,9 @@
 #include "support/translator.h"
 
 #include <boost/regex.hpp>
-#include "support/std_sstream.h"
+
 #include <cmath> // std::abs
+#include <sstream>
 
 using lyx::support::float_equal;
 
@@ -45,8 +46,13 @@ void ExtraData::set(string const & id, string const & data)
 
 bool ResizeData::no_resize() const
 {
-       return float_equal(scale, 0.0, 0.05) &&
-               width.zero() && height.zero();
+       return !usingScale() && width.zero() && height.zero();
+}
+
+
+bool ResizeData::usingScale() const
+{
+       return !float_equal(scale, 0.0, 0.05);
 }
 
 
@@ -90,15 +96,27 @@ string const ResizeLatexCommand::front_impl() const
                return string();
 
         std::ostringstream os;
-       if (!float_equal(data.scale, 0.0, 0.05)) {
+       if (data.usingScale()) {
                double const scl = data.scale / 100.0;
                os << "\\scalebox{" << scl << "}{" << scl << "}{";
        } else {
+               string width  = "!";
+               string height = "!";
+               if (data.keepAspectRatio) {
+                       if (data.width.inPixels(10) > data.height.inPixels(10))
+                               width = data.width.asLatexString();
+                       else
+                               height = data.height.asLatexString();
+               } else {
+                       if (!data.width.zero())
+                               width = data.width.asLatexString();
+                       if (!data.height.zero())
+                               height = data.height.asLatexString();
+               }
+
                os << "\\resizebox{"
-                  << (data.width.zero()  ?
-                      "!" : data.width.asLatexString()) << "}{"
-                  << (data.height.zero() ?
-                      "!" : data.height.asLatexString()) << "}{";
+                  << width << "}{"
+                  << height << "}{";
        }
        return os.str();
 }
@@ -210,7 +228,7 @@ string const ResizeLatexOption::option_impl() const
                return string();
 
         std::ostringstream os;
-       if (!float_equal(data.scale, 0.0, 0.05)) {
+       if (data.usingScale()) {
                if (!float_equal(data.scale, 100.0, 0.05))
                        os << "scale=" << data.scale / 100.0 << ',';
                return os.str();
@@ -258,7 +276,7 @@ string const sanitizeLatexOption(string const & input)
        // "[,,,,foo..." -> "foo..."
        string output;
        boost::smatch what;
-       boost::regex const front("^( *[[],*)(.*)$");
+       static boost::regex const front("^( *[[],*)(.*)$");
 
        regex_match(it, end, what, front, boost::match_partial);
        if (!what[0].matched) {
@@ -271,7 +289,7 @@ string const sanitizeLatexOption(string const & input)
        // Replace any consecutive commas with a single one
        // "foo,,,,bar" -> "foo,bar"
        // with iterator now pointing to 'b'
-       boost::regex const commas("([^,]*)(,,*)(.*)$");
+       static boost::regex const commas("([^,]*)(,,*)(.*)$");
        for (; it != end;) {
                regex_match(it, end, what, commas, boost::match_partial);
                if (!what[0].matched) {
@@ -284,7 +302,7 @@ string const sanitizeLatexOption(string const & input)
 
        // Strip any trailing commas
        // "...foo,,,]" -> "...foo"
-       boost::regex const back("^(.*[^,])(,*[]] *)$");
+       static boost::regex const back("^(.*[^,])(,*[]] *)$");
        regex_match(output, what, back);
        if (!what[0].matched) {
                lyxerr << "Unable to sanitize LaTeX \"Option\": "