Cufón aims to become a worthy alternative to sIFR, which despite its merits still remains painfully tricky to set up and use. To achieve this ambitious goal the following requirements were set:
And now, after nearly a year of planning and research we believe that these requirements have been met.
Cufón consists of two individual parts – a font generator, which converts fonts to a proprietary format and a rendering engine written in JavaScript.
In reality the generator is little more than a web-based interface to FontForge. First, the generator builds a custom FontForge script based on user input and then runs it, saving the result as an SVG font. The SVG font is then parsed and SVG paths are converted to VML paths. This is a crucial step in achieving stellar performance in Internet Explorer, as it supports VML natively. The resulting document is then converted into JSON with a mix of functional JavaScript. This has numerous advantages:
<script> tag as any other JavaScript file and it will be registered automaticallyThe process is then repeated for the rest of the fonts given to the generator (if any) and the resulting JavaScript file is sent back to the client with a distinctive filename.
The renderer is a bit more complicated. It consists of 3 parts – a Core, which provides the API and common functionality, and two rendering engines. One of them renders VML shapes and is used for Internet Explorer (it supports VML from version 5.5), while the other one uses the widely supported HTML5 <canvas> element. Due to the path data already being VML, little work is needed in the VML engine. The canvas engine, however, must convert all paths to the corresponding sets of drawing commands provided by the canvas API. This turned out to be somewhat tricky at first, but a solution was found after two complete rewrites in the form of code generation and caching, resulting in a very fast renderer.
Inline SVG was also considered but quickly turned down due to it being surprisingly slow in the few browsers that actually support it properly.