Localized iPhone Fonts
Typically during production, adding support for non-ASCII character sets is not exactly a high priority for developers (even though it might be for publishers). But unlike most consoles, the iPhone delivers a nearly complete solution out of the box.
And I’m not referring to UIFont. While its results are solid, UIFont is not only slow to load but also carries a heavy performance cost when used in an OpenGL context.
The key is to use the same system that underlies UIFont, which is the Carbon-based CGFont. CGFont provides the same results as its ObjC counterpart, but also gives us a way to minimize the runtime cost. This can be done by creating glyph textures by using a CGBitmapContext as an intermediary between CGFont and OpenGL.
There’s a catch, however: we need glyph indices in order to use this function, and CGFont doesn’t give us any way to convert characters into their corresponding glyph indices. One way to get around this is to use the open source font library FreeType. FreeType has a flexible license, and can be built for the iPhone fairly easily.
The iPhone provides one more thing that we can take advantage of: localized system fonts. These can be found in /System/Library/Fonts/Cache/, and can save valuable time and disk space, as Japanese fonts alone can easily weigh into tens of megabytes. At the same time, there’s also a risk involved: Apple may move or withdraw access to these fonts at any time, so if you use them, be prepared to provide an alternate solution at short notice.
- Andrew
Get the RSS
Browse the Archive