diff options
author | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2017-07-07 09:43:02 +0200 |
---|---|---|
committer | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2017-07-07 09:43:02 +0200 |
commit | b9ce105304f8d381ea7731cd12c2b9c499b4f37c (patch) | |
tree | f01a20b9bc3bff84d7f0c80b8e0bd744d70d2db8 /src/text.js | |
parent | f1bd0b48ea9cc3a499c02c524924e81eb97e9a6e (diff) | |
download | svg.js-b9ce105304f8d381ea7731cd12c2b9c499b4f37c.tar.gz svg.js-b9ce105304f8d381ea7731cd12c2b9c499b4f37c.zip |
reworked textPath (see #705)
Diffstat (limited to 'src/text.js')
-rw-r--r-- | src/text.js | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/src/text.js b/src/text.js index 13dbf92..1e93db7 100644 --- a/src/text.js +++ b/src/text.js @@ -49,10 +49,16 @@ SVG.Text = SVG.invent({ if (typeof text === 'undefined'){ var text = '' var children = this.node.childNodes + var firstLine = 0 for(var i = 0, len = children.length; i < len; ++i){ + // skip textPaths - they are no lines + if(children[i].nodeName == 'textPath') { + if(i == 0) firstLine = 1 + continue + } // add newline if its not the first child and newLined is set to true - if(i != 0 && children[i].nodeType != 3 && SVG.adopt(children[i]).dom.newLined == true){ + if(i != firstLine && children[i].nodeType != 3 && SVG.adopt(children[i]).dom.newLined == true){ text += '\n' } @@ -111,8 +117,8 @@ SVG.Text = SVG.invent({ this.each(function() { if (this.dom.newLined) { - if (!self.textPath()) - this.attr('x', self.attr('x')) + this.attr('x', self.attr('x')) + if(this.text() == '\n') { blankLineOffset += dy }else{ @@ -191,7 +197,6 @@ SVG.Tspan = SVG.invent({ return this.dy(t.dom.leading * t.attr('font-size')).attr('x', t.x()) } } - }) SVG.extend([SVG.Text, SVG.Tspan], { @@ -208,18 +213,18 @@ SVG.extend([SVG.Text, SVG.Tspan], { } // Create a tspan , tspan: function(text) { - var node = (this.textPath && this.textPath() || this).node - , tspan = new SVG.Tspan + var tspan = new SVG.Tspan // clear if build mode is disabled - if (this._build === false) + if (!this._build) this.clear() // add new tspan - node.appendChild(tspan.node) + this.node.appendChild(tspan.node) return tspan.text(text) } + // FIXME: Does this also work for textpath? // Get length of text element , length: function() { return this.node.getComputedTextLength() |