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.
There’s also a bunch of screenshots of the in-progress renderer stumbling over itself. I hope you enjoy the read!
It would be nice if there were a solution which gets 90% of the value in 10% of the code.
And once upon a time, X11 had another weird little format besides PS and TTF fonts, namely "Speedo" fonts[1]. Also used in plenty of other software, as PS/TTF weren't that common and it was made by Bitstream, one of the major font foundry (because no font format helps if there are no legal fonts available for it).
Alas, both not really in use these days.
(like with the pixel grill on CRTs, often older digital formats were subject to some sort of analogue low-pass filtering before being perceived)
https://paulbourke.net/dataformats/hershey/
It seems to describe a "pen" which draws the character. It is indeed pretty cool!
https://github.com/Michaelangel007/game_dev_pdfs/blob/master...
Very simple at their core but you can incrementally do more work to increase the fidelity you get out of them.
My Ruby rewrite is ~600 lines: https://github.com/vidarh/skrift
Libschrift is very readable.
I did my Ruby rewrite basically just top to bottom before reorganizing it. Mine is... readable if you're well versed in Ruby, but still has some warts where it's less than idiomatic Ruby because I stuck closely to the original.
Basically TTF has a crufty binary format, but the basic font data if you're willing to ignore ligatures, hinting, OpenType support and emoticons, is fairly simple (it's basically a bunch of polygons consisting of quadratic beziers and lines, and quadratic beziers are easy to tesselate into lines if you don't want to do a more complex curve renderer), just error-prone to figure out.
If you want/need OpenType you need to support cubic beziers on top of that, which isn't that bad. If you want to support emoticons you need to support a subset of SVG (!)...
So TTF without those bits is pretty much the halfway point.
Also do look at the Canvas C++ header implementation linked in this comment[1]. It's readable, and more featureful than libschrift or my Ruby rewrite, and it's still small while packing a full rendering library in there not just the font renderer. I intend to pillage it (with credits) for ideas ;)
finally, an approach that's conceptually simpler that i've never seen used (though metafont comes close) is to represent the font as a subroutine in a turing-complete bytecode that takes a glyph index as input and produces an image with font metrics data as output. something like the universal machine from the cult of the bound variable is only about a page of code. this requires you to put the bezier rasterization and polygon filling code in your font file instead, so it doesn't simplify the total system
Before TrueType (System 7, 1991), it was the only thing the OS supported out of the box.
(Adobe Type Manager (https://en.wikipedia.org/wiki/Adobe_Type_Manager) is a bit older than 1991, but (obviously from its name) wasn’t an Apple product)
Maybe one day we will support right to left text!
It's not quite one of the "misconceptions programmers have about ..." but in the same vein, IMHO
I have seen some extremely-UI-heavy games which do exactly what you say; building a whole windowing environment entirely from scratch. (I'm working on a game that's doing that right now!).
But most major game engines provide a basic UI toolkit if your needs aren't too intense, and those are often more than enough for most games and are a whole heap less effort; they can typically be themed so that your UI doesn't look like everybody else's UI, and if all you need is a single window with some widgets and buttons and maybe a text field, that's probably going to be more than enough for you. Like, 95% of games would probably be totally fine with just that.
Maybe five years back I worked on and adjacent to a couple large games that were building their UI in an embedded copy of Flash (which wasn't as dead as people think!) Not sure whether large games are still doing that now, but it wouldn't surprise me if there are still some holdouts building their game UIs entirely in Flash!
If you see a font you think is cool, you can pretty much rip off the style without any real consequences. This is often why font licenses for print media are priced very differently than digital media where the font is redistributed.
Both the 68k and PPC (as configured for macs) were big endian.
You’re right that sub-pixel (color) antialiasing has been removed from macOS but regular grayscale antialiasing, and hinting, remain.
My reasoning for not bothering was much what you suggest - if it's acceptable to me now on a resolution that low, I'm not sure I see the point in supporting even worse conditions given how cheap 4K displays are. The need for hinting is only going to go down.
Maybe one day, but I'll note e.g. FreeType also did a lot of work on auto-hinting because as it turns out the hinting in a lot of TTF files is pure garbage.
[1] https://github.com/tomolt/libschrift
[2] https://github.com/vidarh/skrift - X11 integration in https://github.com/vidarh/skrift-x11
People still connect their Apple computers to low-DPI monitors all the time. High-DPI monitors are still a rarity. There's the LG UltraFine, the Studio Display (too expensive for what it is), the Pro Display XDR (the $1000 stand lmao), and that's really it.
I'm writing this comment on a 2K monitor connected to a modern MacBook.
They do, but the fonts are visibly blurry on those, as they did indeed remove the subpixel antialiasing. Thankfully, the Gtk4 developers removed it as well, so Linux (or at least the GNOME desktop) will soon look like crap as well.
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.
It's probably closer to quicktime, which are the basis of mp4.
> Both file formats were developed at Apple around the same time
Thanks for the WIP screenshots; they made me feel much better about my own slicers/rasterisers.
(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)
* like working directly with cubics, à la Jim Blinn?
FTR, in case someone is interested: "predicate" is the name for functions that output booleans, so a more general search term is "geometric predicate".
[1] https://handmade.network/forums/articles/t/7330-implementing....
[2] https://github.com/nothings/stb/blob/master/stb_truetype.h
Having recently implemented a subset of opentype kerning, I can only imagine how stressful it was to implement the whole core truetype spec...
It's also reiterated the importance for me to take screenshots as I go. For many/most projects, these intermediary and bugged out results are gone as quickly as they come if I don't make an effort to persist them.
Sure, things looked blurry, but it didn't matter much when everything would be rotated into weird angles and sizes anyways.
Bezier and implementing correct and FAST filling rules took a lot of effort.
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.
It is a cool format and stack-based language and was an enjoyable and educational time in my career.
Yes!