1 # This file is part of lyx2lyx
2 # Copyright (C) 2003 José Matos <jamatos@fep.up.pt>
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.
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.
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.
21 from parser_tools import find_token
24 def convert_minipage(lines):
25 """ Convert minipages to the box inset.
26 We try to use the same order of arguments as lyx does.
29 inner_pos = ["c","t","b","s"]
33 i = find_token(lines, "\\begin_inset Minipage", i)
37 lines[i] = "\\begin_inset Box Frameless"
40 # convert old to new position using the pos list
41 if lines[i][:8] == "position":
42 lines[i] = 'position "%s"' % pos[int(lines[i][9])]
44 lines.insert(i, 'position "%s"' % pos[0])
47 lines.insert(i, 'hor_pos "c"')
49 lines.insert(i, 'has_inner_box 1')
52 # convert the inner_position
53 if lines[i][:14] == "inner_position":
54 lines[i] = 'inner_pos "%s"' % inner_pos[int(lines[i][15])]
56 lines.insert('inner_pos "%s"' % inner_pos[0])
59 # We need this since the new file format has a height and width
60 # in a different order.
61 if lines[i][:6] == "height":
63 # test for default value of 221 and convert it accordingly
64 if height == ' "0pt"':
70 if lines[i][:5] == "width":
76 if lines[i][:9] == "collapsed":
77 if lines[i][9:] == "true":
85 lines.insert(i, 'use_parbox 0')
87 lines.insert(i, 'width' + width)
89 lines.insert(i, 'special "none"')
91 lines.insert(i, 'height' + height)
93 lines.insert(i, 'height_special "totalheight"')
95 lines.insert(i, 'status ' + status)
98 def convert(header, body):
99 convert_minipage(body)
101 if __name__ == "__main__":