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