]> git.lyx.org Git - lyx.git/blob - lib/lyx2lyx/lyxconvert_220.py
Test for the presence of rpmbuild.
[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         lines[i] = "\\begin_inset Graphics"
31
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)
36
37         k = find_token2(lines, "rotate", i, j)
38         if k != -1:
39             del lines[k]
40             j = j-1
41         else:
42             j = del_token(lines, "rotateAngle", i, j)
43
44         k = find_token2(lines, "size_type", i, j)
45         if k == -1:
46             k = find_token2(lines, "size_kind", i, j)
47         if k != -1:
48             size_type = string.split(lines[k])[1]
49             del lines[k]
50             j = j-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)
60             else:
61                 j = del_token(lines, "scale", i, j)
62
63         k = find_token2(lines, "lyxsize_type", i, j)
64         if k == -1:
65             k = find_token2(lines, "lyxsize_kind", i, j)
66         if k != -1:
67             lyxsize_type = string.split(lines[k])[1]
68             del lines[k]
69             j = j-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)
75         
76         i = i+1
77
78 def change_tabular(lines):
79     i = 0
80     while 1:
81         i = find_token(lines, "<column", i)
82         if i == -1:
83             break
84         if not re.search('width="0pt"', lines[i]):
85             lines[i] = re.sub(' alignment=".*?"',' alignment="block"',lines[i])
86         i = i+1
87
88 def convert(header, body):
89     change_insetgraphics(body)
90     change_tabular(body)
91
92 if __name__ == "__main__":
93     pass