Open dirkschulze opened 6 years ago
The Working Group just discussed stroke-bounding-box and non-scaling-stroke
.
@dstorey @boggydigital @AmeliaBR Here an example of the different computed boxes w/o looking at non-scaling-stroke
.
The first shape is the extreme case with the worst outcome of the heuristic. The second shape is the regular outcome for many shapes in real life.
The tight stroke box in the image is the idealistic outcome. A few implementations are able to compute it correctly in all cases... including paths with cubic curves.
I would actually argue that the bounding box should be calculated assuming a non-dashing stroke.
I would actually argue that the bounding box should be calculated assuming a non-dashing stroke.
And that's currently specified in both algorithms for calculating it: in CSS masking, and in SVG 2.
Where the two algorithms differ is in how they handle mitered corners and line caps. The SVG 2 algorithm uses the actual stroke shape for painting (assuming no dashing), while the CSS Masking algorithm (which explicitly warns that it may be overridden by SVG 2) uses a set of heuristics that add on a little bit extra to the stroke bounding box for path
, polygon
and polyline
based on the value of the line join/cap properties, without actually checking for whether those properties cause the stroke to extend outside the box by (object bounding box + 1/2 stroke width padding).
If we're using the actual stroke shape, then maybe it makes sense to use the shape as painted, with vector effects included. (But that still creates complications of translating that shape back into the current coordinate system.) If we're using the heuristics, then definitely keep it simple.
Has anyone actually implemented any of these algorithms for properties that use a stroke-box
value?
I would actually argue that the bounding box should be calculated assuming a non-dashing stroke.
Yes, otherwise it changes if stroke dash, or offset, is animated.
The SVG Working Group just discussed [css-masking-1] stroke-bounding-box and non-scaling-stroke
, and agreed to the following:
RESOLVED: Desire to use the same heuristic as CSS masking, but modify it to make it apply equally to all shapes, and modify it to incorporate non-scaling stroke. Revisit this once we have specific text
Currently, the stroke bounding box does not take the CSS property
vector-effects
with the valuenon-scaling-stroke
into account.Though browsers do support
non-scaling-stroke
, the implementation can be very different and SVG does not require a specific way. Computing the actualstroke-width
depending on the different applied transforms and thevector-effects
is non trivial. (Note that even browsers currently do not compute thestroke-with
fornon-scaling-stroke
but rather do it as part of the painting process.)I'd like to propose to keep the algorithm as is and mention that
vector-effects
do not affect the stroke bounding box.