]> git.lyx.org Git - lyx.git/blob - lib/lyx2lyx/lyxconvert_220.py
add bibtopic support (bug 870).
[lyx.git] / lib / lyx2lyx / lyxconvert_220.py
1 # This file is part of lyx2lyx
2 # -*- coding: iso-8859-1 -*-
3 # Copyright (C) 2002 Dekel Tsur <dekel@lyx.org>
4 #
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18
19
20 import sys,string,re
21 from parser_tools import *
22
23 def change_insetgraphics(lines):
24     i = 0
25     while 1:
26         i = find_token(lines, "\\begin_inset Graphics", i)
27         if i == -1:
28             break
29         j = find_end_of_inset(lines, i)
30
31         lines[i] = "\\begin_inset Graphics"
32
33         if get_value(lines, "display", i, j) == "default":
34             j = del_token(lines, "display", i, j)
35         if get_value(lines, "rotateOrigin", i, j) == "leftBaseline":
36             j = del_token(lines, "rotateOrigin", i, j)
37
38         k = find_token2(lines, "rotate", i, j)
39         if k != -1:
40             del lines[k]
41             j = j-1
42         else:
43             j = del_token(lines, "rotateAngle", i, j)
44
45         k = find_token2(lines, "size_type", i, j)
46         if k == -1:
47             k = find_token2(lines, "size_kind", i, j)
48         if k != -1:
49             size_type = string.split(lines[k])[1]
50             del lines[k]
51             j = j-1
52             if size_type in ["0", "original"]:
53                 j = del_token(lines, "width", i, j)
54                 j = del_token(lines, "height", i, j)
55                 j = del_token(lines, "scale", i, j)
56             elif size_type in ["2", "scale"]:
57                 j = del_token(lines, "width", i, j)
58                 j = del_token(lines, "height", i, j)
59                 if get_value(lines, "scale", i, j) == "100":
60                     j = del_token(lines, "scale", i, j)
61             else:
62                 j = del_token(lines, "scale", i, j)
63
64         k = find_token2(lines, "lyxsize_type", i, j)
65         if k == -1:
66             k = find_token2(lines, "lyxsize_kind", i, j)
67         if k != -1:
68             lyxsize_type = string.split(lines[k])[1]
69             del lines[k]
70             j = j-1
71             j = del_token(lines, "lyxwidth", i, j)
72             j = del_token(lines, "lyxheight", i, j)
73             if lyxsize_type not in ["2", "scale"] or \
74                get_value(lines, "lyxscale", i, j) == "100":
75                 j = del_token(lines, "lyxscale", i, j)
76
77         i = i+1
78
79 def change_tabular(lines):
80     i = 0
81     while 1:
82         i = find_token(lines, "<column", i)
83         if i == -1:
84             break
85         if not re.search('width="0pt"', lines[i]):
86             lines[i] = re.sub(' alignment=".*?"',' alignment="block"',lines[i])
87         i = i+1
88
89 def convert(header, body):
90     change_insetgraphics(body)
91     change_tabular(body)
92
93 if __name__ == "__main__":
94     pass