Add metadata to PostScript output

as title, creator and further comments.
Unfortunately pstoedit does drop these when converting to other
formats. A pity.
This commit is contained in:
Florian Festi 2021-05-27 22:50:10 +02:00
parent be7115007d
commit b344229c95
2 changed files with 28 additions and 4 deletions

View File

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

View File

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