mirror of
https://github.com/konvajs/konva.git
synced 2025-06-28 15:23:44 +08:00
[WIP] Partially fix unscaled stroke with gradient
This commit is contained in:
parent
d1fbcae49e
commit
e7376cb690
49
konva.js
49
konva.js
@ -2060,7 +2060,9 @@
|
|||||||
if (shape.hasStroke()) {
|
if (shape.hasStroke()) {
|
||||||
if (!strokeScaleEnabled) {
|
if (!strokeScaleEnabled) {
|
||||||
this.save();
|
this.save();
|
||||||
this.setTransform(1, 0, 0, 1, 0, 0);
|
var pixelRatio = this.getCanvas().getPixelRatio();
|
||||||
|
var transform = this._context.currentTransform;
|
||||||
|
this.setTransform(pixelRatio, transform.b, transform.c, pixelRatio, transform.e, transform.f);
|
||||||
}
|
}
|
||||||
|
|
||||||
this._applyLineCap(shape);
|
this._applyLineCap(shape);
|
||||||
@ -2140,7 +2142,9 @@
|
|||||||
shape.getStrokeScaleEnabled() || shape instanceof Konva.Text;
|
shape.getStrokeScaleEnabled() || shape instanceof Konva.Text;
|
||||||
if (!strokeScaleEnabled) {
|
if (!strokeScaleEnabled) {
|
||||||
this.save();
|
this.save();
|
||||||
this.setTransform(1, 0, 0, 1, 0, 0);
|
var pixelRatio = this.getCanvas().getPixelRatio();
|
||||||
|
var transform = this._context.currentTransform;
|
||||||
|
this.setTransform(pixelRatio, transform.b, transform.c, pixelRatio, transform.e, transform.f);
|
||||||
}
|
}
|
||||||
this._applyLineCap(shape);
|
this._applyLineCap(shape);
|
||||||
this.setAttr('lineWidth', shape.strokeWidth());
|
this.setAttr('lineWidth', shape.strokeWidth());
|
||||||
@ -12848,7 +12852,7 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* get/set drag bound function. This is used to override the default
|
* get/set drag bound function. This is used to override the default
|
||||||
* drag and drop position
|
* drag and drop position.
|
||||||
* @name dragBoundFunc
|
* @name dragBoundFunc
|
||||||
* @method
|
* @method
|
||||||
* @memberof Konva.Node.prototype
|
* @memberof Konva.Node.prototype
|
||||||
@ -12860,6 +12864,8 @@
|
|||||||
*
|
*
|
||||||
* // create vertical drag and drop
|
* // create vertical drag and drop
|
||||||
* node.dragBoundFunc(function(pos){
|
* node.dragBoundFunc(function(pos){
|
||||||
|
* // important pos - is absolute position of the node
|
||||||
|
* // you should return absolute position too
|
||||||
* return {
|
* return {
|
||||||
* x: this.getAbsolutePosition().x,
|
* x: this.getAbsolutePosition().x,
|
||||||
* y: pos.y
|
* y: pos.y
|
||||||
@ -16180,7 +16186,8 @@
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
Konva.Path.getPointOnEllipticalArc = function(cx, cy, rx, ry, theta, psi) {
|
Konva.Path.getPointOnEllipticalArc = function(cx, cy, rx, ry, theta, psi) {
|
||||||
var cosPsi = Math.cos(psi), sinPsi = Math.sin(psi);
|
var cosPsi = Math.cos(psi),
|
||||||
|
sinPsi = Math.sin(psi);
|
||||||
var pt = {
|
var pt = {
|
||||||
x: rx * Math.cos(theta),
|
x: rx * Math.cos(theta),
|
||||||
y: ry * Math.sin(theta)
|
y: ry * Math.sin(theta)
|
||||||
@ -16259,26 +16266,35 @@
|
|||||||
// create array
|
// create array
|
||||||
var arr = cs.split('|');
|
var arr = cs.split('|');
|
||||||
var ca = [];
|
var ca = [];
|
||||||
|
var coords = [];
|
||||||
// init context point
|
// init context point
|
||||||
var cpx = 0;
|
var cpx = 0;
|
||||||
var cpy = 0;
|
var cpy = 0;
|
||||||
|
|
||||||
|
var re = /([-+]?((\d+\.\d+)|((\d+)|(\.\d+)))(?:e[-+]?\d+)?)/gi;
|
||||||
|
var match;
|
||||||
for (n = 1; n < arr.length; n++) {
|
for (n = 1; n < arr.length; n++) {
|
||||||
var str = arr[n];
|
var str = arr[n];
|
||||||
var c = str.charAt(0);
|
var c = str.charAt(0);
|
||||||
str = str.slice(1);
|
str = str.slice(1);
|
||||||
// remove ,- for consistency
|
|
||||||
str = str.replace(new RegExp(',-', 'g'), '-');
|
coords.length = 0;
|
||||||
// add commas so that it's easy to split
|
while ((match = re.exec(str))) {
|
||||||
str = str.replace(new RegExp('-', 'g'), ',-');
|
coords.push(match[0]);
|
||||||
str = str.replace(new RegExp('e,-', 'g'), 'e-');
|
|
||||||
var p = str.split(',');
|
|
||||||
if (p.length > 0 && p[0] === '') {
|
|
||||||
p.shift();
|
|
||||||
}
|
}
|
||||||
// convert strings to floats
|
|
||||||
for (var i = 0; i < p.length; i++) {
|
// while ((match = re.exec(str))) {
|
||||||
p[i] = parseFloat(p[i]);
|
// coords.push(match[0]);
|
||||||
|
// }
|
||||||
|
var p = [];
|
||||||
|
|
||||||
|
for (var j = 0, jlen = coords.length; j < jlen; j++) {
|
||||||
|
var parsed = parseFloat(coords[j]);
|
||||||
|
if (!isNaN(parsed)) {
|
||||||
|
p.push(parsed);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
while (p.length > 0) {
|
while (p.length > 0) {
|
||||||
if (isNaN(p[0])) {
|
if (isNaN(p[0])) {
|
||||||
// case for a trailing comma before next command
|
// case for a trailing comma before next command
|
||||||
@ -16287,7 +16303,8 @@
|
|||||||
|
|
||||||
var cmd = null;
|
var cmd = null;
|
||||||
var points = [];
|
var points = [];
|
||||||
var startX = cpx, startY = cpy;
|
var startX = cpx,
|
||||||
|
startY = cpy;
|
||||||
// Move var from within the switch to up here (jshint)
|
// Move var from within the switch to up here (jshint)
|
||||||
var prevCmd, ctlPtx, ctlPty; // Ss, Tt
|
var prevCmd, ctlPtx, ctlPty; // Ss, Tt
|
||||||
var rx, ry, psi, fa, fs, x1, y1; // Aa
|
var rx, ry, psi, fa, fs, x1, y1; // Aa
|
||||||
|
6
konva.min.js
vendored
6
konva.min.js
vendored
File diff suppressed because one or more lines are too long
@ -611,7 +611,9 @@
|
|||||||
if (shape.hasStroke()) {
|
if (shape.hasStroke()) {
|
||||||
if (!strokeScaleEnabled) {
|
if (!strokeScaleEnabled) {
|
||||||
this.save();
|
this.save();
|
||||||
this.setTransform(1, 0, 0, 1, 0, 0);
|
var pixelRatio = this.getCanvas().getPixelRatio();
|
||||||
|
var transform = this._context.currentTransform;
|
||||||
|
this.setTransform(pixelRatio, transform.b, transform.c, pixelRatio, transform.e, transform.f);
|
||||||
}
|
}
|
||||||
|
|
||||||
this._applyLineCap(shape);
|
this._applyLineCap(shape);
|
||||||
@ -691,7 +693,9 @@
|
|||||||
shape.getStrokeScaleEnabled() || shape instanceof Konva.Text;
|
shape.getStrokeScaleEnabled() || shape instanceof Konva.Text;
|
||||||
if (!strokeScaleEnabled) {
|
if (!strokeScaleEnabled) {
|
||||||
this.save();
|
this.save();
|
||||||
this.setTransform(1, 0, 0, 1, 0, 0);
|
var pixelRatio = this.getCanvas().getPixelRatio();
|
||||||
|
var transform = this._context.currentTransform;
|
||||||
|
this.setTransform(pixelRatio, transform.b, transform.c, pixelRatio, transform.e, transform.f);
|
||||||
}
|
}
|
||||||
this._applyLineCap(shape);
|
this._applyLineCap(shape);
|
||||||
this.setAttr('lineWidth', shape.strokeWidth());
|
this.setAttr('lineWidth', shape.strokeWidth());
|
||||||
|
Loading…
Reference in New Issue
Block a user