##// END OF EJS Templates
Merge pull request #3699 from minrk/svgpdfunicode...
Min RK -
r11581:00cebafe merge
parent child Browse files
Show More
@@ -14,6 +14,7 b' one format to another.'
14 #-----------------------------------------------------------------------------
14 #-----------------------------------------------------------------------------
15
15
16 import base64
16 import base64
17 import io
17 import os
18 import os
18 import sys
19 import sys
19 import subprocess
20 import subprocess
@@ -28,9 +29,7 b' from .convertfigures import ConvertFiguresTransformer'
28 # Constants
29 # Constants
29 #-----------------------------------------------------------------------------
30 #-----------------------------------------------------------------------------
30
31
31 INKSCAPE_COMMAND = 'inkscape --without-gui --export-pdf="{to_filename}" "{from_filename}"'
32 INKSCAPE_APP = '/Applications/Inkscape.app/Contents/Resources/bin/inkscape'
32 INKSCAPE_OSX_COMMAND = '/Applications/Inkscape.app/Contents/Resources/bin/inkscape --without-gui --export-pdf="{to_filename}" "{from_filename}"'
33
34
33
35 #-----------------------------------------------------------------------------
34 #-----------------------------------------------------------------------------
36 # Classes
35 # Classes
@@ -43,6 +42,7 b' class SVG2PDFTransformer(ConvertFiguresTransformer):'
43
42
44 from_format = Unicode('svg', config=True, help='Format the converter accepts')
43 from_format = Unicode('svg', config=True, help='Format the converter accepts')
45 to_format = Unicode('pdf', config=False, help='Format the converter writes')
44 to_format = Unicode('pdf', config=False, help='Format the converter writes')
45
46 command = Unicode(config=True,
46 command = Unicode(config=True,
47 help="""The command to use for converting SVG to PDF
47 help="""The command to use for converting SVG to PDF
48
48
@@ -54,13 +54,15 b' class SVG2PDFTransformer(ConvertFiguresTransformer):'
54 """)
54 """)
55
55
56 def _command_default(self):
56 def _command_default(self):
57 return self.inkscape + \
58 ' --without-gui --export-pdf="{to_filename}" "{from_filename}"'
59
60 inkscape = Unicode(config=True, help="The path to Inkscape, if necessary")
61 def _inkscape_default(self):
57 if sys.platform == "darwin":
62 if sys.platform == "darwin":
58 return INKSCAPE_OSX_COMMAND
63 if os.path.isfile(INKSCAPE_APP):
59 elif sys.platform == "win32":
64 return INKSCAPE_APP
60 # windows not yet supported
65 return "inkscape"
61 return ""
62 else:
63 return INKSCAPE_COMMAND
64
66
65
67
66 def convert_figure(self, data_format, data):
68 def convert_figure(self, data_format, data):
@@ -73,7 +75,8 b' class SVG2PDFTransformer(ConvertFiguresTransformer):'
73
75
74 #Write fig to temp file
76 #Write fig to temp file
75 input_filename = os.path.join(tmpdir, 'figure.' + data_format)
77 input_filename = os.path.join(tmpdir, 'figure.' + data_format)
76 with open(input_filename, 'wb') as f:
78 # SVG data is unicode text
79 with io.open(input_filename, 'w', encoding='utf8') as f:
77 f.write(data)
80 f.write(data)
78
81
79 #Call conversion application
82 #Call conversion application
@@ -89,4 +92,4 b' class SVG2PDFTransformer(ConvertFiguresTransformer):'
89 # PDF is a nb supported binary, data type, so base64 encode.
92 # PDF is a nb supported binary, data type, so base64 encode.
90 return base64.encodestring(f.read())
93 return base64.encodestring(f.read())
91 else:
94 else:
92 return TypeError("Inkscape svg to png conversion failed")
95 raise TypeError("Inkscape svg to png conversion failed")
General Comments 0
You need to be logged in to leave comments. Login now