SVGFontKit (under development)

The Problem

Firefox doesn't yet handle embeded SVG fonts. Despite the fact that it handles text, it does so in a way that sucks. I'm sure they have their reasons like "integration with the rest of the text on the page" but it sucks -- increasing or decreasing the size of text on the page changes the text in the SVG, which makes it look stupid since SVG text is absolutely positioned. This is, hopefully, a temporary hack to solve the problems I'm having. Unlike the other parts of SVGKit, it will only be made as general as I (or user requests) need it to be.


This is a hack to replace all SVG <text> and <tspan> elements that reference an embeded SVG font with references to the font's glyphs properly positioned and spaced. This hack is necesary because Firefox lacks support for SVG Fonts, and currently <text> elements are rendered and sized according to the rest of the web pages's fonts rather than pixel-perfectly anti-aliased as demanded the SVG spec seems to require.

The major motivation for this is to render TeX equations for SVGPlot. TeX's fonts are natively specified using METAFONT, which uses a different way of describing fonts compared to PostScript (and SVG). Rather than giving a mathematical description for the outline, which get filled, METAFONT fonts are actually the stroke of a variable-width pen. Also, different sizes aren't just exact scalings of each other -- a whole program gets run with new parameters to generate new strokes. Computer Modern 5 is smaller then 10, but has more relative spacing between the letters and the same stroke thickness for greater readability.

Browse Code in SVN Repository

What it does

It's a stand-alone JavaScript that doesn't require SVGKit or MochiKit that:

Things that make this a horrible hack

To steal from the spec:

<?xml version="1.0" standalone="yes"?>
<svg width="400px" height="300px" version="1.1"
  xmlns = 'http://www.w3.org/2000/svg'>

    <font id="Font1" horiz-adv-x="1000">
      <font-face font-family="Super Sans" font-weight="bold" font-style="normal"
          units-per-em="1000" cap-height="600" x-height="400"
          ascent="700" descent="300"
          alphabetic="0" mathematical="350" ideographic="400" hanging="500">
          <font-face-name name="Super Sans Bold"/>

      <missing-glyph><path d="M0,0h200v200h-200z"/></missing-glyph>
      <glyph unicode="!" horiz-adv-x="300"><!-- Outline of exclam. pt. glyph --></glyph>
      <glyph unicode="@"><!-- Outline of @ glyph --></glyph>
      <!-- more glyphs -->

  <text x="100" y="100" 
           style="font-family: 'Super Sans', Helvetica, sans-serif;
                  font-weight: bold; font-style: normal">Text 
    using embedded font</text>



FreeType Glyph Conventions

What Makes Fonts Hard

SVG Font Issues

No hinting (grid-fitting) -- Hinting has to do with aligning a vector outline to a screen or printer's pixels. This can be good or bad, depending on the application. PDF and SVG are supposed to be device-independent, so hinting should't affect the placement of characters. Unfortunately this means that at low resolution, the text might not look as good as it would with hinting.

Font Recomendations