Convert all SVGs to plain SVGs
- This removes the inkscape metadata that keep changing spontaneously
diff --git a/gds_to_svg.py b/gds_to_svg.py
index ea5b8f2..a2f8788 100755
--- a/gds_to_svg.py
+++ b/gds_to_svg.py
@@ -49,28 +49,23 @@
with open(tmp2_svg, 'w') as f:
f.write(data)
- # Crop the image using inkscape
- p = subprocess.Popen([
- "inkscape",
+ retcode = run_inkscape([
"--verb=FitCanvasToDrawing",
"--verb=FileSave",
"--verb=FileClose",
"--verb=FileQuit",
tmp2_svg])
- try:
- p.wait(timeout=60)
- except subprocess.TimeoutExpired as e:
- print("ERROR: Inkscape cropping timed out! Sending SIGTERM")
- p.terminate()
- try:
- p.wait(timeout=60)
- except subprocess.TimeoutExpired as e:
- print("ERROR: Inkscape cropping timed out! Sending SIGKILL")
- p.kill()
- p.wait()
+ if retcode == 0:
+ break
- if p.returncode == 0:
+ for i in range(0, 3):
+ # Convert to plain SVG
+ retcode = run_inkscape([
+ "--export-plain-svg=%s" % (tmp2_svg),
+ tmp2_svg])
+
+ if retcode == 0:
break
os.unlink(tmp1_svg)
@@ -79,5 +74,21 @@
os.rename(tmp2_svg, output_svg)
print("Created", output_svg)
+def run_inkscape(args):
+ p = subprocess.Popen(["inkscape"] + args)
+
+ try:
+ p.wait(timeout=60)
+ except subprocess.TimeoutExpired as e:
+ print("ERROR: Inkscape timed out! Sending SIGTERM")
+ p.terminate()
+ try:
+ p.wait(timeout=60)
+ except subprocess.TimeoutExpired as e:
+ print("ERROR: Inkscape timed out! Sending SIGKILL")
+ p.kill()
+ p.wait()
+
+ return p.returncode
convert_to_svg(*sys.argv[1:])