From b344229c95f3d0d37709aeb2e2ae969786f9d363 Mon Sep 17 00:00:00 2001 From: Florian Festi Date: Thu, 27 May 2021 22:50:10 +0200 Subject: [PATCH] Add metadata to PostScript output as title, creator and further comments. Unfortunately pstoedit does drop these when converting to other formats. A pity. --- boxes/drawing.py | 30 +++++++++++++++++++++++++++--- documentation/src/faq.rst | 2 +- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/boxes/drawing.py b/boxes/drawing.py index 9fec63a..99c9c89 100644 --- a/boxes/drawing.py +++ b/boxes/drawing.py @@ -577,6 +577,30 @@ class PSSurface(Surface): ('monospaced', True, True) : 'Courier-BoldOblique', } + def _metadata(self): + md = self.metadata + + desc = "" + desc += "%%Title: Boxes.py - {group} - {name}\n".format(**md) + desc += f'%%CreationDate: {datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")}\n' + desc += f'%%Keywords: boxes.py, laser, laser cutter\n' + desc += f'%%Creator: {md.get("url") or md["cli"]}\n' + desc += "%%CreatedBy: Boxes.py (https://festi.info/boxes.py)\n" + for line in (md["short_description"] or "").split("\n"): + desc += "%% %s\n" % line + desc += "%\n" + if "description" in md and md["description"]: + desc += "%\n" + for line in md["description"].split("\n"): + desc += "%% %s\n" % line + desc += "%\n" + + desc += "%% Command line: %s\n" % md["cli"] + if md["url"]: + desc += f'%%Url: {md["url"]}\n' + desc += f'%%SettingsUrl: {md["url"].replace("&render=1", "")}\n' + return desc + def finish(self): extents = self._adjust_coordinates() @@ -586,9 +610,9 @@ class PSSurface(Surface): f = open(self._fname, "w", encoding="latin1", errors="replace") f.write("%!PS-Adobe-2.0\n") - f.write( - f"""%%BoundingBox: 0 0 {w:.0f} {h:.0f} - + f.write(f"%%BoundingBox: 0 0 {w:.0f} {h:.0f}\n") + f.write(self._metadata()) + f.write(""" 1 setlinecap 1 setlinejoin 0.0 0.0 0.0 setrgbcolor diff --git a/documentation/src/faq.rst b/documentation/src/faq.rst index 4420517..aea26cc 100644 --- a/documentation/src/faq.rst +++ b/documentation/src/faq.rst @@ -42,7 +42,7 @@ You can just set ``burn`` to ``0`` to make them go away. But you have then to us What settings were used to generate a drawing? ---------------------------------------------- -If you do have the SVG you can look into the meta data of the file. E.g. by opening it with ``Inkscape`` and look into the ``metadata`` tab in ``Document properties``. You can also just open the file with a text editor and find the details at the beginning of the file. +If you do have the SVG or PostScriptyou can look into the meta data of the file. Most document viewers will have a ``Document properties`` window. You can also just open the file with a text editor and find the details at the first few lines. Note that you can just use the URL in there to get back to the settings page to change some values. The difference between the settings and the rendered drawing is just ``render=0`` or ``render=1`` at the end of the URL.