SVG文本路径在Safari中无法工作

3

我正在尝试通过内联SVG在图像上叠加弧形文本。在Chrome中可以正常工作,但是iOS和桌面版的Safari无法渲染文本。

<svg viewBox="0 0 580 472" width="580" height="472" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1">
    <defs>
        <path id="curvedPath" d="M123.9,309.87s55.27,20.4,148.06,23.54c99.49,3.37,153.33-16.68,153.33-16.68"></path>
        <style type="text/css">
            #text {
                font-size: 24px;
                text-align: center;
                text-anchor: middle;
                fill: rgba(0,0,0,0.8);
            }
        </style>
    </defs>

    <image x="0" y="0" width="580" height="472" xlink:href="https://www.silvity.de/out/pictures/master/product/1/gravur-armband-swarovski-kristall-rosegold-schwarz-111106601.jpg"></image>

    <text id="text" class="Philosopher">
        <textPath href="#curvedPath" startOffset="50%" id="textcontent">Foobar StackOverflow</textPath>
    </text>
</svg>

此代码段在 Chrome 中显示“Foobar StackOverflow”文本,但在 Safari 中不显示。
路径的曲线并不重要,一个直线(M10.100,L100.100)也无法正常工作。我唯一能让文本显示出来的方法是直接嵌入到text标签中,例如:<text id="...">Foobar StackOverflow</text>,但这显然不是我想要的。
在 Safari SVG 中使用textPath是否有任何限制?如何使其在两个浏览器中都正常渲染?
1个回答

5

Safari仅支持xlink:href,而不支持更新的裸href。

<svg viewBox="0 0 580 472" width="580" height="472" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1">
    <defs>
        <path id="curvedPath" d="M123.9,309.87s55.27,20.4,148.06,23.54c99.49,3.37,153.33-16.68,153.33-16.68"></path>
        <style type="text/css">
            #text {
                font-size: 24px;
                text-align: center;
                text-anchor: middle;
                fill: rgba(0,0,0,0.8);
            }
        </style>
    </defs>

    <image x="0" y="0" width="580" height="472" xlink:href="https://www.silvity.de/out/pictures/master/product/1/gravur-armband-swarovski-kristall-rosegold-schwarz-111106601.jpg"></image>

    <text id="text" class="Philosopher">
        <textPath xlink:href="#curvedPath" startOffset="50%" id="textcontent">Foobar StackOverflow</textPath>
    </text>
</svg>


我看到Safari还不支持href,但我确信那是指image标签(已经使用了xlink:href),所以我没有注意到我在textPath上使用了href。非常感谢! - padarom

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接