[cairo] Path Gradients

Bill Spitzak spitzak at thefoundry.co.uk
Fri Jan 4 12:05:14 PST 2008

Behdad Esfahbod wrote:
> On Fri, 2008-01-04 at 11:12 -0800, Bill Spitzak wrote:
>> Behdad Esfahbod wrote:
>>>> It was unclear what happens with multiple-step gradients, which some
>>>> of 
>>>> the examples show. Does it only change the last step, or is there an
>>>> api 
>>>> to change all the steps?
>>> The actual radial stops where done in the code using a Blend object,
>>> that's like just having stops for alpha value.  That is, instead of the
>>> linear interpolation between the two ends, user can provide a detailed
>>> blend function.  No separate color stops.
>> I'm sorry, I thought you were talking about the example where the color 
>> along the edge changes, as shown by the top-left triangle in this picture:
>> http://www.java2s.com/Code/VBImages/PathGradientBrushesDiamondRectangleCirlceandquad.PNG
>> It is apparent from the examples that they support multi-stop gradients, 
>> but there is no example of what happens if you specify *both* this and 
>> if you change the colors along the path. Does it only change the last 
>> stop? Or is there an api to change all the stops? Or does it just not work?
> IIUC the multiple stops are one per path point.  That's for the conical
> part of the thing.  AFAIU you can't do cairo radial gradients using it
> because on the radial side it just accepts a blend function.  No
> separate color data.

The example in this paper, near the bottom, with the colored star, seems 
to show a multi-stop gradient being used:


> That is, given path P, color stops S, center C, center color Cc, and
> blend function F, the color at x0,y0 will be computed as...

Yes this is my best guess as well. However it is unclear how they 
achieve rectangular shapes with nice fixed-thickness edges. If they are 
drawing several shapes with different gradients, this could be very 
annoying, as reproducing the same results without seams will require 
bug-for-bug compatability with whatever they are doing.

More information about the cairo mailing list