Friday, June 12, 2026

Rewriting Apple’s TrueType Hinting Interpreter in Swift

Scott Perry:

My team rewrote Apple's TrueType hinting interpreter in Swift, ask me anything.

[…]

I feel like naming just one would be a disservices to all of the features that made this effort possible (C interop, generics, noncopyable/nonescapable types) but at the end of the day I think the star of the show was the optimizer; despite being faster than the code it replaced, the new code is super readable and that was only possible because the optimizer was able to completely eliminate all of our abstractions.

The new version is faster, but the main motivation was security concerns.

Dmitrii Kalianov:

Is hinting useful/being used in the days of hi-dpi displays? I was under impression that Apple switched to grayscale anti-aliasing and ditched hinting.

Scott Perry:

For the most part hinting isn’t really necessary anymore, but thanks to being Turing-complete it has been Hyrum’s law-ed by at least one CJK font that uses hinting to lay out strokes in its characters.

Alex Rosenberg:

There were three major TrueType implementations at Apple IIRC:

  • The original 68K one
  • A rewrite for Copland that lived with ATS/ATSUI after Copland was cancelled
  • iPhone shipped one derived from heavily-modified FreeType that was current until today

Scott Perry:

One of the axioms for this project was that I wanted my team to write the most boring code possible—nearly identical structurally to the code it was replacing, because to do otherwise would introduce binary compatibility risk. The other axiom was 100% test coverage for all new code as it landed, with the same units testing both interpreters.

Rosyna Keller:

Is the font parsing code itself still C++?

Scott Perry:

There is also a “Safe Font Parser” for WebKit in Lockdown Mode, but it supports a subset of all the myriad features provided by font formats.

Previously:

1 Comment RSS · Twitter · Mastodon


>I was under impression that Apple switched to grayscale anti-aliasing and ditched hinting.

My impression was Apple's subpixel rendering never used hinting, but rather scaled down a larger font, whereas Windows ClearType (_also_ basically deprecated) _did_ use hinting, the trade-off being that ClearType looks sharper, but Apple's approach is more typographically accurate.

>Apple uses FreeType in iOS[14] and macOS[16] next to Apple Advanced Typography.

Does that mean subpixel rendering is related to Copland / ATSUI, whereas grayscale rendering (and _all_ rendering on iOS) is currently FreeType? (Leaving aside Safari's special case.)

Also, does this rewrite mean appleOS 27 _doesn't_ use FreeType?

Leave a Comment