3
$\begingroup$

I wan't create some LED-rope text, using some script font, like the following:

enter image description here

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.

$\endgroup$
2
$\begingroup$

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 <= 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).

$\endgroup$
  • $\begingroup$ +1 - just not need break the font into the parts, because the font itself is stored in the ttf as a pairs of x-y coordinates. (the connections between the points could be straight or some are quadratic beziers). Also see my answer above - it is too complicated for my use-case. Thanks anyway for the answer it kicked me to the right direction - e.g. start studying the ttf font structure. :) $\endgroup$ – jm666 Nov 10 '17 at 9:16
0
$\begingroup$

I decided to solve the LED-rope problem using Inkscape as:

  • enter the wanted text into the Inkscape
  • set the color of the text to yellow
  • add new layer above the text and lock the text layer
  • in the new layer, manually draw over the letters my own wanted bezier path(s)
  • and finally use the tool in Extensions -> Visualise Path -> Measure Path... - this adds the length of the given bezier path into the drawing as text.

The reason why:

I studied a bit the ttf-font structure (the whole new world for me). This blog entry and this Reference manual helped a lot understanding the following (rough) basics.

  • the given glyph (character) is composed from many closed paths, e.g. the letter O is composed from two paths (outer circle and the inner circle).
  • the paths are stored in the font file as pairs of x-y coordinates
  • so it isn't so hard to calculate the length of each path from the given coordinates.
  • but - in such way I will get the lengths of the all outlines. Creating the outlines using the LED-rope it could be even interesting and also it is used at many examples, (like bellow), but this isn't what I want - I want a simple path(s) - as in the image in the question.
  • getting such simple path from the font's many outlines would need some tracing and approximation and other complicated math, which is definitely outside of my area of interest.
  • therefore (for me) would be much easier just manually create the simple path's and measure their length in the Inkscape.

Also,

  • if someone want the length of the font's outlines, it is easily doable
  • just need break apart the text into characters
  • transform the (font) objects into the strokes
  • and use the Measure path... tool

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.