1 # This file is part of lyx2lyx
2 # -*- coding: iso-8859-1 -*-
3 # Copyright (C) 2006 José Matos <jamatos@lyx.org>
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.
19 from parser_tools import find_token_exact, find_tokens, get_value
22 # Notes: Framed/Shaded
25 def revert_framed(file):
28 i = find_tokens(file.body, ["\\begin_inset Note Framed", "\\begin_inset Note Shaded"], i)
32 file.body[i] = "\\begin_inset Note"
40 roman_fonts = {'default' : 'default', 'ae' : 'ae',
41 'times' : 'times', 'palatino' : 'palatino',
42 'helvet' : 'default', 'avant' : 'default',
43 'newcent' : 'newcent', 'bookman' : 'bookman',
45 sans_fonts = {'default' : 'default', 'ae' : 'default',
46 'times' : 'default', 'palatino' : 'default',
47 'helvet' : 'helvet', 'avant' : 'avant',
48 'newcent' : 'default', 'bookman' : 'default',
50 typewriter_fonts = {'default' : 'default', 'ae' : 'default',
51 'times' : 'default', 'palatino' : 'default',
52 'helvet' : 'default', 'avant' : 'default',
53 'newcent' : 'default', 'bookman' : 'default',
54 'pslatex' : 'courier'}
56 def convert_font_settings(file):
58 i = find_token_exact(file.header, "\\fontscheme", i)
60 file.warning("Malformed LyX file: Missing `\\fontscheme'.")
62 font_scheme = get_value(file.header, "\\fontscheme", i, i + 1)
64 file.warning("Malformed LyX file: Empty `\\fontscheme'.")
65 font_scheme = 'default'
66 if not font_scheme in roman_fonts.keys():
67 file.warning("Malformed LyX file: Unknown `\\fontscheme' `%s'." % font_scheme)
68 font_scheme = 'default'
69 file.header[i:i+1] = ['\\font_roman %s' % roman_fonts[font_scheme],
70 '\\font_sans %s' % sans_fonts[font_scheme],
71 '\\font_typewriter %s' % typewriter_fonts[font_scheme],
72 '\\font_default_family default',
75 '\\font_sf_scale 100',
76 '\\font_tt_scale 100']
79 def revert_font_settings(file):
82 fonts = {'roman' : 'default', 'sans' : 'default', 'typewriter' : 'default'}
83 for family in 'roman', 'sans', 'typewriter':
84 name = '\\font_%s' % family
85 i = find_token_exact(file.header, name, i)
87 file.warning("Malformed LyX file: Missing `%s'." % name)
92 fonts[family] = get_value(file.header, name, i, i + 1)
94 i = find_token_exact(file.header, '\\font_default_family', i)
96 file.warning("Malformed LyX file: Missing `\\font_default_family'.")
97 font_default_family = 'default'
99 font_default_family = get_value(file.header, "\\font_default_family", i, i + 1)
101 i = find_token_exact(file.header, '\\font_sc', i)
103 file.warning("Malformed LyX file: Missing `\\font_sc'.")
106 font_sc = get_value(file.header, '\\font_sc', i, i + 1)
108 if font_sc != 'false':
109 file.warning("Conversion of '\\font_sc' not yet implemented.")
110 i = find_token_exact(file.header, '\\font_osf', i)
112 file.warning("Malformed LyX file: Missing `\\font_osf'.")
115 font_osf = get_value(file.header, '\\font_osf', i, i + 1)
117 i = find_token_exact(file.header, '\\font_sf_scale', i)
119 file.warning("Malformed LyX file: Missing `\\font_sf_scale'.")
120 font_sf_scale = '100'
122 font_sf_scale = get_value(file.header, '\\font_sf_scale', i, i + 1)
124 if font_sf_scale != '100':
125 file.warning("Conversion of '\\font_sf_scale' not yet implemented.")
126 i = find_token_exact(file.header, '\\font_tt_scale', i)
128 file.warning("Malformed LyX file: Missing `\\font_tt_scale'.")
129 font_tt_scale = '100'
131 font_tt_scale = get_value(file.header, '\\font_tt_scale', i, i + 1)
133 if font_tt_scale != '100':
134 file.warning("Conversion of '\\font_tt_scale' not yet implemented.")
135 for font_scheme in roman_fonts.keys():
136 if (roman_fonts[font_scheme] == fonts['roman'] and
137 sans_fonts[font_scheme] == fonts['sans'] and
138 typewriter_fonts[font_scheme] == fonts['typewriter']):
139 file.header.insert(insert_line, '\\fontscheme %s' % font_scheme)
140 if font_default_family != 'default':
141 file.preamble.append('\\renewcommand{\\familydefault}{\\%s}' % font_default_family)
142 if font_osf == 'true':
143 file.warning("Ignoring `\\font_osf = true'")
145 font_scheme = 'default'
146 file.header.insert(insert_line, '\\fontscheme %s' % font_scheme)
147 if fonts['roman'] == 'cmr':
148 file.preamble.append('\\renewcommand{\\rmdefault}{cmr}')
149 if font_osf == 'true':
150 file.preamble.append('\\usepackage{eco}')
152 for font in 'lmodern', 'charter', 'utopia', 'beraserif', 'ccfonts', 'chancery':
153 if fonts['roman'] == font:
154 file.preamble.append('\\usepackage{%s}' % font)
155 for font in 'cmss', 'lmss', 'cmbr':
156 if fonts['sans'] == font:
157 file.preamble.append('\\renewcommand{\\sfdefault}{%s}' % font)
158 for font in 'berasans':
159 if fonts['sans'] == font:
160 file.preamble.append('\\usepackage{%s}' % font)
161 for font in 'cmtt', 'lmtt', 'cmtl':
162 if fonts['typewriter'] == font:
163 file.preamble.append('\\renewcommand{\\ttdefault}{%s}' % font)
164 for font in 'courier', 'beramono', 'luximono':
165 if fonts['typewriter'] == font:
166 file.preamble.append('\\usepackage{%s}' % font)
167 if font_default_family != 'default':
168 file.preamble.append('\\renewcommand{\\familydefault}{\\%s}' % font_default_family)
169 if font_osf == 'true':
170 file.warning("Ignoring `\\font_osf = true'")
177 convert = [[246, []],
178 [247, [convert_font_settings]]]
180 revert = [[246, [revert_font_settings]],
181 [245, [revert_framed]]]
183 if __name__ == "__main__":