fix imageSmoothingEnabled on resize. fix #884

This commit is contained in:
Anton Lavrenov
2020-04-07 12:47:22 -05:00
parent 1427cf0efc
commit 865d6c7618
7 changed files with 23 additions and 34 deletions

View File

@@ -37,8 +37,8 @@ export abstract class BaseLayer extends Container<Group | Shape> {
this.on('visibleChange', this._checkVisibility);
this._checkVisibility();
this.on('imageSmoothingEnabledChange', this._checkSmooth);
this._checkSmooth();
this.on('imageSmoothingEnabledChange', this._setSmoothEnabled);
this._setSmoothEnabled();
}
// for nodejs?
createPNGStream() {
@@ -193,6 +193,7 @@ export abstract class BaseLayer extends Container<Group | Shape> {
}
setSize({ width, height }) {
this.canvas.setSize(width, height);
this._setSmoothEnabled();
return this;
}
_toKonvaCanvas(config) {
@@ -214,7 +215,7 @@ export abstract class BaseLayer extends Container<Group | Shape> {
}
}
_checkSmooth() {
_setSmoothEnabled() {
this.getContext()._context.imageSmoothingEnabled = this.imageSmoothingEnabled();
}
/**

View File

@@ -29,10 +29,6 @@ export class FastLayer extends BaseLayer {
Util.throw('You may only add shapes to a fast layer.');
}
}
_setCanvasSize(width, height) {
this.canvas.setSize(width, height);
this._checkSmooth();
}
hitGraphEnabled() {
return false;
}

View File

@@ -50,10 +50,10 @@ export class Layer extends BaseLayer {
pixelRatio: 1
});
_setCanvasSize(width, height) {
this.canvas.setSize(width, height);
setSize({ width, height }) {
super.setSize({ width, height });
this.hitCanvas.setSize(width, height);
this._checkSmooth();
return this;
}
_validateAdd(child) {
var type = child.getType();
@@ -227,11 +227,6 @@ export class Layer extends BaseLayer {
parent.content.appendChild(this.hitCanvas._canvas);
}
}
setSize({ width, height }) {
super.setSize({ width, height });
this.hitCanvas.setSize(width, height);
return this;
}
hitGraphEnabled: GetSet<boolean, this>;
}

View File

@@ -376,7 +376,7 @@ export class Stage extends Container<BaseLayer> {
' layers. Recommended maximum number of layers is 3-5. Adding more layers into the stage may drop the performance. Rethink your tree structure, you can use Konva.Group.'
);
}
layer._setCanvasSize(this.width(), this.height());
layer.setSize({ width: this.width(), height: this.height() });
// draw layer and append canvas to container
layer.draw();