| 1 | # Fontcrunch |
| 2 | |
| 3 | By Raph Levien, Google |
| 4 | |
| 5 | This is a tool for TrueType font spline optimization - a "simplify" command. |
| 6 | It tries to create a visual match for the spline using the smallest number of TrueType points. |
| 7 | It is notable for counting on-curve points interpolated between two off-curve points as "free," making useful filesize savings. |
| 8 | |
| 9 | It depends on fonttools, and has some legacy dependencies on [spiro-0.01](http://www.levien.com/spiro/spiro-0.01.tar.gz) |
| 10 | This code is available under the Apache v2 license. Spiro code is GNU GPL v2 or later, and Spiro curves are subject to a US patent. |
| 11 | |
| 12 | Create 256 directories named 00 .. ff, and populate them with lots of files with .bz extension. |
| 13 | Each of these is a nontrivial segment of quad beziers cut from the font, stored as a `x0 y0 x1 y1 x2 y2` line per bezier. |
| 14 | Lines are represented with `(x1, y1)` at the midpoint of the two endpoints. |
| 15 | |
| 16 | `python fontcrunch.py gen yourfont.ttf` |
| 17 | |
| 18 | Runs the optimizer on each of the .bz files, producing a .bzopt. |
| 19 | You can control the level of precision by editing "penalty" in the code (should of course be a parameter). |
| 20 | On a fast computer, it should go through about 5 glyphs a second, depending on complexity. |
| 21 | |
| 22 | `make -j16 # or whatever level of parallelism makes sense on your computer` |
| 23 | |
| 24 | Regenerate a new TrueType font. You can look at the outlines to check the quality of the result. |
| 25 | |
| 26 | `python fontcrunch.py pack yourfont.ttf > /tmp/outlines.ps newfont.ttf` |