Before moving on, a word of caution about smarts quotes: always use curly quotes
except
when showing code. String literals in programming languages, attributes in XML, and
other such technical code is only correctly presented in dumb quotes, the way it would
compile/parse. Using curly quotes to show code is not only incorrect but looks cluelessly
affected, roughly similar to eating a Snickers bar with fork and knife.
So far, we have avoided the problem of character availability in specific typefaces
by
using typefaces such as Arial which are available in most computers; now we need to
see how
to embed fonts if we are to create specific work that can be reliably displayed in
all
SVG-compliant viewers. For this purpose, SVG provides a font
tag that describes
“SVG fonts”, which are collections of font outlines described in SVG paths.
Our three goals regarding fonts are to see how an SVG font can be embedded, to note
a
couple of important extra sub-elements such as missing-glyph
, and finally to
see how to convert True Type Fonts into SVG fonts.
The following Listing shows how to embed the font “Space Toaster” by Chank
Diesel (originally designed for the Cartoon Network's “Space Ghost Coast to
Coast”). Note how we only need to embed the glyphs for the characters we are going
to
use.
As you can see in the code above, each glyph is defined separately, using the glyph
element. Now when we use the font in any text element, the correct glyphs will be
shown as
demonstrated in the graphic below (the glyph definitions have been omitted from the
listing
to avoid repetition). This selective inclusion of characters allow us to keep the
file as
small as possible. On the other hand, if we use a character that is not defined in
the SVG
font, the figure defined by the missing-glyph
element will appear: