Re: [svgwg] Enhance `<pattern>` to support auto-width or auto-height for pattern tiles with a `viewBox`

"All features" is pretty broad, so I'm changing this to focus on the particular issue you describe: auto-sizing the pattern tile to match the aspect ratio.  Feel free to open separate issues for other missing features.

I think this is useful and probably a reasonable change.

By combining most `width` and `height` attributes with the CSS properties of the same name, [SVG 2 adds an `auto` as the default](https://svgwg.org/svg2-draft/geometry.html#Sizing).  In most cases, `auto` is defined to behave the same as the SVG 1.1 default.  

However, [for `<image>`](https://svgwg.org/svg2-draft/embedded.html#ImageElement), `auto` is defined to match the normal CSS behavior: auto-size based on aspect ratio or intrinsic size.  Although this is technically a "breaking change", it was accepted because it only breaks things that were already broken.  In SVG 1.1, if you didn't specify _both_ height and width for an `<image>`, the image wouldn't be rendered. Now (in browsers that have updated), it is rendered with automatic sizing.

The `width` and `height` attributes on `<pattern>` _aren't_ currently defined as mapping to the CSS properties.  However, the arguments for `<image>` apply equally to `<pattern>`: currently, if you omit either `width` or `height`, the pattern is in error and won't be used.  So if we give the attributes a new `auto` default, we're not breaking anything that isn't already broken.

But there are complications...

First, we then need to define what the `auto` behavior is in all cases:

- `<pattern>` with a `viewBox` and one of height or width set explicitly and the other set to `auto` should be straightforward: fill in the auto-dimension based on the aspect ratio.
- But what if both dimensions are `auto`? Will there be a default size, or will that collapse to zero and therefore still be in error?
- What if the pattern _doesn't_ have a `viewBox`? Use default sizes or collapse to zero? The CSS replaced content sizes (300px by 150px) aren't going to be useful if the pattern tile dimensions are defined in object bounding-box units.

And that gets us to the other complication: object bounding-box units are applied as a non-uniform scale.  Within that scaled coordinate system, the bounding box is treated as if it always has a 1:1 aspect ratio.  The result is then stretched to fit the actual bounding box.  So if you're auto-sizing content within an object bounding-box context (aka, the default `patternUnits` value), it's not going to have the affect you want.  We'd need to significantly re-write how bounding box units are interpretted to make it useful.

By the way, for the specific case of using an `<image>` as a pattern fill, the [Fill and Stroke Module](https://drafts.fxtf.org/fill-stroke-3/) has a better solution: skip the pattern, and just reference the image file directly, with CSS-background-inspired sizing properties.  But there would still be a use case for aspect-ratio sizing for normal SVG patterns.

-- 
GitHub Notification of comment by AmeliaBR
Please view or discuss this issue at https://github.com/w3c/svgwg/issues/342#issuecomment-324718356 using your GitHub account

Received on Thursday, 24 August 2017 18:29:18 UTC