Skip to content

Commit

Permalink
Merge branch 'multiple-inner-shadows'
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkschulze committed Feb 2, 2015
2 parents bfc1050 + 43ec778 commit 50b7b08
Show file tree
Hide file tree
Showing 12 changed files with 1,140 additions and 281 deletions.
8 changes: 1 addition & 7 deletions svgOMGeneratorStyles.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,6 @@
svgNode.style.fx.chromeFX.color = omgUtils.toColor(color);
}

if (svgNode.style.fx.innerShadow) {
color = svgNode.style.fx.innerShadow.color;
svgNode.style.fx.innerShadow.color = omgUtils.toColor(color);

svgNode.style.fx.innerShadow.opacity = svgNode.style.fx.innerShadow.opacity ? svgNode.style.fx.innerShadow.opacity.value / 100 : 1;
}

if (svgNode.style.fx.gradientFill) {
var gradient = omgUtils.toGradient(svgNode.style.fx.gradientFill);
svgNode.style.fx.gradientFill.gradient = gradient;
Expand All @@ -242,6 +235,7 @@

prepareEffect('solidFill', prepareColor);
prepareEffect('dropShadow', prepareColor);
prepareEffect('innerShadow', prepareColor);

if (svgNode.style.fx.frameFX) {
var stroke = {},
Expand Down
75 changes: 41 additions & 34 deletions svgWriterFx.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
this.hasGradientOverlay(ctx) ||
this.hasEffect(ctx, 'solidFill') ||
this.hasSatin(ctx) ||
this.hasInnerShadow(ctx));
this.hasEffect(ctx, 'innerShadow'));
};

this.scanForUnsupportedFeatures = function (ctx) {
Expand Down Expand Up @@ -103,7 +103,7 @@
iFx++;
filterFlavor = "inner-glow";
}
if (this.hasInnerShadow(ctx)) {
if (this.hasEffect(ctx, 'innerShadow')) {
iFx++;
filterFlavor = "inner-shadow";
}
Expand Down Expand Up @@ -461,43 +461,50 @@
return JSON.stringify({ c: innerGlow.color, g: innerGlow.gradient, o: opacity, b: blur });
};

this.hasInnerShadow = function (ctx) {
var omIn = ctx.currentOMNode,
innerShadow;
if (omIn && omIn.style && omIn.style.fx) {
innerShadow = omIn.style.fx.innerShadow;
if (innerShadow && innerShadow.enabled) {
return true;
}
}
return false;
};
this.externalizeInnerShadow = function (ctx, param) {
if (!this.hasEffect(ctx, 'innerShadow')) {
return false;
}
var omIn = ctx.currentOMNode,
innerShadow = omIn.style.fx.innerShadow;
if (!innerShadow || !innerShadow.enabled) {
return;
innerShadowMulti = omIn.style.fx.innerShadowMulti,
specifies = [];

function writeInnerShadow (ctx, innerShadow, ind) {
var color = innerShadow.color,
opacity = round1k(innerShadow.opacity),
distance = innerShadow.distance,
angle = (innerShadow.useGlobalAngle ? ctx.globalLight.angle : innerShadow.localLightingAngle.value) * Math.PI / 180,
blur = round1k(Math.sqrt(innerShadow.blur)),
offset = {
x: -Math.cos(angle) * distance,
y: Math.sin(angle) * distance
};

writeFeOffset(ctx, offset, {in1: 'SourceAlpha'});
writeFeGauss(ctx, blur, {result: 'innerShadowBlur' + ind});
writeFeFlood(ctx, color, opacity);
writeFeComposite(ctx, 'out', {in2: 'innerShadowBlur' + ind});
writeFeComposite(ctx, 'in', {in2: 'SourceAlpha'});

return {m: innerShadow.mode, c: color, o: opacity, b: blur, off: offset};
}
var color = innerShadow.color,
opacity = round1k(innerShadow.opacity),
distance = innerShadow.distance,
angle = (innerShadow.useGlobalAngle ? ctx.globalLight.angle : innerShadow.localLightingAngle.value) * Math.PI / 180,
blur = round1k(Math.sqrt(innerShadow.blur)),
offset = {
x: -Math.cos(angle) * distance,
y: Math.sin(angle) * distance
};

writeFeOffset(ctx, offset, {in1: 'SourceAlpha'});
writeFeGauss(ctx, blur, {result: 'innerShadowBlur'});
writeFeFlood(ctx, color, opacity);
writeFeComposite(ctx, 'out', {in2: 'innerShadowBlur'});
writeFeComposite(ctx, 'in', {in2: 'SourceAlpha'});
writeFeBlend(ctx, innerShadow.mode, {in2: param.pass, result: 'innerShadow'});
param.pass = "innerShadow";

return JSON.stringify({m: innerShadow.mode, c: color, o: opacity, b: blur, off: offset});
innerShadowMulti.forEach(function (ele) {
if (!ele.enabled) {
return;
}
var num = specifies.length,
ind = num ? '-' + num : '',
input = param.pass;

specifies.push(writeInnerShadow(ctx, ele, ind));
param.pass = 'innerShadow' + ind;
writeFeBlend(ctx, ele.mode, {in2: input, result: param.pass});
});

return JSON.stringify(specifies);
};


this.addFxAttr = function (ctx) {
var node = ctx.currentOMNode;
Expand Down
168 changes: 87 additions & 81 deletions tests/data/filter-duplicate-om.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,33 +26,6 @@ module.exports = {
}
},
"fx": {
"innerShadow": {
"enabled": true,
"mode": "multiply",
"color": {
"r": 0,
"g": 0,
"b": 0,
"a": 1
},
"opacity": 0.75,
"useGlobalAngle": true,
"localLightingAngle": {
"value": 120,
"units": "angleUnit"
},
"distance": 5,
"chokeMatte": 0,
"blur": 5,
"noise": {
"value": 0,
"units": "percentUnit"
},
"antiAlias": false,
"transferSpec": {
"name": "Linear"
}
},
"dropShadowMulti": [
{
"enabled": true,
Expand Down Expand Up @@ -82,6 +55,35 @@ module.exports = {
},
"layerConceals": true
}
],
"innerShadowMulti": [
{
"enabled": true,
"mode": "multiply",
"color": {
"r": 0,
"g": 0,
"b": 0,
"a": 1
},
"opacity": 0.75,
"useGlobalAngle": true,
"localLightingAngle": {
"value": 120,
"units": "angleUnit"
},
"distance": 5,
"chokeMatte": 0,
"blur": 5,
"noise": {
"value": 0,
"units": "percentUnit"
},
"antiAlias": false,
"transferSpec": {
"name": "Linear"
}
}
]
}
},
Expand Down Expand Up @@ -119,33 +121,6 @@ module.exports = {
}
},
"fx": {
"innerShadow": {
"enabled": true,
"mode": "multiply",
"color": {
"r": 0,
"g": 0,
"b": 0,
"a": 1
},
"opacity": 0.75,
"useGlobalAngle": true,
"localLightingAngle": {
"value": 120,
"units": "angleUnit"
},
"distance": 5,
"chokeMatte": 0,
"blur": 5,
"noise": {
"value": 0,
"units": "percentUnit"
},
"antiAlias": false,
"transferSpec": {
"name": "Linear"
}
},
"dropShadowMulti": [
{
"enabled": true,
Expand Down Expand Up @@ -175,6 +150,35 @@ module.exports = {
},
"layerConceals": true
}
],
"innerShadowMulti": [
{
"enabled": true,
"mode": "multiply",
"color": {
"r": 0,
"g": 0,
"b": 0,
"a": 1
},
"opacity": 0.75,
"useGlobalAngle": true,
"localLightingAngle": {
"value": 120,
"units": "angleUnit"
},
"distance": 5,
"chokeMatte": 0,
"blur": 5,
"noise": {
"value": 0,
"units": "percentUnit"
},
"antiAlias": false,
"transferSpec": {
"name": "Linear"
}
}
]
}
},
Expand Down Expand Up @@ -212,33 +216,6 @@ module.exports = {
}
},
"fx": {
"innerShadow": {
"enabled": true,
"mode": "multiply",
"color": {
"r": 0,
"g": 0,
"b": 0,
"a": 1
},
"opacity": 0.75,
"useGlobalAngle": true,
"localLightingAngle": {
"value": 120,
"units": "angleUnit"
},
"distance": 5,
"chokeMatte": 0,
"blur": 5,
"noise": {
"value": 0,
"units": "percentUnit"
},
"antiAlias": false,
"transferSpec": {
"name": "Linear"
}
},
"dropShadowMulti": [
{
"enabled": true,
Expand Down Expand Up @@ -268,6 +245,35 @@ module.exports = {
},
"layerConceals": true
}
],
"innerShadowMulti": [
{
"enabled": true,
"mode": "multiply",
"color": {
"r": 0,
"g": 0,
"b": 0,
"a": 1
},
"opacity": 0.75,
"useGlobalAngle": true,
"localLightingAngle": {
"value": 120,
"units": "angleUnit"
},
"distance": 5,
"chokeMatte": 0,
"blur": 5,
"noise": {
"value": 0,
"units": "percentUnit"
},
"antiAlias": false,
"transferSpec": {
"name": "Linear"
}
}
]
}
},
Expand Down
54 changes: 28 additions & 26 deletions tests/data/group-om.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,33 +125,35 @@ module.exports = {
}
},
"fx": {
"innerShadow": {
"enabled": true,
"mode": "multiply",
"color": {
"r": 0.003891,
"g": 54.019456,
"b": 255,
"a": 1
},
"opacity": 0.75,
"useGlobalAngle": true,
"localLightingAngle": {
"value": 120,
"units": "angleUnit"
},
"distance": 15,
"chokeMatte": 0,
"blur": 21,
"noise": {
"value": 0,
"units": "percentUnit"
},
"antiAlias": false,
"transferSpec": {
"name": "Linear"
"innerShadowMulti": [
{
"enabled": true,
"mode": "multiply",
"color": {
"r": 0.003891,
"g": 54.019456,
"b": 255,
"a": 1
},
"opacity": 0.75,
"useGlobalAngle": true,
"localLightingAngle": {
"value": 120,
"units": "angleUnit"
},
"distance": 15,
"chokeMatte": 0,
"blur": 21,
"noise": {
"value": 0,
"units": "percentUnit"
},
"antiAlias": false,
"transferSpec": {
"name": "Linear"
}
}
}
]
}
},
"children": [],
Expand Down
Loading

0 comments on commit 50b7b08

Please sign in to comment.