[cairo] Cairo is non-deterministic?

Vladimir Vukicevic vladimirv at gmail.com
Mon Jan 2 06:11:16 PST 2006


Your path creation is a little strange there.. in particular, the
current path is not part of the gstate, so saving/restoring has no
effect on it.  Also, close_path() is a path operation, adding a
lineto() from the current point to the start of the path -- doing it
after stroke() doesn't really make sense, since the stroke() will
consume the path.  (stroke_preserve doesn't, but it still doesn't make
sense the way you're using it).  rel_move_to is also a path command,
and not a translation matrix command

The reason why things don't work if you invert the two blocks is that
you end up drawing very different paths when you switch the order. 
I'd suggest you structure your rendering like this:

save()
translate(*self.border_pos)
translate(200, 30)

# draw up
save()
new_path()
rel_line_to(0, -100)
stroke()
restore()

# draw line
save()
new_path()
rel_line_to(...) # draw your line bits
stroke()
restore()

Note that the new_path()'s aren't strictly necessary, but it's good
defensive programming in case someone left a path in the context
you're drawing to.

    - Vlad

On 1/2/06, Lawrence Oluyede <l.oluyede at gmail.com> wrote:
> I'm using Cairo (with pycairo) for a test project and meanwhile I'm
> gonna learn to use it but I'm "worried" about somethings that I can't
> handle. Why this works:
>
>     def draw_rows(self):
>         self.context.save()
>         # move down to the border position
>         self.context.move_to(*self.border_pos)
>         self.context.rel_move_to(200, 30)
>
>         # draw one segment up
>         self.context.save()
>         self.context.rel_line_to(0, -100)
>         self.context.stroke()
>         self.context.close_path()
>         self.context.restore()
>
>         # draw an horizontal line (unit = 10 pixels)
>         self.context.save()
>         unit = 10
>         for i in range(4):
>             self.context.rel_line_to(unit, 0)
>         self.context.stroke_preserve()
>         self.context.close_path()
>         self.context.restore()
>
>
>         self.context.restore()
>
> and the same with "draw one segment up" block written after the "draw
> an horizontal line" doesn't?
>
> Is there something I'm missing?
>
> --
> Lawrence
> http://www.oluyede.org/blog
>
> _______________________________________________
> cairo mailing list
> cairo at cairographics.org
> http://cairographics.org/cgi-bin/mailman/listinfo/cairo
>
>


More information about the cairo mailing list