[cairo] Re: Filling and stroking an object with different color/alpha

Christopher Barker Chris.Barker at noaa.gov
Mon May 1 16:19:00 PDT 2006


Carl Worth wrote:
>> "I want a Polygon with a 5 pixel wide black line, filled with Blue"
> 
> Right. That would be a "retained-mode interface" where the system is
> aware of objects, while cairo provides an "immediate-mode interface"
> which accepts only drawing commands, without any notion of objects.

not quite. There is the "retained-mode interface", which sometimes 
people call an Object Canvas. As it happens, wxPython doesn't have one 
of these, but I've written one for it (wx.lib.floatcanvas).

However, there is something a bit in between, which having calls like

dc.SetPen(...)
dc.SetBrush(...)
dc.DrawPolygon(....)

What's nice about this is that renderer knows about the line and the 
fill when doing a drawing operation, so it could, in theory, do 
something smart with how they interact.

> Both kinds of interfaces are useful, and we believe the best
> architecture is a retained-mode interface built on top of an
> immediate-mode interface.

I agree with that, absolutely.

> I would recommend taking a look at goocanvas:

hmm, I wonder if it could be used outside of GTK, for use with other 
Cairo back ends?

> Yes, there is a solution for this---though it can get a bit tricky
> depending on exactly what you want. Basically, any solution involves
> first rendering to an intermediate surface and then using that result.

I had suspected as much, but had no idea how to do it. Thanks for the 
pointers. However, while we're talking pie-in-the-sky, I wonder if the 
"filling and stroking as distinct operations" approach is a bit dated. 
It certainly has issues with alpha channels.

My fantasy would be a fill_and_stroke call, that would do them both at 
once. For instance, for my case (an alpha blended shape with a fat 
stroke), It could render the stroke first, while keeping track of what 
it had done, so that when you rendered the fill, it wouldn't draw over 
the stroke. Of course, that would get tricky with anti-aliasing.

I suppose in the meantime, a call like that could just render to an 
intermediate surface, as you suggested.

By the way, what would happen with PDF and PS? do they support and 
intermediate surface?

> So this
> kind of operation will be getting easier to do in the future.

That's nice. I'm looking forward to it.

> I don't know if the preceding paragraph made much sense at all.

It made perfect sense. Which doesn't mean I could code it, but...

Thanks for all your help.

-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


More information about the cairo mailing list