Hi HN, happy new year!<p>TrueType is really a neat and fun format, packed with esoterica. This post gives some background on the problem of text rendering in general, explains how TrueType works under the hood, and contains lots of tidbits that I hope will be interesting.<p>There’s also a bunch of screenshots of the in-progress renderer stumbling over itself. I hope you enjoy the read!
The first startup I worked at was a TrueType font specialist. We had one of the best auto-hinters and decent manual tooling for improving the auto-hinting.<p>Ultimately, we ran out of traction and money as the CDs full of 100 fonts for $10 came out, but we did some of the original System 7 and Win 3.1 fonts.<p>It is a cool format and stack-based language and was an enjoyable and educational time in my career.
Great to see more accessible references on font internals! I have dabbled on this a bit last year and managed to have a parser and render the points in a glyph's contour (I stopped before Bezier and shape filling stuff). I still have not considered hinting, so it's nice that it's covered. Besides Apple's and Microsoft's extensive documentations, what really helped me is an article from the Handmade Network [1] and the source of stb_truetype [2] (also used in Dear ImGUI).<p>[1] <a href="https://handmade.network/forums/articles/t/7330-implementing_a_font_reader_and_rasterizer_from_scratch%252C_part_1__ttf_font_reader" rel="nofollow">https://handmade.network/forums/articles/t/7330-implementing...</a>.<p>[2] <a href="https://github.com/nothings/stb/blob/master/stb_truetype.h">https://github.com/nothings/stb/blob/master/stb_truetype.h</a>
I really appreciate that you provided a bunch of screenshots of the in-progress development. Graphics programming is very challenging, and it can be frustrating to feel like you've spent multiple days just rendering glitch art. It's always good to show others how much we struggle even if we're experts :)<p>Having recently implemented a subset of opentype kerning, I can only imagine how stressful it was to implement the whole core truetype spec...
Wrote a truetype rasterizer about 20 years ago. I took the easy way out and just simply antialised everything, didn't even try to support TrueType hinting programs.<p>Sure, things looked blurry, but it didn't matter much when everything would be rotated into weird angles and sizes anyways.<p>Bezier and implementing correct and FAST filling rules took a lot of effort.
"There’s few things in this world I love more than taking an opaque binary and gradually uncovering the organization that was present all along. Dissecting the underlying and general structure of a binary is as gratifying as anything I can imagine."<p>Yes!
Working in games, font code is truely the depths of hell that you try to punt to someone else as often as you can.<p>Maybe one day we will support right to left text!
For a problem that is theoretically binary (either in, or out?) filling polys can have really fiddly corner (literally!) cases.<p>Thanks for the WIP screenshots; they made me feel much better about my own slicers/rasterisers.<p>(there's probably a trick I'm missing*, but so far I've had the most robust results for 3D booleans by chasing fiddly overlaps/intersections on lower facets, all the way down to 0-D if necessary)<p>* like working directly with cubics, à la Jim Blinn?
I wonder, is there something on the complexity curve between 8x8 bitmap and fullblown ttf with all the complexity as you've outlined?<p>It would be nice if there were a solution which gets 90% of the value in 10% of the code.
I think TTF isn't that difficult if you just want the basics; I wrote a TTF viewer that simply dumped the outlines into GDI and let the latter do the rasterisation, without any hinting or other fancy stuff. Less than 400 LoC in total including the UI code, and the binary was 7KB.
I couldn't readily tell if this was related to the recent 37C3 iPhone submission, but in case someone missed the irony: <a href="https://securelist.com/operation-triangulation-the-last-hardware-mystery/111669/" rel="nofollow">https://securelist.com/operation-triangulation-the-last-hard...</a> was RCE-ed via a truetype file and it's always been just the gift that keeps on giving <a href="https://cve.mitre.org/cgi-bin/cvekey.cgi?keyword=truetype" rel="nofollow">https://cve.mitre.org/cgi-bin/cvekey.cgi?keyword=truetype</a>
Great article, I’ve had the fun of implementing TTF rendering and this piece hits all the memorable points.<p>One nit, the comparison to Mach-O is anachronistic as TrueType was developed in the late 1980s, while Apple didn’t acquire NeXT until 1996.
Fascinating! I created a tool to parse information out of an OTF for uploading new fonts to a font foundry website so already had some idea of how complex they are (even with the help of “fonttools”, which is a great way to explore to the various tables), but I had no idea about some of this - for example, the VM for hinting!
Correct me if I'm wrong, but I think font hinting isn't needed for high DPI displays? I believe macOS Mojave removed subpixel anti-aliasing because Apple doesn't ship anything but high DPI displays anymore.
Can someone explain how connecting the dots works? How does it know which dot is connected to which? For example, in the curve of an S, the closest dot to the top curve might be under it, instead of beside it.