Skip to content
Browse files

Init sprite-path implementation for Bitmaps

  • Loading branch information...
1 parent 4ea53a0 commit d2068b6ed87b7794a31ca7211d9eca7050e86458 @padolsey padolsey committed Oct 3, 2012
Showing with 27 additions and 1 deletion.
  1. +15 −0 src/renderer/svg/svg.js
  2. +12 −1 src/runner/bitmap.js
View
15 src/renderer/svg/svg.js
@@ -539,6 +539,21 @@ define([
img.setAttributeNS(xlink, 'href', attributes.absoluteUrl);
}
+ if (attributes.spritePath && !img._root) {
+ img._root = createElement('g');
+ img._root.appendChild(img);
+ img._imgClip = this.svg.defs.appendChild(createElement('clipPath'));
+ var clipId = this._genDefUID();
+ img._imgClip.setAttribute('id', clipId);
+ img._root.setAttribute('clip-path', 'url(#' + clipId + ')');
+ img._clipPath = img._imgClip.appendChild(createElement('path'));
+ img.setAttribute('x', -attributes.spritePathMatrix.tx);
+ img.setAttribute('y', -attributes.spritePathMatrix.ty);
+ attributes.spritePathMatrix.tx = 0;
+ attributes.spritePathMatrix.ty = 0;
+ img._clipPath.setAttribute('d', exportToPath(attributes.spritePath));
+ }
+
if (attributes.width == null && attributes.height == null) {
attributes.width = naturalWidth;
attributes.height = naturalHeight;
View
13 src/runner/bitmap.js
@@ -12,6 +12,12 @@ define([
this._owner.request(source);
}
+ var getSpritePath = tools.getter('_spritePath');
+ function setSpritePath(path) {
+ this._spritePath = path._getRenderData();
+ this._spritePathMatrix = path.attr('matrix');
+ }
+
/**
* The Bitmap constructor
*
@@ -49,7 +55,10 @@ define([
_naturalHeight: data(0, true, true),
source: accessor(getSource, setSource, true),
_source: data('', true, true),
- _absoluteUrl: data('', true, true)
+ _absoluteUrl: data('', true, true),
+ spritePath: accessor(getSpritePath, setSpritePath, true),
+ _spritePath: data(null, true, true),
+ _spritePathMatrix: data(0, true, true)
});
var rendererAttributes = this._renderAttributes;
@@ -58,6 +67,8 @@ define([
rendererAttributes.naturalHeight = '_naturalHeight';
rendererAttributes.naturalWidth = '_naturalWidth';
rendererAttributes.absoluteUrl = '_absoluteUrl';
+ rendererAttributes.spritePath = '_spritePath';
+ rendererAttributes.spritePathMatrix = '_spritePathMatrix';
this.attr('source', source);
}

0 comments on commit d2068b6

Please sign in to comment.
Something went wrong with that request. Please try again.