fixed save/restore regression introduced in context._stroke() method

This commit is contained in:
Eric Rowell
2013-09-15 23:42:12 -07:00
parent f31ff0b9e8
commit ede6fb2e17
2 changed files with 22 additions and 40 deletions

View File

@@ -524,13 +524,16 @@
_stroke: function(shape, skipShadow) { _stroke: function(shape, skipShadow) {
var stroke = shape.getStroke(), var stroke = shape.getStroke(),
strokeWidth = shape.getStrokeWidth(), strokeWidth = shape.getStrokeWidth(),
dashArray = shape.getDashArray(); dashArray = shape.getDashArray(),
strokeScaleEnabled = shape.getStrokeScaleEnabled();
if(stroke || strokeWidth) { if(stroke || strokeWidth) {
if (!shape.getStrokeScaleEnabled()) { if (!strokeScaleEnabled) {
this.save(); this.save();
this.setTransform(1, 0, 0, 1, 0, 0); this.setTransform(1, 0, 0, 1, 0, 0);
} }
/////////////////////
this._applyLineCap(shape); this._applyLineCap(shape);
if(dashArray && shape.getDashArrayEnabled()) { if(dashArray && shape.getDashArrayEnabled()) {
this.setLineDash(dashArray); this.setLineDash(dashArray);
@@ -543,9 +546,13 @@
shape._strokeFunc(this); shape._strokeFunc(this);
if(!skipShadow && shape.hasShadow()) { if(!skipShadow && shape.hasShadow()) {
this.restore();
this._stroke(shape, true); this._stroke(shape, true);
} }
/////////////////////
if (!strokeScaleEnabled) {
this.restore();
}
} }
}, },
_applyShadow: function(shape) { _applyShadow: function(shape) {

View File

@@ -339,77 +339,52 @@ suite('Shape-test', function() {
shadowColor: 'black', shadowColor: 'black',
shadowBlur: 10, shadowBlur: 10,
shadowOffset: 10, shadowOffset: 10,
dashArray: [10, 10] dashArray: [10, 10],
scaleX: 3
}); });
layer.add(circle); layer.add(circle);
stage.add(layer); stage.add(layer);
assert.equal(circle.getStrokeScaleEnabled(), true);
assert.equal(circle.getFillEnabled(), true, 'fillEnabled should be true'); assert.equal(circle.getFillEnabled(), true, 'fillEnabled should be true');
assert.equal(circle.getStrokeEnabled(), true, 'strokeEnabled should be true'); assert.equal(circle.getStrokeEnabled(), true, 'strokeEnabled should be true');
assert.equal(circle.getShadowEnabled(), true, 'shadowEnabled should be true'); assert.equal(circle.getShadowEnabled(), true, 'shadowEnabled should be true');
assert.equal(circle.getDashArrayEnabled(), true, 'dashArrayEnabled should be true'); assert.equal(circle.getDashArrayEnabled(), true, 'dashArrayEnabled should be true');
circle.disableFill(); circle.disableStrokeScale();
assert.equal(circle.getStrokeScaleEnabled(), false);
layer.draw();
var trace = layer.getContext().getTrace();
console.log(trace);
assert.equal(trace, 'clearRect(0,0,578,200);save();transform(3,0,0,1,289,100);beginPath();arc(0,0,70,0,6.283,false);closePath();save();shadowColor=black;shadowBlur=10;shadowOffsetX=10;shadowOffsetY=10;fillStyle=green;fill();restore();fillStyle=green;fill();setLineDash([10,10]);lineWidth=4;strokeStyle=black;stroke();restore();clearRect(0,0,578,200);save();transform(3,0,0,1,289,100);beginPath();arc(0,0,70,0,6.283,false);closePath();save();shadowColor=black;shadowBlur=10;shadowOffsetX=10;shadowOffsetY=10;fillStyle=green;fill();restore();fillStyle=green;fill();save();setTransform(1,0,0,1,0,0);setLineDash([10,10]);lineWidth=4;strokeStyle=black;stroke();restore();restore();');
circle.disableFill();
assert.equal(circle.getFillEnabled(), false, 'fillEnabled should be false'); assert.equal(circle.getFillEnabled(), false, 'fillEnabled should be false');
assert.equal(circle.getStrokeEnabled(), true, 'strokeEnabled should be true');
assert.equal(circle.getShadowEnabled(), true, 'shadowEnabled should be true');
assert.equal(circle.getDashArrayEnabled(), true, 'dashArrayEnabled should be true');
circle.disableStroke(); circle.disableStroke();
assert.equal(circle.getFillEnabled(), false, 'fillEnabled should be false');
assert.equal(circle.getStrokeEnabled(), false, 'strokeEnabled should be false'); assert.equal(circle.getStrokeEnabled(), false, 'strokeEnabled should be false');
assert.equal(circle.getShadowEnabled(), true, 'shadowEnabled should be true');
assert.equal(circle.getDashArrayEnabled(), true, 'dashArrayEnabled should be true');
circle.disableShadow(); circle.disableShadow();
assert.equal(circle.getFillEnabled(), false, 'fillEnabled should be false');
assert.equal(circle.getStrokeEnabled(), false, 'strokeEnabled should be false');
assert.equal(circle.getShadowEnabled(), false, 'shadowEnabled should be false'); assert.equal(circle.getShadowEnabled(), false, 'shadowEnabled should be false');
assert.equal(circle.getDashArrayEnabled(), true, 'dashArrayEnabled should be true');
circle.disableDashArray(); circle.disableDashArray();
assert.equal(circle.getFillEnabled(), false, 'fillEnabled should be false');
assert.equal(circle.getStrokeEnabled(), false, 'strokeEnabled should be false');
assert.equal(circle.getShadowEnabled(), false, 'shadowEnabled should be false');
assert.equal(circle.getDashArrayEnabled(), false, 'dashArrayEnabled should be false'); assert.equal(circle.getDashArrayEnabled(), false, 'dashArrayEnabled should be false');
// re-enable // re-enable
circle.enableDashArray(); circle.enableDashArray();
assert.equal(circle.getFillEnabled(), false, 'fillEnabled should be false');
assert.equal(circle.getStrokeEnabled(), false, 'strokeEnabled should be false');
assert.equal(circle.getShadowEnabled(), false, 'shadowEnabled should be false');
assert.equal(circle.getDashArrayEnabled(), true, 'dashArrayEnabled should be true'); assert.equal(circle.getDashArrayEnabled(), true, 'dashArrayEnabled should be true');
circle.enableShadow(); circle.enableShadow();
assert.equal(circle.getFillEnabled(), false, 'fillEnabled should be false');
assert.equal(circle.getStrokeEnabled(), false, 'strokeEnabled should be false');
assert.equal(circle.getShadowEnabled(), true, 'shadowEnabled should be true'); assert.equal(circle.getShadowEnabled(), true, 'shadowEnabled should be true');
assert.equal(circle.getDashArrayEnabled(), true, 'dashArrayEnabled should be true');
circle.enableStroke(); circle.enableStroke();
assert.equal(circle.getFillEnabled(), false, 'fillEnabled should be false');
assert.equal(circle.getStrokeEnabled(), true, 'strokeEnabled should be true'); assert.equal(circle.getStrokeEnabled(), true, 'strokeEnabled should be true');
assert.equal(circle.getShadowEnabled(), true, 'shadowEnabled should be true');
assert.equal(circle.getDashArrayEnabled(), true, 'dashArrayEnabled should be true');
circle.enableFill(); circle.enableFill();
assert.equal(circle.getFillEnabled(), true, 'fillEnabled should be true'); assert.equal(circle.getFillEnabled(), true, 'fillEnabled should be true');
assert.equal(circle.getStrokeEnabled(), true, 'strokeEnabled should be true');
assert.equal(circle.getShadowEnabled(), true, 'shadowEnabled should be true');
assert.equal(circle.getDashArrayEnabled(), true, 'dashArrayEnabled should be true');
var trace = layer.getContext().getTrace();
//console.log(trace);
assert.equal(trace, 'clearRect(0,0,578,200);save();transform(1,0,0,1,289,100);beginPath();arc(0,0,70,0,6.283,false);closePath();save();shadowColor=black;shadowBlur=10;shadowOffsetX=10;shadowOffsetY=10;fillStyle=green;fill();restore();fillStyle=green;fill();setLineDash([10,10]);lineWidth=4;strokeStyle=black;stroke();restore();');
}); });