{"id":52246,"date":"2026-06-12T15:34:17","date_gmt":"2026-06-12T19:34:17","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=52246"},"modified":"2026-06-12T16:43:14","modified_gmt":"2026-06-12T20:43:14","slug":"rewriting-apples-truetype-hinting-interpreter-in-swift","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2026\/06\/12\/rewriting-apples-truetype-hinting-interpreter-in-swift\/","title":{"rendered":"Rewriting Apple&rsquo;s TrueType Hinting Interpreter in Swift"},"content":{"rendered":"<p><a href=\"https:\/\/xoxo.zone\/@numist\/116716469017975106\">Scott Perry<\/a>:<\/p>\n<blockquote cite=\"https:\/\/xoxo.zone\/@numist\/116716469017975106\">\n<p>My team rewrote Apple's TrueType hinting interpreter in Swift, ask me anything.<\/p>\n<p>[&#8230;]<\/p>\n<p>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.<\/p>\n<\/blockquote>\n\n<p>The new version is faster, but the main motivation was security concerns.<\/p>\n\n<p><a href=\"https:\/\/mastodon.online\/@dmitry_vk\/116716571822155164\">Dmitrii Kalianov<\/a>:<\/p>\n<blockquote cite=\"https:\/\/mastodon.online\/@dmitry_vk\/116716571822155164\">\n<p>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.<\/p>\n<\/blockquote>\n\n<p><a href=\"https:\/\/xoxo.zone\/@numist\/116716601962175503\">Scott Perry<\/a>:<\/p>\n<blockquote cite=\"https:\/\/xoxo.zone\/@numist\/116716601962175503\">\n<p>For the most part hinting isn&rsquo;t really necessary anymore, but thanks to being Turing-complete it has been Hyrum&rsquo;s law-ed by at least one CJK font that uses hinting to lay out strokes in its characters.<\/p>\n<\/blockquote>\n\n<p><a href=\"https:\/\/mastodon.online\/@alexr\/116716796743064373\">Alex Rosenberg<\/a>:<\/p>\n<blockquote cite=\"https:\/\/mastodon.online\/@alexr\/116716796743064373\">\n<p>There were three major TrueType implementations at Apple IIRC:<\/p>\n<ul>\n<li>The original 68K one<\/li>\n<li>A rewrite for Copland that lived with ATS\/ATSUI after Copland was cancelled<\/li>\n<li>iPhone shipped one derived from heavily-modified FreeType that was current until today<\/li>\n<\/ul>\n<\/blockquote>\n\n<p><a href=\"https:\/\/xoxo.zone\/@numist\/116717742689971429\">Scott Perry<\/a>:<\/p>\n<blockquote cite=\"https:\/\/xoxo.zone\/@numist\/116717742689971429\">\n<p>One of the axioms for this project was that I wanted my team to write the most boring code possible&mdash;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.<\/p>\n<\/blockquote>\n\n<p><a href=\"https:\/\/mastodon.social\/@rosyna\/116716518907236633\">Rosyna Keller<\/a>:<\/p>\n<blockquote cite=\"https:\/\/mastodon.social\/@rosyna\/116716518907236633\">\n<p>Is the font parsing code itself still C++?<\/p>\n<\/blockquote>\n\n<p><a href=\"https:\/\/xoxo.zone\/@numist\/116716585366522657\">Scott Perry<\/a>:<\/p>\n<blockquote cite=\"https:\/\/xoxo.zone\/@numist\/116716585366522657\">\n<p>There is also a &ldquo;Safe Font Parser&rdquo; for WebKit <a href=\"https:\/\/webkit.org\/blog\/17333\/webkit-features-in-safari-26-0\/#lockdown-mode\">in Lockdown Mode<\/a>, but it supports a subset of all the myriad features provided by font formats.<\/p>\n<\/blockquote>\n\n<p>Previously:<\/p>\n<ul>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2026\/06\/09\/glow-leopard\/\">Glow Leopard<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2024\/06\/25\/llama-ttf\/\">llama.ttf<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2016\/06\/29\/a-year-of-windows-kernel-font-fuzzing\/\">A Year of Windows Kernel Font Fuzzing<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2016\/03\/11\/emoji-fonts-use-undocumented-features\/\">Emoji Fonts Use Undocumented Features<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2015\/07\/15\/font-parsing-vulnerabilities\/\">Font Parsing Vulnerabilities<\/a><\/li>\n<\/ul>","protected":false},"excerpt":{"rendered":"<p>Scott Perry: My team rewrote Apple's TrueType hinting interpreter in Swift, ask me anything. [&#8230;] 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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"2026-06-12T19:34:22Z","apple_news_api_id":"36024eb8-6379-4393-a847-5e3f02fba175","apple_news_api_modified_at":"2026-06-12T20:42:17Z","apple_news_api_revision":"AAAAAAAAAAAAAAAAAAAAAA==","apple_news_api_share_url":"https:\/\/apple.news\/ANgJOuGN5Q5OoR14_AvuhdQ","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[104,2817,31,2887,30,2784,138,270,71,48,2074,901,134],"class_list":["post-52246","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-fontsmoothing","tag-interpreter","tag-ios","tag-ios-27","tag-mac","tag-macos-27","tag-optimization","tag-parser","tag-programming","tag-security","tag-software-rewrite","tag-swift-programming-language","tag-typography"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/52246","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=52246"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/52246\/revisions"}],"predecessor-version":[{"id":52247,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/52246\/revisions\/52247"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=52246"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=52246"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=52246"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}