konva 10.9.0 → 10.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/konva.js +225 -139
- package/konva.min.js +4 -4
- package/lib/Context.d.ts +1 -0
- package/lib/Context.js +15 -1
- package/lib/Global.js +2 -2
- package/lib/Node.d.ts +2 -0
- package/lib/Node.js +44 -50
- package/lib/Shape.d.ts +5 -1
- package/lib/Shape.js +41 -28
- package/lib/Util.js +2 -0
- package/lib/filters/Blur.js +25 -1
- package/lib/filters/Brightness.js +8 -2
- package/lib/filters/Contrast.js +7 -3
- package/lib/filters/Emboss.js +11 -4
- package/lib/shapes/Text.js +4 -4
- package/lib/shapes/TextPath.d.ts +3 -2
- package/lib/shapes/TextPath.js +65 -40
- package/package.json +1 -1
package/lib/shapes/TextPath.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Util } from "../Util.js";
|
|
1
|
+
import { Transform, Util } from "../Util.js";
|
|
2
2
|
import { Factory } from "../Factory.js";
|
|
3
3
|
import { Shape } from "../Shape.js";
|
|
4
4
|
import { Path } from "./Path.js";
|
|
@@ -88,40 +88,49 @@ export class TextPath extends Shape {
|
|
|
88
88
|
context.setAttr('textAlign', 'left');
|
|
89
89
|
context.save();
|
|
90
90
|
const textDecoration = this.textDecoration();
|
|
91
|
-
const fill = this.fill();
|
|
92
91
|
const fontSize = this.fontSize();
|
|
92
|
+
const underlineOffset = this._getUnderlineOffset();
|
|
93
93
|
const glyphInfo = this.glyphInfo;
|
|
94
94
|
const hasUnderline = textDecoration.indexOf('underline') !== -1;
|
|
95
95
|
const hasLineThrough = textDecoration.indexOf('line-through') !== -1;
|
|
96
96
|
if (hasUnderline) {
|
|
97
97
|
context.beginPath();
|
|
98
98
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
99
|
+
try {
|
|
100
|
+
for (let i = 0; i < glyphInfo.length; i++) {
|
|
101
|
+
context.save();
|
|
102
|
+
const p0 = glyphInfo[i].p0;
|
|
103
|
+
const rotation = glyphInfo[i].rotation;
|
|
104
|
+
context.translate(p0.x, p0.y);
|
|
105
|
+
context.rotate(rotation);
|
|
106
|
+
this.partialText = glyphInfo[i].text;
|
|
107
|
+
// keep gradients and patterns in the shape's space, not the glyph's
|
|
108
|
+
this._styleTransform = new Transform()
|
|
109
|
+
.rotate(-rotation)
|
|
110
|
+
.translate(-p0.x, -p0.y);
|
|
111
|
+
context.fillStrokeShape(this);
|
|
112
|
+
if (hasUnderline) {
|
|
113
|
+
if (i === 0) {
|
|
114
|
+
context.moveTo(0, underlineOffset);
|
|
115
|
+
}
|
|
116
|
+
context.lineTo(glyphInfo[i].width, underlineOffset);
|
|
109
117
|
}
|
|
110
|
-
context.
|
|
118
|
+
context.restore();
|
|
119
|
+
//// To assist with debugging visually, uncomment following
|
|
120
|
+
//
|
|
121
|
+
// if (i % 2) context.strokeStyle = 'cyan';
|
|
122
|
+
// else context.strokeStyle = 'green';
|
|
123
|
+
// var p1 = glyphInfo[i].p1;
|
|
124
|
+
// context.moveTo(p0.x, p0.y);
|
|
125
|
+
// context.lineTo(p1.x, p1.y);
|
|
126
|
+
// context.stroke();
|
|
111
127
|
}
|
|
112
|
-
context.restore();
|
|
113
|
-
//// To assist with debugging visually, uncomment following
|
|
114
|
-
//
|
|
115
|
-
// if (i % 2) context.strokeStyle = 'cyan';
|
|
116
|
-
// else context.strokeStyle = 'green';
|
|
117
|
-
// var p1 = glyphInfo[i].p1;
|
|
118
|
-
// context.moveTo(p0.x, p0.y);
|
|
119
|
-
// context.lineTo(p1.x, p1.y);
|
|
120
|
-
// context.stroke();
|
|
121
128
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
129
|
+
finally {
|
|
130
|
+
this._styleTransform = undefined;
|
|
131
|
+
}
|
|
132
|
+
context.lineWidth = getDecorationLineWidth(fontSize);
|
|
133
|
+
if (hasUnderline && context._applyDecorationStyle(this)) {
|
|
125
134
|
context.stroke();
|
|
126
135
|
}
|
|
127
136
|
if (hasLineThrough) {
|
|
@@ -137,9 +146,8 @@ export class TextPath extends Shape {
|
|
|
137
146
|
context.lineTo(glyphInfo[i].width, 0);
|
|
138
147
|
context.restore();
|
|
139
148
|
}
|
|
140
|
-
context.
|
|
141
|
-
|
|
142
|
-
context.stroke();
|
|
149
|
+
if (context._applyDecorationStyle(this))
|
|
150
|
+
context.stroke();
|
|
143
151
|
}
|
|
144
152
|
context.restore();
|
|
145
153
|
}
|
|
@@ -306,12 +314,30 @@ export class TextPath extends Shape {
|
|
|
306
314
|
});
|
|
307
315
|
const rect = Util._getPointsRect(points);
|
|
308
316
|
const fontSize = this.fontSize();
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
317
|
+
let x = rect.x - fontSize / 2, y = rect.y - fontSize / 2, right = rect.x + rect.width + fontSize / 2, bottom = rect.y + rect.height + fontSize / 2;
|
|
318
|
+
if (this.textDecoration().indexOf('underline') !== -1) {
|
|
319
|
+
// the underline is drawn below the glyphs, past the padding
|
|
320
|
+
const lineWidth = getDecorationLineWidth(fontSize), lineY = this._getUnderlineOffset() - lineWidth / 2;
|
|
321
|
+
this.glyphInfo.forEach(function (info) {
|
|
322
|
+
const line = new Transform()
|
|
323
|
+
.translate(info.p0.x, info.p0.y)
|
|
324
|
+
.rotate(info.rotation)
|
|
325
|
+
._getTransformedRect({
|
|
326
|
+
x: 0,
|
|
327
|
+
y: lineY,
|
|
328
|
+
width: info.width,
|
|
329
|
+
height: lineWidth,
|
|
330
|
+
});
|
|
331
|
+
x = Math.min(x, line.x);
|
|
332
|
+
y = Math.min(y, line.y);
|
|
333
|
+
right = Math.max(right, line.x + line.width);
|
|
334
|
+
bottom = Math.max(bottom, line.y + line.height);
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
return { x, y, width: right - x, height: bottom - y };
|
|
338
|
+
}
|
|
339
|
+
_getUnderlineOffset() {
|
|
340
|
+
return this.fontSize() / 2 + 1;
|
|
315
341
|
}
|
|
316
342
|
// Like Text: a glyph stroke is drawn with the text, so it always scales.
|
|
317
343
|
getStrokeScaleEnabled() {
|
|
@@ -334,10 +360,9 @@ TextPath.prototype._strokeFunc = _strokeFunc;
|
|
|
334
360
|
TextPath.prototype._fillFuncHit = _fillFunc;
|
|
335
361
|
TextPath.prototype._strokeFuncHit = _strokeFunc;
|
|
336
362
|
TextPath.prototype.className = 'TextPath';
|
|
337
|
-
|
|
363
|
+
const ATTR_CHANGE_LIST = [
|
|
338
364
|
'text',
|
|
339
365
|
'fontSize',
|
|
340
|
-
'data',
|
|
341
366
|
'align',
|
|
342
367
|
'letterSpacing',
|
|
343
368
|
'kerningFunc',
|
|
@@ -346,16 +371,16 @@ TextPath.prototype._attrsAffectingSize = [
|
|
|
346
371
|
'fontVariant',
|
|
347
372
|
'direction',
|
|
348
373
|
];
|
|
374
|
+
// data relayouts in its own listener; textDecoration changes the bounds
|
|
375
|
+
// through getSelfRect, but needs no relayout
|
|
376
|
+
TextPath.prototype._attrsAffectingSize = ATTR_CHANGE_LIST.concat('data', 'textDecoration');
|
|
349
377
|
_registerNode(TextPath, true);
|
|
350
378
|
TextPath.prototype.on('dataChange.konva', function () {
|
|
351
379
|
this._readDataAttribute();
|
|
352
380
|
this._setTextData();
|
|
353
381
|
});
|
|
354
382
|
// update text data for certain attr changes
|
|
355
|
-
TextPath.prototype.on(
|
|
356
|
-
.filter((attr) => attr !== 'data')
|
|
357
|
-
.map((attr) => attr + 'Change.konva')
|
|
358
|
-
.join(' '), function () {
|
|
383
|
+
TextPath.prototype.on(ATTR_CHANGE_LIST.map((attr) => attr + 'Change.konva').join(' '), function () {
|
|
359
384
|
this._setTextData();
|
|
360
385
|
});
|
|
361
386
|
/**
|