From 76c98826a216a863c689e93782aa4f102db09248 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Spitzm=C3=BCller?= Date: Sat, 12 Jan 2008 09:59:37 +0000 Subject: [PATCH] * lib/lyx2lyx/lyx_1_4.py: * lib/lyx2lyx/lyx_1_6.py: - improve reversion method for floats. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@22508 a592a061-630c-0410-9148-cb99ea01b6c8 --- lib/lyx2lyx/lyx_1_4.py | 11 +++++++---- lib/lyx2lyx/lyx_1_6.py | 41 +++++++++++++++++++++++++++-------------- 2 files changed, 34 insertions(+), 18 deletions(-) diff --git a/lib/lyx2lyx/lyx_1_4.py b/lib/lyx2lyx/lyx_1_4.py index 9952d14a8f..0e04b478cf 100644 --- a/lib/lyx2lyx/lyx_1_4.py +++ b/lib/lyx2lyx/lyx_1_4.py @@ -1832,7 +1832,13 @@ def revert_float(document): i = find_token_exact(document.body, '\\begin_inset Float', i) if i == -1: return - floatline = document.body[i] + line = document.body[i] + r = re.compile(r'\\begin_inset Float (.*)$') + m = r.match(line) + floattype = m.group(1) + if floattype != "figure" and floattype != "table": + i = i + 1 + continue j = find_end_of_inset(document.body, i) if j == -1: document.warning("Malformed lyx document: Missing '\\end_inset'.") @@ -1843,9 +1849,6 @@ def revert_float(document): if l == -1: document.warning("Malformed LyX document: Missing `\\begin_layout Standard' in Float inset.") return - floattype = "table" - if floatline == "\\begin_inset Float figure": - floattype = "figure" document.body[j] = '\\layout Standard\n\\begin_inset ERT\nstatus Collapsed\n\n' \ '\\layout Standard\n\n\n\\backslash\n' \ 'end{sideways' + floattype + '}\n\n\\end_inset\n' diff --git a/lib/lyx2lyx/lyx_1_6.py b/lib/lyx2lyx/lyx_1_6.py index cc93e90fdc..0c50b81afa 100644 --- a/lib/lyx2lyx/lyx_1_6.py +++ b/lib/lyx2lyx/lyx_1_6.py @@ -1140,12 +1140,19 @@ def revert_serbianlatin(document): def revert_rotfloat(document): - " Revert sidewaysalgorithm. " + " Revert sideways custom floats. " i = 0 while 1: - i = find_token(document.body, '\\begin_inset Float algorithm', i) + i = find_token(document.body, "\\begin_inset Float", i) if i == -1: return + line = document.body[i] + r = re.compile(r'\\begin_inset Float (.*)$') + m = r.match(line) + floattype = m.group(1) + if floattype == "figure" or floattype == "table": + i = i + 1 + continue j = find_end_of_inset(document.body, i) if j == -1: document.warning("Malformed lyx document: Missing '\\end_inset'.") @@ -1158,17 +1165,20 @@ def revert_rotfloat(document): return document.body[j] = '\\begin_layout Standard\n\\begin_inset ERT\nstatus collapsed\n\n' \ '\\begin_layout Standard\n\n\n\\backslash\n' \ - 'end{sidewaysalgorithm}\n\\end_layout\n\n\\end_inset\n' + 'end{sideways' + floattype + '}\n\\end_layout\n\n\\end_inset\n' del document.body[i+1:l-1] document.body[i] = '\\begin_inset ERT\nstatus collapsed\n\n' \ '\\begin_layout Standard\n\n\n\\backslash\n' \ - 'begin{sidewaysalgorithm}\n\\end_layout\n\n\\end_inset\n\n\\end_layout\n\n' - add_to_preamble(document, - ['% Commands inserted by lyx2lyx for sideways algorithm float', - '\\usepackage{rotfloat}\n' - '\\floatstyle{ruled}\n' - '\\newfloat{algorithm}{tbp}{loa}\n' - '\\floatname{algorithm}{Algorithm}\n']) + 'begin{sideways' + floattype + '}\n\\end_layout\n\n\\end_inset\n\n\\end_layout\n\n' + if floattype == "algorithm": + add_to_preamble(document, + ['% Commands inserted by lyx2lyx for sideways algorithm float', + '\\usepackage{rotfloat}\n' + '\\floatstyle{ruled}\n' + '\\newfloat{algorithm}{tbp}{loa}\n' + '\\floatname{algorithm}{Algorithm}\n']) + else: + document.warning("Cannot create preamble definition for custom float" + floattype + ".") i = i + 1 continue i = i + 1 @@ -1181,7 +1191,13 @@ def revert_widesideways(document): i = find_token(document.body, '\\begin_inset Float', i) if i == -1: return - floatline = document.body[i] + line = document.body[i] + r = re.compile(r'\\begin_inset Float (.*)$') + m = r.match(line) + floattype = m.group(1) + if floattype != "figure" and floattype != "table": + i = i + 1 + continue j = find_end_of_inset(document.body, i) if j == -1: document.warning("Malformed lyx document: Missing '\\end_inset'.") @@ -1193,9 +1209,6 @@ def revert_widesideways(document): if l == -1: document.warning("Malformed LyX document: Missing `\\begin_layout Standard' in Float inset.") return - floattype = "table" - if floatline == "\\begin_inset Float figure": - floattype = "figure" document.body[j] = '\\begin_layout Standard\n\\begin_inset ERT\nstatus collapsed\n\n' \ '\\begin_layout Standard\n\n\n\\backslash\n' \ 'end{sideways' + floattype + '*}\n\\end_layout\n\n\\end_inset\n'