# I built a zero-browser, pure-JS typesetting engine for bit-…

Hi HN, I'm a film director by trade, and I prefer writing my stories in plain text rather than using clunky screenplay software. Standard markup like Fountain doesn't work for me because I write in mixed languages, so I use Markdown with a custom syntax I invented to resemble standard screenplay st…

- **Page:** https://magpie.gallery/i/i-built-a-zero-browser-pure-js-typesetting-engine-8t55
- **Type:** Link to an idea elsewhere
- **Category:** Creative & design
- **Tags:** typesetting, screenplay, pdf, markdown, javascript

## Source

Web · cosmiciron: I built a zero-browser, pure-JS typesetting engine for bit-perfect PDFs

- **Original:** https://news.ycombinator.com/item?id=47206082

> Hi HN, I'm a film director by trade, and I prefer writing my stories in plain text rather than using clunky screenplay software. Standard markup like Fountain doesn't work for me because I write in mixed languages, so I use Markdown with a custom syntax I invented to resemble standard screenplay structures. This workflow is great until I need to actually generate an industry-standard screenplay PDF. I got tired of manually copying and pasting my text back into the clunky software just to export it, so I decided to write a script to automate the process. That's when I hit a wall. I tried using React-pdf and other high-level libraries, but they failed me on two fronts: true multilingual text shaping, and complex contextual pagination. Specifically, the strict screenplay requirement to automatically inject (MORE) at the bottom of a page and (CONT'D) at the top of the next page when a character's dialogue is split across a page break. You can't really do that elegantly when the layout engine is a black box. So, I bypassed them and built my own typesetting engine from scratch. VMPrint is a deterministic, zero-browser layout VM written in pure TypeScript. It abandons the DOM entirely. It loads OpenType fonts, runs grapheme-accurate text segmentation (Intl.Segmenter), calculates interval-arithmetic spatial boundaries for text wrapping, and outputs a flat array of absolute coordinates. Some stats: Zero dependencies on Node.js APIs or the DOM (runs in Cloudflare Workers, Lambda, browser). 88 KiB core packed. Performance: On a Snapdragon Elite ARM chip, the engine's "God Fixture" (8 pages of mixed CJK, Arabic RTL, drop caps, and multi-page spanning tables) completes layout and rendering in ~28ms. The repo also includes draft2final, the CLI tool I built to convert Markdown into publication-grade PDFs (including the screenplay flavor) using this engine. This is my first open-source launch. The manuscript is still waiting, but the engine shipped instead. I’d love to hear your th

## GitHub projects

- https://github.com/cosmiciron/vmprint

## Rules for reuse

- Build your own version: don't copy another product's code, look, icons, colours or copy.
- The original belongs to its author; Magpie only links to it.
- The original content's copyright belongs to its creator. Magpie doesn't download or re-upload it; we only show the link and the official preview.
