1 # This file is part of lyx2lyx
2 # -*- coding: iso-8859-1 -*-
3 # Copyright (C) 2002 Dekel Tsur <dekel@lyx.org>
4 # Copyright (C) 2004 José Matos <jamatos@lyx.org>
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 from parser_tools import find_token, find_end_of_inset, get_value,\
23 find_token2, del_token
25 def change_insetgraphics(lines):
28 i = find_token(lines, "\\begin_inset Graphics", i)
31 j = find_end_of_inset(lines, i)
33 lines[i] = "\\begin_inset Graphics"
35 if get_value(lines, "display", i, j) == "default":
36 j = del_token(lines, "display", i, j)
37 if get_value(lines, "rotateOrigin", i, j) == "leftBaseline":
38 j = del_token(lines, "rotateOrigin", i, j)
40 k = find_token2(lines, "rotate", i, j)
45 j = del_token(lines, "rotateAngle", i, j)
47 k = find_token2(lines, "size_type", i, j)
49 k = find_token2(lines, "size_kind", i, j)
51 size_type = string.split(lines[k])[1]
54 if size_type in ["0", "original"]:
55 j = del_token(lines, "width", i, j)
56 j = del_token(lines, "height", i, j)
57 j = del_token(lines, "scale", i, j)
58 elif size_type in ["2", "scale"]:
59 j = del_token(lines, "width", i, j)
60 j = del_token(lines, "height", i, j)
61 if get_value(lines, "scale", i, j) == "100":
62 j = del_token(lines, "scale", i, j)
64 j = del_token(lines, "scale", i, j)
66 k = find_token2(lines, "lyxsize_type", i, j)
68 k = find_token2(lines, "lyxsize_kind", i, j)
70 lyxsize_type = string.split(lines[k])[1]
73 j = del_token(lines, "lyxwidth", i, j)
74 j = del_token(lines, "lyxheight", i, j)
75 if lyxsize_type not in ["2", "scale"] or \
76 get_value(lines, "lyxscale", i, j) == "100":
77 j = del_token(lines, "lyxscale", i, j)
82 def change_tabular(lines):
85 i = find_token(lines, "<column", i)
88 if not re.search('width="0pt"', lines[i]):
89 lines[i] = re.sub(' alignment=".*?"',' alignment="block"',lines[i])
93 def convert(header, body, opt):
94 change_insetgraphics(body)
99 def revert(header, body, opt):
100 opt.error("The convertion to an older format (%s) is not implemented." % opt.format)
103 if __name__ == "__main__":