vislite 0.7.0 → 0.7.1-alpha.0

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.
Files changed (90) hide show
  1. package/CHANGELOG +177 -171
  2. package/README.md +135 -135
  3. package/lib/Buffer/index.umd.js +2 -2
  4. package/lib/Buffer/index.umd.min.js +2 -2
  5. package/lib/Canvas/index.umd.js +2 -2
  6. package/lib/Canvas/index.umd.min.js +2 -2
  7. package/lib/Cardinal/index.umd.js +2 -2
  8. package/lib/Cardinal/index.umd.min.js +2 -2
  9. package/lib/Eoap/index.umd.js +2 -2
  10. package/lib/Eoap/index.umd.min.js +2 -2
  11. package/lib/Geometry/index.umd.js +2 -2
  12. package/lib/Geometry/index.umd.min.js +2 -2
  13. package/lib/Hermite/index.umd.js +2 -2
  14. package/lib/Hermite/index.umd.min.js +2 -2
  15. package/lib/Matrix4/index.umd.js +2 -2
  16. package/lib/Matrix4/index.umd.min.js +2 -2
  17. package/lib/Mercator/index.umd.js +2 -2
  18. package/lib/Mercator/index.umd.min.js +2 -2
  19. package/lib/OralCanvas/index.es.js +2 -2
  20. package/lib/OralCanvas/index.es.min.js +2 -2
  21. package/lib/OralWebGL/index.es.js +2 -3
  22. package/lib/OralWebGL/index.es.min.js +3 -3
  23. package/lib/SVG/index.umd.js +2 -2
  24. package/lib/SVG/index.umd.min.js +2 -2
  25. package/lib/Shader/index.umd.js +2 -3
  26. package/lib/Shader/index.umd.min.js +3 -3
  27. package/lib/Texture/index.umd.js +2 -2
  28. package/lib/Texture/index.umd.min.js +2 -2
  29. package/lib/TreeLayout/index.umd.js +2 -2
  30. package/lib/TreeLayout/index.umd.min.js +2 -2
  31. package/lib/WebGL/index.umd.js +2 -3
  32. package/lib/WebGL/index.umd.min.js +3 -3
  33. package/lib/animation/index.umd.js +2 -2
  34. package/lib/animation/index.umd.min.js +2 -2
  35. package/lib/formatColor/index.umd.js +2 -2
  36. package/lib/formatColor/index.umd.min.js +2 -2
  37. package/lib/getLoopColors/index.umd.js +2 -2
  38. package/lib/getLoopColors/index.umd.min.js +2 -2
  39. package/lib/getWebGLContext/index.umd.js +2 -2
  40. package/lib/getWebGLContext/index.umd.min.js +2 -2
  41. package/lib/index.umd.js +2 -3
  42. package/lib/index.umd.min.js +3 -3
  43. package/lib/move/index.umd.js +2 -2
  44. package/lib/move/index.umd.min.js +2 -2
  45. package/lib/resizeObserver/index.umd.js +2 -2
  46. package/lib/resizeObserver/index.umd.min.js +2 -2
  47. package/lib/rotate/index.umd.js +2 -2
  48. package/lib/rotate/index.umd.min.js +2 -2
  49. package/lib/ruler/index.umd.js +2 -2
  50. package/lib/ruler/index.umd.min.js +2 -2
  51. package/lib/scale/index.umd.js +2 -2
  52. package/lib/scale/index.umd.min.js +2 -2
  53. package/lib/throttle/index.umd.js +2 -2
  54. package/lib/throttle/index.umd.min.js +2 -2
  55. package/lib/viewHandler/index.umd.js +2 -2
  56. package/lib/viewHandler/index.umd.min.js +2 -2
  57. package/package.json +70 -70
  58. package/src/Canvas.ts +70 -70
  59. package/src/Geometry.ts +126 -126
  60. package/src/Matrix4/rotate.ts +15 -15
  61. package/src/Matrix4/transform.ts +64 -64
  62. package/src/WebGL.ts +66 -66
  63. package/src/common/assemble.ts +22 -22
  64. package/src/common/canvas/index.ts +177 -177
  65. package/src/common/canvas/painter.ts +419 -419
  66. package/src/common/geometry/prism-vertical.ts +40 -40
  67. package/src/common/geometry/tool/rotateLine.ts +35 -35
  68. package/src/common/setStyle.ts +5 -5
  69. package/src/common/svg/config.ts +190 -190
  70. package/src/common/svg/index.ts +356 -356
  71. package/src/common/svg/tool.ts +44 -44
  72. package/src/common/tree/toInnerTree.ts +59 -59
  73. package/src/common/tree/toPlainTree.ts +132 -132
  74. package/src/common/webgl/buffer.ts +79 -79
  75. package/src/common/webgl/doDraw.ts +108 -108
  76. package/src/common/webgl/getWebGLContext.ts +28 -28
  77. package/src/common/webgl/index.ts +226 -226
  78. package/src/common/webgl/shader.ts +75 -75
  79. package/src/common/webgl/texture.ts +97 -97
  80. package/src/layout/TreeLayout.ts +188 -188
  81. package/src/resizeObserver.ts +37 -37
  82. package/src/ruler.ts +209 -209
  83. package/src/viewHandler.ts +160 -160
  84. package/types/Canvas.d.ts +308 -308
  85. package/types/Geometry.d.ts +65 -65
  86. package/types/Object3D.d.ts +1 -1
  87. package/types/SVGConfig.d.ts +79 -79
  88. package/types/Shader.d.ts +2 -0
  89. package/types/TreeConfig.d.ts +36 -36
  90. package/uni-app/ui-canvas.vue +237 -237
