[cairo] Adventures in line widths - ellipse example
Steven Chaplin
stevech1097 at yahoo.com.au
Fri Apr 28 04:32:23 PDT 2006
On Thu, 2006-04-27 at 14:28 -0700, Christopher Barker wrote:
> This is all a little beyond me, but I was about to post a question here
> that's related.
>
> I'm exploring what I might want to use as the rendering toolkit for a
> mapping engine. I'm evaluating Cairo and Agg at the moment. I see from
> the note you referred to that you've been talking to Maxim, which is
> great; Agg has some very nice features. It's sub-pixel rendering is superb.
>
> Anyway, I was trying to figure out how to draw an ellipse with Cairo. I
> found an example in the docs somewhere that indicated that you need to
> translate and scale appropriately, then draw a circle.
>
> I got this to work, but I've found that the pen gets scaled with the
> circle, so I get very fat lines, and they are fatter in the direction
> that the ellipse is longer.
>
> Here's the Python code I'm using:
>
> def DrawEllipse(self, x, y, width, height):
> ctx = self.ctx
>
> ctx.save()
>
> ctx.translate(x + width / 2., y + height / 2.);
> ctx.scale(1. * (width / 2.), 1. * (height / 2.));
> ctx.arc(0., 0., 1., 0., 2 * N.pi);
>
> self.SetupFill()
> ctx.fill_preserve()
> self.SetupStroke()
> ctx.stroke()
>
> ctx.restore();
>
> Where self.SetupStroke is:
>
> def SetupStroke(self):
> ctx = self.ctx
> ctx.set_source_rgba(*self.PenColor)
> ctx.set_line_width(self.LineWidth)
> ctx.set_dash(*self.DashPattern)
>
> when I do this:
>
> x, y, w, h = 50, 100, 300, 50
>
> dc.LineWidth = 1
> dc.DrawEllipse(x, y, w, h )
> dc.SaveFile("junk6.png")
>
> I get the enclosed PNG.
>
> Could I change the order I make the calls to get this right? Or is this
> being fixed by what this discussion is about?
>
> -Chris
Create the ellipse path and do ctx.restore() before you do the stroke.
Example attached.
In general I thinks its best to have path creation functions and
fill/stroke functions which are separate.
Regards,
Steve
> _______________________________________________
> cairo mailing list
> cairo at cairographics.org
> http://cairographics.org/cgi-bin/mailman/listinfo/cairo
-------------- next part --------------
A non-text attachment was scrubbed...
Name: e1.py
Type: text/x-python
Size: 1305 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/cairo/attachments/20060428/6e873a01/e1.py
More information about the cairo
mailing list