1 # This file is part of lyx2lyx
2 # Copyright (C) 2002 Dekel Tsur <dekel@lyx.org>
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 from parser_tools import *
22 def change_insetgraphics(lines):
25 i = find_token(lines, "\\begin_inset Graphics", i)
28 j = find_end_of_inset(lines, i)
30 lines[i] = "\\begin_inset Graphics"
32 if get_value(lines, "display", i, j) == "default":
33 j = del_token(lines, "display", i, j)
34 if get_value(lines, "rotateOrigin", i, j) == "leftBaseline":
35 j = del_token(lines, "rotateOrigin", i, j)
37 k = find_token2(lines, "rotate", i, j)
42 j = del_token(lines, "rotateAngle", i, j)
44 k = find_token2(lines, "size_type", i, j)
46 k = find_token2(lines, "size_kind", i, j)
48 size_type = string.split(lines[k])[1]
51 if size_type in ["0", "original"]:
52 j = del_token(lines, "width", i, j)
53 j = del_token(lines, "height", i, j)
54 j = del_token(lines, "scale", i, j)
55 elif size_type in ["2", "scale"]:
56 j = del_token(lines, "width", i, j)
57 j = del_token(lines, "height", i, j)
58 if get_value(lines, "scale", i, j) == "100":
59 j = del_token(lines, "scale", i, j)
61 j = del_token(lines, "scale", i, j)
63 k = find_token2(lines, "lyxsize_type", i, j)
65 k = find_token2(lines, "lyxsize_kind", i, j)
67 lyxsize_type = string.split(lines[k])[1]
70 j = del_token(lines, "lyxwidth", i, j)
71 j = del_token(lines, "lyxheight", i, j)
72 if lyxsize_type not in ["2", "scale"] or \
73 get_value(lines, "lyxscale", i, j) == "100":
74 j = del_token(lines, "lyxscale", i, j)
78 def change_tabular(lines):
81 i = find_token(lines, "<column", i)
84 if not re.search('width="0pt"', lines[i]):
85 lines[i] = re.sub(' alignment=".*?"',' alignment="block"',lines[i])
88 def convert(header, body):
89 change_insetgraphics(body)
92 if __name__ == "__main__":