[cairo] How to draw paths with different registration points?
Chris Wilson
chris at chris-wilson.co.uk
Fri Jan 29 05:51:49 PST 2010
On Fri, 29 Jan 2010 02:55:27 -0800 (PST), Stuart Axon <stuaxo2 at yahoo.com> wrote:
> In the Shoebot project were implementing the Nodebox api using Cairo.
> I wonder if anyone on the cairo list would know how we can implement something:
>
> Nodebox lets you set the registration point of paths drawn
> (when you draw a shape in NB it creates a path)
>
> This is set using the transform mode, which can change during the script:
>
> transform(mode=CORNER)
> In this case the current cursor position is the top-left of any path that will be drawn.
>
> transform(mode=CENTER)
> In this case the current cursor position is the middle of any path that will be drawn.
>
> Any ideas ?
This is how I would approach this problem, given a path constructed
outside of my control (forgive the pseudo Python):
draw_path(cr)
extents = cr.path_extents()
path = cr.copy_path()
cr.save()
cr.translate(compute_offset(extents, MODE))
cr.new_path()
cr.append_path(path)
cr.restore()
This does presume that the PyCairo has wrapped paths to hide their ugly C
nature...
-ickle
--
Chris Wilson, Intel Open Source Technology Centre
More information about the cairo
mailing list