]> git.lyx.org Git - features.git/blob - lib/lyx2lyx/lyx_1_0_0.py
Convert all python files to utf-8.
[features.git] / lib / lyx2lyx / lyx_1_0_0.py
1 # This file is part of lyx2lyx
2 # -*- coding: utf-8 -*-
3 # Copyright (C) 2004 José Matos <jamatos@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 """ Convert files to the file format generated by lyx 1.0"""
20
21 import re
22 import string
23 from parser_tools import find_token, find_re
24
25 def obsolete_latex_title(document):
26     " Replace LatexTitle layout with Title. "
27
28     body = document.body
29     i = 0
30     while 1:
31         i = find_token(body, '\\layout', i)
32         if i == -1:
33             return
34
35         if string.find(string.lower(body[i]),'latex title') != -1:
36             body[i] = '\\layout Title'
37
38         i = i + 1
39
40
41 def update_tabular(document):
42     " Update from tabular format 3 to 4 if necessary."
43
44     lines = document.body
45     lyxtable_re = re.compile(r".*\\LyXTable$")
46     i = 0
47     while 1:
48         i = find_re(lines, lyxtable_re, i)
49         if i == -1:
50             break
51         i = i + 1
52         format = lines[i][8:]
53
54         if format != '3':
55             continue
56
57         lines[i] = 'multicol4'
58         i = i + 1
59         rows = int(string.split(lines[i])[0])
60         columns = int(string.split(lines[i])[1])
61
62         lines[i] = lines[i] + ' 0 0 -1 -1 -1 -1'
63         i = i + 1
64
65         for j in range(rows):
66             lines[i] = lines[i] + ' 0 0'
67             i = i + 1
68
69         for j in range(columns):
70             lines[i] = lines[i] + ' '
71             i = i + 1
72
73         while string.strip(lines[i]):
74             lines[i] = lines[i] + ' 0 0 0'
75             i = i + 1
76
77         lines[i] = string.strip(lines[i])
78
79
80 supported_versions = ["1.0.0","1.0"]
81 convert = [[215, [obsolete_latex_title, update_tabular]]]
82 revert  = []
83
84
85 if __name__ == "__main__":
86     pass
87