]> git.lyx.org Git - lyx.git/blob - lib/lyx2lyx/lyxconvert_218.py
Create .cvsignore
[lyx.git] / lib / lyx2lyx / lyxconvert_218.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
20 from parser_tools import *
21
22 floats = {
23     "footnote": ["\\begin_inset Foot\n",
24                  "collapsed true\n"],
25     "margin":   ["\\begin_inset Marginal\n",
26                  "collapsed true\n"],
27     "fig":      ["\\begin_inset Float figure\n",
28                  "placement htbp\n",
29                  "wide false\n",
30                  "collapsed false\n"],
31     "tab":      ["\\begin_inset Float table\n",
32                  "placement htbp\n",
33                  "wide false\n",
34                  "collapsed false\n"],
35     "alg":      ["\\begin_inset Float algorithm\n",
36                  "placement htbp\n",
37                  "wide false\n",
38                  "collapsed false\n"],
39     "wide-fig": ["\\begin_inset Float figure\n",
40                  "placement htbp\n",
41                  "wide true\n",
42                  "collapsed false\n"],
43     "wide-tab": ["\\begin_inset Float table\n",
44                  "placement htbp\n",
45                  "wide true\n",
46                  "collapsed false\n"]
47 }
48
49 def remove_oldfloat(lines):
50     i = 0
51     while 1:
52         i = find_token(lines, "\\begin_float", i)
53         if i == -1:
54             break
55         j = find_token(lines, "\\end_float", i+1)
56         floattype = string.split(lines[i])[1]
57         #print floattype
58         start = floats[floattype]+["\n"]
59         mid = lines[i+1:j]
60         lines[i:j+1]= start+mid+["\\end_inset \n"]
61         i = i+1
62
63 def remove_oldminipage(lines):
64     i = 0
65     flag = 0
66     while 1:
67         i = find_token(lines, "\\pextra_type 2", i)
68         if i == -1:
69             break
70         hfill = 0
71         line = string.split(lines[i])
72         if line[4] == "\\pextra_hfill":
73             line[4:6] = []
74             hfill = 1
75         if line[4] == "\\pextra_start_minipage":
76             line[4:6] = []
77         width = line[5]
78         if line[4] == "\\pextra_widthp":
79             width = line[5]+"col%"
80
81         start = ["\\begin_inset Minipage\n",
82                  "position %s\n" % line[3],
83                  "inner_position 0\n",
84                  'height "0pt"\n',
85                  'width "%s"\n' % width,
86                  "collapsed false\n"
87                  ]
88         if flag:
89             flag = 0
90             if hfill:
91                 start = ["\n","\hfill\n","\n"]+start
92         else:
93             start = ["\\layout Standard\n"] + start
94
95         j = find_token_backwards(lines,"\\layout", i-1)
96         j0 = j
97         mid = lines[j:i]
98
99         j = find_token2(lines,"\\layout", "\\end_float", i+1)
100         mid = mid+lines[i+1:j]
101
102         while 1:
103             i = find_token2(lines,"\\layout", "\\pextra_type", j+1)
104             if i == -1 or not check_token(lines,  "\\pextra_type", i):
105                 break
106             line = string.split(lines[i])
107             if line[4] == "\\pextra_hfill":
108                 line[4:6] = []
109             if line[4] == "\\pextra_start_minipage" and line[5] == "1":
110                 flag = 1
111                 break
112             j = find_token_backwards(lines,"\\layout", i-1)
113             mid = mid+lines[j:i]
114             j = find_token2(lines,"\\layout", "\\end_float", i+1)
115             mid = mid+lines[i+1:j]
116
117         end = ["\\end_inset \n"]
118
119         lines[j0:j] = start+mid+end
120         i = i+1
121
122 def convert(header,body):
123     remove_oldminipage(body)
124     remove_oldfloat(body)
125
126 if __name__ == "__main__":
127     pass
128