Hacker News
Let's Write a PostScript Interpreter
tonyedgecombe
|next
[-]
The internals are quite interesting, I always assumed the interpreter just processed the input as it arrives but it actually starts a PostScript program as soon as the printer boots and that controls the hardware and handling incoming jobs. A lot of this code is available through a console, ie:
userdict begin /start load == end
dumps the first program started by the printer.I have an original LaserWriter which works through the console but doesn't print. Luckily someone has done the work to get the firmware running in MAME.
My interest in this came from working with a QMS distributor in the eighties. At the time I didn't really have a chance to delve that deep into the technology but I was always fascinated by it.
aidos
|root
|parent
|next
[-]
Digging into these details is closer to digital archeology than anything else.
The glyphs inside Type3 fonts are themselves PS programs, right? Theres so much interesting history hidden inside the structure (and in some cases you find weird little edges in the codebases that define the behaviour in a way where that’s likely the only place it lives). There’s decades of legacy in how to draw things with computers.
Glad I’m not the only one who still thinks it’s fascinating enough to spend time understanding!
peterfirefly
|root
|parent
|previous
[-]
fsflyer
|next
|previous
[-]
The postscript image operator in Postscript takes a procedure to return data and it was simple to encode the scene in that procedure. The Postscript image operator scaled the image data between the 500 pixels that image was required to be and the 300 dpi printer resolution and did the grey scale mapping.
The postscript program fit on two pages with comments, many classmates had C or Pascal programs over 20 pages.
The 12 MHz 68000 in the LaserWriter was faster than the 8 MHz in the early Macintoshes or the 4.77 MHz 8086 in the PC clones, so it actually ran faster than many of the other student's ray tracers.
glkindlmann
|next
|previous
[-]
Mainly I learned that Ghostscript is doing a lot to make its PostScript interpreter fast: with the non-graphical test programs I could think up, GhostScript was many times faster interpreting the program (even computationally intensive ones) than my runtime (called "egon") could execute the byte-compiled PostScript. So it was a computation fail but still a pedagogy win.
I've always been meaning to learn more about how Ghostscript is engineered.
a4isms
|next
|previous
[-]
We sold our customers two Apple LaserWriters each, because if one went down just before going to print they'd be screwed. We would print on both in parallel for speed, but could fall back to just one. And the printed ads? Somebody over in the print shop would cut them out in strips and then paste those strips up to be photographed for the printing press. We didn't have full end-to-end digital yet.
PS wasn't easy, but it was very grokkable.
ptspts
|next
|previous
[-]
nedbat
|next
|previous
[-]
It was a really good vacation-week project! :)
tacostakohashi
|next
|previous
[-]
I had always hoped I could work more in that area later on... like either writing printer drivers, printer firmware, work at artifex/ghostsript, etc. Unfortunately though, it seems like employers really don't hire for specific skills/domains like that, they just hire generic embedded / software developers and put them to work on postscript or whatever else they have after the fact. Oh well.
fjfaase
|next
|previous
[-]
Program: https://www.iwriteiam.nl/PostScript_c.txt
PostScript file with first 31 plates: https://www.iwriteiam.nl/Bourgoin.ps
I do not know why I stopped at that point. Maybe it was because I realized that I should have used another approach to describe the geometric patterns and did not want to refactor all the PostScript I already wrote. But it might also that I got obsessed with another problem.
Renina
|next
|previous
[-]
TacticalCoder
|next
|previous
[-]
Then there's that one utility company who screws up my montly invoice and so, invariably, when I need to do KYC for whatever bullshit-state-surveillance reason (which, invariably, happens all the time), KYC fails for my official address doesn't match the technical address the utility company is using on my invoices.
So the PDF gets converted to PostScript, I edit the PostScript, and convert back to PDF. Nowadays I take it I could also have a LLM do it all for me but the thing is: I don't want my PDF to look like a PDF which has been tempered with (which it definitely has been, but fuck KYC and screw that utility company for not using my proper official address). So I like the PDF to PostScript to edit back to PDF cycle.