From b1af53eff0e379a607a4f0e9b9d5476d8a26b5e3 Mon Sep 17 00:00:00 2001 From: Florian Festi Date: Fri, 24 Feb 2023 14:34:13 +0100 Subject: [PATCH] Use full command line for converting file formats and no longer rely on pstoedit being the only tool used Use ps2pdf from GhostScript (which should already be needed by pstoedit) for PDF as it supports keeping the page size from the eps file --- boxes/formats.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/boxes/formats.py b/boxes/formats.py index 98f82c9..c854ce4 100644 --- a/boxes/formats.py +++ b/boxes/formats.py @@ -26,6 +26,7 @@ from boxes.drawing import SVGSurface, PSSurface, LBRN2Surface, Context class Formats: pstoedit_candidates = ["/usr/bin/pstoedit", "pstoedit", "pstoedit.exe"] + ps2pdf_candidates = ["/usr/bin/ps2pdf", "ps2pdf", "ps2pdf.exe"] _BASE_FORMATS = ['svg', 'svg_Ponoko', 'ps', 'lbrn2'] @@ -34,11 +35,11 @@ class Formats: "svg_Ponoko": None, "ps": None, "lbrn2": None, - "dxf": "-flat 0.1 -f dxf:-mm".split(), - "gcode": "-f gcode".split(), - "plt": "-f plot-hpgl".split(), - "ai": "-f ps2ai".split(), - "pdf": "-f pdf".split(), + "dxf": "{pstoedit} -flat 0.1 -f dxf:-mm {input} {output}", + "gcode": "{pstoedit} -f gcode {input} {output}", + "plt": "{pstoedit} -f plot-hpgl {input} {output}", + "ai": "{pstoedit} -f ps2ai {input} {output}", + "pdf": "{ps2pdf} -dEPSCrop {input} {output}", } http_headers = { @@ -58,6 +59,10 @@ class Formats: self.pstoedit = shutil.which(cmd) if self.pstoedit: break + for cmd in self.ps2pdf_candidates: + self.ps2pdf = shutil.which(cmd) + if self.ps2pdf: + break def getFormats(self): if self.pstoedit: @@ -79,7 +84,12 @@ class Formats: if fmt not in self._BASE_FORMATS: fd, tmpfile = tempfile.mkstemp(dir=os.path.dirname(filename)) - cmd = [self.pstoedit] + self.formats[fmt] + [filename, tmpfile] + cmd = self.formats[fmt].format( + pstoedit=self.pstoedit, + ps2pdf=self.ps2pdf, + input=filename, + output=tmpfile).split() + err = subprocess.call(cmd) if err: