]> git.lyx.org Git - lyx.git/blob - lib/lyx2lyx/lyxconvert_220.py
lyxconvert_220 module for Rob's patch
[lyx.git] / lib / lyx2lyx / lyxconvert_220.py
1 # This file is part of lyx2lyx
2 # Copyright (C) 2002 Dekel Tsur <dekel@lyx.org>
3 #
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.
8 #
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.
13 #
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.
17
18
19 import sys,string,re
20 from parser_tools import *
21
22 def change_insetgraphics(lines):
23     i = 0
24     while 1:
25         i = find_token(lines, "\\begin_inset Graphics", i)
26         if i == -1:
27             break
28         j = find_end_of_inset(lines, i)
29
30         if get_value(lines, "display", i, j) == "default":
31             j = del_token(lines, "display", i, j)
32         if get_value(lines, "rotateOrigin", i, j) == "leftBaseline":
33             j = del_token(lines, "rotateOrigin", i, j)
34
35         k = find_token2(lines, "rotate", i, j)
36         if k != -1:
37             del lines[k]
38             j = j-1
39         else:
40             j = del_token(lines, "rotateAngle", i, j)
41
42         k = find_token2(lines, "size_type", i, j)
43         if k == -1:
44             k = find_token2(lines, "size_kind", i, j)
45         size_type = string.split(lines[k])[1]
46         del lines[k]
47         j = j-1
48         if size_type in ["0", "original"]:
49             j = del_token(lines, "width", i, j)
50             j = del_token(lines, "height", i, j)
51             j = del_token(lines, "scale", i, j)
52         elif size_type in ["2", "scale"]:
53             j = del_token(lines, "width", i, j)
54             j = del_token(lines, "height", i, j)
55             if get_value(lines, "scale", i, j) == "100":
56                 j = del_token(lines, "scale", i, j)
57         else:
58             j = del_token(lines, "scale", i, j)
59
60         k = find_token2(lines, "lyxsize_type", i, j)
61         if k == -1:
62             k = find_token2(lines, "lyxsize_kind", i, j)
63         lyxsize_type = string.split(lines[k])[1]
64         del lines[k]
65         j = j-1
66         j = del_token(lines, "lyxwidth", i, j)
67         j = del_token(lines, "lyxheight", i, j)
68         if lyxsize_type not in ["2", "scale"] or \
69            get_value(lines, "lyxscale", i, j) == "100":
70             j = del_token(lines, "lyxscale", i, j)
71         
72         i = i+1
73
74
75 def convert(header, body):
76     change_insetgraphics(body)
77
78 if __name__ == "__main__":
79     pass