W3C home > Mailing lists > Public > www-svg@w3.org > July 2011

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>
To: www-svg@w3.org
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.

For radial gradients we can do something similar (except that for
spreadMethod=pad we just take the last color).

In short, at least for gradients we really ought to be a little less
restrictive, as the "extension" to zero width/height is not that
difficult and provides useful results. (I expect that it's not much more
difficult for other cases where objectBoundingBox can be used, but it
might be less useful there.)
Received on Wednesday, 13 July 2011 12:25:22 GMT

This archive was generated by hypermail 2.3.1 : Friday, 8 March 2013 15:54:48 GMT