Skip to content

Commit

Permalink
Fixed coordinate distortion in CSS sprites (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkphl committed Jan 14, 2015
1 parent a7516b4 commit 0190754
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -997,6 +997,9 @@ Known problems / To-do
Release history
---------------

#### v1.0.11 Bugfix release
* Fixed coordinate distortion in CSS sprites ([#41](https://github.com/jkphl/svg-sprite/issues/41))

#### v1.0.10 Maintenance release
* Added support for custom mode keys
* Fixed external CLI transform configuration support
Expand Down
13 changes: 9 additions & 4 deletions lib/svg-sprite/mode/css.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,19 +192,24 @@ SVGSpriteCss.prototype._layout = function(files, cb) {
positionMap[this._spriter._shapes[index].id] = _.pick(shape.position.absolute, ['x', 'y']);
}

// Rework zero-valued positions
var svg = shape.svg.split('>');

// Replace zero-valued x-positions
var svgX = shape.svg.split(' x="0"');
var svgX = svg[0].split(' x="0"');
if (svgX.length > 1) {
var x = shape.master ? (shape.position.absolute.x - positionMap[shape.master].x) : shape.position.absolute.x;
shape.svg = svgX.shift() + (x ? (' x="' + (-x) + '"') : '') + svgX.join(' x="0"');
svg[0] = svgX.join(x ? (' x="' + (-x) + '"') : '');
}

// Replace zero-valued y-positions
var svgY = shape.svg.split(' y="0"');
var svgY = svg[0].split(' y="0"');
if (svgY.length > 1) {
var y = shape.master ? (shape.position.absolute.y - positionMap[shape.master].y) : shape.position.absolute.y;
shape.svg = svgY.shift() + (y ? (' y="' + (-y) + '"') : '') + svgY.join(' y="0"');
svg[0] = svgY.join(y ? (' y="' + (-y) + '"') : '');
}

shape.svg = svg.join('>');
}

}, this);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "svg-sprite",
"version": "1.0.10",
"version": "1.0.11",
"author": {
"name": "Joschi Kuphal",
"email": "joschi@kuphal.net",
Expand Down

0 comments on commit 0190754

Please sign in to comment.