![](/img/trans.png)
[英]SVG textpath element renders incorrectly in Firefox when generated using Javascript
[英]SVG textPath not rendering when generated by JavaScript
对于svg.js,我编写了一个添加textPath功能的小插件。 该插件非常简洁:
// textpath plugin
SVG.TextPath = function() {
this.constructor.call(this, SVG.create('textPath'))
}
SVG.TextPath.prototype = new SVG.Element
SVG.extend(SVG.TextPath, {
text: function(text) {
while (this.node.firstChild) this.node.removeChild(this.node.firstChild)
this.node.appendChild(document.createTextNode(text))
return this
}
})
SVG.extend(SVG.Text, {
path: function(d){
var textPath = new SVG.TextPath().text(this.content)
while (this.node.firstChild) this.node.removeChild(this.node.firstChild)
this.track = this.doc().defs().path(d)
this.node.appendChild(textPath.node)
textPath.attr('xlink:href', '#' + this.track)
return this
}
})
// example usage
var draw = SVG('canvas').viewbox(0, 0, 1000, 300)
var text = draw.text('We go up, then we go down, then up again')
text.font({ size: 42.5, family: 'Verdana' })
text.path('M 100 200 C 200 100 300 0 400 100 C 500 200 600 300 700 200 C 800 100 900 100 900 100')
draw.use(text.track).attr({ fill: 'none', 'stroke-width': 1, stroke: '#f09' })
这是动态版本的小提琴: http : //jsfiddle.net/wout/LNuWM/
但这是错误的地方,因为未渲染文本。 最初,我认为我的代码有问题,但是当我从检查器复制svg输出并粘贴到svg文档中时,文本将按预期呈现。
这里是静态版本的示例: http : //jsfiddle.net/wout/ZbM7K/
这是浏览器故障还是我错过了什么?
更新:现在已解决: http : //jsfiddle.net/wout/LNuWM/2/
这似乎是SVG.js中的错误。 SVG根元素由于添加了XLink命名空间而变得混乱:
<svg style="position:relative;overflow:hidden;left:0px;top:0px;"xlink="http://www.w3.org/1999/xlink" ...
---------------------------------------------------------------^
|
--------this should read [SPACE]xmlns:xlink=
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.