diff options
author | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2019-01-14 13:10:38 +0100 |
---|---|---|
committer | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2019-01-14 13:10:38 +0100 |
commit | 92b48d2da14a4870c348c50443a2e22d015c3828 (patch) | |
tree | 0972ed3174ee8ec05bd61e479d347b9bec2f1d56 /src/elements/TextPath.js | |
parent | aec779cb019b5ad1c2ea709d9bf8e93d3d1e0c87 (diff) | |
download | svg.js-92b48d2da14a4870c348c50443a2e22d015c3828.tar.gz svg.js-92b48d2da14a4870c348c50443a2e22d015c3828.zip |
fixed `root()`, `textPath()`, `text.path()` and `path.text()` and removed font-family and size from the defaults list3.0.10
Diffstat (limited to 'src/elements/TextPath.js')
-rw-r--r-- | src/elements/TextPath.js | 47 |
1 files changed, 20 insertions, 27 deletions
diff --git a/src/elements/TextPath.js b/src/elements/TextPath.js index 4d07b5d..d8ab125 100644 --- a/src/elements/TextPath.js +++ b/src/elements/TextPath.js @@ -40,41 +40,43 @@ export default class TextPath extends Text { registerMethods({ Container: { textPath: wrapWithAttrCheck(function (text, path) { - // Convert to instance if needed - if (!(path instanceof Path)) { - path = this.defs().path(path) + // Convert text to instance if needed + if (!(text instanceof Text)) { + text = this.text(text) } - // Create textPath - const textPath = path.text(text) - - // Move text to correct container - textPath.parent().addTo(this) - - return textPath + return text.path(path) }) }, Text: { // Create path for text to run on - path: wrapWithAttrCheck(function (track) { - var path = new TextPath() + path: wrapWithAttrCheck(function (track, importNodes = true) { + var textPath = new TextPath() // if track is a path, reuse it if (!(track instanceof Path)) { // create path element - track = this.root().defs().path(track) + track = this.defs().path(track) } // link textPath to path and add content - path.attr('href', '#' + track, xlink) + textPath.attr('href', '#' + track, xlink) + + // Transplant all nodes from text to textPath + let node + if (importNodes) { + while ((node = this.node.firstChild)) { + textPath.node.appendChild(node) + } + } // add textPath element as child node and return textPath - return this.put(path) + return this.put(textPath) }), // Get the textPath children textPath () { - return this.find('textPath')[0] + return this.findOne('textPath') } }, Path: { @@ -85,17 +87,8 @@ registerMethods({ text = new Text().addTo(this.parent()).text(text) } - // Create textPath from text and path - const textPath = text.path(this) - textPath.remove() - - // Transplant all nodes from text to textPath - let node - while ((node = text.node.firstChild)) { - textPath.node.appendChild(node) - } - - return textPath.addTo(text) + // Create textPath from text and path and return + return text.path(this) }), targets () { |