Re: stroke=gradient for lines or horizontal paths

From: Jasper van de Gronde <th.v.d.gronde@hccnet.nl>
Date: Wed, 13 Jul 2011 14:24:53 +0200
Message-ID: <4E1D8E95.1070108@hccnet.nl>

```On 13-07-11 10:42, Dr. Olaf Hoffmann wrote:
> ...
> I think, if width or height of a bounding box is zero, it is not obvious,
> what non zero values in objectBoundingBox units mean.
> Therefore for most gradients or patterns the presentation would
> be undefined, if there would be no such specific rule to ignore
> it or maybe another how to interprete such degenerate cases
> in general.
> ...

A bounding box with zero height or zero width is not a problem in most
cases I can think of. For linear gradients there is hardly any problem
at all, just compute the endpoints like you normally do. Even if the two
endpoints coincide in user space we can still derive a sensible
direction for the gradient based on the bounding box coordinates given.
If you want to formalize this you could probably do something like this
(assuming a bounding box from (0,0) to (bx,by) and a gradient with x1=y1=0):

x2UserMag = sqrt((x2BB*bx)^2 + (y2BB*by)^2)
x2UserDir = atan2(y2BB*(by+eps),x2BB*(bx+eps))

Then take the limit as eps goes to zero from above. This is quite
sensible, as by definition of the bounding box bx and by should be >= 0
in the current user coordinate system. And note that nothing special
happens close to zero, in practice there should be no discernible
difference between having a bounding box with zero width/height and one
with a very slightly larger non-zero width/height.

If x2UserMag is zero we still have a problem, as the gradient goes from
the first to color to the last color over a distance of zero. However,
it's definitely not impossible to give a sensible meaning to this case
as well. If spreadMethod=pad, just draw the first and last color on
either "side" like you normally do. For reflect and repeat I would just
take the average color over the gradient everywhere. These
interpretations just follow directly from imagining what happens when
you shrink a shape further and further.