【问题标题】:when <use>ing a filtered shape - filter disappears in Chrome当 <use> 过滤形状时 - 过滤器在 Chrome 中消失
【发布时间】:2020-01-01 04:05:48
【问题描述】:

我正在尝试创建在 SVG 中应用了过滤器的形状的“镜像”效果。非常简单的镜像 - 只需将其与原始形状保持一定距离并将其翻转即可。原始形状应用了“发光”滤镜。

在不同的浏览器中渲染时:

  • Edge(非 Chromium)渲染完全符合预期。
  • Chrome 不会渲染应用过滤器的镜像形状 - 只会渲染原始路径形状。
  • Firefox 甚至不呈现过滤器。呃。

因此,鉴于 Edge 很快将迁移到 Chromium,我想保留应用了滤镜的镜像形状的这种影响。这就是我正在做的事情 - 我可以做任何不同的事情来让 Edge 出现在 Chrome 中吗?

<svg name="glow only" x="100" y="50" overflow="visible" fill="green" stroke="orange" stroke-width="3.25">
    <defs>
        <filter id="glow" color-interpolation-filters="sRGB" x="-20%" y="-20%" width="140%" height="140%" filterUnits="objectBoundingBox">
            <feColorMatrix in="SourceAlpha" type="matrix" values="0 0 0 0 0.2 0 0 0 0 0.2 0 0 0 0 1 0 0 0 100 0" result="glowColor" />
            <feMorphology operator="dilate" radius="5.5" in="glowColor" result="thickenify" />
            <feGaussianBlur in="thickenify" stdDeviation="2.5" result="glowIt" />
            <feMerge>
                <feMergeNode in="glowIt" />
                <feMergeNode in="SourceGraphic" />
            </feMerge>
        </filter>
    </defs>
    <use id="mirroredContent" xlink:href="#contentForMirroringWithFilter" transform="matrix(1,0,0,-1,4.89842541528951E-16,155.25)" />
    <g id="contentForMirroringWithFilter">
        <path d="M0,0L60,0L72,12L72,72L0,72Z" filter="url(#glow)" />
    </g>
</svg>

有谁知道如何在 Chrome 中实现这一点?


编辑 1:这开始看起来像是翻转的问题。如果我使用其他转换,例如: &lt;use xlink:href="#contentForMirroringWithFilter" transform="rotate(50)"/&gt;&lt;use xlink:href="#contentForMirroringWithFilter" transform="translate(0, 80)"/&gt;,过滤器被保留。即使我申请了一个积极的scale,它也可以工作,比如 &lt;use xlink:href="#contentForMirroringWithFilter" transform="translate(0, 80) scale(1,1.2)"/&gt;

但是,一旦我对翻转应用负比例,它就会翻转并且不显示过滤器: &lt;use xlink:href="#contentForMirroringWithFilter" transform="translate(0, 152) scale(1,-1) "/&gt;.

这是一个错误,还是我应该尝试翻转的其他方式?

编辑 2

  • 已在 bugzilla.mozilla.org/show_bug.cgi?id=1577566 上为 Firefox 提交了一个错误。
  • Kaiido 在 Chrome 中发现的错误已通过此问题进行了修正:https://bugs.chromium.org/p/chromium/issues/detail?id=595244
  • 我仍在寻找一种解决方法,让我可以应用过滤器并随后使用 &lt;use/&gt;'d 形状(应用过滤器),例如设置不同的转换、不透明度等。

【问题讨论】:

  • Firefox 对我来说显示为 Edge,尽管我在这里使用的是 Mac。您是否启用了 webbrender?如果你这样做,你可以尝试通过在 about:config 中设置 gfx.webrender.force-disabled 来禁用它。无论如何,如果您有 Firefox 错误,最好在 bugzilla 中讨论/跟踪
  • 对于 Chrome,这是 feMorphology 的一个已知错误:bugs.chromium.org/p/chromium/issues/detail?id=595244 这是MCVE
  • @RobertLongson,感谢您的回复。我尝试按照您的指示禁用它,但没有效果。我使用的是 v.68.0.2(64 位)Windows 10。
  • @Kaiido。感谢您提供此链接。这看起来像问题。但是已经开了3年了。我以前从未处理过 Chrome 中的实际错误 - 它有可能得到解决吗?我可以做任何事情,比如提交一个新的错误吗?只是不确定我的选择是什么来尝试修复它。
  • 推荐的方法是给问题加星标。一个不太推荐但仍然经常看到的方法是友好地提醒问题本身,它仍然影响活动网站(您的网站)。现在,在你的位置上,我预计不会很快有任何修复,所以我想我会加注星标并继续使用你收到的解决方法。

标签: svg svg-filters


【解决方案1】:

另一种解决方案是将路径和镜像放在同一个 g 元素内,并将过滤器应用于&lt;g&gt;,如下所示:

<svg name="glow only" x="100" y="50" overflow="visible" fill="green" stroke="orange" stroke-width="3.25">
    <defs>
        <filter id="glow" color-interpolation-filters="sRGB" x="-20%" y="-20%" width="140%" height="140%" filterUnits="objectBoundingBox">
            <feColorMatrix in="SourceAlpha" type="matrix" values="0 0 0 0 0.2 0 0 0 0 0.2 0 0 0 0 1 0 0 0 100 0" result="glowColor" />
            <feMorphology operator="dilate" radius="5.5" in="glowColor" result="thickenify" />
            <feGaussianBlur in="thickenify" stdDeviation="2.5" result="glowIt" />
            <feMerge>
                <feMergeNode in="glowIt" />
                <feMergeNode in="SourceGraphic" />
            </feMerge>
        </filter>
    </defs>
  <g filter="url(#glow)">
    <use id="mirroredContent" xlink:href="#contentForMirroringWithFilter" transform="matrix(1,0,0,-1,4.89842541528951E-16,155.25)" />
    <g id="contentForMirroringWithFilter">
        <path d="M0,0L60,0L72,12L72,72L0,72Z"  />
    </g>
  </g>
</svg>

【讨论】:

  • 谢谢,感谢您的回复。不幸的是,我需要进一步修改不应用于原始形状的过滤器,例如镜像对象的大小、偏移量。如果有通过其他方式的解决方法,我很想听听。我尝试使用feImage 过滤器添加另一个&lt;use/&gt;,然后翻转/缩放那个,但它不起作用。所以我对想法一无所知。 :(
猜你喜欢
  • 1970-01-01
  • 2011-01-11
  • 1970-01-01
  • 2018-11-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-21
  • 1970-01-01
相关资源
最近更新 更多