1 # This file is part of lyx2lyx
2 # Copyright (C) 2002 José Matos <jamatos@lyx.org>
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.
18 import re, string, sys
19 from parser_tools import *
21 lyxtable_re = re.compile(r".*\\LyXTable$")
22 def update_tabular(lines):
25 i = find_re(lines, lyxtable_re, i)
29 lines[i] = lines[i][:-9]
33 lines[i] = "\\begin_inset Tabular"
35 head = string.split(lines[i])
37 columns = int(head[1])
39 lines[i] = '<LyXTabular version="1" rows="%s" columns="%s">' % (head[0],head[1])
41 lines.insert(i, '<Features rotate="%s" islongtable="%s" endhead="0" endfirsthead="0" endfoot="0" endlastfoot="0">' % (head[2], head[3]))
47 row_info.append(string.split(lines[i]))
50 for j in range(columns):
51 column_info.append(string.split(lines[i]))
60 for k in range(columns):
61 cell_info.append(string.split(lines[i]))
62 if lines[i][0] != "2":
67 cell_location.append(tmp)
70 for k in cell_location[j]:
71 sys.stderr.write("%d\t" % (k))
72 sys.stderr.write("\n")
83 tmp.append('<Row topline="%s" bottomline="%s" newpage="%s">' % (row_info[j][0],row_info[j][1],row_info[j][2]))
85 for k in range(columns):
87 tmp.append('<Column>')
89 tmp.append('<Column alignment="%s" valignment="0" leftline="%s" rightline="%s" width=%s special=%s>' % (column_info[k][0],column_info[k][1], column_info[k][2], column_info[k][3], column_info[k][4]))
91 sys.stderr.write("%d\t%d\t%d\n" % (j,k,m))
92 tmp.append('<Cell multicolumn="%s" alignment="%s" valignment="0" topline="%s" bottomline="%s" leftline="%s" rightline="%s" rotate="%s" usebox="0" width=%s special=%s>' % (cell_info[m][0],cell_info[m][1],cell_info[m][2],cell_info[m][3],cell_info[m][4],cell_info[m][5],cell_info[m][6],cell_info[m][7],cell_info[m][8]))
93 tmp.append('\\begin_inset Text')
95 tmp.append('\\layout Standard')
98 if m not in cell_location[j]:
99 tmp.append('\\end_inset ')
100 tmp.append('</Cell>')
101 tmp.append('</Column>')
105 end = find_tokens(lines, ['\\layout','\\the_end'], i)
107 sys.stderr.write("Malformed lyx file\n")
112 paragraph.append(lines[i])
115 tmp.extend(set_paragraph_properties(paragraph))
118 while lines[i] != '\\newline ':
119 paragraph.append(lines[i])
122 tmp.extend(set_paragraph_properties(paragraph))
124 tmp.append('\\end_inset ')
125 tmp.append('</Cell>')
126 tmp.append('</Column>')
130 tmp.append('</LyXTabular>')
132 tmp.append('\\end_inset ')
140 prop_exp = re.compile(r"\\(\S*)\s*(\S*)")
141 def set_paragraph_properties(lines):
142 # we need to preserve the order of options
143 properties = ["family","series","shape","size",
144 "emph","bar","noun","latex","color"]
145 prop_value = {"family":"roman", "series" : "medium",
146 "shape" : "up", "size" : "normal",
147 "emph" : "off", "bar" : "no",
148 "noun" : "off", "latex" : "no_latex", "color" : "none"}
155 while i<n and lines[i] == "":
159 while i<n and lines[i][:1] == "\\":
160 result = prop_exp.match(lines[i])
161 sys.stderr.write(lines[i]+"\n")
162 prop = result.group(1)
163 if prop not in properties:
164 sys.stderr.write("Unknown property: %s\n" % (prop))
166 prop_value[prop] = result.group(2)
171 for prop in properties:
173 aux.append("\\%s %s" % (prop, prop_value[prop]))
174 elif prop == "family":
175 if prop_value[prop] != "roman":
176 aux.append("\\%s %s " % (prop, prop_value[prop]))
178 aux.append("\\%s %s " % (prop, prop_value[prop]))
181 return lines[:start] + aux[:] + lines[end:]
183 def convert(header,body):
184 sys.stderr.write("%d\n" % len(body))
186 sys.stderr.write("%d\n" % len(body))
188 if __name__ == "__main__":