-
Notifications
You must be signed in to change notification settings - Fork 131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bounding box algorithm is not precise #422
Comments
In addition, the stroke shape computation code is not specific enough:
There is more that contributes to the stroke bounds:
The algorithm in the mask spec is more specific: https://drafts.fxtf.org/css-masking-1/#compute-stroke-bounding-box This algorithm is used for Maybe we should just reference that one. |
The CSS stroke bounding box algorithm is fairly loose. It exaggerates the bounds a lot for shapes that use mitred joins. A mitre limit of 10 is fairly typical (it is the PDF and PS default). So the padding around any shape would be five times the stroke width. See demo: https://jsfiddle.net/5y8zt05h/18/ I'm not sure that the CSS algorithm would be suitable in the SVG context. |
@BigBadaboom Please take a look at the linked algorithm first. This is not fairly loose but very specific and for SVG elements exclusively. |
Bad choice of words on my part, I guess, I meant loose in the sense that it is not a very tight bounding box. |
@BigBadaboom for strokes it is not the tight bounding box. For Masking, transform, fill and stroke and many other specs it has the very practical reason that graphic libraries provide different boxes for the stroke bounding box depending on their capabilities. For a keyword like |
@dirkschulze If that is the case, then I think the Bounding Box section of the spec will need to be updated. The paragraph starting "For curved shapes, the bounding box..." gives the strong impression that all bounding boxes should be tight. |
Not blocking updated 2.0 CR publication - assigning 2.0 Recommendation milestone to clean this up before 2.0 REC |
The algorithm in Bounding Boxes describes how to compute the different boxes sizes depending on the booleans fill, stroke, markers, clipped.
However, with the exception of fill, all algorithms have the description:
However, box is specified to get initialized as (0,0,0,0) and therefore has an actual value. If box wasn't set to fill already, then all boxes will include the point (0,0) which is not what we want to have.
Maybe we should let each boolean initialize box to the value returned by each operation if it isn't initialized already, otherwise create the union of box and the specific rects.
Edit: Stroke bounding box includes the fill bounding box, always. Therefore, for stroke we can also just initialize box to the computed stroke bounding box if the value of
stroke
is notnone
.If either none of the flags was set or no operation initialized/contributed to box, initialize it to (0,0,0,0) and return box.
Personal note: The dictionary might not be easy to feature detect. It might be quite some work to figure out which flag is supported by an implementation or not.
The text was updated successfully, but these errors were encountered: