Skip to content

Commit

Permalink
Add support for transforms to gradients. Fixes issue #52
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkschulze committed Mar 31, 2015
1 parent fab2168 commit 0742c8c
Show file tree
Hide file tree
Showing 62 changed files with 382 additions and 125 deletions.
38 changes: 21 additions & 17 deletions svgWriterGradient.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
Tag = require("./svgWriterTag.js");

var round10k = svgWriterUtils.round10k,
gradientStops = {};
var ctxCapture = svgWriterUtils.ctxCapture;
gradientStops = {},
ctxCapture = svgWriterUtils.ctxCapture,
getTransform = svgWriterUtils.getTransform;

function removeDups(lines) {
var out = [lines[0]];
Expand All @@ -41,30 +42,28 @@
var x1 = gradient.x1 + (ctx._shiftContentX || 0),
x2 = gradient.x2 + (ctx._shiftContentX || 0),
y1 = gradient.y1 + (ctx._shiftContentY || 0),
y2 = gradient.y2 + (ctx._shiftContentY || 0);
if (link) {
tag.setAttributes({
y2 = gradient.y2 + (ctx._shiftContentY || 0),
attr = {
x1: x1,
y1: y1,
x2: x2,
y2: y2,
"xlink:href": "#" + link.id
});
gradientTransform: getTransform(gradient.transform)
};
if (link) {
attr["xlink:href"] = "#" + link.id;
tag.setAttributes(attr);
} else {
gradientStops[lines] = {
id: gradientID,
x1: x1,
y1: y1,
x2: x2,
y2: y2
y2: y2,
gradientTransform: getTransform(gradient.transform)
};
tag.setAttributes({
gradientUnits: "userSpaceOnUse",
x1: x1,
y1: y1,
x2: x2,
y2: y2
});
attr.gradientUnits = "userSpaceOnUse";
tag.setAttributes(attr);
tag.children = removeDups(lines);
}
},
Expand All @@ -77,7 +76,8 @@
attr = {
cx: cx,
cy: cy,
r: r
r: r,
gradientTransform: getTransform(gradient.transform)
};
if (isFinite(fx) && fx != cx) {
attr.fx = fx;
Expand All @@ -95,7 +95,8 @@
cy: cy,
fx: fx,
fy: fy,
r: r
r: r,
gradientTransform: getTransform(gradient.transform)
};
attr.gradientUnits = "userSpaceOnUse";
tag.setAttributes(attr);
Expand Down Expand Up @@ -146,7 +147,10 @@
y1: round10k(gradient.y1),
x2: round10k(gradient.x2),
y2: round10k(gradient.y2),
fx: round10k(gradient.fx),
fy: round10k(gradient.fy),
r: round10k(gradient.r),
transform: gradient.transform,
stops: stops,
gradientSpace: gradientSpace
});
Expand Down
2 changes: 1 addition & 1 deletion tests/data/artboards-3.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tests/data/artboards-3/artboards-3-3.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tests/data/artboards-3/artboards-3-5.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tests/data/artboards-3/artboards-3-7.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tests/data/artboards-3/artboards-3-8.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions tests/data/gradient-color-overlay-om.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ module.exports = {
"width": 400,
"height": 400,
"preserveAspectRatio": "none",
"xlink:href": "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiBwcmVzZXJ2ZUFzcGVjdFJhdGlvPSJ4TWlkWU1pZCIgd2lkdGg9IjQwMCIgaGVpZ2h0PSI0MDAiIHZpZXdCb3g9IjAgMCA0MDAgNDAwIj4KICA8ZGVmcz4KICAgIDxzdHlsZT4KICAgICAgLmNscy0xIHsKICAgICAgICB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AiLz4KICAgIDwvbGluZWFyR3JhZGllbnQ+CiAgPC9kZWZzPgogIDxyZWN0IHdpZHRoPSI0MDAiIGhlaWdodD0iNDAwIiBjbGFzcz0iY2xzLTEiLz4KPC9zdmc+Cg=="
},
{
"name": "feComposite",
Expand Down Expand Up @@ -324,4 +324,4 @@ module.exports = {
}
},
"title": "gradient-color-overlay.psd"
}
}
2 changes: 1 addition & 1 deletion tests/data/gradient-color-overlay.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tests/data/gradient-duplicate.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions tests/data/gradient-reverse.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tests/data/gradient-scale-2-minify.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions tests/data/gradient-scale-reflected.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions tests/data/gradient-scale.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 0742c8c

Please sign in to comment.