Skip to content

Commit

Permalink
Support drawing shadows with no shadowBlur.
Browse files Browse the repository at this point in the history
  • Loading branch information
lehni committed Feb 12, 2016
1 parent 84a75e3 commit e38829e
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 12 deletions.
10 changes: 6 additions & 4 deletions src/item/Item.js
Original file line number Diff line number Diff line change
Expand Up @@ -3954,11 +3954,13 @@ new function() { // // Scope to inject various item event handlers
}
}
if (shadowColor) {
var shadowBlur = style.getShadowBlur();
if (shadowBlur > 0) {
var blur = style.getShadowBlur(),
offset = this.getShadowOffset();
// In order to draw a shadow, we need either a shadow blur or an
// offset, or both.
if (blur > 0 || !offset.isZero()) {
ctx.shadowColor = shadowColor.toCanvasStyle(ctx);
ctx.shadowBlur = shadowBlur;
var offset = this.getShadowOffset();
ctx.shadowBlur = blur;
ctx.shadowOffsetX = offset.x;
ctx.shadowOffsetY = offset.y;
}
Expand Down
2 changes: 1 addition & 1 deletion src/item/Shape.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ var Shape = Item.extend(/** @lends Shape# */{
this._setStyles(ctx);
if (hasFill) {
ctx.fill(style.getFillRule());
ctx.shadowBlur = 0;
ctx.shadowColor = 'rgba(0,0,0,0)';
}
if (hasStroke)
ctx.stroke();
Expand Down
2 changes: 1 addition & 1 deletion src/path/CompoundPath.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ var CompoundPath = PathItem.extend(/** @lends CompoundPath# */{
var style = this._style;
if (style.hasFill()) {
ctx.fill(style.getFillRule());
ctx.shadowBlur = 0;
ctx.shadowColor = 'rgba(0,0,0,0)';
}
if (style.hasStroke())
ctx.stroke();
Expand Down
2 changes: 1 addition & 1 deletion src/path/Path.js
Original file line number Diff line number Diff line change
Expand Up @@ -2171,7 +2171,7 @@ new function() { // Scope for drawing
// If shadowColor is defined, clear it after fill, so it
// won't be applied to both fill and stroke. If the path is
// only stroked, we don't have to clear it.
ctx.shadowBlur = 0;
ctx.shadowColor = 'rgba(0,0,0,0)';
}
if (hasStroke) {
if (dashLength) {
Expand Down
2 changes: 1 addition & 1 deletion src/style/Style.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ var Style = Base.extend(new function() {

// DOCS: Style#hasShadow()
hasShadow: function() {
return !!this.getShadowColor() && this.getShadowBlur() > 0;
return !!this.getShadowColor();
},

/**
Expand Down
8 changes: 4 additions & 4 deletions src/text/PointText.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,16 @@ var PointText = TextItem.extend(/** @lends PointText# */{
hasFill = style.hasFill(),
hasStroke = style.hasStroke(),
leading = style.getLeading(),
shadowBlur = ctx.shadowBlur;
shadowColor = ctx.shadowColor;
ctx.font = style.getFontStyle();
ctx.textAlign = style.getJustification();
for (var i = 0, l = lines.length; i < l; i++) {
// See Path._draw() for explanation about ctx.shadowBlur
ctx.shadowBlur = shadowBlur;
// See Path._draw() for explanation about ctx.shadowColor
ctx.shadowColor = shadowColor;
var line = lines[i];
if (hasFill) {
ctx.fillText(line, 0, 0);
ctx.shadowBlur = 0;
ctx.shadowColor = 'rgba(0,0,0,0)';
}
if (hasStroke)
ctx.strokeText(line, 0, 0);
Expand Down

0 comments on commit e38829e

Please sign in to comment.