@@ -1,420 +1,420 @@
1
- import type { arcCapType } from '../../../types/painterConfig'
2
- import type CanvasOptsType from '../../../types/CanvasOpts'
3
-
4
- import { initText, initArc, initCircle, initRect } from './config'
5
- import texts from './texts'
6
-
7
- class Painter {
8
-
9
- painter: CanvasRenderingContext2D
10
- __region: Painter | null | undefined = null
11
-
12
- __onlyRegion: boolean = false
13
- __isPainter: boolean
14
-
15
- // 用于记录配置
16
- // 因为部分配置的设置比较特殊,只先记录意图
17
- __specialConfig = {
18
-
19
- // 文字大小
20
- "fontSize": 16,
21
-
22
- // 字体
23
- "fontFamily": "sans-serif",
24
-
25
- // 字重
26
- "fontWeight": 400,
27
-
28
- // 字类型
29
- "fontStyle": "normal",
30
-
31
- // 圆弧开始端闭合方式("butt"直线闭合、"round"圆帽闭合)
32
- "arcStartCap": <arcCapType>'butt',
33
-
34
- // 圆弧结束端闭合方式,和上一个类似
35
- "arcEndCap": <arcCapType>'butt'
36
- } as {
37
- [key: string]: any
38
- }
39
-
40
- private __initConfig = {
41
-
42
- // 填充色或图案
43
- "fillStyle": 'black',
44
-
45
- // 轮廓色或图案
46
- "strokeStyle": 'black',
47
-
48
- // 线条宽度(单位px,下同)
49
- "lineWidth": 1,
50
-
51
- // 文字水平对齐方式("left"左对齐、"center"居中和"right"右对齐)
52
- "textAlign": 'left',
53
-
54
- // 文字垂直对齐方式("middle"垂直居中、"top"上对齐和"bottom"下对齐)
55
- "textBaseline": 'middle',
56
-
57
- // 设置线条虚线,应该是一个数组[number,...]
58
- "lineDash": [],
59
-
60
- // 阴影的模糊系数,默认0,也就是无阴影
61
- "shadowBlur": 0,
62
-
63
- // 阴影的颜色
64
- "shadowColor": "black"
65
-
66
- }
67
-
68
- constructor(canvas: HTMLCanvasElement, opts: CanvasOptsType = {}, region?: Painter, isPainter = false) {
69
- this.painter = canvas.getContext("2d", opts) as CanvasRenderingContext2D
70
- this.__region = region
71
- this.__isPainter = isPainter
72
-
73
- // 默认配置canvas2D对象已经存在的属性
74
- this.painter.textBaseline = 'middle'
75
- this.painter.textAlign = 'left'
76
- }
77
-
78
- useConfig(key: string, value: any) {
79
- if (this.__region) {
80
- if (['fillStyle', 'strokeStyle', 'shadowBlur', 'shadowColor'].indexOf(key) < 0) {
81
- this.__region.useConfig(key, value)
82
- }
83
- }
84
-
85
- if (this.__isPainter && this.__onlyRegion) return this
86
-
87
- /**
88
- * -----------------------------
89
- * 特殊的设置开始
90
- * -----------------------------
91
- */
92
-
93
- if (key == 'lineDash') {
94
- if (this.painter.setLineDash) this.painter.setLineDash(value)
95
- }
96
-
97
- /**
98
- * -----------------------------
99
- * 常规的配置开始
100
- * -----------------------------
101
- */
102
-
103
- // 如果已经存在默认配置中,说明只需要缓存起来即可
104
- else if (key in this.__specialConfig) {
105
-
106
- // 文字非整数可能存在问题,修复一下
107
- if (key == 'fontSize') {
108
- value = Math.round(value)
109
- }
110
-
111
- this.__specialConfig[key] = value
112
- }
113
-
114
- // 其它情况直接生效即可
115
- else if (key in this.__initConfig) {
116
- this.painter[key] = value
117
- }
118
-
119
- // 如果属性未被定义
120
- else {
121
- throw new Error('Illegal configuration item of painter : ' + key + " !")
122
- }
123
-
124
- return this
125
- }
126
-
127
- // 文字
128
- fillText(text: string, x: number, y: number, deg: number = 0) {
129
- if (this.__region) this.__region.fillText(text, x, y, deg)
130
-
131
- if (this.__isPainter && this.__onlyRegion) return this
132
-
133
- this.painter.save()
134
- initText(this.painter, this.__specialConfig, x, y, deg).fillText(text, 0, 0)
135
- this.painter.restore()
136
- return this
137
- }
138
- strokeText(text: string, x: number, y: number, deg: number = 0) {
139
- if (this.__region) this.__region.strokeText(text, x, y, deg)
140
-
141
- if (this.__isPainter && this.__onlyRegion) return this
142
-
143
- this.painter.save()
144
- initText(this.painter, this.__specialConfig, x, y, deg).strokeText(text, 0, 0)
145
- this.painter.restore()
146
- return this
147
- }
148
- fullText(text: string, x: number, y: number, deg: number = 0) {
149
- if (this.__region) this.__region.fullText(text, x, y, deg)
150
-
151
- if (this.__isPainter && this.__onlyRegion) return this
152
-
153
- this.painter.save()
154
- initText(this.painter, this.__specialConfig, x, y, deg)
155
- this.painter.fillText(text, 0, 0)
156
- this.painter.strokeText(text, 0, 0)
157
- this.painter.restore()
158
- return this
159
- }
160
-
161
- // 多行文字
162
- fillTexts(contents: string, x: number, y: number, width: number, lineHeight: number = 1.2, deg: number = 0) {
163
- let h = 0
164
- if (this.__region) h = this.__region.fillTexts(contents, x, y, width, lineHeight)
165
-
166
- if (this.__isPainter && this.__onlyRegion) return h
167
-
168
- this.painter.save()
169
- initText(this.painter, this.__specialConfig, x, y, deg)
170
-
171
- const height = texts(this.painter, contents, width, this.__specialConfig.fontSize * lineHeight, (content, top) => {
172
- this.painter.fillText(content, 0, top)
173
- })
174
-
175
- this.painter.restore()
176
- return height
177
- }
178
- strokeTexts(contents: string, x: number, y: number, width: number, lineHeight: number = 1.2, deg: number = 0) {
179
- let h = 0
180
- if (this.__region) h = this.__region.fillTexts(contents, x, y, width, lineHeight)
181
-
182
- if (this.__isPainter && this.__onlyRegion) return h
183
-
184
- this.painter.save()
185
- initText(this.painter, this.__specialConfig, x, y, deg)
186
-
187
- const height = texts(this.painter, contents, width, this.__specialConfig.fontSize * lineHeight, (content, top) => {
188
- this.painter.strokeText(content, 0, top)
189
- })
190
-
191
- this.painter.restore()
192
- return height
193
- }
194
- fullTexts(contents: string, x: number, y: number, width: number, lineHeight: number = 1.2, deg: number = 0) {
195
- let h = 0
196
- if (this.__region) h = this.__region.fillTexts(contents, x, y, width, lineHeight)
197
-
198
- if (this.__isPainter && this.__onlyRegion) return h
199
-
200
- this.painter.save()
201
- initText(this.painter, this.__specialConfig, x, y, deg)
202
-
203
- const height = texts(this.painter, contents, width, this.__specialConfig.fontSize * lineHeight, (content, top) => {
204
- this.painter.fillText(content, 0, top)
205
- this.painter.strokeText(content, 0, top)
206
- })
207
-
208
- this.painter.restore()
209
- return height
210
- }
211
-
212
- // 路径
213
- beginPath() {
214
- if (this.__region) this.__region.beginPath()
215
-
216
- if (this.__isPainter && this.__onlyRegion) return this
217
-
218
- this.painter.beginPath()
219
- return this
220
- }
221
- closePath() {
222
- if (this.__region) this.__region.closePath()
223
-
224
- if (this.__isPainter && this.__onlyRegion) return this
225
-
226
- this.painter.closePath()
227
- return this
228
- }
229
- moveTo(x: number, y: number) {
230
- if (this.__region) this.__region.moveTo(x, y)
231
-
232
- if (this.__isPainter && this.__onlyRegion) return this
233
-
234
- // 解决1px模糊问题,别的地方类似原因
235
- this.painter.moveTo(Math.round(x) + 0.5, Math.round(y) + 0.5)
236
- return this
237
- }
238
- lineTo(x: number, y: number) {
239
- if (this.__region) this.__region.lineTo(x, y)
240
-
241
- if (this.__isPainter && this.__onlyRegion) return this
242
-
243
- this.painter.lineTo(Math.round(x) + 0.5, Math.round(y) + 0.5)
244
- return this
245
- }
246
- arc(x: number, y: number, r: number, beginDeg: number, deg: number) {
247
- if (this.__region) this.__region.arc(x, y, r, beginDeg, deg)
248
-
249
- if (this.__isPainter && this.__onlyRegion) return this
250
-
251
- this.painter.arc(x, y, r, beginDeg, beginDeg + deg, deg < 0)
252
- return this
253
- }
254
- fill() {
255
- if (this.__region) this.__region.fill()
256
-
257
- if (this.__isPainter && this.__onlyRegion) return this
258
-
259
- this.painter.fill()
260
- return this
261
- }
262
- stroke() {
263
- if (this.__region) this.__region.stroke()
264
-
265
- if (this.__isPainter && this.__onlyRegion) return this
266
-
267
- this.painter.stroke()
268
- return this
269
- }
270
- full() {
271
- if (this.__region) this.__region.full()
272
-
273
- if (this.__isPainter && this.__onlyRegion) return this
274
-
275
- this.painter.fill()
276
- this.painter.stroke()
277
- return this
278
- }
279
-
280
- save() {
281
- if (this.__region) this.__region.save()
282
-
283
- if (this.__isPainter && this.__onlyRegion) return this
284
-
285
- this.painter.save()
286
- return this
287
- }
288
- restore() {
289
- if (this.__region) this.__region.restore()
290
-
291
- if (this.__isPainter && this.__onlyRegion) return this
292
-
293
- this.painter.restore()
294
- return this
295
- }
296
- clip() {
297
- if (this.__region) this.__region.clip()
298
-
299
- if (this.__isPainter && this.__onlyRegion) return this
300
-
301
- this.painter.clip()
302
- return this
303
- }
304
-
305
- // 路径 - 贝塞尔曲线
306
- quadraticCurveTo(cpx: number, cpy: number, x: number, y: number) {
307
- if (this.__region) this.__region.quadraticCurveTo(cpx, cpy, x, y)
308
-
309
- if (this.__isPainter && this.__onlyRegion) return this
310
-
311
- this.painter.quadraticCurveTo(cpx, cpy, x, y)
312
- return this
313
- }
314
- bezierCurveTo(cp1x: number, cp1y: number, cp2x: number, cp2y: number, x: number, y: number) {
315
- if (this.__region) this.__region.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y)
316
-
317
- if (this.__isPainter && this.__onlyRegion) return this
318
-
319
- this.painter.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y)
320
- return this
321
- }
322
-
323
- // 擦除画面
324
- clearRect(x: number, y: number, w: number, h: number) {
325
- if (this.__region) this.__region.clearRect(x, y, w, h)
326
-
327
- if (this.__isPainter && this.__onlyRegion) return this
328
-
329
- this.painter.clearRect(x, y, w, h)
330
- return this
331
- }
332
-
333
- // 弧
334
- fillArc(cx: number, cy: number, r1: number, r2: number, beginDeg: number, deg: number) {
335
- if (this.__region) this.__region.fillArc(cx, cy, r1, r2, beginDeg, deg)
336
-
337
- if (this.__isPainter && this.__onlyRegion) return this
338
-
339
- initArc(this.painter, this.__specialConfig, cx, cy, r1, r2, beginDeg, deg).fill()
340
- return this
341
- }
342
- strokeArc(cx: number, cy: number, r1: number, r2: number, beginDeg: number, deg: number) {
343
- if (this.__region) this.__region.strokeArc(cx, cy, r1, r2, beginDeg, deg)
344
-
345
- if (this.__isPainter && this.__onlyRegion) return this
346
-
347
- initArc(this.painter, this.__specialConfig, cx, cy, r1, r2, beginDeg, deg).stroke()
348
- return this
349
- }
350
- fullArc(cx: number, cy: number, r1: number, r2: number, beginDeg: number, deg: number) {
351
- if (this.__region) this.__region.fullArc(cx, cy, r1, r2, beginDeg, deg)
352
-
353
- if (this.__isPainter && this.__onlyRegion) return this
354
-
355
- initArc(this.painter, this.__specialConfig, cx, cy, r1, r2, beginDeg, deg)
356
- this.painter.fill()
357
- this.painter.stroke()
358
- return this
359
- }
360
-
361
- // 圆形
362
- fillCircle(cx: number, cy: number, r: number) {
363
- if (this.__region) this.__region.fillCircle(cx, cy, r)
364
-
365
- if (this.__isPainter && this.__onlyRegion) return this
366
-
367
- initCircle(this.painter, cx, cy, r).fill()
368
- return this
369
- }
370
- strokeCircle(cx: number, cy: number, r: number) {
371
- if (this.__region) this.__region.strokeCircle(cx, cy, r)
372
-
373
- if (this.__isPainter && this.__onlyRegion) return this
374
-
375
- initCircle(this.painter, cx, cy, r).stroke()
376
- return this
377
- }
378
- fullCircle(cx: number, cy: number, r: number) {
379
- if (this.__region) this.__region.fullCircle(cx, cy, r)
380
-
381
- if (this.__isPainter && this.__onlyRegion) return this
382
-
383
- initCircle(this.painter, cx, cy, r)
384
- this.painter.fill()
385
- this.painter.stroke()
386
- return this
387
- }
388
-
389
- // 矩形
390
- fillRect(x: number, y: number, width: number, height: number) {
391
- if (this.__region) this.__region.fillRect(x, y, width, height)
392
-
393
- if (this.__isPainter && this.__onlyRegion) return this
394
-
395
- initRect(this.painter, x, y, width, height).fill()
396
- return this
397
- }
398
- strokeRect(x: number, y: number, width: number, height: number) {
399
- if (this.__region) this.__region.strokeRect(x, y, width, height)
400
-
401
- if (this.__isPainter && this.__onlyRegion) return this
402
-
403
- initRect(this.painter, x, y, width, height).stroke()
404
- return this
405
- }
406
- fullRect(x: number, y: number, width: number, height: number) {
407
- if (this.__region) this.__region.fullRect(x, y, width, height)
408
-
409
- if (this.__isPainter && this.__onlyRegion) return this
410
-
411
- initRect(this.painter, x, y, width, height)
412
- this.painter.fill()
413
- this.painter.stroke()
414
- return this
415
- }
416
-
417
- draw() { }
418
- }
419
-
1
+ import type { arcCapType } from '../../../types/painterConfig'
2
+ import type CanvasOptsType from '../../../types/CanvasOpts'
3
+
4
+ import { initText, initArc, initCircle, initRect } from './config'
5
+ import texts from './texts'
6
+
7
+ class Painter {
8
+
9
+ painter: CanvasRenderingContext2D
10
+ __region: Painter | null | undefined = null
11
+
12
+ __onlyRegion: boolean = false
13
+ __isPainter: boolean
14
+
15
+ // 用于记录配置
16
+ // 因为部分配置的设置比较特殊,只先记录意图
17
+ __specialConfig = {
18
+
19
+ // 文字大小
20
+ "fontSize": 16,
21
+
22
+ // 字体
23
+ "fontFamily": "sans-serif",
24
+
25
+ // 字重
26
+ "fontWeight": 400,
27
+
28
+ // 字类型
29
+ "fontStyle": "normal",
30
+
31
+ // 圆弧开始端闭合方式("butt"直线闭合、"round"圆帽闭合)
32
+ "arcStartCap": <arcCapType>'butt',
33
+
34
+ // 圆弧结束端闭合方式,和上一个类似
35
+ "arcEndCap": <arcCapType>'butt'
36
+ } as {
37
+ [key: string]: any
38
+ }
39
+
40
+ private __initConfig = {
41
+
42
+ // 填充色或图案
43
+ "fillStyle": 'black',
44
+
45
+ // 轮廓色或图案
46
+ "strokeStyle": 'black',
47
+
48
+ // 线条宽度(单位px,下同)
49
+ "lineWidth": 1,
50
+
51
+ // 文字水平对齐方式("left"左对齐、"center"居中和"right"右对齐)
52
+ "textAlign": 'left',
53
+
54
+ // 文字垂直对齐方式("middle"垂直居中、"top"上对齐和"bottom"下对齐)
55
+ "textBaseline": 'middle',
56
+
57
+ // 设置线条虚线,应该是一个数组[number,...]
58
+ "lineDash": [],
59
+
60
+ // 阴影的模糊系数,默认0,也就是无阴影
61
+ "shadowBlur": 0,
62
+
63
+ // 阴影的颜色
64
+ "shadowColor": "black"
65
+
66
+ }
67
+
68
+ constructor(canvas: HTMLCanvasElement, opts: CanvasOptsType = {}, region?: Painter, isPainter = false) {
69
+ this.painter = canvas.getContext("2d", opts) as CanvasRenderingContext2D
70
+ this.__region = region
71
+ this.__isPainter = isPainter
72
+
73
+ // 默认配置canvas2D对象已经存在的属性
74
+ this.painter.textBaseline = 'middle'
75
+ this.painter.textAlign = 'left'
76
+ }
77
+
78
+ useConfig(key: string, value: any) {
79
+ if (this.__region) {
80
+ if (['fillStyle', 'strokeStyle', 'shadowBlur', 'shadowColor'].indexOf(key) < 0) {
81
+ this.__region.useConfig(key, value)
82
+ }
83
+ }
84
+
85
+ if (this.__isPainter && this.__onlyRegion) return this
86
+
87
+ /**
88
+ * -----------------------------
89
+ * 特殊的设置开始
90
+ * -----------------------------
91
+ */
92
+
93
+ if (key == 'lineDash') {
94
+ if (this.painter.setLineDash) this.painter.setLineDash(value)
95
+ }
96
+
97
+ /**
98
+ * -----------------------------
99
+ * 常规的配置开始
100
+ * -----------------------------
101
+ */
102
+
103
+ // 如果已经存在默认配置中,说明只需要缓存起来即可
104
+ else if (key in this.__specialConfig) {
105
+
106
+ // 文字非整数可能存在问题,修复一下
107
+ if (key == 'fontSize') {
108
+ value = Math.round(value)
109
+ }
110
+
111
+ this.__specialConfig[key] = value
112
+ }
113
+
114
+ // 其它情况直接生效即可
115
+ else if (key in this.__initConfig) {
116
+ this.painter[key] = value
117
+ }
118
+
119
+ // 如果属性未被定义
120
+ else {
121
+ throw new Error('Illegal configuration item of painter : ' + key + " !")
122
+ }
123
+
124
+ return this
125
+ }
126
+
127
+ // 文字
128
+ fillText(text: string, x: number, y: number, deg: number = 0) {
129
+ if (this.__region) this.__region.fillText(text, x, y, deg)
130
+
131
+ if (this.__isPainter && this.__onlyRegion) return this
132
+
133
+ this.painter.save()
134
+ initText(this.painter, this.__specialConfig, x, y, deg).fillText(text, 0, 0)
135
+ this.painter.restore()
136
+ return this
137
+ }
138
+ strokeText(text: string, x: number, y: number, deg: number = 0) {
139
+ if (this.__region) this.__region.strokeText(text, x, y, deg)
140
+
141
+ if (this.__isPainter && this.__onlyRegion) return this
142
+
143
+ this.painter.save()
144
+ initText(this.painter, this.__specialConfig, x, y, deg).strokeText(text, 0, 0)
145
+ this.painter.restore()
146
+ return this
147
+ }
148
+ fullText(text: string, x: number, y: number, deg: number = 0) {
149
+ if (this.__region) this.__region.fullText(text, x, y, deg)
150
+
151
+ if (this.__isPainter && this.__onlyRegion) return this
152
+
153
+ this.painter.save()
154
+ initText(this.painter, this.__specialConfig, x, y, deg)
155
+ this.painter.fillText(text, 0, 0)
156
+ this.painter.strokeText(text, 0, 0)
157
+ this.painter.restore()
158
+ return this
159
+ }
160
+
161
+ // 多行文字
162
+ fillTexts(contents: string, x: number, y: number, width: number, lineHeight: number = 1.2, deg: number = 0) {
163
+ let h = 0
164
+ if (this.__region) h = this.__region.fillTexts(contents, x, y, width, lineHeight)
165
+
166
+ if (this.__isPainter && this.__onlyRegion) return h
167
+
168
+ this.painter.save()
169
+ initText(this.painter, this.__specialConfig, x, y, deg)
170
+
171
+ const height = texts(this.painter, contents, width, this.__specialConfig.fontSize * lineHeight, (content, top) => {
172
+ this.painter.fillText(content, 0, top)
173
+ })
174
+
175
+ this.painter.restore()
176
+ return height
177
+ }
178
+ strokeTexts(contents: string, x: number, y: number, width: number, lineHeight: number = 1.2, deg: number = 0) {
179
+ let h = 0
180
+ if (this.__region) h = this.__region.fillTexts(contents, x, y, width, lineHeight)
181
+
182
+ if (this.__isPainter && this.__onlyRegion) return h
183
+
184
+ this.painter.save()
185
+ initText(this.painter, this.__specialConfig, x, y, deg)
186
+
187
+ const height = texts(this.painter, contents, width, this.__specialConfig.fontSize * lineHeight, (content, top) => {
188
+ this.painter.strokeText(content, 0, top)
189
+ })
190
+
191
+ this.painter.restore()
192
+ return height
193
+ }
194
+ fullTexts(contents: string, x: number, y: number, width: number, lineHeight: number = 1.2, deg: number = 0) {
195
+ let h = 0
196
+ if (this.__region) h = this.__region.fillTexts(contents, x, y, width, lineHeight)
197
+
198
+ if (this.__isPainter && this.__onlyRegion) return h
199
+
200
+ this.painter.save()
201
+ initText(this.painter, this.__specialConfig, x, y, deg)
202
+
203
+ const height = texts(this.painter, contents, width, this.__specialConfig.fontSize * lineHeight, (content, top) => {
204
+ this.painter.fillText(content, 0, top)
205
+ this.painter.strokeText(content, 0, top)
206
+ })
207
+
208
+ this.painter.restore()
209
+ return height
210
+ }
211
+
212
+ // 路径
213
+ beginPath() {
214
+ if (this.__region) this.__region.beginPath()
215
+
216
+ if (this.__isPainter && this.__onlyRegion) return this
217
+
218
+ this.painter.beginPath()
219
+ return this
220
+ }
221
+ closePath() {
222
+ if (this.__region) this.__region.closePath()
223
+
224
+ if (this.__isPainter && this.__onlyRegion) return this
225
+
226
+ this.painter.closePath()
227
+ return this
228
+ }
229
+ moveTo(x: number, y: number) {
230
+ if (this.__region) this.__region.moveTo(x, y)
231
+
232
+ if (this.__isPainter && this.__onlyRegion) return this
233
+
234
+ // 解决1px模糊问题,别的地方类似原因
235
+ this.painter.moveTo(Math.round(x) + 0.5, Math.round(y) + 0.5)
236
+ return this
237
+ }
238
+ lineTo(x: number, y: number) {
239
+ if (this.__region) this.__region.lineTo(x, y)
240
+
241
+ if (this.__isPainter && this.__onlyRegion) return this
242
+
243
+ this.painter.lineTo(Math.round(x) + 0.5, Math.round(y) + 0.5)
244
+ return this
245
+ }
246
+ arc(x: number, y: number, r: number, beginDeg: number, deg: number) {
247
+ if (this.__region) this.__region.arc(x, y, r, beginDeg, deg)
248
+
249
+ if (this.__isPainter && this.__onlyRegion) return this
250
+
251
+ this.painter.arc(x, y, r, beginDeg, beginDeg + deg, deg < 0)
252
+ return this
253
+ }
254
+ fill() {
255
+ if (this.__region) this.__region.fill()
256
+
257
+ if (this.__isPainter && this.__onlyRegion) return this
258
+
259
+ this.painter.fill()
260
+ return this
261
+ }
262
+ stroke() {
263
+ if (this.__region) this.__region.stroke()
264
+
265
+ if (this.__isPainter && this.__onlyRegion) return this
266
+
267
+ this.painter.stroke()
268
+ return this
269
+ }
270
+ full() {
271
+ if (this.__region) this.__region.full()
272
+
273
+ if (this.__isPainter && this.__onlyRegion) return this
274
+
275
+ this.painter.fill()
276
+ this.painter.stroke()
277
+ return this
278
+ }
279
+
280
+ save() {
281
+ if (this.__region) this.__region.save()
282
+
283
+ if (this.__isPainter && this.__onlyRegion) return this
284
+
285
+ this.painter.save()
286
+ return this
287
+ }
288
+ restore() {
289
+ if (this.__region) this.__region.restore()
290
+
291
+ if (this.__isPainter && this.__onlyRegion) return this
292
+
293
+ this.painter.restore()
294
+ return this
295
+ }
296
+ clip() {
297
+ if (this.__region) this.__region.clip()
298
+
299
+ if (this.__isPainter && this.__onlyRegion) return this
300
+
301
+ this.painter.clip()
302
+ return this
303
+ }
304
+
305
+ // 路径 - 贝塞尔曲线
306
+ quadraticCurveTo(cpx: number, cpy: number, x: number, y: number) {
307
+ if (this.__region) this.__region.quadraticCurveTo(cpx, cpy, x, y)
308
+
309
+ if (this.__isPainter && this.__onlyRegion) return this
310
+
311
+ this.painter.quadraticCurveTo(cpx, cpy, x, y)
312
+ return this
313
+ }
314
+ bezierCurveTo(cp1x: number, cp1y: number, cp2x: number, cp2y: number, x: number, y: number) {
315
+ if (this.__region) this.__region.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y)
316
+
317
+ if (this.__isPainter && this.__onlyRegion) return this
318
+
319
+ this.painter.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y)
320
+ return this
321
+ }
322
+
323
+ // 擦除画面
324
+ clearRect(x: number, y: number, w: number, h: number) {
325
+ if (this.__region) this.__region.clearRect(x, y, w, h)
326
+
327
+ if (this.__isPainter && this.__onlyRegion) return this
328
+
329
+ this.painter.clearRect(x, y, w, h)
330
+ return this
331
+ }
332
+
333
+ // 弧
334
+ fillArc(cx: number, cy: number, r1: number, r2: number, beginDeg: number, deg: number) {
335
+ if (this.__region) this.__region.fillArc(cx, cy, r1, r2, beginDeg, deg)
336
+
337
+ if (this.__isPainter && this.__onlyRegion) return this
338
+
339
+ initArc(this.painter, this.__specialConfig, cx, cy, r1, r2, beginDeg, deg).fill()
340
+ return this
341
+ }
342
+ strokeArc(cx: number, cy: number, r1: number, r2: number, beginDeg: number, deg: number) {
343
+ if (this.__region) this.__region.strokeArc(cx, cy, r1, r2, beginDeg, deg)
344
+
345
+ if (this.__isPainter && this.__onlyRegion) return this
346
+
347
+ initArc(this.painter, this.__specialConfig, cx, cy, r1, r2, beginDeg, deg).stroke()
348
+ return this
349
+ }
350
+ fullArc(cx: number, cy: number, r1: number, r2: number, beginDeg: number, deg: number) {
351
+ if (this.__region) this.__region.fullArc(cx, cy, r1, r2, beginDeg, deg)
352
+
353
+ if (this.__isPainter && this.__onlyRegion) return this
354
+
355
+ initArc(this.painter, this.__specialConfig, cx, cy, r1, r2, beginDeg, deg)
356
+ this.painter.fill()
357
+ this.painter.stroke()
358
+ return this
359
+ }
360
+
361
+ // 圆形
362
+ fillCircle(cx: number, cy: number, r: number) {
363
+ if (this.__region) this.__region.fillCircle(cx, cy, r)
364
+
365
+ if (this.__isPainter && this.__onlyRegion) return this
366
+
367
+ initCircle(this.painter, cx, cy, r).fill()
368
+ return this
369
+ }
370
+ strokeCircle(cx: number, cy: number, r: number) {
371
+ if (this.__region) this.__region.strokeCircle(cx, cy, r)
372
+
373
+ if (this.__isPainter && this.__onlyRegion) return this
374
+
375
+ initCircle(this.painter, cx, cy, r).stroke()
376
+ return this
377
+ }
378
+ fullCircle(cx: number, cy: number, r: number) {
379
+ if (this.__region) this.__region.fullCircle(cx, cy, r)
380
+
381
+ if (this.__isPainter && this.__onlyRegion) return this
382
+
383
+ initCircle(this.painter, cx, cy, r)
384
+ this.painter.fill()
385
+ this.painter.stroke()
386
+ return this
387
+ }
388
+
389
+ // 矩形
390
+ fillRect(x: number, y: number, width: number, height: number) {
391
+ if (this.__region) this.__region.fillRect(x, y, width, height)
392
+
393
+ if (this.__isPainter && this.__onlyRegion) return this
394
+
395
+ initRect(this.painter, x, y, width, height).fill()
396
+ return this
397
+ }
398
+ strokeRect(x: number, y: number, width: number, height: number) {
399
+ if (this.__region) this.__region.strokeRect(x, y, width, height)
400
+
401
+ if (this.__isPainter && this.__onlyRegion) return this
402
+
403
+ initRect(this.painter, x, y, width, height).stroke()
404
+ return this
405
+ }
406
+ fullRect(x: number, y: number, width: number, height: number) {
407
+ if (this.__region) this.__region.fullRect(x, y, width, height)
408
+
409
+ if (this.__isPainter && this.__onlyRegion) return this
410
+
411
+ initRect(this.painter, x, y, width, height)
412
+ this.painter.fill()
413
+ this.painter.stroke()
414
+ return this
415
+ }
416
+
417
+ draw() { }
418
+ }
419
+
420
420
  export default Painter