1 # -*- coding: utf-8 -*-
3 # file prefs2prefs-prefs.py
4 # This file is part of LyX, the document processor.
5 # Licence details can be found in the file COPYING.
9 # Full author contact details are available in file CREDITS
11 # This file houses conversion information for the preferences file.
13 # The converter functions take a line as argument and return a list:
15 # where the Bool says if we've modified anything and the NewLine is
16 # the new line, if so, which will be used to replace the old line.
18 # Incremented to format 2, r39670 by jrioux
19 # Support for multiple file extensions per format.
20 # No conversion necessary.
22 # Incremented to format 3, r39705 by tommaso
23 # Support for file formats that are natively (g)zipped.
24 # We must add the flag zipped=native to formats that
25 # were previously hardcoded in the C++ source: dia.
27 # Incremented to format 4, r40028 by vfr
28 # Remove support for default paper size.
30 # Incremented to format 5, r40030 by vfr
31 # Add a default length unit.
32 # No conversion necessary.
34 # Incremented to format 6, r40515 by younes
35 # Add use_qimage option.
36 # No conversion necessary.
38 # Incremented to format 7, r40789 by gb
39 # Add mime type to file format
41 # Incremented to format 8, 288c1e0f by rgh
42 # Add "nice" flag for converters
43 # No conversion necessary.
45 # Incremented to format 9, a18af620 by spitz
46 # Remove default_language rc.
48 # Incremented to format 10, 4985015 by tommaso
49 # Add close_buffer_with_last_view in preferences.
50 # No conversion necessary.
52 # Incremented to format 11, by gb
53 # Split pdf format into pdf and pdf6
55 # Incremented to format 12, by vfr
56 # Add option to use the system's theme icons
57 # No conversion necessary.
59 # Incremented to format 13, by bh
60 # Rename mac_like_word_movement to mac_like_cursor_movement
62 # Incremented to format 14, by spitz
63 # New RC default_otf_view_format
64 # No conversion necessary.
66 # Incremented to format 15, by prannoy
67 # Add fullscreen_statusbar
68 # No conversion necessary.
70 # Incremented to format 16, by lasgouttes
71 # Remove force_paint_single_char rc.
73 # Incremented to format 17, by lasgouttes
74 # Remove rtl_support rc.
76 # Incremented to format 18, by ef
77 # Add option to allow saving the document directory
78 # No conversion necessary.
80 # Incremented to format 19, by rgh
81 # remove print support
83 # NOTE: The format should also be updated in LYXRC.cpp and
88 ###########################################################
99 while i < len(line) and line[i] != '"':
100 if line[i] == '\\' and i < len(line) - 1 and line[i+1] == '"':
105 entries.append(line[beg:end].replace('\\"', '"'))
108 elif not line[i].isspace():
110 while i < len(line) and not line[i].isspace():
113 entries.append(line[beg:end])
118 def simple_renaming(line, old, new):
119 i = line.lower().find(old.lower())
122 line = line[:i] + new + line[i+len(old):]
125 no_match = (False, [])
127 ######################################
128 ### Format 1 conversions (for LyX 2.0)
130 def remove_obsolete(line):
131 tags = ("\\use_tempdir", "\\spell_command", "\\personal_dictionary",
132 "\\plaintext_roff_command", "\\use_alt_language",
133 "\\use_escape_chars", "\\use_input_encoding",
134 "\\use_personal_dictionary", "\\use_pspell",
136 line = line.lower().lstrip()
138 if line.lower().startswith(tag):
143 def language_use_babel(line):
144 if not line.lower().startswith("\language_use_babel"):
146 re_lub = re.compile(r'^\\language_use_babel\s+"?(true|false)', re.IGNORECASE)
147 m = re_lub.match(line)
152 newline = "\\language_package_selection " + newval
153 return (True, newline)
156 def language_package(line):
157 return simple_renaming(line, "\\language_package", "\\language_custom_package")
160 lfre = re.compile(r'^\\converter\s+"?(\w+)"?\s+"?(\w+)"?\s+"([^"]*?)"\s+"latex"', re.IGNORECASE)
161 def latex_flavor(line):
162 if not line.lower().startswith("\\converter"):
171 "luatex": "lualatex",
175 if conv in conv2fl.keys():
176 flavor = conv2fl[conv]
179 if flavor == "latex":
182 "\\converter \"%s\" \"%s\" \"%s\" \"latex=%s\"" % (conv, fmat, args, flavor))
185 emre = re.compile(r'^\\format\s+(.*)\s+"(document[^"]*?)"', re.IGNORECASE)
186 def export_menu(line):
187 if not line.lower().startswith("\\format"):
195 "\\Format %s \"%s,menu=export\"" % (fmat, opts))
197 # End format 1 conversions (for LyX 2.0)
198 ########################################
200 #################################
201 # Conversions from LyX 2.0 to 2.1
202 zipre = re.compile(r'^\\format\s+("?dia"?\s+.*)\s+"([^"]*?)"', re.IGNORECASE)
203 def zipped_native(line):
204 if not line.lower().startswith("\\format"):
206 m = zipre.match(line)
212 "\\Format %s \"%s,zipped=native\"" % (fmat, opts))
214 def remove_default_papersize(line):
215 if not line.lower().startswith("\\default_papersize"):
219 def add_mime_types(line):
220 if not line.lower().startswith("\\format"):
222 entries = get_format(line)
226 converted = converted + ' ""'
228 formats = {'tgif':'application/x-tgif', \
229 'fig':'application/x-xfig', \
230 'dia':'application/x-dia-diagram', \
231 'odg':'application/vnd.oasis.opendocument.graphics', \
232 'svg':'image/svg+xml', \
233 'bmp':'image/x-bmp', \
235 'jpg':'image/jpeg', \
236 'pbm':'image/x-portable-bitmap', \
237 'pgm':'image/x-portable-graymap', \
238 'png':'image/x-png', \
239 'ppm':'image/x-portable-pixmap', \
240 'tiff':'image/tiff', \
241 'xbm':'image/x-xbitmap', \
242 'xpm':'image/x-xpixmap', \
243 'docbook-xml':'application/docbook+xml', \
244 'dot':'text/vnd.graphviz', \
245 'ly':'text/x-lilypond', \
246 'latex':'text/x-tex', \
247 'text':'text/plain', \
248 'gnumeric':'application/x-gnumeric', \
249 'excel':'application/vnd.ms-excel', \
250 'oocalc':'application/vnd.oasis.opendocument.spreadsheet', \
251 'xhtml':'application/xhtml+xml', \
252 'bib':'text/x-bibtex', \
253 'eps':'image/x-eps', \
254 'ps':'application/postscript', \
255 'pdf':'application/pdf', \
256 'dvi':'application/x-dvi', \
257 'html':'text/html', \
258 'odt':'application/vnd.oasis.opendocument.text', \
259 'sxw':'application/vnd.sun.xml.writer', \
260 'rtf':'application/rtf', \
261 'doc':'application/msword', \
263 'lyx':'application/x-lyx', \
264 'wmf':'image/x-wmf', \
266 if entries[1] in formats.keys():
267 converted = converted + ' "' + formats[entries[1]] + '"'
269 converted = converted + ' ""'
270 return (True, converted)
272 re_converter = re.compile(r'^\\converter\s+', re.IGNORECASE)
274 def split_pdf_format(line):
275 # strictly speaking, a new format would not require to bump the
276 # version number, but the old pdf format was hardcoded at several
277 # places in the C++ code, so an update seemed like a good idea.
278 if line.lower().startswith("\\format"):
279 entries = get_format(line)
280 if entries[1] == 'pdf':
285 converted = line.replace('application/pdf', '') + '''
286 \Format pdf6 pdf "PDF (graphics)" "" "''' + viewer + '" "" "vector" "application/pdf"'
287 return (True, converted)
288 elif line.lower().startswith("\\viewer_alternatives") or \
289 line.lower().startswith("\\editor_alternatives"):
290 entries = get_format(line)
291 if entries[1] == 'pdf':
292 converted = line + "\n" + entries[0] + ' pdf6 "' + entries[2] + '"'
293 return (True, converted)
294 elif re_converter.match(line):
295 entries = get_format(line)
296 # The only converter from pdf that is touched is pdf->eps:
297 # All other converters are likely meant for further processing on export.
298 # The only converter to pdf that stays untouched is dvi->pdf:
299 # All other converters are likely meant for graphics.
300 if len(entries) > 2 and \
301 ((entries[1] == 'pdf' and entries[2] == 'eps') or \
302 (entries[1] != 'ps' and entries[2] == 'pdf')):
303 if entries[1] == 'pdf':
304 converted = entries[0] + ' pdf6 ' + entries[2]
306 converted = entries[0] + ' ' + entries[1] + ' pdf6'
308 while i < len(entries):
309 converted = converted + ' "' + entries[i] + '"'
311 return (True, converted)
314 def remove_default_language(line):
315 if not line.lower().startswith("\\default_language"):
319 def mac_cursor_movement(line):
320 return simple_renaming(line, "\\mac_like_word_movement", "\\mac_like_cursor_movement")
322 # End conversions for LyX 2.0 to 2.1
323 ####################################
326 #################################
327 # Conversions from LyX 2.1 to 2.2
329 def remove_force_paint_single_char(line):
330 if not line.lower().startswith("\\force_paint_single_char"):
334 def remove_rtl(line):
335 if not line.lower().startswith("\\rtl "):
339 def remove_print_support(line):
340 tags = ("\\printer", "\\print_adapt_output", "\\print_command",
341 "\\print_evenpage_flag", "\\print_oddpage_flag", "\\print_pagerange_flag",
342 "\\print_copies_flag", "\\print_collcopies_flag", "\\print_reverse_flag",
343 "\\print_to_printer", "\\print_to_file", "\\print_file_extension")
344 line = line.lower().lstrip()
346 if line.lower().startswith(tag):
350 # End conversions for LyX 2.1 to 2.2
351 ####################################
354 [ 1, [ # there were several conversions for format 1
362 [ 3, [ zipped_native ]],
363 [ 4, [ remove_default_papersize ]],
366 [ 7, [add_mime_types]],
368 [ 9, [ remove_default_language ]],
370 [ 11, [split_pdf_format]],
372 [ 13, [mac_cursor_movement]],
375 [ 16, [remove_force_paint_single_char]],
378 [ 19, [remove_print_support]]