可以将文本添加到SVG路径吗? [英] Can text be added to an SVG path?
本文介绍了可以将文本添加到SVG路径吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以在svg路径中添加文本,我已经创建了svg三角形,并想在其中心添加一个字母,但不确定是否可行?
Is it possible to add text to an svg path, I have created a svg triangle and would like to add a letter to the center of this but not sure if this is possible?
推荐答案
是.请参见SVG1.1规范的第10.13节(标题为路径")以获取有关使用 textPath
元素的信息.
Yes. See section 10.13 of the SVG1.1 specification (titled "Text on a path") for information on using the textPath
element.
总结:
- 为路径提供
id
属性. - 创建
<textPath xlink:href="#pathid">My text here</textPath>
- Give your path an
id
attribute. - Create
<textPath xlink:href="#pathid">My text here</textPath>
这是一个直接来自规范的示例:
Here's an example straight from the spec:
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="12cm" height="3.6cm" viewBox="0 0 1000 300" version="1.1"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<path id="MyPath"
d="M 100 200
C 200 100 300 0 400 100
C 500 200 600 300 700 200
C 800 100 900 100 900 100" />
</defs>
<desc>Example toap01 - simple text on a path</desc>
<use xlink:href="#MyPath" fill="none" stroke="red" />
<text font-family="Verdana" font-size="42.5" fill="blue" >
<textPath xlink:href="#MyPath">
We go up, then we go down, then up again
</textPath>
</text>
</svg>
这篇关于可以将文本添加到SVG路径吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文