3 ms·
Hi HN, I built a PostScript interpreter from scratch in Python. PostForge implements the full PostScript Level 2 specification — operators, graphics model, fon
by AndyCappDev 8mo ago
Hi HN, I built a PostScript interpreter from scratch in Python.
PostForge implements the full PostScript Level 2 specification — operators, graphics model, font system, save/restore VM, the works. It reads .ps and .eps files and outputs PNG, PDF, SVG, or renders to an interactive Qt window.
Why build this? GhostScript is the only real game in town for PostScript interpretation, and it's a 35-year-old C codebase. I wanted something where you could actually read the code, step through execution, and understand what's happening. PostForge is modular and approachable — each operator category lives in its own file, the type system is clean, and there's an interactive prompt where you can poke at the interpreter state.
Some technical highlights:
- Full Level 2 compliance with selected Level 3 features - PDF output with Type 1 font reconstruction/subsetting and TrueType/CID embedding - ICC color management (sRGB, CMYK, Gray profiles via lcms2) - Optional Cython-compiled execution loop (15-40% speedup) - 2,500+ unit tests written in PostScript itself using a custom assertion framework - Interactive executive mode with live Qt display — useful for debugging PS programs
What it's not: A GhostScript replacement for production/printer use. It's interpreted Python, so it's slower. But it handles complex real-world PostScript files well and the output quality is solid.
I'd love feedback, especially from anyone who's worked with PostScript or built language interpreters. The architecture docs are at docs/developer/architecture-overview.md if you want to dig in.
- tonyedgecombe 8mo agoInteresting, I’ve been writing a PostScript interpreter over the last year with the intention of making it as close to the original Apple LaserWriter as possible. I’ve been using Rust for my project and so far have avoided any 3rd party libraries. I have an original LaserWriter although it won’t feed paper. I pulled the ROMs and have them running in the game emulator MAME. I’m currently working on the clip/eoclip operators.
- AndyCappDev 8mo agoYea... the first two interpreters I wrote in C used no third party libraries either. But I admit that I did not write a rasterizer for those as all they needed to do whas convert to other formats. I did write rasterization code for a Win95 driver for HP that was very fast. I used Michael Abrash's Zen of Graphics Programming as a starting point and extended/expanded on his algorithms. This time around I wanted to focus on the PostScript language itself and cairo saved me a lot of time on the hind end. Though it does have some bugs... Like it's strokepath implementation for dashed lines. I worked around them though by writing my own strokepath and feed them to cario as raw paths. The LaserWriter angle is certainly interesting though. Why specific to the LaserWriter may I ask?
- tonyedgecombe 8mo agoI did consider using Cairo but figured a simple PDF driver would take care of most of the work. That would have been fine if not for the pathforall operator. I ended up doing all the stroke path implementation for dashed lines as well. I used to work for the UK distributor for QMS who were Adobe's second largest OEM for PostScript so I had a lot of exposure to early PostScript printers. Also I've always thought the LaserWriter was more significant to Apple than most people realise. I lost count of the number of companies I visited who had a bunch of Macs and a LaserWriter networked over AppleTalk.
- fithisux 8mo agoIs there any repository?
- fithisux 8mo agoFantastic job.