Fix scaling dash lines

This commit is contained in:
MaxGraey
2018-03-20 20:37:02 +02:00
parent 87e1e329f6
commit 1c360db96f
3 changed files with 31 additions and 9 deletions

View File

@@ -2,7 +2,7 @@
* Konva JavaScript Framework v2.0.2
* http://konvajs.github.io/
* Licensed under the MIT
* Date: Mon Mar 19 2018
* Date: Tue Mar 20 2018
*
* Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS)
* Modified work Copyright (C) 2014 - present by Anton Lavrenov (Konva)
@@ -2069,6 +2069,9 @@
strokeScaleEnabled =
shape.getStrokeScaleEnabled() || shape instanceof Konva.Text;
var scale = 1;
var pixelRatio = this.getCanvas().getPixelRatio();
if (shape.hasStroke()) {
/* if (!strokeScaleEnabled) {
this.save();
@@ -2079,13 +2082,21 @@
this._applyLineCap(shape);
if (dash && shape.dashEnabled()) {
this.setLineDash(dash);
if (!strokeScaleEnabled) {
scale = pixelRatio / (this._context.currentTransform ? this._context.currentTransform.a : 1);
var newDash = dash.slice();
for (var i = 0, len = dash.length; i < len; i++) {
newDash[i] *= scale;
}
this.setLineDash(newDash);
} else {
this.setLineDash(dash);
}
this.setAttr('lineDashOffset', shape.dashOffset());
}
if (!strokeScaleEnabled) {
var pixelRatio = this.getCanvas().getPixelRatio();
var scale = pixelRatio / (this._context.currentTransform ? this._context.currentTransform.a : 1);
scale = pixelRatio / (this._context.currentTransform ? this._context.currentTransform.a : 1);
this.setAttr('lineWidth', shape.strokeWidth() * scale);
} else {
this.setAttr('lineWidth', shape.strokeWidth());

4
konva.min.js vendored

File diff suppressed because one or more lines are too long

View File

@@ -620,6 +620,9 @@
strokeScaleEnabled =
shape.getStrokeScaleEnabled() || shape instanceof Konva.Text;
var scale = 1;
var pixelRatio = this.getCanvas().getPixelRatio();
if (shape.hasStroke()) {
/* if (!strokeScaleEnabled) {
this.save();
@@ -630,13 +633,21 @@
this._applyLineCap(shape);
if (dash && shape.dashEnabled()) {
this.setLineDash(dash);
if (!strokeScaleEnabled) {
scale = pixelRatio / (this._context.currentTransform ? this._context.currentTransform.a : 1);
var newDash = dash.slice();
for (var i = 0, len = dash.length; i < len; i++) {
newDash[i] *= scale;
}
this.setLineDash(newDash);
} else {
this.setLineDash(dash);
}
this.setAttr('lineDashOffset', shape.dashOffset());
}
if (!strokeScaleEnabled) {
var pixelRatio = this.getCanvas().getPixelRatio();
var scale = pixelRatio / (this._context.currentTransform ? this._context.currentTransform.a : 1);
scale = pixelRatio / (this._context.currentTransform ? this._context.currentTransform.a : 1);
this.setAttr('lineWidth', shape.strokeWidth() * scale);
} else {
this.setAttr('lineWidth', shape.strokeWidth());