]> git.lyx.org Git - lyx.git/blob - lib/scripts/convertDefault.py
Document the IBus + Qt4 known issue (#9362)
[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 fout = os.popen('convert -version 2>&1')
24 output = fout.readline()
25 fout.close()
26 version = re_version.match(output)
27
28 # Imagemagick by default
29 gm = False
30
31 if version != None:
32     major = int(version.group(1))
33     minor = int(version.group(2))
34     patch = int(version.group(3))
35     version = hex(major * 65536 + minor * 256 + patch)
36 else:
37     # Try GraphicsMagick
38     re_version = re.compile(r'^GraphicsMagick.*http:..www.GraphicsMagick.org.*$')
39     version = re_version.match(output)
40     if version != None:
41         gm = True
42
43 opts = "-depth 8"
44
45 # If supported, add the -define option for pdf source formats
46 if sys.argv[1] == 'pdf' and (version >= 0x060206 or gm):
47     opts = '-define pdf:use-cropbox=true ' + opts
48
49 # If supported, add the -flatten option for ppm target formats (see bug 4749)
50 if sys.argv[3] == 'ppm' and (version >= 0x060305 or gm):
51     opts = opts + ' -flatten'
52
53 if os.system(r'convert %s "%s" "%s"' % (opts, sys.argv[2], sys.argv[3] + ':' + sys.argv[4])) != 0:
54     print >> sys.stderr, sys.argv[0], 'ERROR'
55     print >> sys.stderr, 'Execution of "convert" failed.'
56     sys.exit(1)