tonyedgecombe 2 days ago

My retirement project is a PostScript interpreter. I've done about 260 of the 286 operators in the original Apple LaserWriter. I'm about half way through the last tricky bit, Type 1 fonts.

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 2 days ago

    I’ve spent more time in pdf than ps, but they’re close.

    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!

    • dhosek 1 day ago

      Type 3 are PS programs, Type 1 are a special format whose format was not published outside of Adobe until the late 80s when they published the “black book” which had the format description covered in it. It’s a more compact format, with more limited capabilities (strictly splines and hinting information for each character) which I have only a vague recollection of now since it’s many decades since I dealt with data at that level.

      PDF began life as a simplified PS, stripping out the programmability aspects of the language and then gradually adding in new complications along the way because, it seems, any document specification language eventually evolves into a Turing-complete programming language.

    • tonyedgecombe 1 day ago

      >The glyphs inside Type3 fonts are themselves PS programs, right?

      Yes, Type 3 was relatively easy to implement. There are two variants, Type 3 for PostScript and Type 3 for PDF. The PostScript variant contains PostScript operators and the PDF contains PDF operators.

      I don't convert between the two, just draw the glyphs to the driver.

  • peterfirefly 2 days ago

    Probably easier to "just" emulate the LaserWriter. The firmware for some of the models is available, the 68K/68020 emulator can be downloaded from somewhere, and the rest is actually documented well enough for some models that writing an emulator is a very realistic prospect.

    • tonyedgecombe 1 day ago

      I wasn't looking for something easy, quite the opposite.

      >the 68K/68020 emulator can be downloaded from somewhere

      I have one 3rd party dependency (for parsing the command line) and that will be removed at some point.

      Also no use of AI in the project.

      • peterfirefly 1 day ago

        Cool. I might write a LaserWriter emulator at some point, though. With my own 68K emulator, of course. Other people's code is icky.

fsflyer 2 days ago

This brings back memories. In the very early 90s I took a graduate level graphics class and one assignment was to write ray tracer. The professor allowed any programming language in the class, so I used a language that was suited to the assignment. The results had to be printed out to turn in, and color printers were rare, so the assignment was in grey scale.

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.

  • mek6800d2 21 hours ago

    You reminded me of a 1993 genomics paper by D.B. Searls, "Doing sequence analysis with your printer", about Rapid Sequence Visualization in PostScript (RSVP) with which he did something similar to what you did. Two great minds, you and Searls, thought alike! https://academic.oup.com/bioinformatics/article/9/4/421/2068... (abstract, with link to PDF)

a4isms 2 days ago

My very first professional gig in the mid-80s was on a classified ad-taking application for what were then called penny-savers, physical newspaper-like publications that were nearly 100% classifieds. Penny-savers would be distributed in boxes around urban centres and could be very profitable. Our app ran on MP/M, a multi-user CP/M variant. And when it was time to go to print, our code generated PS directly, there was no "printer driver" or abstraction of any kind.

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.

glkindlmann 2 days ago

I tried to write (in C) a PostScript byte compiler for a grad school project. It is a very appealing language to work with, with the simplicity of stack machine. And like with this post, I didn't get into the graphical elements that make PostScript useful.

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.

Renina 3 days ago

Writing a tiny interpreter is one of those exercises that teaches you more about programming languages than months of just using them

nedbat 2 days ago

I worked a ton with PostScript back in the day. A few years ago I implemented an interpreter in Python, including graphics with PyCairo: https://github.com/nedbat/stilted

It was a really good vacation-week project! :)

tacostakohashi 2 days ago

I used ps / gs quite a bit for a few years as part of work early in my career... 20 years ago. I rather enjoyed it.

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.

librasteve 17 hours ago

According to my fading brain Weitek Corp (of FPU fame) wrote a clean room PostScript clone (commissioned by Apple) in the 1980s. Technically the tricky bits were font hints, so they had a light table and compared bit for bit output with that from an Apple LaserWriter. Commercially the plan was for Apple to have source code of a legitimate clone to avoid being dependent on Adobe as a monopoly supplier. I don’t think it ever made it to production with Apple, but maybe Canon? Anyway whoever picked up the Weitek IP rights probably could decide to open source it after all these years, I guess.

fjfaase 2 days ago

Nice page. In 2009, I wrote ('hacked together') a partial PostScript interpreter in C to debug some PostScript code I was writing to reproduce plate 13 from the Eléments de l'art arabe by Jules Bourgoin as reproduced in Arabic Geometrical Pattern & Design.

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.

TacticalCoder 2 days ago

I still mess with PostScript once in a while. For example I generate little puzzles for my daughter/nephews (words to find in an hexagonal grid, where each hexagon contains one letter): wrote that in Clojure but it generates PostScript (nowadays I could ask a LLM to write the whole thing for me though as the potential for disaster is limited).

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.

  • robinsonb5 2 days ago

    I've written more Postscript in the last year than the preceding 20, doing weird specific impositions of variable data printing jobs that InDesign just isn't flexible enough to handle.

    It's been a joy to dust off those skills!

pstuart 1 day ago

This brings to mind Don Lancaster's articles on the power of PostScript.

His site is still available although he reached EOF a couple years ago: https://www.tinaja.com/pssamp1.shtml

I had the Blue and Red books and spent time spelunking in PS but ADHD made staying with that impossible.

throwaway81523 3 days ago

Postscript (the language) is very simple, given run of the mill interpreter machinery. An actual working Postscript implementation is about graphics and font rendering, not the language interpreter. That stuff is still not trivial.

  • cmrx64 2 days ago

    the amount of care to detail in the base language is great though. reading PLRM is a joy

  • dang 1 day ago

    Whoa - please don't post swipes or put down other people's work. Your comment would be fine without that first bit, which is mean and superfluous.

    If you wouldn't mind reviewing https://news.ycombinator.com/newsguidelines.html and taking the intended spirit of the site more to heart, we'd be grateful.

    • throwaway81523 23 hours ago

      Oops, sorry, I didn't realize that the developer had posted it. Anyway yes, implementing interpreters is fun, and PostScript has cool ideas in it while still being reasonably efficient on limited CPU's like the one in the original Apple LaserWriter. Besides the language itself though, implementing the graphics primitives (font rendering, shading, colors, etc.) are likely to be an even bigger challenge than writing the interpreter.

      Dang, please feel free to delete my original comment if it's inappropriate.

      • dang 22 hours ago

        Thanks for the kind reply. I've taken the liberty of removing the swipe ("This is a yawner, ") and also removing the downvotes and flags on your GP comment. I hope that's ok! (That way we get the substantive part of what you post, and you don't get the hit for the bit that no longer exists.)