13 Fonts


Contents


 

13.1 Introduction

Reliable delivery of fonts is considered a critical requirement for SVG. Designers should be able to create SVG graphics with whatever fonts they care to use and then the same fonts should appear in the end user's browser when viewing an SVG drawing, even if the given end user hasn't purchased the fonts in question. This parallels the print world, where the designer uses a given font when authoring a drawing for print, but when the end user views the same drawing within a magazine the text appears with the correct font.

SVG utilizes the web font facility defined in the "Cascading Style Sheets (CSS) level 2" specification [CSS2] as a key mechanism for reliable delivery of font data to end users. A common scenario is that SVG authoring applications will generate compressed, subsetted web fonts for all text elements included in a given SVG document. Typically, the web fonts will be saved in a nearby location to the SVG document itself.

One disadvantage to CSS2's Webfont facility to date is that CSS2 did not specify particular font formats that were required to be supported. The result was that different implementations supported different web font formats, thereby making it difficult for web site creators to post a single web site that is supported by a large percentage of installed browsers.

To provide a common font format that will exist in all conforming SVG user agents, SVG includes elements which allow for fonts to be defined in SVG. See SVG Fonts for more information.

13.2 SVG fonts

13.2.1 Overview of SVG fonts

An SVG font is a font defined using SVG's <font> element.

The purpose of SVG fonts is to allow for delivery of glyph outlines in display-only environments. SVG fonts that accompany web pages should be supported only in browsing and viewing situations. Graphics editing applications or file translation tools should not attempt convert SVG fonts into system fonts. The intent is that SVG files should be interchangeable between two content creators, but not the SVG fonts that accompany these SVG files . Instead, each content creator will need to license the given font before being able to successfully edit the SVG file. The fullFontName attribute indicates the name of licensed font to use for editing,

SVG fonts contain unhinted font outlines. Because of this, on many implementations there will be limitations regarding the quality and legibility of text in small font sizes. For increased quality and legibility in small font sizes, content creators may want to use an alternate font technology, such as fonts that ship with operating systems or an alternate web font format.

Because SVG fonts are expressed using SVG elements and attributes, in some cases the SVG font will take up more space than if the font were expressed in a different web font format which was especially designed for compact expression of font data. For the fastest delivery of web pages, content creators may want to use an alternate font technology.

A key value of SVG fonts is guaranteed availability in SVG user agents. In some situations, it may be appropriate for an SVG font to be the first choice for rendering some text. In other situations, the SVG font might be an alternate, back-up font in case the first choice font (perhaps a hinted system font) is not available to a given user.

The characteristics and attributes of SVG fonts correspond closely to the font characteristics and parameters described in the "Cascading Style Sheets (CSS) level 2" specification [CSS2].

An SVG font can be either embedded within the SVG document that uses the font or saved as an external file and referenced via a URI reference.

Here is an example of how you might embed an SVG font inside of an SVG document:

<?xml version="1.0" standalone="yes"?>
<svg width="400px" height="300px"
  xmlns = 'http://www.w3.org/Graphics/SVG/SVG-19990812.dtd'>
  <defs>
    <font id="MyFont" fullFontName="Super Sans" >
      <glyph unicode="33"><path d="..."/></glyph>
      <glyph unicode="34"><path d="..."/></glyph>
      <!-- more glyphs -->
    </font>
    <style>
      <![CDATA[
        @font-face {
          font-family: "MyFont";
          src: url("#MyFont") format(svg)
        }
      ]]>
    </style>
  </defs>
  <text style="font-family: MyFont, Helvetica, sans-serif">Text 
    using embedded font</text>
</svg>

Download this example

Here is an example of how you might reference an SVG font which is saved in an external file. First referenced SVG font file:

<?xml version="1.0" standalone="yes"?>
<svg width="100%" height="100%"
 xmlns = 'http://www.w3.org/Graphics/SVG/SVG-19990812.dtd'>
  <defs>
    <font id="MyFont" fullFontName="Super Sans" >
      <glyph unicode="33"><path d="..."/></glyph>
      <glyph unicode="34"><path d="..."/></glyph>
      <!-- more glyphs -->
    </font>
  </defs>
</svg>

Download this example

The SVG file which uses/references the above SVG font

<?xml version="1.0" standalone="yes"?>
<svg width="400px" height="300px"
 xmlns = 'http://www.w3.org/Graphics/SVG/SVG-19990812.dtd'>  <defs>
    <style>
      <![CDATA[
        @font-face {
          font-family: "MyFont";
          src: url("myfont.svg#MyFont") format(svg)
        }
      ]]>
   </style>
  </defs>
  <text style="font-family: MyFont">Text using embedded font</text>
</svg>

Download this example

13.2.2 The <font> element

The <font> element defines an SVG font.

<!ELEMENT font (desc?,title?,missingGlyph,(glyph|kern)*) >
<!ATTLIST font
  id ID #IMPLIED
  fontStyle CDATA #IMPLIED
  fontVariant CDATA #IMPLIED
  fontWeight CDATA #IMPLIED
  fontStretch CDATA #IMPLIED
  unicodeRange CDATA #IMPLIED
  unitsPerEm CDATA #REQUIRED
  panose1 CDATA #IMPLIED
  slope CDATA #IMPLIED
  capHeight CDATA #REQUIRED
  xHeight CDATA #REQUIRED
  accentHeight CDATA #IMPLIED
  ascent CDATA #REQUIRED
  descent CDATA #REQUIRED
  horizOriginX CDATA #IMPLIED
  horizOriginY CDATA #IMPLIED
  horizAdvX CDATA #IMPLIED
  vertOriginX CDATA #IMPLIED
  vertOriginY CDATA #IMPLIED
  vertAdvY CDATA #IMPLIED
  bbox CDATA #REQUIRED
  baseline CDATA #REQUIRED
  centerline CDATA #REQUIRED
  mathline CDATA #REQUIRED
  topline CDATA #REQUIRED
  fullFontName CDATA #IMPLIED
  underlinePosition CDATA #IMPLIED
  underlineThickness CDATA #IMPLIED
  strikethroughPosition CDATA #IMPLIED
  strikethroughThickness CDATA #IMPLIED
  overlinePosition CDATA #IMPLIED
  overlineThickness CDATA #IMPLIED >

Attribute definitions:

fontStyle = "all | [ normal | italic | oblique] [, [normal | italic | oblique]]*"
The style of a font. Takes on the same values as the 'font-style' property, except that a comma-separated list is permitted. The default value is all.
fontVariant = "[normal | small-caps] [,[normal | small-caps]]*"
Indication of whether this face is the small-caps variant of a font. Takes on the same values as the 'font-variant' property, except that a comma-separated list is permitted. The default value is normal.
fontWeight = "all | [normal | bold |100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900] [, [normal | bold |100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900]]*"
The weight of a face relative to others in the same font family. Takes on the same values as the 'font-weight' property with three exceptions:
  1. relative keywords (bolder, lighter) are not permitted
  2. a comma-separated list of values is permitted, for fonts that contain multiple weights
  3. an additional keyword, 'all', is permitted, which means that the font will match for all possible weights; either because it contains multiple weights, or because that face only has a single weight.
The default value is all.
fontStretch = "all | [ normal | ultra-condensed | extra-condensed | condensed | semi-condensed | semi-expanded | expanded | extra-expanded | ultra-expanded] [, [ normal | ultra-condensed | extra-condensed | condensed | semi-condensed | semi-expanded | expanded | extra-expanded | ultra-expanded] ]*"
Indication of the condensed or expanded nature of the face relative to others in the same font family. Takes on the same values as the 'font-stretch' property except that:
  • relative keywords (wider,narrower) are not permitted
  • a comma-separated list is permitted
  • the keyword 'all' is permitted
The default value is normal.
unicodeRange = "<urange> [, <urage>]*"
The range of ISO 10646 characters [UNICODE] covered by the font. For more information, see the description of the 'unicode-range' descriptor in the "Cascading Style Sheets (CSS) level 2" specification [CSS2]. The default value is U+0-7FFFFFFF.
unitsPerEm = "<number>"
The number of coordinate units on the em square, the size of the design grid on which glyphs are laid out. For more information, see the description of the 'units-per-em' descriptor in the "Cascading Style Sheets (CSS) level 2" specification [CSS2].
panose1 = "[<integer>]{10}"
The Panose-1 number, consisting of ten decimal integers, separated by whitespace. For more information, see the description of the 'panose-1' descriptor in the "Cascading Style Sheets (CSS) level 2" specification [CSS2]. The default value is 0 0 0 0 0 0 0 0 0 0.
slope = "<number>"
The vertical stroke angle of the font. For more information, see the description of the 'slope' descriptor in the "Cascading Style Sheets (CSS) level 2" specification [CSS2]. The default value is 0.
capHeight = "<number>"
The height of uppercase glyphs in the font within the font coordinate system. For more information, see the description of the 'cap-height' descriptor in the "Cascading Style Sheets (CSS) level 2" specification [CSS2].
xHeight = "<number>"
The height of lowercase glyphs in the font within the font coordinate system. For more information, see the description of the 'x-height' descriptor in the "Cascading Style Sheets (CSS) level 2" specification [CSS2].
accentHeight = "<number>"
The distance from the baseline to the top of accent characters, measure by a distance within the font coordinate system. The default value is the value of the ascent attribute.
ascent = "<number>"
The maximum unaccented height of the font within the font coordinate system. For more information, see the description of the 'ascent' descriptor in the "Cascading Style Sheets (CSS) level 2" specification [CSS2].
descent = "<number>"
The maximum unaccented depth of the font within the font coordinate system. For more information, see the description of the 'descent' descriptor in the "Cascading Style Sheets (CSS) level 2" specification [CSS2].
horizOriginX = "<number>"
The X-coordinate in the font coordinate system of the origin of a glyph to be used when drawing horizontally oriented text. The default value is 0.
horizOriginY = "<number>"
The Y-coordinate in the font coordinate system of the origin of a glyph to be used when drawing horizontally oriented text. The default value is 0.
horizAdvX = "<number>"
The default horizontal advance after rendering a glyph in horizontal orientation. The default value is the width of the font's bbox.
vertOriginX = "<number>"
The X-coordinate in the font coordinate system of the origin of a glyph to be used when drawing vertically oriented text. The default value is the center position within the font's bbox.
vertOriginY = "<number>"
The Y-coordinate in the font coordinate system of the origin of a glyph to be used when drawing vertically oriented text. The default value is the position specified by the font's ascent attribute.
vertAdvY = "<number>"
The default vertical advance after rendering a glyph in vertical orientation. The default value is the height of the font's bbox.
bbox = "<number>, <number>, <number>, <number>"
The maximum bounding box of the font within the font coordinate system. The value is a comma-separated list of exactly four numbers specifying, in order, the minimum x, minimum y, maximum width and maximum height. (Note that these four parameters differ from the 'bbox' descriptor in the "Cascading Style Sheets (CSS) level 2" specification [CSS2], which calls for lower left x, lower left y, upper right x and upper right y, instead.) For more information, see the description of the 'bbox' descriptor in the "Cascading Style Sheets (CSS) level 2" specification [CSS2].
baseline = "<number>"
The lower baseline of a font within the font coordinate system. For more information, see the description of the 'baseline' descriptor in the "Cascading Style Sheets (CSS) level 2" specification [CSS2].
centerline = "<number>"
The central baseline of a font within the font coordinate system. For more information, see the description of the 'centerline' descriptor in the "Cascading Style Sheets (CSS) level 2" specification [CSS2].
mathline = "<number>"
The mathematical baseline of a font within the font coordinate system. For more information, see the description of the 'mathline' descriptor in the "Cascading Style Sheets (CSS) level 2" specification [CSS2].
topline = "<number>"
The top baseline of a font within the font coordinate system. For more information, see the description of the 'topline' descriptor in the "Cascading Style Sheets (CSS) level 2" specification [CSS2].
fullFontName = "<string>"
The full name of a particular face of a font family. It typically includes a variety of non-standardized textual qualifiers or adornments appended to the font family name. For more information, see the description of full font names in the "Cascading Style Sheets (CSS) level 2" specification [CSS2].
underlinePosition = "<number>"
The ideal position of an underline within the font coordinate system.
underlineThickness = "<number>"
The ideal thickness of an underline, expressed as a length within the font coordinate system.
strikethroughPosition = "<number>"
The ideal position of a strike-through within the font coordinate system.
strikethroughThickness = "<number>"
The ideal thickness of a strike-through, expressed as a length within the font coordinate system.
overlinePosition = "<number>"
The ideal position of an overline within the font coordinate system.
overlineThickness = "<number>"
The ideal thickness of an overline, expressed as a length within the font coordinate system.

Attributes defined elsewhere:
id.

13.2.3 The <glyph> element

The <glyph> element defines the graphics for a given glyph. The coordinate system for the glyph is defined by the various attributes in the <font> element.

The contents of a <glyph> can be any SVG graphics elements. However, in some implementations, faster font rendering (and possibly improved quality) may occur when glyph definitions consist of a single <path> element.
<!ELEMENT glyph (defs?,desc?,title?,
                  (path|text|rect|circle|ellipse|line|polyline|polygon|
                   use|image|g|switch)*)>
<!ATTLIST glyph
  unicode CDATA #REQUIRED
  glyphName CDATA #IMPLIED
  vertTextOrient CDATA #IMPLIED
  arabic CDATA #IMPLIED
  han CDATA #IMPLIED
  horizAdvX CDATA #IMPLIED
  vertAdvY CDATA #IMPLIED
  bbox CDATA #IMPLIED >

Attribute definitions:

unicode = "<number> [, <number> ]* "
One or more decimal numbers indicating the sequence of Unicode characters which corresponds to this glyph. If a single decimal number is provided, then this glyph corresponds to the given Unicode character number. If a list of numbers is provided, then this glyph corresponds to the given sequence of Unicode characters. One use of a list of numbers is for ligatures. For example, if unicode="102 102 108", which corresponds to the letters "f", "f", and "l", then the given glyph will be used to render the sequence of characters "ffl". When determining the glyph to draw a given character sequence, longer Unicode number list matches take precedence over shorter list matches.
glyphName = "<name> [, <name> ]* "
One or more strings (without white space or commas) which represent names for the glyph. The glyph names can be used in situations where Unicode character numbers do not provide sufficient information to access the correct glyph.
vertTextOrient = "default | h | v"
When drawing vertical text, indicates whether the given glyph is meant to be drawn with a vertical or horizontal orientation. The default value is vertOrient="default", which indicates that the Unicode character number should determine the orientation of this glyph.
arabic = "initial | medial | terminal | standard"
For Arabic glyphs, indicates which of the four possible forms this glyph represents.
han = "ja | zht | zhs | kor"
For glyphs in the Han range, indicates which of the four possible forms this glyph represents.
horizAdvX = "<number>"
The horizontal advance after rendering a glyph in horizontal orientation. The default value is the value of the font's horizAdvX attribute.
vertAdvY = "<number>"
The vertical advance after rendering a glyph in vertical orientation. The default value is the value of the font's vertAdvY attribute.
bbox = "<number>, <number>, <number>, <number>"
The bounding box of the glyph within the font coordinate system. The value is a comma-separated list of exactly four numbers specifying, in order, the minimum x, minimum y, maximum width and maximum height. The default value is the value of the font's bbox attribute.

13.2.4 The <missingGlyph> element

The <missingGlyph> element defines the graphics to use if there is an attempt to draw a glyph from a given font and the given glyph has been defined. The attributes on the <missingGlyph> element have the same meaning as the corresponding attributes on the <glyph> element.
<!ELEMENT missingGlyph (defs?,desc?,title?,
                  (path|text|rect|circle|ellipse|line|polyline|polygon|
                   use|image|g|switch)*)>
<!ATTLIST missingGlyph
  horizAdvX CDATA #IMPLIED
  vertAdvY CDATA #IMPLIED
  bbox CDATA #IMPLIED >

Attributes defined elsewhere:
horizAdvX, vertAdvY, bbox.

13.2.5 The <kern> element

The <kern> element defines kerning pairs and adjustment values in the horizontal advance value when drawing pairs of glyphs together horizontally. The spacing between characters is reduced by the kerning adjustment.

<!ELEMENT kern EMPTY >
<!ATTLIST kern
  u1 CDATA #IMPLIED
  g1 CDATA #IMPLIED
  u2 CDATA #IMPLIED
  g2 CDATA #IMPLIED
  k CDATA #REQUIRED >

Attribute definitions:

u1 = "[<number> | <urange>] [, [<number> | <urange>] ]* "
One or more decimal numbers and/or unicode ranges identifying the characters which can be the first character in this kerning adjustment definition.
g1 = "<name> [, <name> ]* "
One or more glyph names identifying the characters which can be the first character in this kerning adjustment definition.
u2 = "[<number> | <urange>] [, [<number> | <urange>] ]* "
One or more decimal numbers and/or unicode ranges identifying the characters which can be the second character in this kerning adjustment definition.
g2 = "<name> [, <name> ]* "
One or more glyph names identifying the characters which can be the second character in this kerning adjustment definition.
k = "<number>"
The amount to decrease the spacing between the two glyphs in the kerning pair. The value is in the font coordinate system. bbox attribute.

At least one each of u1 or g1 and at least one of u2 or g2 must be provided.