w3c / csswg-drafts

CSS Working Group Editor Drafts
https://drafts.csswg.org/
Other
4.51k stars 671 forks source link

[css-filter-effects-1] Missing definition of a reference for percentage values if filterUnits="userSpaceOnUse" #10563

Open ccprog opened 4 months ago

ccprog commented 4 months ago

Consider a SVG <filter> element with the following attributes:

<filter id="myFilter" filterUnits="userSpaceOnUse">

It would be expanded according to the initial values defined in § 8 to

<filter id="myFilter" filterUnits="userSpaceOnUse" x="-10%" y="-10%" width="120%" height="120%">

§ 7 defines the unit of the x, y, width, height values as <length-percentage> as defined in CSS Values and Units Level 4.

This spec notes about percentages:

Percentage values are always relative to another quantity, for example a length. Each property that allows percentages also defines the quantity to which the percentage refers.

Such a reference is missing. The text currently only says

If filterUnits is equal to userSpaceOnUse, x, y, width, height represent values in the current user coordinate system in place at the time when the filter element is referenced (i.e., the user coordinate system for the element referencing the filter element via a filter property).


Current browser implementations seem to have filled the gap by falling back to the following rule in the SVG 1.1 spec:

For percentage values that are defined to be relative to the size of viewport:

  • For any x-coordinate value or width value expressed as a percentage of the viewport, the value to use is the specified percentage of the actual-width in user units for the nearest containing viewport, where actual-width is the width dimension of the viewport element within the user coordinate system for the viewport element.
  • For any y-coordinate value or height value expressed as a percentage of the viewport, the value to use is the specified percentage of the actual-height in user units for the nearest containing viewport, where actual-height is the height dimension of the viewport element within the user coordinate system for the viewport element.

To me that seems to be a bit arbitrary, since there is no mention of "the size of the viewport" in the context of filter units. Also, this fallback is no longer applicable from the CSS Filter Effects module.

And finally, if the viewport is used as reference, it can have unexpected results.

longsonr commented 4 months ago

See https://bugzilla.mozilla.org/show_bug.cgi?id=866655 It may well be too late to change now given the number of interoperable implementations and the likelihood of content that depends on that.

ccprog commented 4 months ago

The pattern spec contains the explicit sentence for the case patternUnits="userSpaceOnUse"

Percentages represent values relative to the current SVG viewport.

For filters, a comparable sentence is missing.

longsonr commented 4 months ago

patterns, filters and clipPaths should work the same though.