[cairo] Text Along Path

Behdad Esfahbod behdad.esfahbod at gmail.com
Tue Nov 24 14:45:02 PST 2015

On 15-11-24 04:22 PM, Lawrence D'Oliveiro wrote:
> On Tue, 24 Nov 2015 12:13:11 -0600, Behdad Esfahbod wrote:
>> I wrote this many years ago, and serves as proof of concept rather
>> than fully fleshed out code.
> Did you ever figure out why large y-values would magnify the error from
> Cairo flattening the path? And not large x-values, for example? I had a
> quick look at the code (src/cairo-spline.c), and it seems to be doing
> the usual De Casteljau thing.

When you De Casteljau the curve, the new line spline has slightly different
tangent at every point of the curve, and hence different normal vector.
Normally, this is invisible and fine.  But the different normal vector is then
magnified by the y-value, so the error is magnified.

It's possible to fix it this way: Use De Casteljau or forward differencing to
find the t-value corresponding the requested x-value.  Then use the true cubic
curve to calculate the curve normal at t and use that to offset for y-value.

To do that, change draw_twisted() to enable cairo_copy_path() instead of
cairo_copy_path_flat().  Then change the piece of code with a "FIXME" in it to
calculate a better ratio using De Casteljau when it's currently doing this:

  ratio = the_x / parametrization[i];

You can also significantly optimize curve_length() by implementing De
Casteljau instead of calling cairo.



More information about the cairo mailing list