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