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_output/svgo_output.py

77 lines
2.1 KiB
Python

#!/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 SVGOOutput(inkex.EffectExtension):
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):
# "node.exe" or "node" on Windows or just "node" on Linux
command = "node svgo.js --file=" + self.options.input_file
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__':
SVGOOutput().run()