Several times recently, people have asked on IRC how they can use nice fonts with SVG. My answer in the long-ago past, when Adobe’s excellent SVG Viewer plugin roamed the Earth, was to use SVG Fonts directly embedded in the SVG file… but that’s no longer practical with the current varied browser support.
Authoring tools, like Inkscape and Adobe Illustrator, should simply manage this for authors, but until that happens, I thought I’d share a relatively simple workflow that has helped others. (Warning: I will use the words font and typeface with careless abandon to semantics in this article, though I know the difference. I’m afraid the more sensitive souls among you may suffer apoplectic righteous indignation.)
I will walk you through this workflow step-by-step, but if you get lost, just look at the source code… it’s pretty self-explanatory.
- Find a font you like. For this example, I chose Riesling, an Art Deco typeface by â€œBright Ideasâ€. I made sure the font was free and didn’t have any restrictions for online or commercial use.
- Upload the font to FontSquirrel’s
@font-facegenerator, and download the resulting package. This contains the webfonts, as well as some sample files (though not an example of how to use the files in SVG).
- Copy the resulting webfont files (
*.svg) into the same directory as the SVG file that will reference them. (Note: do not confuse the SVG file in the FontSquirrel package for a content file; it is an SVG font, with no rendering content.)
- Copy the CSS
@font-facestyle rule from the FontSquirrel package file (“stylesheet.css”), and put it in your SVG’s <style> element.
- Optionally, for local testing, install the original TTF file as a system font, and add the
localvalue to the
- Add a style rule for
textelements, using the resulting
font-family. In my example, I also created a style rule for
- No, really, that’s it. You’re done.
Here is the resulting SVG using webfonts:
A Word on the Future of SVG Fonts
Since I’ve mentioned SVG Fonts a couple of times, I thought I’d leave you with a final note about what the future seems to hold for them.
SVG Fonts were added in SVG 1.0, way back in 1999, as a way to embed fonts in the same file, using vectors and all the capabilities of SVG, including separate fill and stroke (which could be gradients or other paint sources), and even exotic features like clip-paths, animation, and so on; JÃ©rÃ©mie Patonnier has a great article on the topic. As cool as this is, it doesn’t necessarily work well with existing font engines… The Adobe SVG Viewer had support for SVG Fonts, and Opera and WebKit added support for the less-powerful SVG Tiny 1.2 subset as well; but Mozilla and Microsoft decided not to add support for SVG Fonts, and that limits their usefulness. It doesn’t seem likely that SVG2 (being developed now) will include SVG Fonts, not necessarily even the more limited subset (though there is not yet consensus in the SVG Working Group).
In practical usage, SVG Fonts were once the only way to use webfonts on iOS devices (e.g. the iPhone and iPad), which is why FontSquirrel includes them in their font-face package; but this is no longer the case, and iOS 4.2 added support for TTF fonts, which reportedly perform better. I expect this use of SVG Fonts to dwindle away… people will naturally want to use as few font formats as possible.
But for all of you out there who, like me, love the cool things you can do with SVG Fonts that aren’t possible in traditional outline font formats, don’t despair! Even as I write this, a proposal is being prepared by the SVG glyphs for OpenType Community Group to add a subset of SVG to OpenType, for more interesting typeface capabilities.
SVG Fonts are dead! Long live SVG Fonts!