2

I can't get Chrome (and Opera) to use SVG filters with decimal values in radius.

Go to http://oreillymedia.github.io/svg-essentials-examples/ch11/fe_morphology.html and try putting 0 or 0.5 in the radius field. In Chrome there is no change but in Firefox the erode works.

I have a locale with decimal COMMA, does that play a role? With comma it gets interpreted as x,y though.

Is that a known issue? Any workarounds?

HH321
  • 502
  • 1
  • 6
  • 20

1 Answers1

3

Zero is not a valid value for the radius attribute. To quote the spec:

radius = "number-optional-number"

The radius (or radii) for the operation. If two numbers are provided, the first number represents a x-radius and the second value represents a y-radius. If one number is provided, then that value is used for both X and Y. The values are in the coordinate system established by attribute ‘primitiveUnits’ on the ‘filter’ element. A negative value is an error (see Error processing). A value of zero disables the effect of the given filter primitive (i.e., the result is a transparent black image). If the attribute is not specified, then the effect is as if a value of 0 were specified.

The radius value determines the size of a convolution matrix that is used to process the image. By definition that matrix has to have an integer number of columns and rows. However the spec is not clear on whether fractions should be rounded up or down.

It appears that Firefox always rounds up, whereas Chrome/Webkit always rounds down.

In any case, fractional values are meaningless, so you should always use integers.

Paul LeBeau
  • 97,474
  • 9
  • 154
  • 181
  • I agree, it seems to be a rounding issue. – Waruyama Feb 06 '19 at 07:20
  • 1
    https://dxr.mozilla.org/mozilla-central/source/dom/svg/SVGFEMorphologyElement.cpp#101 – Robert Longson Feb 06 '19 at 07:28
  • But why should they be rounded? The spec also says; ` Real numbers are specified in one of two ways.` I have a viewbox 100x100 on an SVG that can be 10000 pixels wide. I've tried setting the primitiveUnits to either of the possible values. – HH321 Feb 06 '19 at 08:23
  • 1
    They need to be rounded because those values are used to determine the size of a matrix. You can't have 0.3 of a matrix cell. A "Number" can be either an integer or a real. It could have been defined in the spec as an integer, but one of the reasons that is not done, is because often people want to interpolate/animate attributes. Real numbers work better for that. – Paul LeBeau Feb 06 '19 at 14:09
  • I see, that sucks. I shouldn't have to worry about the fact that it's implemented with a convolution matrix especially since the spec doesn't specify that. Thanks for the answer, anyway. – HH321 Feb 06 '19 at 22:44
  • In the spec it says: "The dilation (or erosion) kernel is a rectangle with a width of 2*x-radius and a height of 2*y-radius...." – Paul LeBeau Feb 08 '19 at 01:38