aboutsummaryrefslogtreecommitdiffstats
path: root/src/elements/Image.js
diff options
context:
space:
mode:
authorUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2018-11-08 10:05:28 +0100
committerUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2018-11-08 10:05:28 +0100
commit4702522137dac17a6312c521f3c1974eb839c5eb (patch)
tree97c158c2c4e8005d3e56e037eab16dfffcf3da42 /src/elements/Image.js
parentdec70426b32ccf3979046e1637174b66bfdd1a8d (diff)
downloadsvg.js-4702522137dac17a6312c521f3c1974eb839c5eb.tar.gz
svg.js-4702522137dac17a6312c521f3c1974eb839c5eb.zip
added insertAfter/Before, introduce attrHooks, move few methods, SVG.Text.textPath returns first textPath child now
Diffstat (limited to 'src/elements/Image.js')
-rw-r--r--src/elements/Image.js21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/elements/Image.js b/src/elements/Image.js
index 5e672f4..ec9459f 100644
--- a/src/elements/Image.js
+++ b/src/elements/Image.js
@@ -1,5 +1,7 @@
+import { isImage } from '../modules/core/regex.js'
import { nodeOrNew, register } from '../utils/adopter.js'
import { off, on } from '../modules/core/event.js'
+import { registerAttrHook } from '../modules/core/attr.js'
import { registerMethods } from '../utils/methods.js'
import { xlink } from '../modules/core/namespaces.js'
import Pattern from './Pattern.js'
@@ -48,13 +50,24 @@ export default class Image extends Shape {
return this.attr('href', (img.src = url), xlink)
}
+}
+
+registerAttrHook(function (attr, val, _this) {
+ // convert image fill and stroke to patterns
+ if (attr === 'fill' || attr === 'stroke') {
+ if (isImage.test(val)) {
+ val = _this.doc().defs().image(val)
+ }
+ }
- attrHook (obj) {
- return obj.doc().defs().pattern(0, 0, (pattern) => {
- pattern.add(this)
+ if (val instanceof Image) {
+ val = _this.doc().defs().pattern(0, 0, (pattern) => {
+ pattern.add(val)
})
}
-}
+
+ return val
+})
registerMethods({
Container: {