Re: SVG Fonts inside of OpenType fonts? [Cross-post from]

On Wed, Jun 29, 2011 at 8:03 PM, Erik Dahlstrom <> wrote:

> The reason why I like SVG Fonts is because they're different to the other
> formats. It's easy to build a new SVG Font using javascript and to use it
> directly in the browser. If an SVG Font is stored in an OFF container I take
> it that would mean that it's not possible to change it dynamically?

Not directly, but it would still be possible to generate new fonts on the
fly --- use a JS library that wraps SVG glyphs in an OpenType container, and
load the result using Blob URL. JS engines are good at manipulating binary
data these days.

I remember discussing javascript in SVG Fonts with Dave Crossland at a
> conference, and there are some interesting things you could do with that,
> e.g randomize glyph selection (to make a more natural handwriting font for
> example). This is a bit of a pain to do today, but you can do that with
> altGlyph (note: altGlyph isn't part of the font itself, it's an operation on
> the text, but it can be used together with an SVG Font to give the custom
> glyph-selection functionality). Such a script would need to operate on the
> document that uses the font and needs access to the SVG Font too for knowing
> what glyphs to map to, so it's rather context-dependent. There's currently
> no way to define random glyph-mapping in the svg font itself. Out of
> curiosity I'd be interested in hearing if there are any other use-cases that
> would be helped by having script support in the font itself.

Having script run in the font itself has all the same issues that having
script run in SVG images would have --- and more. Just a taste: what would
you do if your font does "document.location = '';" (i.e.,
replaces the font document with some HTML document)? Get script turned on in
SVG images in Opera, then we can talk again :-).

I don't see how having script run in the font itself even helps your
use-case. All you need are extra glyphs in the font and a way to mark up
content to pick specific glyphs. I believe OpenType supports named glyphs,
so we could just define <altGlyph glyphRef="name"> to pick them, or if the
glyphs aren't named we could make <altGlyph glyphRef="123"> pick them by ID.
To help a script mark up the document, we could create an API to let the
script read arbitrary font tables*, and provide a special table in the font
listing the random alternates.
* But if you do that, you may want a same-origin restriction on fonts :-)

Another approach --- probably better --- would be to present the extra
glyphs as OpenType alternate stylistic sets, and then use the CSS
font-variant-alternates property to select them at random:

But I think here we might be drifting too far towards picking the most
bizarre use-cases we can think of and trying to ensure we support them :-).
We should focus on things Web authors want to do.

"If we claim to be without sin, we deceive ourselves and the truth is not in
us. If we confess our sins, he is faithful and just and will forgive us our
sins and purify us from all unrighteousness. If we claim we have not sinned,
we make him out to be a liar and his word is not in us." [1 John 1:8-10]

Received on Wednesday, 29 June 2011 10:02:19 UTC