kfb-view 2.1.10 → 2.1.13
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/.idea/git_toolbox_prj.xml +5 -0
- package/.idea/workspace.xml +82 -70
- package/example/index.js +2 -1
- package/lib/kfb-view.js +1 -1
- package/package.json +1 -1
- package/src/components/board/index.js +19 -2
- package/src/components/rotation/index.js +2 -0
- package/src/components/shape/index.js +39 -8
- package/src/components/tailoring/index.js +4 -8
- package/src/index.js +2 -1
- package/src/model/label.model.js +8 -3
- package/src/tool/Arrow.js +2 -9
- package/src/tool/Bilateral.js +2 -9
- package/src/tool/Brush.js +14 -8
- package/src/tool/Combination.js +5 -1
- package/src/tool/Dot.js +3 -5
- package/src/tool/Ellipse.js +6 -14
- package/src/tool/Flag.js +2 -8
- package/src/tool/Font.js +2 -3
- package/src/tool/Line.js +2 -4
- package/src/tool/Polygon.js +6 -23
- package/src/tool/Rectangle.js +5 -14
- package/src/tool/Star.js +3 -6
- package/src/util/canvas.js +0 -4
- package/test.html +315 -0
package/package.json
CHANGED
|
@@ -140,7 +140,9 @@ export class Board extends ViewerCommon {
|
|
|
140
140
|
this.points = [point];
|
|
141
141
|
}
|
|
142
142
|
this.clearCanvas();
|
|
143
|
+
this[tool].startDraw();
|
|
143
144
|
this[tool].draw(this.imageToViewerElementPoints(this.points));
|
|
145
|
+
this[tool].endDraw();
|
|
144
146
|
this.$emit(EVENT_START_PAINTING, this.getPaintOptions());
|
|
145
147
|
}
|
|
146
148
|
|
|
@@ -166,7 +168,9 @@ export class Board extends ViewerCommon {
|
|
|
166
168
|
this.points = [point, point];
|
|
167
169
|
}
|
|
168
170
|
this.clearCanvas();
|
|
171
|
+
this[tool].startDraw();
|
|
169
172
|
this[tool].draw(this.imageToViewerElementPoints(this.points));
|
|
173
|
+
this[tool].endDraw();
|
|
170
174
|
this.$emit(EVENT_IN_PAINTING, this.getPaintOptions());
|
|
171
175
|
}
|
|
172
176
|
|
|
@@ -244,7 +248,9 @@ export class Board extends ViewerCommon {
|
|
|
244
248
|
this.points.pop();
|
|
245
249
|
this.points.push(point);
|
|
246
250
|
this.clearCanvas();
|
|
251
|
+
this[tool].startDraw();
|
|
247
252
|
this[tool].draw(this.imageToViewerElementPoints(this.points));
|
|
253
|
+
this[tool].endDraw();
|
|
248
254
|
this.$emit(EVENT_IN_PAINTING, this.getPaintOptions());
|
|
249
255
|
}
|
|
250
256
|
}
|
|
@@ -282,8 +288,17 @@ export class Board extends ViewerCommon {
|
|
|
282
288
|
* @return {boolean}
|
|
283
289
|
*/
|
|
284
290
|
isInROI(point) {
|
|
285
|
-
|
|
286
|
-
this[this.tool].options.isROI
|
|
291
|
+
if (this.options.ROI) {
|
|
292
|
+
return this[this.tool].options.isROI ||
|
|
293
|
+
this.isContainerLabel(point, this.ROIList);
|
|
294
|
+
} else if (this.ROIList.length > 0) {
|
|
295
|
+
return this[this.tool].options.isROI ||
|
|
296
|
+
this.isContainerLabel(point, this.ROIList);
|
|
297
|
+
} else {
|
|
298
|
+
return true;
|
|
299
|
+
}
|
|
300
|
+
/* return !this.options.ROI || this.isContainerLabel(point, this.ROIList) ||
|
|
301
|
+
this[this.tool].options.isROI;*/
|
|
287
302
|
}
|
|
288
303
|
|
|
289
304
|
/**
|
|
@@ -310,7 +325,9 @@ export class Board extends ViewerCommon {
|
|
|
310
325
|
if (!this.isInDraw || this.points.length === 0) return;
|
|
311
326
|
const points = this.imageToViewerElementPoints(this.points);
|
|
312
327
|
this.clearCanvas();
|
|
328
|
+
this[this.tool].startDraw();
|
|
313
329
|
this[this.tool].draw(points);
|
|
330
|
+
this[this.tool].endDraw();
|
|
314
331
|
this.$emit(EVENT_IN_PAINTING, this.getPaintOptions());
|
|
315
332
|
}
|
|
316
333
|
}
|
|
@@ -38,8 +38,10 @@ class Rotation extends ViewerCommon {
|
|
|
38
38
|
drawRect(startPoint, endPoint) {
|
|
39
39
|
const rect = this.viewport.imageToViewportRectangle(0, 0, this.imgWidth,
|
|
40
40
|
this.imgHeight);
|
|
41
|
+
this.rect.startDraw();
|
|
41
42
|
this.rect.draw([startPoint, endPoint], this.viewport.getRotation(),
|
|
42
43
|
this.viewport.viewportToViewerElementRectangle(rect));
|
|
44
|
+
this.rect.endDraw();
|
|
43
45
|
this.drawThumbPoint();
|
|
44
46
|
}
|
|
45
47
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
NO_NORMAL_REGION_TYPES,
|
|
2
|
+
HAS_REGION_TYPES, MARKS,
|
|
3
|
+
NO_NORMAL_REGION_TYPES, POINT_TYPES,
|
|
4
4
|
} from '../../const/mark';
|
|
5
5
|
import {ViewerCommon} from '../common/common';
|
|
6
6
|
import * as Tools from '../../tool';
|
|
@@ -65,14 +65,28 @@ export class Shape extends ViewerCommon {
|
|
|
65
65
|
child: [],
|
|
66
66
|
self: item,
|
|
67
67
|
}));
|
|
68
|
+
// strokeStyle, lineWidth, fillStyle 相同认为是一个路径下的图形,一起绘制,优化性能
|
|
69
|
+
const sameFixWidthLabel = {}; // star, flag, star, font lineWidth固定为2
|
|
70
|
+
const sameNormalLabel = {};
|
|
68
71
|
this.labelList.forEach((item) => {
|
|
69
72
|
if (!this.isInCanvas(item.region)) return;
|
|
70
73
|
if (item.show === false) return;
|
|
71
74
|
if (!this[item.tool]) return;
|
|
72
|
-
|
|
73
|
-
|
|
75
|
+
const key = `${item.strokeStyle ?? ''}_${item.lineWidth ??
|
|
76
|
+
''}_${item.fillStyle ?? ''}`;
|
|
77
|
+
const regionKey = `${item.strokeStyle ?? ''}_${item.lineWidth ?? ''}`;
|
|
78
|
+
if (POINT_TYPES.includes(item.tool)) {
|
|
79
|
+
if (sameFixWidthLabel[key]) {
|
|
80
|
+
sameFixWidthLabel[key].push(item);
|
|
81
|
+
} else {
|
|
82
|
+
sameFixWidthLabel[key] = [item];
|
|
83
|
+
}
|
|
74
84
|
} else {
|
|
75
|
-
|
|
85
|
+
if (sameNormalLabel[regionKey]) {
|
|
86
|
+
sameNormalLabel[regionKey].push(item);
|
|
87
|
+
} else {
|
|
88
|
+
sameNormalLabel[regionKey] = [item];
|
|
89
|
+
}
|
|
76
90
|
}
|
|
77
91
|
const parent = regionLabelList.find(
|
|
78
92
|
(parent) => parent.self !== item && item.points.every(
|
|
@@ -81,6 +95,26 @@ export class Shape extends ViewerCommon {
|
|
|
81
95
|
parent.child.push(item);
|
|
82
96
|
}
|
|
83
97
|
});
|
|
98
|
+
Object.values(sameFixWidthLabel).forEach((labels) => {
|
|
99
|
+
const ctx = this.canvas.getContext('2d');
|
|
100
|
+
ctx.beginPath();
|
|
101
|
+
labels.forEach((item) => {
|
|
102
|
+
this.drawLabel(item);
|
|
103
|
+
});
|
|
104
|
+
ctx.stroke();
|
|
105
|
+
if (labels?.[0]?.fillStyle) {
|
|
106
|
+
ctx.fill();
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
Object.values(sameNormalLabel).forEach((labels) => {
|
|
110
|
+
const ctx = this.canvas.getContext('2d');
|
|
111
|
+
ctx.beginPath();
|
|
112
|
+
labels.forEach((item) => {
|
|
113
|
+
this.drawLabel(item);
|
|
114
|
+
});
|
|
115
|
+
ctx.stroke();
|
|
116
|
+
});
|
|
117
|
+
|
|
84
118
|
regionLabelList.forEach((item) => {
|
|
85
119
|
if (!this.isInCanvas(item.region)) return;
|
|
86
120
|
if (item.show === false) return;
|
|
@@ -103,9 +137,6 @@ export class Shape extends ViewerCommon {
|
|
|
103
137
|
if (!NO_NORMAL_REGION_TYPES.includes(item.tool)) {
|
|
104
138
|
this[item.tool].draw(points, this.viewport.getRotation(),
|
|
105
139
|
this.imageToViewerElementRectangle(item.region));
|
|
106
|
-
} else if (item.tool === POLYGON) {
|
|
107
|
-
this[item.tool].draw(points);
|
|
108
|
-
this[item.tool].drawEndPoints(points);
|
|
109
140
|
} else {
|
|
110
141
|
this[item.tool].draw(points, scale);
|
|
111
142
|
}
|
|
@@ -41,6 +41,7 @@ export class Tailoring extends ViewerCommon {
|
|
|
41
41
|
pointList[8]];
|
|
42
42
|
if (now) {
|
|
43
43
|
this.$emit(EVENT_TAILORING_SCREENSHOT, this.getScreenCanvasImage());
|
|
44
|
+
this.stopTailoring();
|
|
44
45
|
} else {
|
|
45
46
|
this.color = color || '#FFF';
|
|
46
47
|
this.change();
|
|
@@ -226,15 +227,10 @@ export class Tailoring extends ViewerCommon {
|
|
|
226
227
|
}
|
|
227
228
|
|
|
228
229
|
onCanvasDblClick(position) {
|
|
229
|
-
if (this.tailoringPoints.length
|
|
230
|
-
this.
|
|
231
|
-
} else {
|
|
232
|
-
if (this.isPointInMatrix(position)) {
|
|
233
|
-
this.$emit(EVENT_TAILORING_SCREENSHOT, this.getScreenCanvasImage());
|
|
234
|
-
} else {
|
|
235
|
-
this.stopTailoring();
|
|
236
|
-
}
|
|
230
|
+
if (this.tailoringPoints.length > 0 && this.isPointInMatrix(position)) {
|
|
231
|
+
this.$emit(EVENT_TAILORING_SCREENSHOT, this.getScreenCanvasImage());
|
|
237
232
|
}
|
|
233
|
+
this.stopTailoring();
|
|
238
234
|
}
|
|
239
235
|
|
|
240
236
|
/**
|
package/src/index.js
CHANGED
package/src/model/label.model.js
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
|
+
import {DOT, FLAG, STAR} from '../const/mark';
|
|
2
|
+
|
|
1
3
|
export class LabelModel {
|
|
2
4
|
constructor(data = {}) {
|
|
3
5
|
if (!data) data = {};
|
|
4
6
|
this.id = data.id; // id标识
|
|
5
|
-
this.lineWidth = data.lineWidth
|
|
6
|
-
|
|
7
|
+
this.lineWidth = !data.lineWidth ?
|
|
8
|
+
(data.tool === STAR ? 15 :
|
|
9
|
+
data.tool === FLAG ? 30 : data.tool === DOT ? 10 : 2) :
|
|
10
|
+
data.lineWidth; // 标注宽度
|
|
11
|
+
this.strokeStyle = data.strokeStyle || '#027AFF'; // 标注颜色
|
|
7
12
|
this.fillStyle = data.fillStyle; // 填充颜色
|
|
8
13
|
this.description = data.description; // 描述
|
|
9
14
|
this.fontSize = data.fontSize; // 字号
|
|
@@ -17,7 +22,7 @@ export class LabelModel {
|
|
|
17
22
|
this.move = data.move; // 是否可移动
|
|
18
23
|
this.resize = data.resize; // 是否可拖动大小
|
|
19
24
|
this.isROI = data.isROI ?? false; // 是否是ROI
|
|
20
|
-
this.isClose = data.isClose ?? true; //
|
|
25
|
+
this.isClose = data.isClose ?? true; // 是否是闭合标注
|
|
21
26
|
this.select = data.select ?? false; // 是否是选中状态
|
|
22
27
|
this.show = data.show ?? true; // 是否显示
|
|
23
28
|
this.__other__ = data.__other__ || {}; // 其他信息
|
package/src/tool/Arrow.js
CHANGED
|
@@ -10,7 +10,6 @@ class Arrow extends Brush {
|
|
|
10
10
|
*/
|
|
11
11
|
constructor() {
|
|
12
12
|
super();
|
|
13
|
-
this.lineWidth = 2;
|
|
14
13
|
}
|
|
15
14
|
|
|
16
15
|
/**
|
|
@@ -23,17 +22,11 @@ class Arrow extends Brush {
|
|
|
23
22
|
const startPoint = points[0];
|
|
24
23
|
const endPoint = points[points.length - 1];
|
|
25
24
|
const ctx = this.canvas.getContext('2d');
|
|
26
|
-
ctx.
|
|
27
|
-
ctx.
|
|
28
|
-
ctx.strokeStyle = this.options.strokeStyle || '#0000FF';
|
|
25
|
+
ctx.lineWidth = this.options.lineWidth;
|
|
26
|
+
ctx.strokeStyle = this.options.strokeStyle;
|
|
29
27
|
ctx.moveTo(startPoint.x, startPoint.y);
|
|
30
28
|
ctx.lineTo(endPoint.x, endPoint.y);
|
|
31
|
-
ctx.stroke();
|
|
32
|
-
ctx.closePath();
|
|
33
|
-
ctx.beginPath();
|
|
34
29
|
ctx.drawArrow(startPoint, endPoint);
|
|
35
|
-
ctx.stroke();
|
|
36
|
-
ctx.closePath();
|
|
37
30
|
}
|
|
38
31
|
}
|
|
39
32
|
|
package/src/tool/Bilateral.js
CHANGED
|
@@ -10,7 +10,6 @@ class Bilateral extends Brush {
|
|
|
10
10
|
*/
|
|
11
11
|
constructor() {
|
|
12
12
|
super();
|
|
13
|
-
this.lineWidth = 2;
|
|
14
13
|
}
|
|
15
14
|
|
|
16
15
|
/**
|
|
@@ -23,18 +22,12 @@ class Bilateral extends Brush {
|
|
|
23
22
|
const startPoint = points[0];
|
|
24
23
|
const endPoint = points[points.length - 1];
|
|
25
24
|
const ctx = this.canvas.getContext('2d');
|
|
26
|
-
ctx.
|
|
27
|
-
ctx.
|
|
28
|
-
ctx.strokeStyle = this.options.strokeStyle || '#0000FF';
|
|
25
|
+
ctx.lineWidth = this.options.lineWidth;
|
|
26
|
+
ctx.strokeStyle = this.options.strokeStyle;
|
|
29
27
|
ctx.moveTo(startPoint.x, startPoint.y);
|
|
30
28
|
ctx.lineTo(endPoint.x, endPoint.y);
|
|
31
|
-
ctx.stroke();
|
|
32
|
-
ctx.closePath();
|
|
33
|
-
ctx.beginPath();
|
|
34
29
|
ctx.drawArrow(startPoint, endPoint);
|
|
35
30
|
ctx.drawArrow(endPoint, startPoint);
|
|
36
|
-
ctx.stroke();
|
|
37
|
-
ctx.closePath();
|
|
38
31
|
}
|
|
39
32
|
}
|
|
40
33
|
|
package/src/tool/Brush.js
CHANGED
|
@@ -10,11 +10,7 @@ class Brush {
|
|
|
10
10
|
*/
|
|
11
11
|
constructor() {
|
|
12
12
|
this.thumb = new Thumb();
|
|
13
|
-
this.options = {
|
|
14
|
-
lineWidth: 2,
|
|
15
|
-
fillStyle: '',
|
|
16
|
-
strokeStyle: '#0000ff',
|
|
17
|
-
};
|
|
13
|
+
this.options = {};
|
|
18
14
|
}
|
|
19
15
|
|
|
20
16
|
/**
|
|
@@ -26,13 +22,23 @@ class Brush {
|
|
|
26
22
|
this.canvas = canvas;
|
|
27
23
|
this.thumb.setCanvas(canvas);
|
|
28
24
|
this.options = {
|
|
29
|
-
lineWidth: 2,
|
|
30
|
-
fillStyle: '',
|
|
31
|
-
strokeStyle: '#0000ff',
|
|
32
25
|
...options,
|
|
33
26
|
};
|
|
34
27
|
}
|
|
35
28
|
|
|
29
|
+
startDraw() {
|
|
30
|
+
const ctx = this.canvas.getContext('2d');
|
|
31
|
+
ctx.beginPath();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
endDraw() {
|
|
35
|
+
const ctx = this.canvas.getContext('2d');
|
|
36
|
+
ctx.stroke();
|
|
37
|
+
if (this.options.fillStyle) {
|
|
38
|
+
ctx.fill();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
36
42
|
/**
|
|
37
43
|
* 画点
|
|
38
44
|
* @param {Object} point
|
package/src/tool/Combination.js
CHANGED
|
@@ -48,6 +48,7 @@ class Combination extends Brush {
|
|
|
48
48
|
ctx.restore();
|
|
49
49
|
children.forEach(({tool, points}) => {
|
|
50
50
|
ctx.save();
|
|
51
|
+
ctx.beginPath();
|
|
51
52
|
const region = pointsToRegion(points);
|
|
52
53
|
const centerPoint = {
|
|
53
54
|
x: region.x + region.width / 2,
|
|
@@ -72,7 +73,10 @@ class Combination extends Brush {
|
|
|
72
73
|
} else if (tool === ELLIPSE) {
|
|
73
74
|
ctx.drawOval(0, 0, region.width / 2, region.height / 2, true);
|
|
74
75
|
}
|
|
75
|
-
|
|
76
|
+
if (this.options.fillStyle) {
|
|
77
|
+
ctx.fillStyle = this.options.fillStyle;
|
|
78
|
+
ctx.fill();
|
|
79
|
+
}
|
|
76
80
|
ctx.restore();
|
|
77
81
|
});
|
|
78
82
|
if (this.options.fillStyle) {
|
package/src/tool/Dot.js
CHANGED
|
@@ -21,20 +21,18 @@ class Dot extends Brush {
|
|
|
21
21
|
* @param {number} scale
|
|
22
22
|
*/
|
|
23
23
|
draw(points, scale = 1) {
|
|
24
|
-
let dist = this.options.lineWidth
|
|
24
|
+
let dist = this.options.lineWidth;
|
|
25
25
|
dist *= scale;
|
|
26
26
|
const point = points[0];
|
|
27
27
|
const ctx = this.canvas.getContext('2d');
|
|
28
28
|
const {x, y} = point;
|
|
29
29
|
ctx.lineWidth = 2;
|
|
30
|
-
ctx.
|
|
30
|
+
ctx.moveTo(x + dist, y);
|
|
31
31
|
ctx.arc(x, y, dist, 0, Math.PI * 2, !1);
|
|
32
32
|
if (this.options.fillStyle) {
|
|
33
33
|
ctx.fillStyle = this.options.fillStyle;
|
|
34
|
-
ctx.fill();
|
|
35
34
|
}
|
|
36
|
-
ctx.strokeStyle = this.options.strokeStyle
|
|
37
|
-
ctx.stroke();
|
|
35
|
+
ctx.strokeStyle = this.options.strokeStyle;
|
|
38
36
|
}
|
|
39
37
|
}
|
|
40
38
|
|
package/src/tool/Ellipse.js
CHANGED
|
@@ -24,8 +24,12 @@ class Ellipse extends Brush {
|
|
|
24
24
|
const startPoint = points[0];
|
|
25
25
|
const endPoint = points[points.length - 1];
|
|
26
26
|
const ctx = this.canvas.getContext('2d');
|
|
27
|
+
ctx.lineWidth = this.options.lineWidth;
|
|
28
|
+
ctx.strokeStyle = this.options.strokeStyle;
|
|
29
|
+
if (this.options.fillStyle) {
|
|
30
|
+
ctx.fillStyle = this.options.fillStyle;
|
|
31
|
+
}
|
|
27
32
|
ctx.save();
|
|
28
|
-
ctx.beginPath();
|
|
29
33
|
const centerPoint = {
|
|
30
34
|
x: (startPoint.x + endPoint.x) / 2,
|
|
31
35
|
y: (startPoint.y + endPoint.y) / 2,
|
|
@@ -38,23 +42,11 @@ class Ellipse extends Brush {
|
|
|
38
42
|
Math.abs(endPoint.y - startPoint.y);
|
|
39
43
|
ctx.translate(centerPoint.x, centerPoint.y);
|
|
40
44
|
ctx.rotate(rotation * Math.PI / 180);
|
|
41
|
-
ctx.lineWidth = this.options.lineWidth || 2;
|
|
42
|
-
ctx.strokeStyle = this.options.strokeStyle || '#0000FF';
|
|
43
45
|
if (rotation < 90 && rotation >= 0 || rotation > 180 && rotation < 270) {
|
|
44
46
|
ctx.drawOval(0, 0, width / 2, height / 2);
|
|
45
|
-
if (this.options.fillStyle) {
|
|
46
|
-
ctx.fillStyle = this.options.fillStyle;
|
|
47
|
-
ctx.drawOval(0, 0, width / 2, height / 2);
|
|
48
|
-
ctx.fill();
|
|
49
|
-
}
|
|
50
47
|
} else {
|
|
51
|
-
|
|
52
|
-
ctx.fillStyle = this.options.fillStyle;
|
|
53
|
-
ctx.drawOval(0, 0, height / 2, width / 2);
|
|
54
|
-
ctx.fill();
|
|
55
|
-
}
|
|
48
|
+
ctx.drawOval(0, 0, height / 2, width / 2);
|
|
56
49
|
}
|
|
57
|
-
ctx.stroke();
|
|
58
50
|
ctx.restore();
|
|
59
51
|
}
|
|
60
52
|
}
|
package/src/tool/Flag.js
CHANGED
|
@@ -13,16 +13,14 @@ class Flag extends Brush {
|
|
|
13
13
|
* @param {number} scale
|
|
14
14
|
*/
|
|
15
15
|
draw(points, scale = 1) {
|
|
16
|
-
let dist = this.options.lineWidth
|
|
16
|
+
let dist = this.options.lineWidth;
|
|
17
17
|
dist *= scale;
|
|
18
18
|
const point = points[0];
|
|
19
19
|
const ctx = this.canvas.getContext('2d');
|
|
20
|
-
ctx.beginPath();
|
|
21
20
|
ctx.lineWidth = 2;
|
|
22
|
-
ctx.strokeStyle = this.options.strokeStyle
|
|
21
|
+
ctx.strokeStyle = this.options.strokeStyle;
|
|
23
22
|
ctx.moveTo(point.x, point.y);
|
|
24
23
|
ctx.lineTo(point.x, point.y - dist);
|
|
25
|
-
ctx.stroke();
|
|
26
24
|
const _dist = dist / 5;
|
|
27
25
|
const p1 = {
|
|
28
26
|
x: point.x + _dist,
|
|
@@ -41,10 +39,8 @@ class Flag extends Brush {
|
|
|
41
39
|
y: point.y - dist,
|
|
42
40
|
};
|
|
43
41
|
ctx.bezierCurve([p1, p2, p3, p4]);
|
|
44
|
-
ctx.stroke();
|
|
45
42
|
ctx.moveTo(p4.x, p4.y);
|
|
46
43
|
ctx.lineTo(p4.x, p4.y + dist / 2);
|
|
47
|
-
ctx.stroke();
|
|
48
44
|
const p11 = {
|
|
49
45
|
x: point.x + _dist,
|
|
50
46
|
y: point.y - dist / 2,
|
|
@@ -62,10 +58,8 @@ class Flag extends Brush {
|
|
|
62
58
|
y: point.y - dist / 2,
|
|
63
59
|
};
|
|
64
60
|
ctx.bezierCurve([p11, p22, p33, p44]);
|
|
65
|
-
ctx.stroke();
|
|
66
61
|
ctx.moveTo(p1.x, p1.y);
|
|
67
62
|
ctx.lineTo(p11.x, p11.y);
|
|
68
|
-
ctx.stroke();
|
|
69
63
|
}
|
|
70
64
|
}
|
|
71
65
|
|
package/src/tool/Font.js
CHANGED
|
@@ -24,15 +24,14 @@ class Font extends Brush {
|
|
|
24
24
|
const angle = this.options.angle || 0;
|
|
25
25
|
const text = this.options.text || '编辑文字';
|
|
26
26
|
const ctx = this.canvas.getContext('2d');
|
|
27
|
-
ctx.
|
|
27
|
+
ctx.fillStyle = this.options.fillStyle || this.options.strokeStyle ||
|
|
28
|
+
'#FDFDFD';
|
|
28
29
|
ctx.save();
|
|
29
30
|
ctx.translate(point.x, point.y);
|
|
30
31
|
ctx.rotate(angle / 180 * Math.PI);
|
|
31
32
|
ctx.scale(scale, scale);
|
|
32
33
|
ctx.font = `${this.options.fontSize || 14}px Arial`;
|
|
33
|
-
ctx.fillStyle = this.options.strokeStyle || '#FDFDFD';
|
|
34
34
|
ctx.fillText(text, 0, 0);
|
|
35
|
-
ctx.stroke();
|
|
36
35
|
ctx.restore();
|
|
37
36
|
}
|
|
38
37
|
}
|
package/src/tool/Line.js
CHANGED
|
@@ -22,9 +22,8 @@ class Line extends Brush {
|
|
|
22
22
|
const startPoint = points[0];
|
|
23
23
|
const endPoint = points[points.length - 1];
|
|
24
24
|
const ctx = this.canvas.getContext('2d');
|
|
25
|
-
ctx.
|
|
26
|
-
ctx.
|
|
27
|
-
ctx.strokeStyle = this.options.strokeStyle || '#0000FF';
|
|
25
|
+
ctx.lineWidth = this.options.lineWidth;
|
|
26
|
+
ctx.strokeStyle = this.options.strokeStyle;
|
|
28
27
|
ctx.moveTo(startPoint.x, startPoint.y);
|
|
29
28
|
ctx.lineTo(endPoint.x, endPoint.y);
|
|
30
29
|
const deg = Math.atan2((endPoint.y - startPoint.y),
|
|
@@ -35,7 +34,6 @@ class Line extends Brush {
|
|
|
35
34
|
ctx.lineTo(startPoint.x - distX, startPoint.y + distY);
|
|
36
35
|
ctx.moveTo(endPoint.x + distX, endPoint.y - distY);
|
|
37
36
|
ctx.lineTo(endPoint.x - distX, endPoint.y + distY);
|
|
38
|
-
ctx.stroke();
|
|
39
37
|
}
|
|
40
38
|
}
|
|
41
39
|
|
package/src/tool/Polygon.js
CHANGED
|
@@ -5,22 +5,6 @@ import {Brush} from './Brush';
|
|
|
5
5
|
* @class
|
|
6
6
|
*/
|
|
7
7
|
class Polygon extends Brush {
|
|
8
|
-
/**
|
|
9
|
-
* 绘制结束点
|
|
10
|
-
* @param {Object[]} points - 绘制的点
|
|
11
|
-
* @param {number} points[].x - 绘制的点x坐标.
|
|
12
|
-
* @param {number} points[].y - 绘制的点y坐标.
|
|
13
|
-
*/
|
|
14
|
-
drawEndPoints(points) {
|
|
15
|
-
const ctx = this.canvas.getContext('2d');
|
|
16
|
-
ctx.beginPath();
|
|
17
|
-
ctx.lineWidth = this.options.lineWidth || 2;
|
|
18
|
-
ctx.strokeStyle = this.options.strokeStyle || '#0000FF';
|
|
19
|
-
ctx.moveTo(points[points.length - 1].x, points[points.length - 1].y);
|
|
20
|
-
ctx.lineTo(points[0].x, points[0].y);
|
|
21
|
-
ctx.stroke();
|
|
22
|
-
}
|
|
23
|
-
|
|
24
8
|
/**
|
|
25
9
|
* 绘制
|
|
26
10
|
* @param {Object[]} points - 绘制的点
|
|
@@ -29,19 +13,18 @@ class Polygon extends Brush {
|
|
|
29
13
|
*/
|
|
30
14
|
draw(points) {
|
|
31
15
|
const ctx = this.canvas.getContext('2d');
|
|
32
|
-
ctx.
|
|
33
|
-
ctx.
|
|
34
|
-
ctx.strokeStyle = this.options.strokeStyle || '#0000FF';
|
|
16
|
+
ctx.lineWidth = this.options.lineWidth;
|
|
17
|
+
ctx.strokeStyle = this.options.strokeStyle;
|
|
35
18
|
ctx.moveTo(points[0].x, points[0].y);
|
|
36
19
|
points.forEach((point) => {
|
|
37
20
|
ctx.lineTo(point.x, point.y);
|
|
38
21
|
});
|
|
39
|
-
if (this.options.
|
|
22
|
+
if (this.options.isClose) {
|
|
40
23
|
ctx.lineTo(points[0].x, points[0].y);
|
|
41
|
-
|
|
42
|
-
|
|
24
|
+
if (this.options.fillStyle) {
|
|
25
|
+
ctx.fillStyle = this.options.fillStyle;
|
|
26
|
+
}
|
|
43
27
|
}
|
|
44
|
-
ctx.stroke();
|
|
45
28
|
}
|
|
46
29
|
}
|
|
47
30
|
|
package/src/tool/Rectangle.js
CHANGED
|
@@ -24,8 +24,12 @@ class Rectangle extends Brush {
|
|
|
24
24
|
const startPoint = points[0];
|
|
25
25
|
const endPoint = points[points.length - 1];
|
|
26
26
|
const ctx = this.canvas.getContext('2d');
|
|
27
|
+
ctx.lineWidth = this.options.lineWidth;
|
|
28
|
+
ctx.strokeStyle = this.options.strokeStyle;
|
|
29
|
+
if (this.options.fillStyle) {
|
|
30
|
+
ctx.fillStyle = this.options.fillStyle;
|
|
31
|
+
}
|
|
27
32
|
ctx.save();
|
|
28
|
-
ctx.beginPath();
|
|
29
33
|
const centerPoint = {
|
|
30
34
|
x: (startPoint.x + endPoint.x) / 2,
|
|
31
35
|
y: (startPoint.y + endPoint.y) / 2,
|
|
@@ -37,26 +41,13 @@ class Rectangle extends Brush {
|
|
|
37
41
|
Math.abs(region.height) :
|
|
38
42
|
Math.abs(endPoint.y - startPoint.y);
|
|
39
43
|
ctx.translate(centerPoint.x, centerPoint.y);
|
|
40
|
-
ctx.lineWidth = this.options.lineWidth || 2;
|
|
41
|
-
ctx.strokeStyle = this.options.strokeStyle || '#0000FF';
|
|
42
44
|
if (rotation < 90 && rotation >= 0 || rotation > 180 && rotation < 270) {
|
|
43
45
|
ctx.rotate(rotation * Math.PI / 180);
|
|
44
46
|
ctx.rect(-width / 2, -height / 2, width, height);
|
|
45
|
-
if (this.options.fillStyle) {
|
|
46
|
-
ctx.fillStyle = this.options.fillStyle;
|
|
47
|
-
ctx.rect(-width / 2, -height / 2, width, height);
|
|
48
|
-
ctx.fill();
|
|
49
|
-
}
|
|
50
47
|
} else {
|
|
51
48
|
ctx.rotate(rotation * Math.PI / 180);
|
|
52
49
|
ctx.rect(-height / 2, -width / 2, height, width);
|
|
53
|
-
if (this.options.fillStyle) {
|
|
54
|
-
ctx.fillStyle = this.options.fillStyle;
|
|
55
|
-
ctx.rect(-height / 2, -width / 2, height, width);
|
|
56
|
-
ctx.fill();
|
|
57
|
-
}
|
|
58
50
|
}
|
|
59
|
-
ctx.stroke();
|
|
60
51
|
ctx.restore();
|
|
61
52
|
}
|
|
62
53
|
}
|
package/src/tool/Star.js
CHANGED
|
@@ -21,7 +21,7 @@ class Star extends Brush {
|
|
|
21
21
|
* @param {number} scale
|
|
22
22
|
*/
|
|
23
23
|
draw(points, scale = 1) {
|
|
24
|
-
let dist = this.options.lineWidth
|
|
24
|
+
let dist = this.options.lineWidth;
|
|
25
25
|
const point = points[0];
|
|
26
26
|
dist *= scale;
|
|
27
27
|
this.endPoint = {x: point.x, y: point.y};
|
|
@@ -67,8 +67,7 @@ class Star extends Brush {
|
|
|
67
67
|
y: point.y - dist + short_side * Math.cos(angle),
|
|
68
68
|
};
|
|
69
69
|
const ctx = this.canvas.getContext('2d');
|
|
70
|
-
ctx.
|
|
71
|
-
ctx.lineWidth = 1;
|
|
70
|
+
ctx.lineWidth = 2;
|
|
72
71
|
ctx.moveTo(p1.x, p1.y);
|
|
73
72
|
ctx.lineTo(p2.x, p2.y);
|
|
74
73
|
ctx.lineTo(p3.x, p3.y);
|
|
@@ -80,11 +79,9 @@ class Star extends Brush {
|
|
|
80
79
|
ctx.lineTo(p9.x, p9.y);
|
|
81
80
|
ctx.lineTo(p10.x, p10.y);
|
|
82
81
|
ctx.lineTo(p1.x, p1.y);
|
|
83
|
-
ctx.strokeStyle = this.options.strokeStyle
|
|
84
|
-
ctx.stroke();
|
|
82
|
+
ctx.strokeStyle = this.options.strokeStyle;
|
|
85
83
|
if (this.options.fillStyle) {
|
|
86
84
|
ctx.fillStyle = this.options.fillStyle;
|
|
87
|
-
ctx.fill();
|
|
88
85
|
}
|
|
89
86
|
}
|
|
90
87
|
}
|
package/src/util/canvas.js
CHANGED
|
@@ -153,20 +153,17 @@ CanvasRenderingContext2D.prototype.bezierCurve = function(...rest) {
|
|
|
153
153
|
throw new SyntaxError('Parameter length greater than 1');
|
|
154
154
|
}
|
|
155
155
|
if (points.length === 2) {
|
|
156
|
-
this.beginPath();
|
|
157
156
|
this.moveTo(points[0].x, points[0].y);
|
|
158
157
|
this.lineTo(points[1].x, points[1].y);
|
|
159
158
|
this.stroke();
|
|
160
159
|
}
|
|
161
160
|
if (points.length === 3) {
|
|
162
|
-
this.beginPath();
|
|
163
161
|
const startPoint = points[0];
|
|
164
162
|
this.moveTo(startPoint.x, startPoint.y);
|
|
165
163
|
this.quadraticCurveTo(points[1].x, points[1].y, points[2].x,
|
|
166
164
|
points[2].y);
|
|
167
165
|
this.stroke();
|
|
168
166
|
} else if (points.length === 4) {
|
|
169
|
-
this.beginPath();
|
|
170
167
|
const startPoint = points[0];
|
|
171
168
|
this.moveTo(startPoint.x, startPoint.y);
|
|
172
169
|
this.bezierCurveTo(points[1].x, points[1].y, points[2].x, points[2].y,
|
|
@@ -177,7 +174,6 @@ CanvasRenderingContext2D.prototype.bezierCurve = function(...rest) {
|
|
|
177
174
|
const calculationPoints = [...new Array(101)].map(
|
|
178
175
|
(item, index) => bezierCurve.calculationPoint(index / 100));
|
|
179
176
|
for (let t = 1; t < 101; t++) {
|
|
180
|
-
this.beginPath();
|
|
181
177
|
this.moveTo(calculationPoints[t - 1].x, calculationPoints[t - 1].y);
|
|
182
178
|
this.lineTo(calculationPoints[t].x, calculationPoints[t].y);
|
|
183
179
|
this.stroke();
|