2002-08-24 12:13:44 +00:00
|
|
|
# This file is part of lyx2lyx
|
2006-08-02 14:19:22 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2002-08-24 12:13:44 +00:00
|
|
|
# Copyright (C) 2002 Dekel Tsur <dekel@lyx.org>
|
2006-08-02 14:19:22 +00:00
|
|
|
# Copyright (C) 2004 José Matos <jamatos@lyx.org>
|
2002-08-24 12:13:44 +00:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
2006-08-02 14:19:22 +00:00
|
|
|
""" Convert files to the file format generated by lyx 1.3"""
|
|
|
|
|
2004-04-14 08:45:46 +00:00
|
|
|
import re
|
2006-07-27 18:30:13 +00:00
|
|
|
from parser_tools import find_token, find_end_of, get_value,\
|
2006-03-17 09:52:13 +00:00
|
|
|
find_token_exact, del_token
|
2002-08-24 12:13:44 +00:00
|
|
|
|
2006-07-27 18:30:13 +00:00
|
|
|
####################################################################
|
|
|
|
# Private helper functions
|
|
|
|
|
|
|
|
def find_end_of_inset(lines, i):
|
|
|
|
"Finds the matching \end_inset"
|
|
|
|
return find_end_of(lines, i, "\\begin_inset", "\\end_inset")
|
|
|
|
|
|
|
|
# End of helper functions
|
|
|
|
####################################################################
|
|
|
|
|
|
|
|
|
2006-08-02 14:19:22 +00:00
|
|
|
def change_insetgraphics(document):
|
|
|
|
" Change inset Graphics."
|
|
|
|
lines = document.body
|
2002-08-24 12:13:44 +00:00
|
|
|
i = 0
|
|
|
|
while 1:
|
2006-07-01 19:16:09 +00:00
|
|
|
i = find_token(lines, "\\begin_inset Graphics", i)
|
|
|
|
if i == -1:
|
|
|
|
break
|
|
|
|
j = find_end_of_inset(lines, i)
|
2002-08-24 12:13:44 +00:00
|
|
|
|
2006-07-01 19:16:09 +00:00
|
|
|
lines[i] = "\\begin_inset Graphics"
|
2002-08-24 12:19:28 +00:00
|
|
|
|
2006-07-01 19:16:09 +00:00
|
|
|
if get_value(lines, "display", i, j) == "default":
|
|
|
|
j = del_token(lines, "display", i, j)
|
|
|
|
if get_value(lines, "rotateOrigin", i, j) == "leftBaseline":
|
|
|
|
j = del_token(lines, "rotateOrigin", i, j)
|
2002-08-24 12:13:44 +00:00
|
|
|
|
2006-07-01 19:16:09 +00:00
|
|
|
k = find_token_exact(lines, "rotate", i, j)
|
|
|
|
if k != -1:
|
|
|
|
del lines[k]
|
|
|
|
j = j-1
|
|
|
|
else:
|
|
|
|
j = del_token(lines, "rotateAngle", i, j)
|
2002-08-24 12:13:44 +00:00
|
|
|
|
2006-07-01 19:16:09 +00:00
|
|
|
k = find_token_exact(lines, "size_type", i, j)
|
|
|
|
if k == -1:
|
|
|
|
k = find_token_exact(lines, "size_kind", i, j)
|
|
|
|
if k != -1:
|
2006-08-02 15:45:44 +00:00
|
|
|
size_type = lines[k].split()[1]
|
2006-07-01 19:16:09 +00:00
|
|
|
del lines[k]
|
|
|
|
j = j-1
|
|
|
|
if size_type in ["0", "original"]:
|
|
|
|
j = del_token(lines, "width", i, j)
|
|
|
|
j = del_token(lines, "height", i, j)
|
|
|
|
j = del_token(lines, "scale", i, j)
|
|
|
|
elif size_type in ["2", "scale"]:
|
|
|
|
j = del_token(lines, "width", i, j)
|
|
|
|
j = del_token(lines, "height", i, j)
|
|
|
|
if get_value(lines, "scale", i, j) == "100":
|
|
|
|
j = del_token(lines, "scale", i, j)
|
|
|
|
else:
|
|
|
|
j = del_token(lines, "scale", i, j)
|
2002-08-24 12:13:44 +00:00
|
|
|
|
2006-07-01 19:16:09 +00:00
|
|
|
k = find_token_exact(lines, "lyxsize_type", i, j)
|
|
|
|
if k == -1:
|
|
|
|
k = find_token_exact(lines, "lyxsize_kind", i, j)
|
|
|
|
if k != -1:
|
2006-08-02 15:45:44 +00:00
|
|
|
lyxsize_type = lines[k].split()[1]
|
2006-07-01 19:16:09 +00:00
|
|
|
del lines[k]
|
|
|
|
j = j-1
|
|
|
|
j = del_token(lines, "lyxwidth", i, j)
|
|
|
|
j = del_token(lines, "lyxheight", i, j)
|
|
|
|
if lyxsize_type not in ["2", "scale"] or \
|
|
|
|
get_value(lines, "lyxscale", i, j) == "100":
|
|
|
|
j = del_token(lines, "lyxscale", i, j)
|
2003-10-13 09:50:10 +00:00
|
|
|
|
2006-07-01 19:16:09 +00:00
|
|
|
i = i+1
|
2002-08-24 12:13:44 +00:00
|
|
|
|
2004-04-14 08:45:46 +00:00
|
|
|
|
2006-08-02 14:19:22 +00:00
|
|
|
def change_tabular(document):
|
|
|
|
" Change tabular."
|
|
|
|
lines = document.body
|
2003-01-04 16:16:40 +00:00
|
|
|
i = 0
|
|
|
|
while 1:
|
|
|
|
i = find_token(lines, "<column", i)
|
|
|
|
if i == -1:
|
|
|
|
break
|
|
|
|
if not re.search('width="0pt"', lines[i]):
|
|
|
|
lines[i] = re.sub(' alignment=".*?"',' alignment="block"',lines[i])
|
|
|
|
i = i+1
|
2002-08-24 12:13:44 +00:00
|
|
|
|
2004-04-14 08:45:46 +00:00
|
|
|
|
2006-08-02 14:19:22 +00:00
|
|
|
supported_versions = ["1.3.%d" % i for i in range(8)] + ["1.3"]
|
2005-01-05 18:52:59 +00:00
|
|
|
convert = [[221, [change_insetgraphics, change_tabular]]]
|
|
|
|
revert = []
|
2004-04-14 08:45:46 +00:00
|
|
|
|
2002-08-24 12:13:44 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
pass
|