]> git.lyx.org Git - lyx.git/blob - lib/scripts/convertDefault.py
Consistent output of breakable/non-breakable dashes on all TeX engines.
[lyx.git] / lib / scripts / convertDefault.py
1 # -*- coding: utf-8 -*-
2
3 # file convertDefault.py
4 # This file is part of LyX, the document processor.
5 # Licence details can be found in the file COPYING.
6
7 # \author Herbert Voß
8 # \author Bo Peng
9
10 # Full author contact details are available in file CREDITS.
11
12 # The default converter if no other has been defined by the user from the
13 # Conversion->Converter tab of the Preferences dialog.
14
15 # The user can also redefine this default converter, placing their
16 # replacement in ~/.lyx/scripts
17
18 # converts an image $2 (format $1) to $4 (format $3)
19 import os, re, sys
20
21 # We may need some extra options only supported by recent convert versions
22 re_version = re.compile(r'^Version:.*ImageMagick\s*(\d*)\.(\d*)\.(\d*).*$')
23 # imagemagick 7
24 command = 'magick'
25 fout = os.popen('magick -version 2>&1')
26 output = fout.readline()
27 if fout.close() != None:
28     # older versions
29     # caution: windows has a convert.exe for converting file systems
30     command = 'convert'
31     fout = os.popen('convert -version 2>&1')
32     output = fout.readline()
33     fout.close()
34 version = re_version.match(output)
35
36 # Imagemagick by default
37 im = False
38 gm = False
39
40 if version != None:
41     major = int(version.group(1))
42     minor = int(version.group(2))
43     patch = int(version.group(3))
44     version = hex(major * 65536 + minor * 256 + patch)
45     im = True
46 else:
47     # Try GraphicsMagick
48     re_version = re.compile(r'^GraphicsMagick.*http:..www.GraphicsMagick.org.*$')
49     version = re_version.match(output)
50     if version != None:
51         gm = True
52
53 if im or gm:
54     opts = "-depth 8"
55 elif sys.platform == 'darwin':
56     command = 'lyxconvert'
57
58 # If supported, add the -define option for pdf source formats
59 if sys.argv[1] == 'pdf' and (version >= 0x060206 or gm):
60     opts = '-define pdf:use-cropbox=true ' + opts
61
62 # If supported, add the -flatten option for ppm target formats (see bug 4749)
63 if sys.argv[3] == 'ppm' and (im and version >= 0x060305 or gm):
64     opts = opts + ' -flatten'
65
66 # print >> sys.stdout, command, sys.argv[2], sys.argv[4]
67 if (im or gm) and os.system(r'%s %s "%s" "%s"' % (command, opts, sys.argv[2], sys.argv[3] + ':' + sys.argv[4])) != 0:
68     print >> sys.stderr, sys.argv[0], 'ERROR'
69     print >> sys.stderr, ('Execution of "%s" failed.' % command)
70     sys.exit(1)
71 elif not im and not gm and sys.platform == 'darwin' and os.system(r'%s "%s" "%s"' % (command, sys.argv[2], sys.argv[4])) != 0:
72     print >> sys.stderr, sys.argv[0], 'ERROR'
73     print >> sys.stderr, ('Execution of "%s" failed.' % command)
74     sys.exit(1)