views:

302

answers:

2

I have an application that needs to apply some transformations to text (including non-affine transformations). Does anyone know of a toolkit (or group of tools) that would let me bring in a True Type or Postscript Font, get the glyphs as outlines, then apply transformations to the outlines and render it as a bitmap or svg file ? Flash won't do non-affine transformations so it is out. Illustrator has a function which converts text to outlines, but Illustrator scripting is very unstable so I can't really use it for this. Thanks for any help.

A: 

cairo might do for this.

Ignacio Vazquez-Abrams
I've looked at cairo, I didn't see the functions I was looking for. Also it is a C library and it seems there is a lot of overhead in installing another binding, since I don't want to use C. Here is something like what I'm looking for in a Perl/FreeType library. I'd like to use PHP, or maybe C#. http://search.cpan.org/~geoffr/Font-FreeType-0.03/lib/Font/FreeType/Glyph.pm
azgolfer
FreeType will give you the glyphs, but 1) not many of its bindings are stable, and 2) you'll still need to render the glyphs, and cairo is the best choice for that.Also, `cairo_matrix_t` does offer some transformations; which transforms were you interested in that it doesn't support?
Ignacio Vazquez-Abrams
Well, the FreeType lib gives you the glyphs as either PostScript or SVG drawing commands. So then you have a standard format set of curves for which there are presumably many libs which will let you make the text follow a sine wave, make it expand to an enveloping shape, etc. Does cairo give you access to the paths that the font uses in drawing so you can manipulate the points ?
azgolfer
I did not see anything that allows you to go down to the granularity of the glyph curves.
Ignacio Vazquez-Abrams
A: 

You could use the Batik TTF to SVG Font converter. The SVG font format uses the same path data format that the SVG <path> element uses.

For example, this is the output from converting Gentium Basic Regular using the above tool. With the right coordinate system, you can just grab out the path data, transform it however you like, and then draw it with a <path>. Note though that the glyph coordinate system in SVG fonts is actually inverted, with the (0,0) at the bottom left corner of the glyph cell box, compared to the regular SVG canvas which has (0,0) at the top left corner. So don't forget to flip the glyph, e.g. by putting transform="scale(1,-1)" on the <path> you use to render the glyph.

Once you have the SVG document that renders the glyphs as shapes you can convert it to a bitmap using your favourite tool. (Batik can do that too.)

heycam
Thanks, I'll look into this
azgolfer