#include "support/lstrings.h"
#include "support/lyxlib.h" // float_equal
+#include "support/convert.h"
#include "support/translator.h"
#include <boost/regex.hpp>
#include <cmath> // std::abs
#include <sstream>
-using lyx::support::float_equal;
-
-using std::string;
-
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);
bool ResizeData::usingScale() const
{
- return !float_equal(scale, 0.0, 0.05);
+ return (!scale.empty() && !float_equal(convert<double>(scale), 0.0, 0.05));
}
bool RotationData::no_rotation() const
{
- return (std::abs(angle()) < 0.1);
+ return (angle.empty() || std::abs(convert<double>(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<double>(angle);
+ if (std::abs(rotAngle) > 360.0) {
+ rotAngle -= 360.0 * floor(rotAngle / 360.0);
+ return convert<string>(rotAngle);
+ }
+ return angle;
}
std::ostringstream os;
if (data.usingScale()) {
- double const scl = data.scale / 100.0;
- os << "\\scalebox{" << scl << "}{" << scl << "}{";
+ double const scl = convert<double>(data.scale) / 100.0;
+ os << "\\scalebox{" << scl << "}[" << scl << "]{";
} else {
string width = "!";
string height = "!";
if (data.origin() != RotationData::DEFAULT)
os << "[origin=" << data.origin() << ']';
- os << '{' << data.angle() << "}{";
+ os << '{' << data.angle << "}{";
return os.str();
}
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<double>(data.scale);
+ if (!float_equal(scl, 100.0, 0.05))
+ os << "scale=" << scl / 100.0 << ',';
return os.str();
}
return string();
std::ostringstream os;
- os << "angle=" << data.angle() << ',';
+ os << "angle=" << data.angle << ',';
if (data.origin() != RotationData::DEFAULT)
os << "origin=" << data.origin() << ',';
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("^( *[[],*)(.*)$");
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;
}
// 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\": "
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 <typename Factory, typename Data, typename Transformer>