[cairo] Adventures in line widths

Christopher Barker Chris.Barker at noaa.gov
Thu Apr 27 14:28:47 PDT 2006


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

-- 
Christopher Barker, Ph.D.
Oceanographer
                                     		
NOAA/OR&R/HAZMAT         (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov
-------------- next part --------------
A non-text attachment was scrubbed...
Name: junk6.png
Type: image/png
Size: 3897 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/cairo/attachments/20060427/e7b97b4d/junk6.png


More information about the cairo mailing list