mirror of
https://github.com/konvajs/konva.git
synced 2025-04-05 20:48:28 +08:00
fixed save/restore regression introduced in context._stroke() method
This commit is contained in:
parent
f31ff0b9e8
commit
ede6fb2e17
@ -524,13 +524,16 @@
|
||||
_stroke: function(shape, skipShadow) {
|
||||
var stroke = shape.getStroke(),
|
||||
strokeWidth = shape.getStrokeWidth(),
|
||||
dashArray = shape.getDashArray();
|
||||
dashArray = shape.getDashArray(),
|
||||
strokeScaleEnabled = shape.getStrokeScaleEnabled();
|
||||
|
||||
if(stroke || strokeWidth) {
|
||||
if (!shape.getStrokeScaleEnabled()) {
|
||||
if (!strokeScaleEnabled) {
|
||||
this.save();
|
||||
this.setTransform(1, 0, 0, 1, 0, 0);
|
||||
}
|
||||
|
||||
/////////////////////
|
||||
this._applyLineCap(shape);
|
||||
if(dashArray && shape.getDashArrayEnabled()) {
|
||||
this.setLineDash(dashArray);
|
||||
@ -543,9 +546,13 @@
|
||||
shape._strokeFunc(this);
|
||||
|
||||
if(!skipShadow && shape.hasShadow()) {
|
||||
this.restore();
|
||||
this._stroke(shape, true);
|
||||
}
|
||||
/////////////////////
|
||||
|
||||
if (!strokeScaleEnabled) {
|
||||
this.restore();
|
||||
}
|
||||
}
|
||||
},
|
||||
_applyShadow: function(shape) {
|
||||
|
@ -339,77 +339,52 @@ suite('Shape-test', function() {
|
||||
shadowColor: 'black',
|
||||
shadowBlur: 10,
|
||||
shadowOffset: 10,
|
||||
dashArray: [10, 10]
|
||||
dashArray: [10, 10],
|
||||
scaleX: 3
|
||||
});
|
||||
layer.add(circle);
|
||||
stage.add(layer);
|
||||
|
||||
assert.equal(circle.getStrokeScaleEnabled(), 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');
|
||||
|
||||
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.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();
|
||||
|
||||
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.getDashArrayEnabled(), true, 'dashArrayEnabled should be true');
|
||||
|
||||
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.getDashArrayEnabled(), true, 'dashArrayEnabled should be true');
|
||||
|
||||
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');
|
||||
|
||||
// re-enable
|
||||
|
||||
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');
|
||||
|
||||
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.getDashArrayEnabled(), true, 'dashArrayEnabled should be true');
|
||||
|
||||
circle.enableStroke();
|
||||
|
||||
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.enableFill();
|
||||
|
||||
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();');
|
||||
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user