Show HN: QR code renderer in a TrueType font

qr.jim.sh

114 points by foodevl 1 week ago

In 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).

layer8 6 days ago

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.

  • sosborn 1 day ago

    If they know it's a url, all they need to do is wrap it in an <a> tag. Laziness probably wins out though.

  • extraduder_ire 17 hours ago

    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.

dlcarrier 18 hours ago

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.)

WenboS 1 week ago

This is absolute black magic. I never realized OpenType rules were powerful enough to render something as complex as a QR matrix inline.

  • giraffe_lady 6 days ago

    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.

    • asveikau 1 day ago

      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.

      • butvacuum 1 day ago

        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.

      • WorldMaker 1 day ago

        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

jqpabc123 6 days ago

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.

bigboss2700 1 week ago

That's a wonderfully cursed idea.

magnat 6 days ago

Selecting parts of the code (in F7 mode or with SHIFT-LEFT/RIGHT) highlights which individual pixels corresponds to the actual letters.

1bpp 1 week ago

This is terrifying, great job!

henryagi 6 days ago

That's a wonderfully idea. I Like

red_hare 6 days ago

Wow. This is so freaking cool.