Skip to content
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

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

Open
ccprog opened this issue Jul 12, 2024 · 3 comments

Comments

@ccprog
Copy link

ccprog commented Jul 12, 2024

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
Copy link

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
Copy link
Author

ccprog commented Jul 15, 2024

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
Copy link

patterns, filters and clipPaths should work the same though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants