X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2FExternalTransforms.C;h=16d6406881abb38747c5288a0c96f52a121e1794;hb=e28331ed63062dea10d0a21b9ec12034b4b17b9a;hp=05b66b7b05b5345700171e21df4433f43b7a6bd4;hpb=bc045d9320859d700c50c9cd4498d147c60cfc30;p=lyx.git diff --git a/src/insets/ExternalTransforms.C b/src/insets/ExternalTransforms.C index 05b66b7b05..16d6406881 100644 --- a/src/insets/ExternalTransforms.C +++ b/src/insets/ExternalTransforms.C @@ -16,20 +16,22 @@ #include "support/lstrings.h" #include "support/lyxlib.h" // float_equal +#include "support/convert.h" #include "support/translator.h" #include -#include "support/std_sstream.h" -#include // std::abs - -using lyx::support::float_equal; -using std::string; +#include // std::abs +#include namespace lyx { namespace external { +using support::float_equal; +using std::string; + + string const ExtraData::get(string const & id) const { std::map::const_iterator it = data_.find(id); @@ -51,21 +53,25 @@ bool ResizeData::no_resize() const bool ResizeData::usingScale() const { - return !float_equal(scale, 0.0, 0.05); + return (!scale.empty() && !float_equal(convert(scale), 0.0, 0.05)); } bool RotationData::no_rotation() const { - return (std::abs(angle()) < 0.1); + return (angle.empty() || std::abs(convert(angle)) < 0.1); } -void RotationData::angle(double a) +string const RotationData::adjAngle() const { - // Ensure that angle_ lies in the range -360 < angle_ < 360. - int const multiples = int(a) / 360; - angle_ = a - (multiples * 360); + // Ensure that angle lies in the range -360 < angle < 360 + double rotAngle = convert(angle); + if (std::abs(rotAngle) > 360.0) { + rotAngle -= 360.0 * floor(rotAngle / 360.0); + return convert(rotAngle); + } + return angle; } @@ -94,10 +100,10 @@ string const ResizeLatexCommand::front_impl() const if (data.no_resize()) return string(); - std::ostringstream os; + std::ostringstream os; if (data.usingScale()) { - double const scl = data.scale / 100.0; - os << "\\scalebox{" << scl << "}{" << scl << "}{"; + double const scl = convert(data.scale) / 100.0; + os << "\\scalebox{" << scl << "}[" << scl << "]{"; } else { string width = "!"; string height = "!"; @@ -112,7 +118,7 @@ string const ResizeLatexCommand::front_impl() const if (!data.height.zero()) height = data.height.asLatexString(); } - + os << "\\resizebox{" << width << "}{" << height << "}{"; @@ -187,14 +193,14 @@ string const RotationLatexCommand::front_impl() const if (data.no_rotation()) return string(); - std::ostringstream os; - os << "\\rotatebox"; + std::ostringstream os; + os << "\\rotatebox"; if (data.origin() != RotationData::DEFAULT) os << "[origin=" << data.origin() << ']'; - os << '{' << data.angle() << "}{"; - return os.str(); + os << '{' << data.angle << "}{"; + return os.str(); } @@ -226,10 +232,11 @@ string const ResizeLatexOption::option_impl() const if (data.no_resize()) return string(); - std::ostringstream os; + std::ostringstream os; if (data.usingScale()) { - if (!float_equal(data.scale, 100.0, 0.05)) - os << "scale=" << data.scale / 100.0 << ','; + double const scl = convert(data.scale); + if (!float_equal(scl, 100.0, 0.05)) + os << "scale=" << scl / 100.0 << ','; return os.str(); } @@ -250,7 +257,7 @@ string const RotationLatexOption ::option_impl() const return string(); std::ostringstream os; - os << "angle=" << data.angle() << ','; + os << "angle=" << data.angle << ','; if (data.origin() != RotationData::DEFAULT) os << "origin=" << data.origin() << ','; @@ -272,7 +279,7 @@ string const sanitizeLatexOption(string const & input) string::const_iterator it = begin; // Strip any leading commas - // "[,,,,foo..." -> "foo..." + // "[,,,,foo..." -> "foo..." ("foo..." may be empty) string output; boost::smatch what; static boost::regex const front("^( *[[],*)(.*)$"); @@ -280,7 +287,7 @@ string const sanitizeLatexOption(string const & input) regex_match(it, end, what, front, boost::match_partial); if (!what[0].matched) { lyxerr << "Unable to sanitize LaTeX \"Option\": " - << output << '\n'; + << input << '\n'; return string(); } it = what[1].second; @@ -300,8 +307,8 @@ string const sanitizeLatexOption(string const & input) } // Strip any trailing commas - // "...foo,,,]" -> "...foo" - static boost::regex const back("^(.*[^,])(,*[]] *)$"); + // "...foo,,,]" -> "...foo" ("...foo,,," may be empty) + static boost::regex const back("^(.*[^,])?,*[]] *$"); regex_match(output, what, back); if (!what[0].matched) { lyxerr << "Unable to sanitize LaTeX \"Option\": " @@ -311,19 +318,13 @@ string const sanitizeLatexOption(string const & input) output = what.str(1); // Remove any surrounding whitespace - output = lyx::support::trim(output); + output = support::trim(output); // If the thing is empty, leave it so, else wrap it in square brackets. return output.empty() ? output : "[" + output + "]"; } -string const sanitizeLinuxDocOption(string const & input) -{ - return input; -} - - namespace { template