[cairo] Path Gradients

Bill Spitzak spitzak at thefoundry.co.uk
Sat Dec 22 18:42:25 PST 2007


What it is probably doing is connecting matching points in the two 
paths. Both paths are divided into the same number of small straight 
line segments, and matching pairs are joined together by straight lines 
to make quadralaterals, and these are Gourand shaded with the gradient.

Exactly how the paths are joined together can be determined from the 
GDI+ interface. If it requires the two paths to have the same number of 
points, it is probably just matching up the points (of a segment is a 
bezier, both it and the opposite segment are divided into the same 
number of straight lines).

If the paths really can be arbitrary then they are doing something 
tricky. I don't think they are just dividing them into the same number 
of segments, as users would expect sharp corners in the two paths to 
connect together. Perhaps it tries to guess the matching control 
points, and then divides the segment opposite any unmatched points 
evenly to line them up.

If instead of a path there is a center point, it degenerates from 
quadralaterals to a fan of triangles from this center point to the 
path.

It may also make sense to take this out of Cairo and put it in calling 
code, such as a library. Cairo then gets quads to color with the 
gradient. However this will require a method to not antialias the edges 
of the quads so that they join together correctly. This is also useful 
for the meshes mentioned earlier. I am not absolutely certain it would 
work, but my proposal is to allow edge antialiasing to be turned on/off 
for each segment in a path.

> Ok then. From what I understand of the GDI+ implementation, you have a 
> path and a center point (or an outer path and an inner path instead of 
> a single center point). Then you set color stops that define how the 
> gradient looks going from the center point (or the inner path) to the 
> outer path. IIRC, if you use an inner path, the entire path is filled 
> with the first color stop, and then the gradient starts at the edges 
> of the inner path.
>
> So perhaps an API that looks something like this:
>
> cairo_pattern_t* cairo_pattern_create_path_gradient(const cairo_path_t 
> *outer_path, const cairo_path_t *inner_path);
>
> Then you can add colors stops as needed. It seems to me that the 
> center point could be represented using the function above. But you 
> could also provide an additional function that creates a pattern based 
> on an X and Y center point instead of an inner_path. Another function 
> could be provided that uses the current path (and either inner_path or 
> center point) to construct the pattern.
>
> Questions, thoughts, etc.?
>
>
> BTW - here is a good page on using GDI+ path gradients: 
> http://msdn2.microsoft.com/en-us/library/ms533917.aspx
>
>> -----Original Message-----
>> From: behdad at behdad.org
>> Sent: Wed, 19 Dec 2007 16:48:33 -0500
>> To: bobby8934 at inbox.com
>> Subject: Re: [cairo] Path Gradients
>>
>> On Wed, 2007-12-19 at 16:29 -0500, Bobby Salazar wrote:
>>> That's too bad. Perhaps it would help if I were to put up some money 
>>> to
>>> the
>>> person or people who implement it? Speak up if you're interested in
>>> working
>>> on this, and I can come up with an amount.
>>>
>>> As for the API, I don't really care how it worked as long as it was
>>> simple and
>>> straight-forward. And you could always take a look at the GDI+ API 
>>> for
>>> this.
>>
>> Maybe you can look at the GDI+ API and come up with a suggestion based
>> on it?  That helps more than monetary offers...
>>
>>
>> behdad
>>
>>>> -----Original Message-----
>>>> From: cworth at cworth.org
>>>> Sent: Wed, 19 Dec 2007 10:42:05 -0800
>>>> To: bobby8934 at inbox.com
>>>> Subject: Re: [cairo] Path Gradients
>>>>
>>>> On Tue, 18 Dec 2007 14:03:50 -0800, Bobby Salazar wrote:
>>>>> Is it possible to fill a shape with a path gradient (similar to
>>>>> GDI+) using Cairo?
>>>>
>>>> Not currently, no.
>>>>
>>>> People have expressed interest in something like that before. The 
>>>> two
>>>> things we are missing are:
>>>>
>>>> 	1. A detailed description of what the API would look like.
>>>>
>>>> 	2. An implementation of that.
>>>>
>>>> Anyone is free to help out with either or both parts as they would
>>>> like to.
>>>>
>>>> Sorry that we don't have anything like this yet. But I do hope you
>>>> still have fun with cairo!
>>>>
>>>> -Carl
>>>
>>> ____________________________________________________________
>>> GET FREE SMILEYS FOR YOUR IM & EMAIL - Learn more at
>>> http://www.inbox.com/smileys
>>> Works with AIM®, MSN® Messenger, Yahoo!® Messenger, ICQ®, Google 
>>> Talk™
>>> and most webmails
>>> _______________________________________________
>>> cairo mailing list
>>> cairo at cairographics.org
>>> http://lists.cairographics.org/mailman/listinfo/cairo
>> --
>> behdad
>> http://behdad.org/
>>
>> ...very few phenomena can pull someone out of Deep Hack Mode, with two
>> noted exceptions: being struck by lightning, or worse, your *computer*
>> being struck by lightning.  -- Matt Welsh
> _______________________________________________
> cairo mailing list
> cairo at cairographics.org
> http://lists.cairographics.org/mailman/listinfo/cairo


More information about the cairo mailing list