I am developing a game where letters of the alphabet are being rendered using Bézier / Hermite curves. At the moment I’m defining the curve points myself using a simple spline editor, but this method is ineffective given that I’ll eventually have to build 52 glyph splines (All uppercase and lowercase letters). So I am trying to find a way to get this data from a third party source.
Note that I’m not looking for glyph outlines (ex: a polygon) but the “skeleton” of a glyph, or what it would look like if you had drawn the glyph with a pencil.
It occurred to me yesterday that it might be possible to extract this data from a font file (of some flavor) but most of my googling in this area points me to the GlyphRun class from the Microsoft GDI, which is not what I’m looking for.
So does anyone know an easy way to extract this data from font files? Or is there another resource somewhere where I can get this data? Once I have the vector points I will serialize them to a format my game can read, so the process of extracting the vector data does not necessarily need to happen at runtime.
There is no easy way. However you could get FlyingText3D, which has code that parses TrueType fonts. The purpose is to create polygons, but there is some commented-out code I used for debugging that creates outlines using Vectrosity. Since you get the source code, you could hack away at it to produce the effect you want. It would at least be far easier and faster than creating your own TrueType parser, since that stuff is quite arcane. (Or maybe you could just use FlyingText3D as-is, with an outline shader for the letter objects.)
Based on what i’m seeing, it looks like most font data is represented as an outline of the glyph (which makes it easy to produce polygons as in FlyingText3D). But I really only need points describing the “stroke” if you will.
For example the glyph ‘A’ would have 5 points representing the beginning and end of each stoke, plus data describing the stroke order and points involved IE: 1 => 2, 1 => 3, 4 => 5. Where point 1 is the top of the A, points 2 3 are the ends of the ‘legs’ and points 4 and 5 are the line in the middle.
Would I have better luck with vector font definitions? I’ve been trying to figure out how SVG files deal with font, but no luck.
Oh, I see what you’re saying. I don’t know of any font data like that; SVG fonts are also outlines. So I’d say hpjohn is right in that drawing them yourself is the way to go.