Support drawing shadows with no shadowBlur.

Closes #955
This commit is contained in:
Jürg Lehni 2016-02-12 21:05:05 +01:00
parent 84a75e375a
commit e38829eb96
6 changed files with 14 additions and 12 deletions

View file

@ -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;
}

View file

@ -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();

View file

@ -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();

View file

@ -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) {

View file

@ -293,7 +293,7 @@ var Style = Base.extend(new function() {
// DOCS: Style#hasShadow()
hasShadow: function() {
return !!this.getShadowColor() && this.getShadowBlur() > 0;
return !!this.getShadowColor();
},
/**

View file

@ -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);