Show HN: QR code renderer in a TrueType font
qr.jim.shIn the "Libre Barcode Project" discussion yesterday, 1bpp asked: "Is anyone willing to sacrifice their sanity for the sake of implementing a QR renderer as TTF hinting code?"
Yes. I had some tokens to burn and was curious... turns out, it's possible. This was put together by a mix of Gemini, GPT, and Claude (depending on which usage limits kept running out).
Side question: Why is nobody making QR codes on web pages clickable (regardless if it’s an image or text-based)? Not every QR code represents a URL, of course, but many do. Maybe there should be a qrcode URL scheme that lets browsers behave the same way as a camera scanning a QR code.
If they know it's a url, all they need to do is wrap it in an <a> tag. Laziness probably wins out though.
I am surprised no browser/OS that I've seen allows scanning them from the screen using an interface like the one used to take a screenshot.
This would be even better if it used reserved characters instead of brackets, so you could also use it as a normal font. You could even use different characters to start different QR code sizes. E.g. type 'ctrl+shift+u 11 enter' to start the QR code and 'ctrl+shift+u 14 enter' to end it, but for larger QR codes enter 12 or 13, instead of 11. (Or maybe you'd need to change the end character, to select the QR code size.)
This is absolute black magic. I never realized OpenType rules were powerful enough to render something as complex as a QR matrix inline.
Font shaping rules are actually turing complete. An incredible amount of engineering effort has gone into this not being a total disaster everywhere at all times.
Coming late to this thread, but this is reminding me that many remote execution vulnerabilities have come from font rendering code paths.
If there is a turing complete VM inside the font renderer that makes perfect sense.
I'm not sure if it's the case but at one point on Windows, font rendering happened in the kernel.
Microsoft began the push to move TTF rendering out of the kernel in Vista. I'm sure there are still bits here-and-there that are still kernel.
as an aside- I find the fact even microsoft's own modal dialogs don't all support DPI scaling- aka they are blurry.
More than one Turing Complete VM inside the font renderer stack, at that. One of the biggest recurring CVE generators in both Windows and Macintosh was 1984's legacy of the Adobe Type 1 font format [1]. Everyone had to license it for backward compatibility with PostScript documents. It shared enough Turing completeness with PostScript despite being a subset.
Both Windows and Macintosh spent years trying to isolate type rendering from kernel operations specifically because of Adobe Type 1's legacy alone, including the fact that it was an ugly vendored 3rd party spaghetti. IIRC, both Apple and Microsoft ended up paying Adobe tons of money to rewrite their Type 1 Font Manager code from scratch rather than keep paying Adobe to write that code. (TTF and OpenType were also both somewhat direct responses to Type 1's legacy and mistakes.)
[1] https://en.wikipedia.org/wiki/PostScript_fonts
It’s basically Turing-complete: https://simoncozens.github.io/fonts-and-layout/features.html
Once something is Turing-complete, the magic turns from black to white. ;)
1bpp's comment suggesting this yesterday: https://news.ycombinator.com/item?id=48682460
See https://github.com/jimparis/qr-font/blob/master/design.md for the actual design. As who have written a QR code encoder library... I'm in shock and awe.
Impressive work!
Not mentioned is the fact that the resulting QR Fonts are huge --- much larger than the javascript needed to render a QR code.
That's a wonderfully cursed idea.
Selecting parts of the code (in F7 mode or with SHIFT-LEFT/RIGHT) highlights which individual pixels corresponds to the actual letters.
This is terrifying, great job!
That's a wonderfully idea. I Like
Wow. This is so freaking cool.