From 04233bf5eb7a99dfb821d9bba683f4d3a7f0be49 Mon Sep 17 00:00:00 2001 From: Georg Baum Date: Sun, 12 Dec 2010 17:47:36 +0000 Subject: [PATCH] Increase tex2lyx output format to 275. Nothing to do for 274: tex2lyx did not implement the special whitespace handling that would have been needed for the old format. Use the scaleBeforeRotation keyword for graphics (275). This fixes actually a bug with the old version, that implicitly converted all graphics to scale before rotation. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@36843 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/tex2lyx/tex2lyx.h | 2 +- src/tex2lyx/text.cpp | 33 ++++++++++++++++++++++++--------- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/tex2lyx/tex2lyx.h b/src/tex2lyx/tex2lyx.h index b51dd68f32..8dfc16f228 100644 --- a/src/tex2lyx/tex2lyx.h +++ b/src/tex2lyx/tex2lyx.h @@ -114,7 +114,7 @@ extern CommandMap known_math_environments; /// extern bool noweb_mode; /// LyX format that is created by tex2lyx -int const LYX_FORMAT = 273; +int const LYX_FORMAT = 275; /// path of the master .tex file extern std::string getMasterFilePath(); diff --git a/src/tex2lyx/text.cpp b/src/tex2lyx/text.cpp index 1fb49af13d..9784a3ab07 100644 --- a/src/tex2lyx/text.cpp +++ b/src/tex2lyx/text.cpp @@ -199,19 +199,20 @@ char const * const known_coded_spaces[] = { "space{}", "space{}", "negthinspace{}", 0}; -/// splits "x=z, y=b" into a map -map split_map(string const & s) +/// splits "x=z, y=b" into a map and an ordered keyword vector +void split_map(string const & s, map & res, vector & keys) { - map res; vector v; split(s, v); + res.clear(); + keys.resize(v.size()); for (size_t i = 0; i < v.size(); ++i) { size_t const pos = v[i].find('='); - string const index = v[i].substr(0, pos); - string const value = v[i].substr(pos + 1, string::npos); - res[trim(index)] = trim(value); + string const index = trim(v[i].substr(0, pos)); + string const value = trim(v[i].substr(pos + 1, string::npos)); + res[index] = value; + keys[i] = index; } - return res; } @@ -1655,7 +1656,10 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, bool const clip = p.next_token().asInput() == "*"; if (clip) p.get_token(); - map opts = split_map(p.getArg('[', ']')); + string const arg = p.getArg('[', ']'); + map opts; + vector keys; + split_map(arg, opts, keys); if (clip) opts["clip"] = string(); string name = normalize_filename(p.verbatim_item()); @@ -1715,9 +1719,20 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, val = val*100; os << "\tscale " << val << '\n'; } - if (opts.find("angle") != opts.end()) + if (opts.find("angle") != opts.end()) { os << "\trotateAngle " << opts["angle"] << '\n'; + vector::const_iterator a = + find(keys.begin(), keys.end(), "angle"); + vector::const_iterator s = + find(keys.begin(), keys.end(), "width"); + if (s == keys.end()) + s = find(keys.begin(), keys.end(), "height"); + if (s == keys.end()) + s = find(keys.begin(), keys.end(), "scale"); + if (s != keys.end() && distance(s, a) > 0) + os << "\tscaleBeforeRotation\n"; + } if (opts.find("origin") != opts.end()) { ostringstream ss; string const opt = opts["origin"];