]> git.lyx.org Git - lyx.git/blob - lib/lyx2lyx/lyx_1_3.py
0439f72ded59ca4604fc1d1f78a7acc73bf57a24
[lyx.git] / lib / lyx2lyx / lyx_1_3.py
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>
5 #
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.
10 #
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.
15 #
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.
19
20 import string
21 import re
22 from parser_tools import find_token, find_end_of, get_value,\
23                          find_token_exact, del_token
24
25 ####################################################################
26 # Private helper functions
27
28 def find_end_of_inset(lines, i):
29     "Finds the matching \end_inset"
30     return find_end_of(lines, i, "\\begin_inset", "\\end_inset")
31
32 # End of helper functions
33 ####################################################################
34
35
36 def change_insetgraphics(file):
37     lines = file.body
38     i = 0
39     while 1:
40         i = find_token(lines, "\\begin_inset Graphics", i)
41         if i == -1:
42             break
43         j = find_end_of_inset(lines, i)
44
45         lines[i] = "\\begin_inset Graphics"
46
47         if get_value(lines, "display", i, j) == "default":
48             j = del_token(lines, "display", i, j)
49         if get_value(lines, "rotateOrigin", i, j) == "leftBaseline":
50             j = del_token(lines, "rotateOrigin", i, j)
51
52         k = find_token_exact(lines, "rotate", i, j)
53         if k != -1:
54             del lines[k]
55             j = j-1
56         else:
57             j = del_token(lines, "rotateAngle", i, j)
58
59         k = find_token_exact(lines, "size_type", i, j)
60         if k == -1:
61             k = find_token_exact(lines, "size_kind", i, j)
62         if k != -1:
63             size_type = string.split(lines[k])[1]
64             del lines[k]
65             j = j-1
66             if size_type in ["0", "original"]:
67                 j = del_token(lines, "width", i, j)
68                 j = del_token(lines, "height", i, j)
69                 j = del_token(lines, "scale", i, j)
70             elif size_type in ["2", "scale"]:
71                 j = del_token(lines, "width", i, j)
72                 j = del_token(lines, "height", i, j)
73                 if get_value(lines, "scale", i, j) == "100":
74                     j = del_token(lines, "scale", i, j)
75             else:
76                 j = del_token(lines, "scale", i, j)
77
78         k = find_token_exact(lines, "lyxsize_type", i, j)
79         if k == -1:
80             k = find_token_exact(lines, "lyxsize_kind", i, j)
81         if k != -1:
82             lyxsize_type = string.split(lines[k])[1]
83             del lines[k]
84             j = j-1
85             j = del_token(lines, "lyxwidth", i, j)
86             j = del_token(lines, "lyxheight", i, j)
87             if lyxsize_type not in ["2", "scale"] or \
88                get_value(lines, "lyxscale", i, j) == "100":
89                 j = del_token(lines, "lyxscale", i, j)
90
91         i = i+1
92
93
94 def change_tabular(file):
95     lines = file.body
96     i = 0
97     while 1:
98         i = find_token(lines, "<column", i)
99         if i == -1:
100             break
101         if not re.search('width="0pt"', lines[i]):
102             lines[i] = re.sub(' alignment=".*?"',' alignment="block"',lines[i])
103         i = i+1
104
105
106 convert = [[221, [change_insetgraphics, change_tabular]]]
107 revert  = []
108
109
110 if __name__ == "__main__":
111     pass