2 # -*- coding: utf-8 -*-
4 # file prefs2prefs-lfuns.py
5 # This file is part of LyX, the document processor.
6 # Licence details can be found in the file COPYING.
10 # Full author contact details are available in file CREDITS
12 # This file houses conversion information for the preferences file.
14 # The converter functions take a line as argument and return a list:
16 # where the Bool says if we've modified anything and the NewLine is
17 # the new line, if so, which will be used to replace the old line.
19 # Incremented to format 2, r39670 by jrioux
20 # Support for multiple file extensions per format.
21 # No conversion necessary.
23 # Incremented to format 3, r39705 by tommaso
24 # Support for file formats that are natively (g)zipped.
25 # We must add the flag zipped=native to formats that
26 # were previously hardcoded in the C++ source: dia.
28 # Incremented to format 4, r40028 by vfr
29 # Remove support for default paper size.
31 # Incremented to format 5, r40030 by vfr
32 # Add a default length unit.
33 # No conversion necessary.
35 # Incremented to format 6, r40515 by younes
36 # Add use_qimage option.
37 # No conversion necessary.
39 # Incremented to format 7, r40789 by gb
40 # Add mime type to file format
44 ###########################################################
55 while i < len(line) and line[i] != '"':
56 if line[i] == '\\' and i < len(line) - 1 and line[i+1] == '"':
61 entries.append(line[beg:end].replace('\\"', '"'))
64 elif not line[i].isspace():
66 while not line[i].isspace():
69 entries.append(line[beg:end])
74 def simple_renaming(line, old, new):
75 i = line.lower().find(old.lower())
78 line = line[:i] + new + line[i+len(old):]
81 no_match = (False, [])
83 ########################
84 ### Format 1 conversions
86 def remove_obsolete(line):
87 tags = ("\\use_tempdir", "\\spell_command", "\\personal_dictionary",
88 "\\plaintext_roff_command", "\\use_alt_language",
89 "\\use_escape_chars", "\\use_input_encoding",
90 "\\use_personal_dictionary", "\\use_pspell",
92 line = line.lower().lstrip()
94 if line.lower().startswith(tag):
98 def language_use_babel(line):
99 if not line.lower().startswith("\language_use_babel"):
101 re_lub = re.compile(r'^\\language_use_babel\s+"?(true|false)', re.IGNORECASE)
102 m = re_lub.match(line)
107 newline = "\\language_package_selection " + newval
108 return (True, newline)
110 def language_package(line):
111 return simple_renaming(line, "\\language_package", "\\language_custom_package")
113 lfre = re.compile(r'^\\converter\s+"?(\w+)"?\s+"?(\w+)"?\s+"([^"]*?)"\s+"latex"', re.IGNORECASE)
114 def latex_flavor(line):
115 if not line.lower().startswith("\\converter"):
124 "luatex": "lualatex",
128 if conv in conv2fl.keys():
129 flavor = conv2fl[conv]
132 if flavor == "latex":
135 "\\converter \"%s\" \"%s\" \"%s\" \"latex=%s\"" % (conv, fmat, args, flavor))
137 emre = re.compile(r'^\\format\s+(.*)\s+"(document[^"]*?)"', re.IGNORECASE)
138 def export_menu(line):
139 if not line.lower().startswith("\\format"):
147 "\\Format %s \"%s,menu=export\"" % (fmat, opts))
149 zipre = re.compile(r'^\\format\s+("?dia"?\s+.*)\s+"([^"]*?)"', re.IGNORECASE)
150 def zipped_native(line):
151 if not line.lower().startswith("\\format"):
153 m = zipre.match(line)
159 "\\Format %s \"%s,zipped=native\"" % (fmat, opts))
161 def remove_default_papersize(line):
162 if not line.lower().startswith("\\default_papersize"):
166 def add_mime_types(line):
167 if not line.lower().startswith("\\format"):
169 entries = get_format(line)
173 converted = converted + ' ""'
175 formats = {'tgif':'application/x-tgif', \
176 'fig':'application/x-xfig', \
177 'dia':'application/x-dia-diagram', \
178 'odg':'application/vnd.oasis.opendocument.graphics', \
179 'svg':'image/svg+xml', \
180 'bmp':'image/x-bmp', \
182 'jpg':'image/jpeg', \
183 'pbm':'image/x-portable-bitmap', \
184 'pgm':'image/x-portable-graymap', \
185 'png':'image/x-png', \
186 'ppm':'image/x-portable-pixmap', \
187 'tiff':'image/tiff', \
188 'xbm':'image/x-xbitmap', \
189 'xpm':'image/x-xpixmap', \
190 'docbook-xml':'application/docbook+xml', \
191 'dot':'text/vnd.graphviz', \
192 'ly':'text/x-lilypond', \
193 'latex':'text/x-tex', \
194 'text':'text/plain', \
195 'gnumeric':'application/x-gnumeric', \
196 'excel':'application/vnd.ms-excel', \
197 'oocalc':'application/vnd.oasis.opendocument.spreadsheet', \
198 'xhtml':'application/xhtml+xml', \
199 'bib':'text/x-bibtex', \
200 'eps':'image/x-eps', \
201 'ps':'application/postscript', \
202 'pdf':'application/pdf', \
203 'dvi':'application/x-dvi', \
204 'html':'text/html', \
205 'odt':'application/vnd.oasis.opendocument.text', \
206 'sxw':'application/vnd.sun.xml.writer', \
207 'rtf':'application/rtf', \
208 'doc':'application/msword', \
210 'lyx':'application/x-lyx', \
211 'wmf':'image/x-wmf', \
213 if entries[1] in formats.keys():
214 converted = converted + ' "' + formats[entries[1]] + '"'
216 converted = converted + ' ""'
217 return (True, converted)
220 ########################
224 [ 1, [ # this will be a long list of conversions to format 1
232 [ 3, [ zipped_native ]],
233 [ 4, [ remove_default_papersize ]],
236 [ 7, [add_mime_types]],