TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Writing a TrueType font renderer

317 点作者 codyd51超过 1 年前
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!

15 条评论

sokoloff超过 1 年前
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.
signaru超过 1 年前
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&#x27;s contour (I stopped before Bezier and shape filling stuff). I still have not considered hinting, so it&#x27;s nice that it&#x27;s covered. Besides Apple&#x27;s and Microsoft&#x27;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:&#x2F;&#x2F;handmade.network&#x2F;forums&#x2F;articles&#x2F;t&#x2F;7330-implementing_a_font_reader_and_rasterizer_from_scratch%252C_part_1__ttf_font_reader" rel="nofollow">https:&#x2F;&#x2F;handmade.network&#x2F;forums&#x2F;articles&#x2F;t&#x2F;7330-implementing...</a>.<p>[2] <a href="https:&#x2F;&#x2F;github.com&#x2F;nothings&#x2F;stb&#x2F;blob&#x2F;master&#x2F;stb_truetype.h">https:&#x2F;&#x2F;github.com&#x2F;nothings&#x2F;stb&#x2F;blob&#x2F;master&#x2F;stb_truetype.h</a>
评论 #38853103 未加载
kevingadd超过 1 年前
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&#x27;ve spent multiple days just rendering glitch art. It&#x27;s always good to show others how much we struggle even if we&#x27;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...
评论 #38840579 未加载
ianlevesque超过 1 年前
&gt; Inexplicably, though, the TTF stores all fields in big endian<p>Both the 68k and PPC (as configured for macs) were big endian.
评论 #38837488 未加载
评论 #38844225 未加载
评论 #38839415 未加载
vardump超过 1 年前
Wrote a truetype rasterizer about 20 years ago. I took the easy way out and just simply antialised everything, didn&#x27;t even try to support TrueType hinting programs.<p>Sure, things looked blurry, but it didn&#x27;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.
评论 #38836370 未加载
cbrpnk超过 1 年前
&quot;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.&quot;<p>Yes!
darknavi超过 1 年前
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!
评论 #38837395 未加载
评论 #38843911 未加载
评论 #38837890 未加载
评论 #38836633 未加载
082349872349872超过 1 年前
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&#x2F;rasterisers.<p>(there&#x27;s probably a trick I&#x27;m missing*, but so far I&#x27;ve had the most robust results for 3D booleans by chasing fiddly overlaps&#x2F;intersections on lower facets, all the way down to 0-D if necessary)<p>* like working directly with cubics, à la Jim Blinn?
评论 #38835764 未加载
评论 #38834889 未加载
评论 #38840543 未加载
vitiral超过 1 年前
I wonder, is there something on the complexity curve between 8x8 bitmap and fullblown ttf with all the complexity as you&#x27;ve outlined?<p>It would be nice if there were a solution which gets 90% of the value in 10% of the code.
评论 #38837279 未加载
评论 #38836377 未加载
评论 #38835718 未加载
评论 #38858742 未加载
评论 #38838338 未加载
评论 #38837026 未加载
评论 #38836150 未加载
评论 #38838298 未加载
评论 #38835874 未加载
评论 #38836639 未加载
userbinator超过 1 年前
I think TTF isn&#x27;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.
评论 #38836245 未加载
评论 #38836250 未加载
评论 #38835981 未加载
mdaniel超过 1 年前
I couldn&#x27;t readily tell if this was related to the recent 37C3 iPhone submission, but in case someone missed the irony: <a href="https:&#x2F;&#x2F;securelist.com&#x2F;operation-triangulation-the-last-hardware-mystery&#x2F;111669&#x2F;" rel="nofollow">https:&#x2F;&#x2F;securelist.com&#x2F;operation-triangulation-the-last-hard...</a> was RCE-ed via a truetype file and it&#x27;s always been just the gift that keeps on giving <a href="https:&#x2F;&#x2F;cve.mitre.org&#x2F;cgi-bin&#x2F;cvekey.cgi?keyword=truetype" rel="nofollow">https:&#x2F;&#x2F;cve.mitre.org&#x2F;cgi-bin&#x2F;cvekey.cgi?keyword=truetype</a>
jahewson超过 1 年前
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.
评论 #38838070 未加载
评论 #38840556 未加载
评论 #38836392 未加载
tomduncalf超过 1 年前
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!
评论 #38839201 未加载
评论 #38840520 未加载
hgs3超过 1 年前
Correct me if I&#x27;m wrong, but I think font hinting isn&#x27;t needed for high DPI displays? I believe macOS Mojave removed subpixel anti-aliasing because Apple doesn&#x27;t ship anything but high DPI displays anymore.
评论 #38836146 未加载
评论 #38836226 未加载
评论 #38836100 未加载
neontomo超过 1 年前
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.
评论 #38838582 未加载
评论 #38838400 未加载