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