Unfortunately, your complex script shaping for Arabic and Devanagari is wrong. The Arabic is missing the joining (all forms are isolated), and the Devanagari doesn't have the vowels combining (so you see those dotted circles).
To fix this you'll need Harfbuzz or something similar. Taking a quick look at the code, it seems like you're just doing a glyph at a time through the cmap. That, uh, won't do.
You are completely right on all fronts. Thank you for taking a look at the code!
You hit the exact architectural bottleneck. Right now, the engine uses Intl.Segmenter to find the grapheme boundaries, but then it just does a direct cmap lookup to get the advance widths. It currently lacks a parser for the OpenType GSUB (Glyph Substitution) and GPOS (Glyph Positioning) tables, which is why Arabic defaults to isolated forms and Indic matras don't fuse.
The standard advice is exactly what you suggested: "just drop in HarfBuzz." But that creates an existential problem for this specific project. HarfBuzz is a massive C++ library. To run it in an Edge worker or pure V8 environment, I'd have to ship a WebAssembly binary that is often upwards of 1MB. That entirely defeats the purpose of building an 88 KiB, pure-JS, zero-dependency layout VM.
Doing complex text layout (CTL) and shaping purely in JavaScript without exploding the bundle size is essentially the final boss of this project. The roadmap is to either implement a highly tree-shakeable, pure-JS parser for the most critical GSUB/GPOS rules, or find a way to pre-compile shaping instructions.
For right now, it's a known trade-off: lightning-fast, edge-native pure JS layout, at the cost of failing on complex cursive ligatures. If you know of any micro-footprint pure-JS shaping libraries that don't rely on WASM, I am all ears!
Looks interesting, but the "Why Not Just Use" section in the readme is definitely missing Typst. Would be interesting to know how they compare, since Typst is the obvious choice for typesetting nowadays, rather than LaTeX.
That is a very fair point, and I will absolutely add Typst to the "Why not just use..." section of the README! Typst is a phenomenal piece of software, but it operates in a very different architectural space than VMPrint.
The core differences come down to the runtime environment and the integration paradigm:
1. Edge-Native vs. WASM: Typst is written in Rust. To run it in a serverless environment, you have to ship and instantiate a WebAssembly binary. In strict Edge environments (like Cloudflare Workers or Vercel Edge) where bundle sizes and cold starts are heavily penalized, WASM can be a bottleneck. VMPrint is an 88 KiB pure-JS engine. It drops natively into any V8/Edge runtime with zero WASM bridge, allowing you to synchronously generate and stream deterministic PDFs directly from the edge in milliseconds.
2. Programmatic AST vs. Custom Markup: Typst is a markup compiler—you write in its .typ language. VMPrint is a lower-level layout VM. It doesn't parse markup; it consumes a flat JSON instruction stream (an AST) and spits out absolute X/Y coordinates. It's designed for developers who want to build their own custom document generators programmatically, rather than writing a document by hand.
3. Mid-Flight Pagination Control: My specific pain point was screenplays. I needed strict contextual rules, like automatically injecting (MORE) at the bottom of a page and (CONT'D) at the top of the next if a dialogue block splits across a page break. Achieving that kind of hyper-specific programmatic intervention is tough in a closed compiler. With VMPrint's two-stage pipeline, you have absolute access to the layout tree in native JS to manipulate it before it ever hits the renderer.
In short: if you want a beautiful, incredibly fast LaTeX replacement to write documents, use Typst. If you are a JS developer who needs to build a custom document pipeline and wants a lightweight, native layout VM to run the heavy math at the edge, that's VMPrint.
Incredible eye. You are absolutely right, and that is actually an artifact of the engine's current architecture!
That screenshot includes the Hindi word 'देवनागरी' (Devanagari) and some Arabic text with diacritics. Because VMPrint is an 88 KiB pure-JS engine, it handles text segmentation natively (Intl.Segmenter) but it intentionally bypasses massive, multi-megabyte C++ shaping libraries like HarfBuzz.
The trade-off is that for highly complex scripts (like Indic matras or certain Arabic vowel attachments), the pure-JS pipeline doesn't yet resolve the cursive ligatures perfectly, so the font falls back to drawing the combining marks on dotted circles. It mathematically calculates the bounding boxes correctly, but the visual glyph substitution isn't fused. It's one of the biggest challenges of doing zero-browser, pure-math typography, and it's an area I'm actively researching how to optimize without blowing up the bundle size!
Unfortunately, your complex script shaping for Arabic and Devanagari is wrong. The Arabic is missing the joining (all forms are isolated), and the Devanagari doesn't have the vowels combining (so you see those dotted circles).
To fix this you'll need Harfbuzz or something similar. Taking a quick look at the code, it seems like you're just doing a glyph at a time through the cmap. That, uh, won't do.
You are completely right on all fronts. Thank you for taking a look at the code!
You hit the exact architectural bottleneck. Right now, the engine uses Intl.Segmenter to find the grapheme boundaries, but then it just does a direct cmap lookup to get the advance widths. It currently lacks a parser for the OpenType GSUB (Glyph Substitution) and GPOS (Glyph Positioning) tables, which is why Arabic defaults to isolated forms and Indic matras don't fuse.
The standard advice is exactly what you suggested: "just drop in HarfBuzz." But that creates an existential problem for this specific project. HarfBuzz is a massive C++ library. To run it in an Edge worker or pure V8 environment, I'd have to ship a WebAssembly binary that is often upwards of 1MB. That entirely defeats the purpose of building an 88 KiB, pure-JS, zero-dependency layout VM.
Doing complex text layout (CTL) and shaping purely in JavaScript without exploding the bundle size is essentially the final boss of this project. The roadmap is to either implement a highly tree-shakeable, pure-JS parser for the most critical GSUB/GPOS rules, or find a way to pre-compile shaping instructions.
For right now, it's a known trade-off: lightning-fast, edge-native pure JS layout, at the cost of failing on complex cursive ligatures. If you know of any micro-footprint pure-JS shaping libraries that don't rely on WASM, I am all ears!
Looks interesting, but the "Why Not Just Use" section in the readme is definitely missing Typst. Would be interesting to know how they compare, since Typst is the obvious choice for typesetting nowadays, rather than LaTeX.
That is a very fair point, and I will absolutely add Typst to the "Why not just use..." section of the README! Typst is a phenomenal piece of software, but it operates in a very different architectural space than VMPrint.
The core differences come down to the runtime environment and the integration paradigm:
1. Edge-Native vs. WASM: Typst is written in Rust. To run it in a serverless environment, you have to ship and instantiate a WebAssembly binary. In strict Edge environments (like Cloudflare Workers or Vercel Edge) where bundle sizes and cold starts are heavily penalized, WASM can be a bottleneck. VMPrint is an 88 KiB pure-JS engine. It drops natively into any V8/Edge runtime with zero WASM bridge, allowing you to synchronously generate and stream deterministic PDFs directly from the edge in milliseconds.
2. Programmatic AST vs. Custom Markup: Typst is a markup compiler—you write in its .typ language. VMPrint is a lower-level layout VM. It doesn't parse markup; it consumes a flat JSON instruction stream (an AST) and spits out absolute X/Y coordinates. It's designed for developers who want to build their own custom document generators programmatically, rather than writing a document by hand.
3. Mid-Flight Pagination Control: My specific pain point was screenplays. I needed strict contextual rules, like automatically injecting (MORE) at the bottom of a page and (CONT'D) at the top of the next if a dialogue block splits across a page break. Achieving that kind of hyper-specific programmatic intervention is tough in a closed compiler. With VMPrint's two-stage pipeline, you have absolute access to the layout tree in native JS to manipulate it before it ever hits the renderer.
In short: if you want a beautiful, incredibly fast LaTeX replacement to write documents, use Typst. If you are a JS developer who needs to build a custom document pipeline and wants a lightweight, native layout VM to run the heavy math at the edge, that's VMPrint.
Oh man -- I just wrote of these browserless markdown to pdf a few days ago.... Thanks for publishing [https://github.com/speajus/markdown-to-pdf.git](https://speajus.github.io/markdown-to-pdf). I didn't need anything this exacting. Anyways nice work; excited to look deeper.
Define "I"
devnagri in the screenshot is wrongly rendered.
Also can you share some names of films you have been part of as film director.
Every single screenshot of Arabic in the README is malformed, the letters are squished together and not connected.
Are Unicode combining characters (dotted circles) visible on the screenshot by design?
Incredible eye. You are absolutely right, and that is actually an artifact of the engine's current architecture!
That screenshot includes the Hindi word 'देवनागरी' (Devanagari) and some Arabic text with diacritics. Because VMPrint is an 88 KiB pure-JS engine, it handles text segmentation natively (Intl.Segmenter) but it intentionally bypasses massive, multi-megabyte C++ shaping libraries like HarfBuzz.
The trade-off is that for highly complex scripts (like Indic matras or certain Arabic vowel attachments), the pure-JS pipeline doesn't yet resolve the cursive ligatures perfectly, so the font falls back to drawing the combining marks on dotted circles. It mathematically calculates the bounding boxes correctly, but the visual glyph substitution isn't fused. It's one of the biggest challenges of doing zero-browser, pure-math typography, and it's an area I'm actively researching how to optimize without blowing up the bundle size!