kfb-view 3.2.7 → 3.2.9

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "kfb-view",
3
3
  "description": "一个在线kfb的阅片软件",
4
- "version": "3.2.7",
4
+ "version": "3.2.9",
5
5
  "author": "qifeng.fan <qifeng.fan@hzztai.com>",
6
6
  "license": "MIT",
7
7
  "main": "lib/kfb-view.js",
@@ -105,12 +105,14 @@ export class Shape extends ViewerCommon {
105
105
  clearTimeout(this.delaytimer);
106
106
  this.delaytimer = undefined;
107
107
  }
108
- this.deepDrawLabel(sameFixWidthLabel, sameNormalLabel, regionLabelList,
109
- imageLabel, 1, bounds);
108
+ // 优先绘制图片标注
109
+ imageLabel.forEach((item) => {
110
+ this.drawLabel(item);
111
+ });
112
+ this.deepDrawLabel(sameFixWidthLabel, sameNormalLabel, regionLabelList, 1, bounds);
110
113
  }
111
114
 
112
- deepDrawLabel(sameFixWidthLabel, sameNormalLabel, regionLabelList,
113
- imageLabel, count, bounds) {
115
+ deepDrawLabel(sameFixWidthLabel, sameNormalLabel, regionLabelList, count, bounds) {
114
116
  let currentDrawCount = 0; // 当前已绘制数量
115
117
  const ctx = this.canvas.getContext('2d');
116
118
  const remainFixLabel = {};
@@ -118,7 +120,7 @@ export class Shape extends ViewerCommon {
118
120
  const labels = sameFixWidthLabel[key];
119
121
  ctx.beginPath();
120
122
  labels.forEach((item) => {
121
- if (currentDrawCount >= 2000) { // 一次最多绘制2000个标注,多余标注延迟绘制
123
+ if (currentDrawCount >= 4000) { // 一次最多绘制4000个点,多余标注延迟绘制
122
124
  if (remainFixLabel[key]) {
123
125
  remainFixLabel[key].push(item);
124
126
  } else {
@@ -127,7 +129,7 @@ export class Shape extends ViewerCommon {
127
129
  } else {
128
130
  this.drawLabel(item);
129
131
  }
130
- currentDrawCount++;
132
+ currentDrawCount = currentDrawCount + item.points.length;
131
133
  });
132
134
  const firstLabel = labels?.[0];
133
135
  if (firstLabel?.fillStyle) {
@@ -142,7 +144,7 @@ export class Shape extends ViewerCommon {
142
144
  const labels = sameNormalLabel[key];
143
145
  ctx.beginPath();
144
146
  labels.forEach((item) => {
145
- if (currentDrawCount >= 2000) { // 一次最多绘制2000个标注,多余标注延迟绘制
147
+ if (currentDrawCount >= 4000) { // 一次最多绘制4000个点,多余标注延迟绘制
146
148
  if (remainNormalLabel[key]) {
147
149
  remainNormalLabel[key].push(item);
148
150
  } else {
@@ -151,7 +153,7 @@ export class Shape extends ViewerCommon {
151
153
  } else {
152
154
  this.drawLabel(item);
153
155
  }
154
- currentDrawCount++;
156
+ currentDrawCount = currentDrawCount + item.points.length;
155
157
  });
156
158
  const firstLabel = labels?.[0];
157
159
  ctx.lineWidth = firstLabel.lineWidth;
@@ -162,9 +164,6 @@ export class Shape extends ViewerCommon {
162
164
  Object.keys(remainNormalLabel).length === 0) {
163
165
  console.log(`end deep draw label, draw count: ${count}`);
164
166
  this.delaytimer = undefined;
165
- imageLabel.forEach((item) => {
166
- this.drawLabel(item);
167
- });
168
167
  regionLabelList.forEach((item) => {
169
168
  this.combination.setContent(this.canvas, item);
170
169
  this.combination.draw({
@@ -177,8 +176,7 @@ export class Shape extends ViewerCommon {
177
176
  });
178
177
  } else {
179
178
  this.delaytimer = setTimeout(() => {
180
- this.deepDrawLabel(remainFixLabel, remainNormalLabel, regionLabelList,
181
- imageLabel, count + 1,
179
+ this.deepDrawLabel(remainFixLabel, remainNormalLabel, regionLabelList, count + 1,
182
180
  bounds);
183
181
  }, 100);
184
182
  }
@@ -137,17 +137,27 @@ export class Tailoring extends ViewerCommon {
137
137
  ctx.stroke();
138
138
  ctx.beginPath();
139
139
  ctx.fillStyle = '#000000';
140
- ctx.rect(rightTop.x + 4, rightTop.y, 100, 40);
140
+ let areaInterval = 4;
141
+ let areaDist = 100;
142
+ if (rightTop.x + areaDist + areaInterval > this.canvas.width) {
143
+ areaDist = -100;
144
+ areaInterval = -4;
145
+ }
146
+ ctx.rect(rightTop.x + areaInterval, rightTop.y, areaDist, 40);
141
147
  ctx.fill();
142
148
  ctx.save();
143
149
  ctx.beginPath();
144
- ctx.translate(rightTop.x + 54, rightTop.y - 5);
150
+ ctx.translate(rightTop.x + areaInterval + areaDist / 2, rightTop.y - 5);
145
151
  ctx.fillStyle = '#ffffff';
146
152
  ctx.drawConfirm();
147
153
  ctx.restore();
148
154
  ctx.save();
149
155
  ctx.beginPath();
150
- ctx.translate(rightTop.x + 4, rightTop.y - 5);
156
+ if (areaDist < 0) {
157
+ ctx.translate(rightTop.x + areaDist + areaInterval, rightTop.y - 5);
158
+ } else {
159
+ ctx.translate(rightTop.x + areaInterval, rightTop.y - 5);
160
+ }
151
161
  ctx.fillStyle = '#ffffff';
152
162
  ctx.drawCancel();
153
163
  ctx.restore();
@@ -163,8 +173,15 @@ export class Tailoring extends ViewerCommon {
163
173
  this.movePointIndex = this.tailoringPoints.findIndex(
164
174
  (point) => pointInOtherPoint(point, {x, y}, 30));
165
175
  const rightTopPoint = this.tailoringPoints[1];
166
- const cancelArea = new Rect(rightTopPoint.x + 14, rightTopPoint.y, 30, 40);
167
- const confirmArea = new Rect(rightTopPoint.x + 64, rightTopPoint.y, 30, 40);
176
+
177
+ let areaInterval = 4;
178
+ let areaDist = 100;
179
+ let cancelArea = new Rect(rightTopPoint.x + 14, rightTopPoint.y, 30, 40);
180
+ let confirmArea = new Rect(rightTopPoint.x + 64, rightTopPoint.y, 30, 40);
181
+ if (rightTopPoint.x + areaDist + areaInterval > this.canvas.width) {
182
+ cancelArea = new Rect(rightTopPoint.x - 94, rightTopPoint.y, 30, 40);
183
+ confirmArea = new Rect(rightTopPoint.x - 44, rightTopPoint.y, 30, 40);
184
+ }
168
185
  const point = new Point(x, y);
169
186
  if (cancelArea.containsPoint(point)) {
170
187
  this.stopTailoring();
@@ -257,6 +274,20 @@ export class Tailoring extends ViewerCommon {
257
274
  };
258
275
  break;
259
276
  }
277
+ this.tailoringPoints.forEach((i) => {
278
+ if (i.x < 0) {
279
+ i.x = 0;
280
+ }
281
+ if (i.y < 0) {
282
+ i.y = 0;
283
+ }
284
+ if (i.x > this.canvas.width) {
285
+ i.x = this.canvas.width;
286
+ }
287
+ if (i.y > this.canvas.height) {
288
+ i.y = this.canvas.height;
289
+ }
290
+ });
260
291
  this.clearCanvas();
261
292
  this.drawRect();
262
293
  this.drawTailoring();
package/src/tool/Image.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import {Brush} from './Brush';
2
- import {pointsToRegion} from '../util/calculate';
2
+ import {getDistance, getRectPoints} from '../util/calculate';
3
3
  import {EventEmitter} from '../util/event-emitter';
4
4
 
5
5
  const et = new EventEmitter();
@@ -22,22 +22,41 @@ class Image extends Brush {
22
22
  * @param {number} points[].x - 绘制的点x坐标
23
23
  * @param {number} points[].y - 绘制的点y坐标
24
24
  * @param {number=} scale
25
+ * @param {number=} angle
25
26
  */
26
- draw(points, scale = 1) {
27
- const region = pointsToRegion(points);
27
+ draw(points, scale = 1, angle = 0) {
28
+ if (points.length === 2) {
29
+ points = getRectPoints(points);
30
+ }
31
+ const width = getDistance(points[1], points[0]);
32
+ const height = getDistance(points[2], points[0]);
33
+ const region = {
34
+ ...points[0],
35
+ width,
36
+ height,
37
+ };
28
38
  if (this.options.imgLoadSuccess) {
29
- this.drawImage(this.options.img, region);
39
+ this.drawImage(this.options.img, region, angle);
30
40
  } else if (this.options.img) {
31
41
  const img = this.options.img;
32
42
  et.$once('load', () => {
33
- this.drawImage(img, region);
43
+ this.drawImage(img, region, angle);
34
44
  }, true, img);
35
45
  }
36
46
  }
37
47
 
38
- drawImage(img, region) {
48
+ drawImage(img, region, angle = 0) {
39
49
  const ctx = this.canvas.getContext('2d');
40
- ctx.drawImage(img, region.x, region.y, region.width, region.height);
50
+ ctx.beginPath();
51
+ ctx.save();
52
+ ctx.translate(region.x, region.y);
53
+ if (angle < 0) {
54
+ angle += 360;
55
+ }
56
+ const _rotation = angle % 360;
57
+ ctx.rotate(_rotation * Math.PI / 180);
58
+ ctx.drawImage(img, 0, 0, region.width, region.height);
59
+ ctx.restore();
41
60
  }
42
61
  }
43
62