[cairo] Radii of radial gradients

Bill Spitzak spitzak at d2.com
Fri Mar 2 17:03:33 PST 2007


Never mind my discussion of cones below, I was wrong about that.

Here is (I hope) a consistent proposal:

EXTEND_NONE should be very similar (but not exactly) the same as adding 
a transparent color stop at 1. It should actually act like 
EXTEND_REPEAT but clip the gradient with a antia-aliased path. This is 
similar to how EXTEND_NONE should work for images (producing a sharp 
anti-aliased clipping quadralateral of the EXTEND_REPEAT image).

1. If the 0 circle is entirely inside the 1 circle, the clip is the 1 
circle, thus producing a solid circle.

2. If the 0 circle intersects or is outside the 1 circle then your 
calculation should take the *lower* root, and the clip is the union of 
the two circles and the trapazoid formed by the tangent lines and lines 
joining the tangent points. The result will look like a truncated cone 
(if the 0 circle is not a point) that points up out of the paper toward 
you. This must be drawn to be continous with the previous case.

3. If the 0 circle completely encloses the 1 circle then the clipping 
should be the 0 circle and filled with a constant 0 color stop.

To draw the PDF cone using the above:

The above Cairo gradient can be used directly if the extend is set so 
the 0 circle is filled in and/or the 0 circle has zero size. Otherwise:

1. If the 0 circle is entirely inside the 1 circle, clip out the 0 
circle before drawing the gradient, thus producing a "donut".

2. If the 0 circle encloses the 1 circle, make another gradient with 
all the stops reversed and the circles swapped. If the 1 end should be 
opaque you can just use this gradient. If the 1 end should be 
transparent you should clip out the 1 circle and use this gradient.

3. Otherwise two gradients must be composited. First draw the "back" of 
the cone by doing case 2 above (even though the circles intersect). 
Then do case 1 atop that. Use the resulting temporary surface as the 
source.

On Mar 2, 2007, at 12:13 PM, Bill Spitzak wrote:

> For your first cone drawing, EXTEND_NONE would clip it with the union 
> of the larger circle and a triangle so you get a cone with a sharp 
> point even if the smaller circle is non-zero.
>
> For the second cone drawing, EXTEND_NONE would clip it with the same 
> "hole" as before, so there is just a transparent circle, you still see 
> the infinite linear gradient. This is necessary or there will still be 
> the problems with discontinuities as inner circle moves outside the 
> outer one. Also for my PDF solution (below) it avoids double 
> multiplying of the edge pixels which would leak some back-side pixels 
> where they should not be seen.



More information about the cairo mailing list