为什么与Blink和Gecko相比,Webkit / Safari(iOS,macOS)以不同的顺序渲染我的SVG转换?

我有一个星号图标的最小SVG图像:

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">
    <defs>
        <style>
        .a {
            fill: red;
            transform-box: fill-box;
            transform-origin: center;
        }
        </style>
    </defs>
    <!-- x = 45 because it's 10px wide and centered around x=50, so x0 == 45, x1 == 55 -->
    <rect class="a" x="45" y="0" width="10" height="100"/>
    <rect class="a" x="45" y="0" width="10" height="100" transform="rotate(-45)"/>
    <rect class="a" x="45" y="0" width="10" height="100" transform="rotate( 45)"/>
    <rect class="a" x="45" y="0" width="10" height="100" transform="rotate(-90)"/>
</svg>

这可以在Firefox 75和Chrome 80中正确显示,但在iOS或macOS上无法正确显示:

Firefox 75:

在此处输入图片说明

Chrome 80:

在此处输入图片说明

iOS 13上的Safari

但是在Safari上,与每个元素transform-origintransform=""属性相比,似乎被忽略或乱序应用<rect>

在此处输入图片说明

有人告诉我它在macOS Safari上呈现相同的损坏图像(我现在无法立即访问macOS Safari,因此无法从此处发布屏幕截图,抱歉)。

I've searched around Google to see if Safari/WebKit is lacking support for transform-box, transform-origin or transform="rotate(deg)" but as far as I can tell they've all been fully supported by Safari for years - so I don't understand why it's applying the transformations out-of-order and causing the broken rendering.

Dai

After fiddling with the SVG in Safari, Safari's Web Inspector does seem to recognize the transform-origin SVG style property, but it doesn't actually use it when applying transformations, which is weird (e.g. using transform-origin: center; or transform-origin: 0px 0px or transform-origin: 50px 50px had no effect) - so a fix lies in changing the rotation centre using some other means.

As far as I can tell, macOS Safari and iOS Safari both only use transform-origin for CSS-based transformations using the transform property and not when using SVG attribute-based transformations using transform="" - whereas Blink and Gecko both use transform-origin for both attribute-based and CSS-based transformations.

Using a translate step

One approach is to add a translate step so the centre of rotation is centred in the canvas, then perform the rotation, then undo the translate step:

transform="translate( 50, 50 ) rotate(45) translate( -50, -50 )"

Like so:

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" width="100" height="100">
    <rect fill="red"    x="45" y="0" width="10" height="100" />
    <rect fill="blue"   x="45" y="0" width="10" height="100" transform="translate(50,50) rotate(-45) translate(-50,-50)" />
    <rect fill="green"  x="45" y="0" width="10" height="100" transform="translate(50,50) rotate( 45) translate(-50,-50)" />
    <rect fill="orange" x="45" y="0" width="10" height="100" transform="translate(50,50) rotate(-90) translate(-50,-50)" />
</svg>

Better approach: Using rotate( angle, x, y ):

我看到转换功能支持使用其他参数指定旋转中心而不是translatetransform链上应用初始步骤,因此可以在Safari,Chrome(+ Edge + Opera)和Firefox中使用:rotate

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" width="100" height="100">
    <rect fill="red"    x="45" y="0" width="10" height="100" />
    <rect fill="blue"   x="45" y="0" width="10" height="100" transform="rotate(-45, 50, 50)" />
    <rect fill="green"  x="45" y="0" width="10" height="100" transform="rotate( 45, 50, 50)" />
    <rect fill="orange" x="45" y="0" width="10" height="100" transform="rotate(-90, 50, 50)" />
</svg>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

为什么与IIS相比,Visual Studio调试中的HashTable顺序不同

为什么filter(shadow)导致我的SVG在Safari中消失?

为什么dict和dict.items()的顺序不同?

如何修复iOS11和macOS10.12 Safari上损坏的转换原点?

为什么conj和cons具有不同的参数顺序

为什么我们经常只看到适用于Apple和Safari Web浏览器的Webkit css标签?我们也应该使用其他渲染引擎标签吗?

为什么我的-webkit-background-clip无法处理文本

为什么将图像写入流与直接保存到文件相比,给我带来不同的结果?

Safari为什么不显示我的SVG路径元素?

为什么Kotlin / JS与===相比Kotlin / JVM返回不同的结果?

为什么Google Chrome浏览器使用-webkit- *前缀,而Chrome在Blink上运行(IOS除外,它们在Webkit上运行)

在Safari和Webkit上进行测试有什么区别?

为什么我的内嵌svg无法在Safari(台式机和移动设备)上正确显示?

为什么我的SQL查询产生不同的顺序?

为什么SwiftUI动画在iOS和macOS上的行为和对齐方式不同?

为什么我从hexdump获得的输出与xxd相比有所不同?

SVG在WebKit和Firefox中的位置不同

与xev相比,为什么showkey显示的键码不同?

Safari和IE中的SVG渲染

为什么在CentOS和RHEL上发现显示不同的顺序?

Webkit转换为更改<p>元素的宽度...为什么?

与 chrome 相比,为什么 Safari 对待转换的翻译不同?

svg 不同的渲染结果在 chrome 和 safari 中具有相同的 linearGradient id

与 MAPE(平均绝对百分比误差)相比,为什么我的 MAE(平均绝对误差)和 MSE(均方误差)高?

为什么在字典中,当我们有相同的值和不同的键名时,为什么它会选择一个与另一个相比

与观察者 hoc 相比,为什么 useObserver 钩子不会重新渲染两次?

为什么钩子的代码(功能)不断渲染?(与班级相比)

为什么我在 Teradata 和 Snowflake 中执行的同一查询的排序顺序不同?

与使用“is”的关键字“list”和“set”相比,为什么空列表和集合上的 type() 会产生不同的答案?