summaryrefslogtreecommitdiffstats
path: root/src/elements
diff options
context:
space:
mode:
authorUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2019-01-14 11:01:25 +0100
committerUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2019-01-14 11:01:25 +0100
commitaec779cb019b5ad1c2ea709d9bf8e93d3d1e0c87 (patch)
tree41ec3b5c369374c33750091d291320aa3de8bc7c /src/elements
parent1388b1f67b18cb2bc561840079f981253fa1643e (diff)
downloadsvg.js-aec779cb019b5ad1c2ea709d9bf8e93d3d1e0c87.tar.gz
svg.js-aec779cb019b5ad1c2ea709d9bf8e93d3d1e0c87.zip
fixed `textPath()` and `path().text()`
Diffstat (limited to 'src/elements')
-rw-r--r--src/elements/TextPath.js32
1 files changed, 27 insertions, 5 deletions
diff --git a/src/elements/TextPath.js b/src/elements/TextPath.js
index 91c48ae..4d07b5d 100644
--- a/src/elements/TextPath.js
+++ b/src/elements/TextPath.js
@@ -40,7 +40,18 @@ export default class TextPath extends Text {
registerMethods({
Container: {
textPath: wrapWithAttrCheck(function (text, path) {
- return this.defs().path(path).text(text).addTo(this)
+ // Convert to instance if needed
+ if (!(path instanceof Path)) {
+ path = this.defs().path(path)
+ }
+
+ // Create textPath
+ const textPath = path.text(text)
+
+ // Move text to correct container
+ textPath.parent().addTo(this)
+
+ return textPath
})
},
Text: {
@@ -69,11 +80,22 @@ registerMethods({
Path: {
// creates a textPath from this path
text: wrapWithAttrCheck(function (text) {
- if (text instanceof Text) {
- var txt = text.text()
- return text.clear().path(this).text(txt)
+ // Convert text to instance if needed
+ if (!(text instanceof Text)) {
+ text = new Text().addTo(this.parent()).text(text)
}
- return this.parent().put(new Text()).path(this).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)
}),
targets () {