Show More
@@ -14,6 +14,7 b' one format to another.' | |||
|
14 | 14 | #----------------------------------------------------------------------------- |
|
15 | 15 | |
|
16 | 16 | import base64 |
|
17 | import io | |
|
17 | 18 | import os |
|
18 | 19 | import sys |
|
19 | 20 | import subprocess |
@@ -28,9 +29,7 b' from .convertfigures import ConvertFiguresTransformer' | |||
|
28 | 29 | # Constants |
|
29 | 30 | #----------------------------------------------------------------------------- |
|
30 | 31 | |
|
31 | INKSCAPE_COMMAND = 'inkscape --without-gui --export-pdf="{to_filename}" "{from_filename}"' | |
|
32 | INKSCAPE_OSX_COMMAND = '/Applications/Inkscape.app/Contents/Resources/bin/inkscape --without-gui --export-pdf="{to_filename}" "{from_filename}"' | |
|
33 | ||
|
32 | INKSCAPE_APP = '/Applications/Inkscape.app/Contents/Resources/bin/inkscape' | |
|
34 | 33 | |
|
35 | 34 | #----------------------------------------------------------------------------- |
|
36 | 35 | # Classes |
@@ -43,6 +42,7 b' class SVG2PDFTransformer(ConvertFiguresTransformer):' | |||
|
43 | 42 | |
|
44 | 43 | from_format = Unicode('svg', config=True, help='Format the converter accepts') |
|
45 | 44 | to_format = Unicode('pdf', config=False, help='Format the converter writes') |
|
45 | ||
|
46 | 46 | command = Unicode(config=True, |
|
47 | 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 | 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 | 62 | if sys.platform == "darwin": |
|
58 | return INKSCAPE_OSX_COMMAND | |
|
59 | elif sys.platform == "win32": | |
|
60 | # windows not yet supported | |
|
61 | return "" | |
|
62 | else: | |
|
63 | return INKSCAPE_COMMAND | |
|
63 | if os.path.isfile(INKSCAPE_APP): | |
|
64 | return INKSCAPE_APP | |
|
65 | return "inkscape" | |
|
64 | 66 | |
|
65 | 67 | |
|
66 | 68 | def convert_figure(self, data_format, data): |
@@ -73,7 +75,8 b' class SVG2PDFTransformer(ConvertFiguresTransformer):' | |||
|
73 | 75 | |
|
74 | 76 | #Write fig to temp file |
|
75 | 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 | 80 | f.write(data) |
|
78 | 81 | |
|
79 | 82 | #Call conversion application |
@@ -89,4 +92,4 b' class SVG2PDFTransformer(ConvertFiguresTransformer):' | |||
|
89 | 92 | # PDF is a nb supported binary, data type, so base64 encode. |
|
90 | 93 | return base64.encodestring(f.read()) |
|
91 | 94 | else: |
|
92 |
re |
|
|
95 | raise TypeError("Inkscape svg to png conversion failed") |
General Comments 0
You need to be logged in to leave comments.
Login now