This repository has been archived on 2023-03-25. You can view files and clone it, but cannot push or open issues or pull requests.
mightyscape-1.1-deprecated/extensions/fablabchemnitz/svgo-inkscape/svgo.inkscape.py

79 lines
2.1 KiB
Python
Raw Normal View History

2020-07-30 01:16:18 +02:00
#!/usr/bin/env python
#-*- coding: utf-8 -*-
import sys, inkex, os
options = {
"cleanupAttrs": True,
"removeDoctype": True,
"removeXMLProcInst": True,
"removeComments": True,
"removeMetadata": True,
"removeTitle": False,
"removeDesc": True,
"removeUselessDefs": True,
"removeEditorsNSData": True,
"removeEmptyAttrs": True,
"removeHiddenElems": True,
"removeEmptyText": True,
"removeEmptyContainers": True,
"removeViewBox": True,
"cleanupEnableBackground": True,
"convertStyleToAttrs": True,
"convertColors": True,
"convertPathData": True,
"convertTransform": True,
"removeUnknownsAndDefaults": True,
"removeNonInheritableGroupAttrs": True,
"removeUselessStrokeAndFill": True,
"removeUnusedNS": True,
"cleanupIDs": True,
"cleanupNumericValues": True,
"moveElemsAttrsToGroup": True,
"moveGroupAttrsToElems": True,
"collapseGroups": True,
"removeRasterImages": False,
"mergePaths": True,
"convertShapeToPath": True,
"sortAttrs": False,
"transformsWithOnePath": False,
"removeDimensions": False,
"removeAttrs": False,
"addClassesToSVGElement": False
}
class SvgoInkscape (inkex.Effect):
def __init__(self):
inkex.Effect.__init__(self)
self.arg_parser.add_argument("--tabs",
type=str,
dest="tab")
for key in options:
self.arg_parser.add_argument("--" + key, type=inkex.Boolean,
dest=key, default=options[key])
def getCommand(self, name, option):
return " --"+ name + " " + str(option).lower()
def effect(self):
2021-04-09 12:03:02 +02:00
# "node.exe" or "node" on Windows or just "node" on Linux
command = "node svgo.js --file=" + self.options.input_file
2020-07-30 01:16:18 +02:00
optionsDict = self.options.__dict__
for key in options:
command += self.getCommand(key, optionsDict[key])
p = os.popen(command)
result = p.read()
p.close()
sys.stdout.write(result)
sys.stdout.close()
if __name__ == '__main__':
e = SvgoInkscape()
e.run()