[cairo] Path Representation In Qahirah
ldo at geek-central.gen.nz
Tue Mar 24 15:09:32 PDT 2015
It is handy to be able to perform manipulations on paths. In my Qahirah
wrapper for Cairo <https://github.com/ldo/qahirah>, I originally stored
a Path as a sequence of Elements--LineTo, MoveTo, CurveTo and Close
objects, directly mapping to the obvious Cairo drawing calls.
However, this representation makes it hard to do certain kinds of
manipulations, such as constructing mesh patches following the shape of
the path to produce a shadow effect.
So I have changed the internal representation I use. This is now a
sequence of Segments, each of which is a sequence of Points, together
with an open/closed indication for the Segment. Each Point has a
coordinate Vector, together with an on-curve/off-curve flag. Two
successive on-curve points produce a straight line; a single off-curve
point in-between defines a quadratic Bézier, while two off-curve points
in-between make for a cubic Bézier. Each Segment must begin and end
with an on-curve Point.
I still support the Element representation, by providing conversions
to/from the Segment representation, since Elements still provide the
most natural mapping to the way paths are drawn in Cairo.
More information about the cairo