1 # This file is part of lyx2lyx
2 # -*- coding: iso-8859-1 -*-
3 # Copyright (C) 2003 José Matos <jamatos@fep.up.pt>
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.
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.
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.
22 from parser_tools import find_token
25 def convert_minipage(lines):
26 """ Convert minipages to the box inset.
27 We try to use the same order of arguments as lyx does.
30 inner_pos = ["c","t","b","s"]
34 i = find_token(lines, "\\begin_inset Minipage", i)
38 lines[i] = "\\begin_inset Box Frameless"
41 # convert old to new position using the pos list
42 if lines[i][:8] == "position":
43 lines[i] = 'position "%s"' % pos[int(lines[i][9])]
45 lines.insert(i, 'position "%s"' % pos[0])
48 lines.insert(i, 'hor_pos "c"')
50 lines.insert(i, 'has_inner_box 1')
53 # convert the inner_position
54 if lines[i][:14] == "inner_position":
55 lines[i] = 'inner_pos "%s"' % inner_pos[int(lines[i][15])]
57 lines.insert('inner_pos "%s"' % inner_pos[0])
60 # We need this since the new file format has a height and width
61 # in a different order.
62 if lines[i][:6] == "height":
64 # test for default value of 221 and convert it accordingly
65 if height == ' "0pt"':
71 if lines[i][:5] == "width":
77 if lines[i][:9] == "collapsed":
78 if lines[i][9:] == "true":
86 lines.insert(i, 'use_parbox 0')
88 lines.insert(i, 'width' + width)
90 lines.insert(i, 'special "none"')
92 lines.insert(i, 'height' + height)
94 lines.insert(i, 'height_special "totalheight"')
96 lines.insert(i, 'status ' + status)
99 def convert(header, body):
100 convert_minipage(body)
102 if __name__ == "__main__":