How to get the length of paths in an given font/character I wan't create some LED-rope text, using some script font, like the following:



For this I need somewhat estimate the needed length of the LED-rope for the given letter (or combinations of letters).

Some more info:


The font will be TTF or FT2.
I could manage some programs in perl using the FreeType library, eg. read some properties of the character in the font-file - if this helps.
Also could install Inkscape (Illustrator  open-source alternative) or even could use Illustrator at my friend - if any of this tools could help.


Looking for some suggestions how to measure the length of paths in the given font for the particular character (or whole text).

I don't need exact precision, (see the purpose above) and looking for the solution as simple as possible, but I haven't any idea how even approach this problem. :(

Of course, I always could print the text and buy some inexpensive curve runner, but would be better to have some computer-based solution. :)

Ps: I'm not fully sure that this is the right place to ask such question, if not - I will delete it, but please suggest some better place.
The way I would approach this is to get the outline curves of the font and then break each one down into some fixed number of steps (like, say, 100), and make a series of very small straight lines.

So if you've got some bezier curve, you loop t from 0 to 1 in 100 steps and plug it into the equation:

double x = calculateBezier(0.0, c0.x, c1.x, c2.x, c3.x);
double y = calculateBezier(0.0, c0.y, c1.y, c2.y, c3.y);
double dist = 0.0;
for (double t = 0.01; t &lt;= 1.0; t+= 0.01)
{
    double nextX = calculateBezier(t, c0.x, c1.x, c2.x, c3.x);
    double nextY = calculateBezier(t, c0.y, c1.y, c2.y, c3.y);
    double nextDist = sqrt((nextX - x) * (nextX - x) + (nextY - y) * (nextY - y));
    dist += nextDist;
}


Where calculateBezier() is a function that calculates a point on a bezier curve given the parameter t and control points c0 through c3:

double calculateBezier(double t, double c0, double c1, double c2, double c3)
{
    double t1 = 1.0 - t;

    return (t1 * t1 * t1) * c0 + 3.0 * (t1 * t1) * c1 + 
            3.0 * t1 * (t * t) * c2 + (t * t * t) * c3;
}


And just add the distances of each part of the curve until you're out of curves.

Note that this assumes cubic bezier curves. For quadratic, the calculateBezier function would calculate a quadratic one (like described here).