From f2d6c172d44f071c4859d99f46d0f8ecd1b30553 Mon Sep 17 00:00:00 2001 From: Dekel Tsur Date: Sat, 24 Aug 2002 12:13:44 +0000 Subject: [PATCH] lyxconvert_220 module for Rob's patch git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@5089 a592a061-630c-0410-9148-cb99ea01b6c8 --- lib/lyx2lyx/lyxconvert_220.py | 79 +++++++++++++++++++++++++++++++++++ lib/lyx2lyx/parser_tools.py | 21 +++++++++- 2 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 lib/lyx2lyx/lyxconvert_220.py diff --git a/lib/lyx2lyx/lyxconvert_220.py b/lib/lyx2lyx/lyxconvert_220.py new file mode 100644 index 0000000000..e3089711e5 --- /dev/null +++ b/lib/lyx2lyx/lyxconvert_220.py @@ -0,0 +1,79 @@ +# This file is part of lyx2lyx +# Copyright (C) 2002 Dekel Tsur +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + +import sys,string,re +from parser_tools import * + +def change_insetgraphics(lines): + i = 0 + while 1: + i = find_token(lines, "\\begin_inset Graphics", i) + if i == -1: + break + j = find_end_of_inset(lines, i) + + if get_value(lines, "display", i, j) == "default": + j = del_token(lines, "display", i, j) + if get_value(lines, "rotateOrigin", i, j) == "leftBaseline": + j = del_token(lines, "rotateOrigin", i, j) + + k = find_token2(lines, "rotate", i, j) + if k != -1: + del lines[k] + j = j-1 + else: + j = del_token(lines, "rotateAngle", i, j) + + k = find_token2(lines, "size_type", i, j) + if k == -1: + k = find_token2(lines, "size_kind", i, j) + size_type = string.split(lines[k])[1] + del lines[k] + j = j-1 + if size_type in ["0", "original"]: + j = del_token(lines, "width", i, j) + j = del_token(lines, "height", i, j) + j = del_token(lines, "scale", i, j) + elif size_type in ["2", "scale"]: + j = del_token(lines, "width", i, j) + j = del_token(lines, "height", i, j) + if get_value(lines, "scale", i, j) == "100": + j = del_token(lines, "scale", i, j) + else: + j = del_token(lines, "scale", i, j) + + k = find_token2(lines, "lyxsize_type", i, j) + if k == -1: + k = find_token2(lines, "lyxsize_kind", i, j) + lyxsize_type = string.split(lines[k])[1] + del lines[k] + j = j-1 + j = del_token(lines, "lyxwidth", i, j) + j = del_token(lines, "lyxheight", i, j) + if lyxsize_type not in ["2", "scale"] or \ + get_value(lines, "lyxscale", i, j) == "100": + j = del_token(lines, "lyxscale", i, j) + + i = i+1 + + +def convert(header, body): + change_insetgraphics(body) + +if __name__ == "__main__": + pass diff --git a/lib/lyx2lyx/parser_tools.py b/lib/lyx2lyx/parser_tools.py index 850bc95acb..8d9c45e35c 100644 --- a/lib/lyx2lyx/parser_tools.py +++ b/lib/lyx2lyx/parser_tools.py @@ -33,6 +33,15 @@ def find_token(lines, token, start, end = 0): return i return -1 +def find_token2(lines, token, start, end = 0): + if end == 0: + end = len(lines) + for i in xrange(start, end): + x = string.split(lines[i]) + if len(x) > 0 and x[0] == token: + return i + return -1 + def find_tokens(lines, tokens, start, end = 0): if end == 0: end = len(lines) @@ -68,11 +77,19 @@ def find_tokens_backwards(lines, tokens, start): return -1 def get_value(lines, token, start, end = 0): - i = find_token(lines, token, start, end) + i = find_token2(lines, token, start, end) if i == -1: return "" return string.split(lines[i])[1] +def del_token(lines, token, i, j): + k = find_token2(lines, token, i, j) + if k == -1: + return j + else: + del lines[k] + return j-1 + # Finds the paragraph that contains line i. def get_paragraph(lines, i): while 1: @@ -132,7 +149,7 @@ def set_comment(lines, number): elif x < 220: version = "1.1" else: - version = "1.2" + version = str((x-220)/10.0+1.2) lines[0] = "#LyX %s created this file. For more info see http://www.lyx.org/" % version if lines[1][0] == '#':