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
This commit is contained in:
Florian Festi 2023-02-24 14:34:13 +01:00
parent b605693925
commit b1af53eff0
1 changed files with 16 additions and 6 deletions

View File

@ -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: