previous   next   contents   properties   index  

20 Fonts


Contents


 

20.1 Introduction

Reliable delivery of fonts is considered a critical requirement for SVG. Designers require the ability to create SVG graphics with whatever fonts they care to use and then have the same fonts 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 used by a given SVG document fragment. Typically, the web fonts will be saved in a location relative to the referencing document.

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.

SVG fonts can improve the semantic richness of graphics that represent text. For example, many company logos consist of the company name drawn artistically. In some cases, accessibility might be enhanced by expressing the logo as a series of glyphs in an SVG font and then rendering the logo as a 'text' element which references this font.

20.2 SVG fonts

20.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 must be supported only in browsing and viewing situations. Graphics editing applications or file translation tools must not attempt convert SVG fonts into system fonts. The intent is that SVG files be interchangeable between two content creators, but not the SVG fonts that might 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 font-face-name 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 might 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].

SVG fonts and their associated glyphs do not specify bounding box information. Because the glyph outlines are expressed as SVG graphics elements, the implementation has the option to render the glyphs either using standard graphics calls or by using special-purpose font rendering technology, in which case any necessary maximum bounding box and overhang calculations can be performed from analysis of the graphics elements contained within the glyph outlines.

An SVG font can be either embedded within the SVG document fragment 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/2000/svg-20000303-stylable'>
  <defs>
    <font id="MyFont" font-face-name="Super Sans"
          units-per-em="1000" cap-height="600" x-height="400"
          ascent="700" descent="300" horiz-adv-x="1000"
          text-bottom="-300" baseline="0" centerline="350"
          mathline="350" ideographic="400" hanging="500"
          topline="700" text-top="700">
      <missing-glyph><path d="M0,0h200v200h-200z"/></glyph>
      <glyph unicode="33"><path d="M0,0L200,200L400,0z"/></glyph>
      <glyph unicode="34"><path d="M0,0L200,200L400,0z"/></glyph>
      <!-- more glyphs -->
    </font>
    <style type="text/css">
      <![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/2000/svg-20000303-stylable'>
  <defs>
    <font id="MyFont" font-face-name="Super Sans" 
          units-per-em="1000" cap-height="600" x-height="400"
          ascent="700" descent="300" horiz-adv-x="1000"
          text-bottom="-300" baseline="0" centerline="350"
          mathline="350" ideographic="400" hanging="500"
          topline="700" text-top="700">
      <missing-glyph><path d="M0,0h200v200h-200z"/></glyph>
      <glyph unicode="33"><path d="M0,0L200,200L400,0z"/></glyph>
      <glyph unicode="34"><path d="M0,0L200,200L400,0z"/></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/2000/svg-20000303-stylable'>  <defs>
    <style type="text/css">
      <![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

20.2.2 The 'font' element

The 'font' element defines an SVG font.

<!ENTITY % fontExt "" >
<!ELEMENT font (%descTitle;,missing-glyph,(glyph|hkern|vkern
                   %fontExt;)*) >
<!ATTLIST font
  %stdAttrs;
  externalResourcesRequired %Boolean; #IMPLIED
  font-style CDATA #IMPLIED
  font-variant CDATA #IMPLIED
  font-weight CDATA #IMPLIED
  font-stretch CDATA #IMPLIED
  unicode-range CDATA #IMPLIED
  units-per-em %Number; #REQUIRED
  panose-1 CDATA #IMPLIED
  slope %Number; #IMPLIED
  cap-height %Number; #REQUIRED
  x-height %Number; #REQUIRED
  accent-height %Number; #IMPLIED
  ascent %Number; #REQUIRED
  descent %Number; #REQUIRED
  horiz-origin-x %Number; #IMPLIED
  horiz-origin-y %Number; #IMPLIED
  horiz-adv-x %Number; #REQUIRED
  vert-origin-x %Number; #IMPLIED
  vert-origin-y %Number; #IMPLIED
  vert-adv-y %Number; #IMPLIED
  text-bottom %Number; #REQUIRED
  baseline %Number; #REQUIRED
  centerline %Number; #REQUIRED
  mathline %Number; #REQUIRED
  ideographic %Number; #REQUIRED
  hanging %Number; #REQUIRED
  topline %Number; #REQUIRED
  text-top %Number; #REQUIRED
  font-face-name CDATA #IMPLIED
  underline-position %Number; #IMPLIED
  underline-thickness %Number; #IMPLIED
  strikethrough-position %Number; #IMPLIED
  strikethrough-thickness %Number; #IMPLIED
  overline-position %Number; #IMPLIED
  overline-thickness %Number; #IMPLIED >

Attribute definitions:

font-style = "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.
Animatable: no.
font-variant = "[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.
Animatable: no.
font-weight = "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.
Animatable: no.
font-stretch = "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.
Animatable: no.
unicode-range = "<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.
Animatable: no.
units-per-em = "<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].
Animatable: no.
panose-1 = "[<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.
Animatable: no.
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.
Animatable: no.
cap-height = "<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].
Animatable: no.
x-height = "<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].
Animatable: no.
accent-height = "<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.
Animatable: no.
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].
Animatable: no.
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].
Animatable: no.
horiz-origin-x = "<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.
Animatable: no.
horiz-origin-y = "<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.
Animatable: no.
horiz-adv-x = "<number>"
The default horizontal advance after rendering a glyph in horizontal orientation. Glyph widths are required to be positive, even if the glyph is typically rendered right-to-left, as in Hebrew and Arabic scripts.
Animatable: no.
vert-origin-x = "<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 half of the value of attribute horiz-adv-x.
Animatable: no.
vert-origin-y = "<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.
Animatable: no.
vert-adv-y = "<number>"
The default vertical advance after rendering a glyph in vertical orientation. The default value is the sum of the values of attributes ascent and. descent.
Animatable: no.
text-bottom = "<number>"
The bottom of the font within the font coordinate system. For more information, see the description of the 'text-bottom' value for the 'vertical-align' property in the "Cascading Style Sheets (CSS) level 2" specification [CSS2].
Animatable: no.
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].
Animatable: no.
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].
Animatable: no.
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].
Animatable: no.
ideographic = "<number>"
The ideographic baseline of a font within the font coordinate system.
Animatable: no.
hanging = "<number>"
The hanging baseline of a font within the font coordinate system.
Animatable: no.
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].
Animatable: no.
text-top = "<number>"
The top of the font within the font coordinate system. For more information, see the description of the 'text-top' value for the 'vertical-align' property in the "Cascading Style Sheets (CSS) level 2" specification [CSS2].
Animatable: no.
font-face-name = "<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].
Animatable: no.
underline-position = "<number>"
The ideal position of an underline within the font coordinate system.
Animatable: no.
underline-thickness = "<number>"
The ideal thickness of an underline, expressed as a length within the font coordinate system.
Animatable: no.
strikethrough-position = "<number>"
The ideal position of a strike-through within the font coordinate system.
Animatable: no.
strikethrough-thickness = "<number>"
The ideal thickness of a strike-through, expressed as a length within the font coordinate system.
Animatable: no.
overline-position = "<number>"
The ideal position of an overline within the font coordinate system.
Animatable: no.
overline-thickness = "<number>"
The ideal thickness of an overline, expressed as a length within the font coordinate system.
Animatable: no.

Attributes defined elsewhere:
%stdAttrs;.

20.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) might occur when glyph definitions consist of a single 'path' element.

<!ENTITY % glyphExt "" >
<!ELEMENT glyph (%descTitleDefs;,
                  (path|text|rect|circle|ellipse|line|polyline|polygon|
                   use|image|g|switch
                   %glyphExt;)*) >
<!ATTLIST glyph
  %stdAttrs;
  unicode CDATA #REQUIRED
  glyph-name CDATA #IMPLIED
  vert-text-orient CDATA #IMPLIED
  arabic CDATA #IMPLIED
  han CDATA #IMPLIED
  horiz-adv-x %Number; #IMPLIED
  vert-adv-y %Number; #IMPLIED >

Attribute definitions:

unicode = "<string>"
One or more Unicode characters indicating the sequence of Unicode characters which corresponds to this glyph. If a character is provided, then this glyph corresponds to the given Unicode character. If a list of characters 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="ffl", then the given glyph will be used to render the sequence of characters "f", "f", and "l". (This could alternatively have been expressed using character entities, using XML character references expressed in hexadecimal notation: unicode="&#x66;&#x66;&#x6c;", or XML character references expressed in decimal notation: unicode="&#102;&#102;&#108;".) When determining the glyph(s) to draw a given character sequence, the 'font' element is searched from its first 'glyph' element to its last in lexical order to see if the upcoming sequence of Unicode characters to be rendered match the sequence of Unicode characters specified in the unicode attribute for the given 'glyph' element. The first successful match is used.

Note that any occurrences of 'altGlyph' take precedence over the glyph selection rules within an SVG font.
Animatable: no.
glyph-name = "<name> [, <name> ]* "
A name for the glyph. It is recommended that glyph names be unique across a font. The glyph names can be used in situations where Unicode character numbers do not provide sufficient information to access the correct glyph, such as when there are multiple glyphs per Unicode character. The glyph names can be referenced in kerning definitions.
Animatable: no.
vert-text-orient = "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 determines the orientation of this glyph.
Animatable: no.
arabic = "initial | medial | terminal | isolated"
For Arabic glyphs, indicates which of the four possible forms this glyph represents.
Animatable: no.
han = "ja | zht | zhs | kor"
For glyphs in the Han range, indicates which of the four possible forms this glyph represents.
Animatable: no.
horiz-adv-x = "<number>"
The horizontal advance after rendering a glyph in horizontal orientation. The default value is the value of the font's horizAdvX attribute. Glyph widths are required to be positive, even if the glyph is typically rendered right-to-left, as in Hebrew and Arabic scripts.
Animatable: no.
vert-adv-y = "<number>"
The vertical advance after rendering a glyph in vertical orientation. The default value is the value of the font's vertAdvY attribute.
Animatable: no.

Attributes defined elsewhere:
%stdAttrs;.

20.2.4 The 'missing-glyph' element

The 'missing-glyph' 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 'missing-glyph' element have the same meaning as the corresponding attributes on the 'glyph' element.

<!ENTITY % missing-glyphExt "" >
<!ELEMENT missing-glyph (%descTitleDefs;,
                  (path|text|rect|circle|ellipse|line|polyline|polygon|
                   use|image|g|switch
                   %missing-glyphExt;)*) >
<!ATTLIST missing-glyph
  %stdAttrs;
  horiz-adv-x %Number; #IMPLIED
  vert-adv-y %Number; #IMPLIED >
Attributes defined elsewhere:
%stdAttrs;, horiz-adv-x, vert-adv-y.

20.2.5 The 'hkern' and 'vkern' elements

The 'hkern' and 'vkern' elements define kerning pairs for horizontally-oriented and vertically-oriented pairs of glyphs, respectively.

Kern pairs identify pairs of glyphs within a single font whose inter-glyph spacing is adjusted when the pair of glyphs are rendered next to each other. In addition to the requirement that the pair of glyphs are from the same font, SVG font kerning happens only when the two glyphs correspond to characters which have the same values for properties 'font-family', 'font-size', 'font-style', 'font-weight', 'font-variant', 'font-stretch', 'font-size-adjust' and 'font'.

An example of a kerning pair are the letters "Va", where the typographic result might look better if the letters "V" and the "a" were rendered slightly closer together.

Right-to-left and bi-directional text in SVG is laid out in a two-step process, which is described in Relationship with bi-directionality. If SVG fonts are used, before kerning is aplied, characters are re-ordered into left-to-right (or top-to-bottom, for vertical text) visual rendering order. Kerning from SVG fonts is then applied on pairs of glyphs which are rendered contiguously. The first glyph in the kerning pair is the left (or top) glyph in visual rendering order. The second glyph in the kerning pair is the right (or bottom) glyph in the pair.

For convenience to font designers and to minimize file sizes, a single 'hkern' and 'vkern' can define a single kerning adjustment value between one set of glyphs (e.g., a range of Unicode characters) and another set of glyphs (e.g., another range of Unicode characters).

The 'hkern' element defines kerning pairs and adjustment values in the horizontal advance value when drawing pairs of glyphs which the two glyphs are contiguous and are both rendered horizontally (i.e., side-by-side). The spacing between characters is reduced by the kerning adjustment. (Negative kerning adjustments increase the spacing between characters.)

<!ELEMENT hkern EMPTY >
<!ATTLIST hkern
  %stdAttrs;
  u1 CDATA #IMPLIED
  g1 CDATA #IMPLIED
  u2 CDATA #IMPLIED
  g2 CDATA #IMPLIED
  k %Number; #REQUIRED >

Attribute definitions:

u1 = "[<character> | <urange> ] [, [<character> | <urange>] ]* "
A sequence (comma-separated) of Unicode characters (refer to the description of the unicode attribute to the 'glyph' element for a description of how to express individual Unicode characters) and/or unicode ranges (see description of unicode ranges in [CSS2]) which identify a set of possible first glyphs in the kerning pair. If a given Unicode character within the set has multiple corresponding 'glyph' elements (i.e., there are multiple 'glyph' elements with the same unicode attribute value, but different glyphName values), then all such glyphs are included in the set. Comma is the separator character; thus, to kern a comma, specify the comma as part of a Unicode range or as a glyph name using the g1 attribute. The total set of possible first glyphs in the kerning pair is the union of glyphs specified by the u1 and g1 attributes.
Animatable: no.
g1 = "<name> [, <name> ]* "
A sequence (comma-separated) of glyph names (i.e., values that match glyphName attributes on 'glyph' elements) which identify a set of possible first glyphs in the kerning pair. All glyphs with the given glyph name are included in the set. The total set of possible first glyphs in the kerning pair is the union of glyphs specified by the u1 and g1 attributes.
Animatable: no.
u2 = "[<number> | <urange>] [, [<number> | <urange>] ]* "
Same as the u1 attribute, except that u2 specifies possible second glyphs in the kerning pair.
Animatable: no.
g2 = "<name> [, <name> ]* "
Same as the g1 attribute, except that g2 specifies possible second glyphs in the kerning pair.
Animatable: no.
k = "<number>"
The amount to decrease the spacing between the two glyphs in the kerning pair. The value is in the font coordinate system.
Animatable: no.

Attributes defined elsewhere:
%stdAttrs;.

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

The 'vkern' element defines kerning pairs and adjustment values in the vertical advance value when drawing pairs of glyphs together when stacked vertically. The spacing between characters is reduced by the kerning adjustment.

<!ELEMENT vkern EMPTY >
<!ATTLIST vkern
  %stdAttrs;
  u1 CDATA #IMPLIED
  g1 CDATA #IMPLIED
  u2 CDATA #IMPLIED
  g2 CDATA #IMPLIED
  k %Number; #REQUIRED >
Attributes defined elsewhere:
%stdAttrs;, u1. g1. u2. g2. k.

20.3 DOM interfaces

The following interfaces are defined below: SVGFontElement, SVGGlyphElement, SVGMissingGlyphElement, SVGHKernElement, SVGVKernElement.


Interface SVGFontElement

The SVGFontElement interface corresponds to the 'font' element.

Object-oriented access to the attributes of the 'font' element via the SVG DOM is not available.


IDL Definition
interface SVGFontElement : SVGElement;


Interface SVGGlyphElement

The SVGGlyphElement interface corresponds to the 'glyph' element.

Object-oriented access to the attributes of the 'glyph' element via the SVG DOM is not available.


IDL Definition
interface SVGGlyphElement : SVGElement;


Interface SVGMissingGlyphElement

The SVGMissingGlyphElement interface corresponds to the 'missing-glyph' element.

Object-oriented access to the attributes of the 'missing-glyph' element via the SVG DOM is not available.


IDL Definition
interface SVGMissingGlyphElement : SVGElement;


Interface SVGHKernElement

The SVGHKernElement interface corresponds to the 'hkern' element.

Object-oriented access to the attributes of the 'hkern' element via the SVG DOM is not available.


IDL Definition
interface SVGHKernElement : SVGElement;


Interface SVGVKernElement

The SVGVKernElement interface corresponds to the 'vkern' element.

Object-oriented access to the attributes of the 'vkern' element via the SVG DOM is not available.


IDL Definition
interface SVGVKernElement : SVGElement;

previous   next   contents   properties   index