aboutsummaryrefslogtreecommitdiffstats
path: root/src/text.js
diff options
context:
space:
mode:
authorwout <wout@impinc.co.uk>2014-08-25 10:33:35 +0200
committerwout <wout@impinc.co.uk>2014-08-25 10:33:35 +0200
commit7b8e6f1d5afe2472cd1245f9bb73b6d59238e541 (patch)
tree51f85409971875f642315b8cd3b67d8bbf0cc504 /src/text.js
parent7c195432d30bf2c179d2f5c2682b85d76ef9458b (diff)
downloadsvg.js-7b8e6f1d5afe2472cd1245f9bb73b6d59238e541.tar.gz
svg.js-7b8e6f1d5afe2472cd1245f9bb73b6d59238e541.zip
Removed internal references from SVG.Text
Diffstat (limited to 'src/text.js')
-rwxr-xr-xsrc/text.js26
1 files changed, 17 insertions, 9 deletions
diff --git a/src/text.js b/src/text.js
index 7970492..d697681 100755
--- a/src/text.js
+++ b/src/text.js
@@ -24,7 +24,7 @@ SVG.Text = SVG.invent({
// move lines as well if no textPath is present
if (!this.textPath)
- this.lines.each(function() { if (this.newLined) this.x(x) })
+ this.lines().each(function() { if (this.newLined) this.x(x) })
return this.attr('x', x)
}
@@ -86,6 +86,16 @@ SVG.Text = SVG.invent({
return this.rebuild()
}
+ // Get all the first level lines
+ , lines: function() {
+ // filter tspans and map them to SVG.js instances
+ for (var i = 0, il = this.node.childNodes.length, lines = []; i < il; i++)
+ if (this.node.childNodes[i] instanceof SVGElement)
+ lines.push(SVG.adopt(this.node.childNodes[i]))
+
+ // return an instance of SVG.set
+ return new SVG.Set(lines)
+ }
// Rebuild appearance type
, rebuild: function(rebuild) {
// store new rebuild flag if given
@@ -96,10 +106,11 @@ SVG.Text = SVG.invent({
if (this._rebuild) {
var self = this
- this.lines.each(function() {
+ this.lines().each(function() {
if (this.newLined) {
if (!this.textPath)
this.attr('x', self.attr('x'))
+
this.attr('dy', self._leading * new SVG.Number(self.attr('font-size')))
}
})
@@ -182,7 +193,7 @@ SVG.extend(SVG.Text, SVG.Tspan, {
}
// Create a tspan
, tspan: function(text) {
- var node = (this.textPath || this).node
+ var node = (this.textPath() || this).node
, tspan = new SVG.Tspan
// clear if build mode is disabled
@@ -194,24 +205,21 @@ SVG.extend(SVG.Text, SVG.Tspan, {
// only first level tspans are considered to be "lines"
if (this instanceof SVG.Text)
- this.lines.add(tspan)
+ this.lines().add(tspan)
return tspan.text(text)
}
// Clear all lines
, clear: function() {
- var node = (this.textPath || this).node
+ var node = (this.textPath() || this).node
// remove existing child nodes
while (node.hasChildNodes())
node.removeChild(node.lastChild)
// reset content references
- if (this instanceof SVG.Text) {
- delete this.lines
- this.lines = new SVG.Set
+ if (this instanceof SVG.Text)
this.content = ''
- }
return this
}