Skip to content

Commit

Permalink
add support for inkscape 1.0
Browse files Browse the repository at this point in the history
fix #4
  • Loading branch information
olibia committed Jun 29, 2020
1 parent 1f628b3 commit 8ef0394
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 49 deletions.
1 change: 0 additions & 1 deletion multipage_export.inx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<name>Multipage</name>
<id>hardpixel.eu.multipage_export</id>
<dependency type="executable" location="extensions">multipage_export.py</dependency>
<dependency type="executable" location="extensions">simplestyle.py</dependency>

<param name="description" type="description" indent="-1">Select a set of objects to export as single files.</param>
<param name="properties-title" type="description" appearance="header">Export Properties</param>
Expand Down
100 changes: 52 additions & 48 deletions multipage_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,67 @@
import subprocess
import lxml.etree as et

__version__ = '1.0'

inkex.localize()

class MultipageExport(inkex.Effect):

def __init__(self):
inkex.Effect.__init__(self)

self.OptionParser.add_option('-n', '--name', action='store', type='string', dest='name', help='Base name')
self.OptionParser.add_option('-e', '--exporter', action='store', type='string', dest='exporter', help='Exporter')
self.OptionParser.add_option('-f', '--format', action='store', type='string', dest='format', help='File format')
self.OptionParser.add_option('-a', '--autoname', action='store', type='string', dest='autoname', help='Use IDs for names')
self.OptionParser.add_option('-r', '--replace', action='store', type='string', dest='replace', help='Replace existing files')
self.OptionParser.add_option('-c', '--combine', action='store', type='string', dest='combine', help='Combine into single PDF')
self.arg_parser.add_argument(
'-n', '--name',
type=str,
dest='name',
help='Base name'
)

self.arg_parser.add_argument(
'-e', '--exporter',
type=str,
dest='exporter',
help='Exporter'
)

self.arg_parser.add_argument(
'-f', '--format',
type=str,
dest='format',
help='File format'
)

self.arg_parser.add_argument(
'-a', '--autoname',
type=str,
dest='autoname',
help='Use IDs for names'
)

self.arg_parser.add_argument(
'-r', '--replace',
type=str,
dest='replace',
help='Replace existing files'
)

self.arg_parser.add_argument(
'-c', '--combine',
type=str,
dest='combine',
help='Combine into single PDF'
)

def run_command(self, args):
try:
proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
proc.wait()
with subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) as proc:
proc.wait(timeout=300)
except OSError:
inkex.errormsg('Program "%s" is not installed!' % args[0])
exit()

def write_tempfile(self):
desc, tmpfile = tempfile.mkstemp(suffix='.svg', prefix='multipage-export-')
self.document.write(os.fdopen(desc, 'wb'))
file = os.fdopen(desc, 'wb')

self.document.write(file)
file.close()

return tmpfile

Expand Down Expand Up @@ -66,46 +100,16 @@ def remove_pt(self, path, fformat):
svg.attrib['height'] = svg.attrib['height'].replace('pt', '')
xml.write(path)

def inkscape_export_png(self, oid, output, tmpfile):
self.run_command([
'inkscape',
'--export-id=%s' % oid,
'--export-png=%s' % output,
tmpfile
])

def inkscape_export_format(self, oid, fformat, output):
tmpfile = self.write_tempfile()
fformat = 'plain-svg' if fformat == 'svg' else fformat

self.run_command([
'inkscape',
'--select=%s' % oid,
'--verb=EditCut',
'--verb=EditSelectAll',
'--verb=EditDelete',
'--verb=EditPaste',
'--verb=EditSelectAll',
'--verb=FitCanvasToSelection',
'--verb=FileSave',
'--verb=FileClose',
'--verb=FileQuit',
tmpfile
])

def inkscape_export(self, oid, fformat, output, tmpfile):
self.run_command([
'inkscape',
'--vacuum-defs',
'--export-%s=%s' % (fformat, output),
'--export-id=%s' % oid,
'--export-id-only',
'--export-filename=%s' % output,
tmpfile
])

def inkscape_export(self, oid, fformat, output, tmpfile):
if fformat == 'png':
self.inkscape_export_png(oid, output, tmpfile)
else:
self.inkscape_export_format(oid, fformat, output)

def rsvg_export(self, oid, fformat, output, tmpfile):
self.run_command([
'rsvg-convert',
Expand Down Expand Up @@ -172,4 +176,4 @@ def effect(self):

if __name__ == '__main__':
exporter = MultipageExport()
exporter.affect()
exporter.run()

0 comments on commit 8ef0394

Please sign in to comment.