Processing order of mask and filter in SVG

时间秒杀一切 提交于 2021-01-29 18:35:10

问题


The SVG below contains a rectangle with a blur filter and a circular mask applied. The result is a red circle, so obviously the filter is applied before the mask. This seems to be the same on all browsers.

<svg width="300" height="300">
  <defs>
    <filter id="f1">
      <feGaussianBlur stdDeviation="10" />
    </filter>
    <mask id="m1">
      <circle cx="150" cy="150" r="50" fill="#fff"/>
    </mask>
  </defs>
  <rect x="50" y="50" width="200" height="200" fill="red" mask="url(#m1)" filter="url(#f1)"/>
</svg>

My question is: Why is the filter processed before the mask? Is this specified somewhere in the specification? Or is it just a coincidence that all browsers apply the same processing order? Can I rely on this order or is it better to introduce a parent element, so each element has only one operation?


回答1:


The SVG 1.1 spec is here:

The element is first painted onto the temporary canvas.. Then any filter effects specified for the graphics element are applied to create a modified temporary canvas. The modified temporary canvas is then composited into the background, taking into account any clipping, masking and object opacity settings on the graphics element.

For SVG 2, this has been moved to the CSS Filter effects and Masking modules, with both stating order as

first any filter effect is applied, then any clipping, masking and opacity.



来源:https://stackoverflow.com/questions/49791815/processing-order-of-mask-and-filter-in-svg

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!