circuit-to-canvas 0.0.14 → 0.0.15
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/dist/index.d.ts +29 -29
- package/dist/index.js +157 -138
- package/lib/drawer/CircuitToCanvasDrawer.ts +21 -21
- package/lib/drawer/elements/pcb-board.ts +5 -5
- package/lib/drawer/elements/pcb-copper-pour.ts +13 -10
- package/lib/drawer/elements/pcb-copper-text.ts +4 -4
- package/lib/drawer/elements/pcb-cutout.ts +5 -5
- package/lib/drawer/elements/pcb-fabrication-note-path.ts +3 -3
- package/lib/drawer/elements/pcb-fabrication-note-rect.ts +3 -3
- package/lib/drawer/elements/pcb-fabrication-note-text.ts +4 -4
- package/lib/drawer/elements/pcb-hole.ts +8 -8
- package/lib/drawer/elements/pcb-note-line.ts +5 -5
- package/lib/drawer/elements/pcb-note-path.ts +3 -3
- package/lib/drawer/elements/pcb-note-rect.ts +3 -3
- package/lib/drawer/elements/pcb-note-text.ts +4 -4
- package/lib/drawer/elements/pcb-plated-hole.ts +14 -14
- package/lib/drawer/elements/pcb-silkscreen.ts +16 -16
- package/lib/drawer/elements/pcb-smtpad.ts +8 -8
- package/lib/drawer/elements/pcb-trace.ts +3 -3
- package/lib/drawer/elements/pcb-via.ts +4 -4
- package/lib/drawer/shapes/circle.ts +4 -4
- package/lib/drawer/shapes/line.ts +5 -5
- package/lib/drawer/shapes/oval.ts +13 -5
- package/lib/drawer/shapes/path.ts +8 -8
- package/lib/drawer/shapes/pill.ts +13 -5
- package/lib/drawer/shapes/polygon.ts +7 -7
- package/lib/drawer/shapes/rect.ts +7 -7
- package/lib/drawer/shapes/text.ts +5 -5
- package/lib/drawer/types.ts +1 -1
- package/package.json +1 -1
- package/tests/shapes/circle.test.ts +1 -1
- package/tests/shapes/oval.test.ts +1 -1
- package/tests/shapes/pill.test.ts +2 -2
- package/tests/shapes/rect.test.ts +2 -2
|
@@ -9,12 +9,12 @@ import { drawPill } from "../shapes/pill"
|
|
|
9
9
|
export interface DrawPcbPlatedHoleParams {
|
|
10
10
|
ctx: CanvasContext
|
|
11
11
|
hole: PcbPlatedHole
|
|
12
|
-
|
|
12
|
+
realToCanvasMat: Matrix
|
|
13
13
|
colorMap: PcbColorMap
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export function drawPcbPlatedHole(params: DrawPcbPlatedHoleParams): void {
|
|
17
|
-
const { ctx, hole,
|
|
17
|
+
const { ctx, hole, realToCanvasMat, colorMap } = params
|
|
18
18
|
|
|
19
19
|
if (hole.shape === "circle") {
|
|
20
20
|
// Draw outer copper ring
|
|
@@ -23,7 +23,7 @@ export function drawPcbPlatedHole(params: DrawPcbPlatedHoleParams): void {
|
|
|
23
23
|
center: { x: hole.x, y: hole.y },
|
|
24
24
|
radius: hole.outer_diameter / 2,
|
|
25
25
|
fill: colorMap.copper.top,
|
|
26
|
-
|
|
26
|
+
realToCanvasMat,
|
|
27
27
|
})
|
|
28
28
|
|
|
29
29
|
// Draw inner drill hole
|
|
@@ -32,7 +32,7 @@ export function drawPcbPlatedHole(params: DrawPcbPlatedHoleParams): void {
|
|
|
32
32
|
center: { x: hole.x, y: hole.y },
|
|
33
33
|
radius: hole.hole_diameter / 2,
|
|
34
34
|
fill: colorMap.drill,
|
|
35
|
-
|
|
35
|
+
realToCanvasMat,
|
|
36
36
|
})
|
|
37
37
|
return
|
|
38
38
|
}
|
|
@@ -45,7 +45,7 @@ export function drawPcbPlatedHole(params: DrawPcbPlatedHoleParams): void {
|
|
|
45
45
|
width: hole.outer_width,
|
|
46
46
|
height: hole.outer_height,
|
|
47
47
|
fill: colorMap.copper.top,
|
|
48
|
-
|
|
48
|
+
realToCanvasMat,
|
|
49
49
|
rotation: hole.ccw_rotation,
|
|
50
50
|
})
|
|
51
51
|
|
|
@@ -56,7 +56,7 @@ export function drawPcbPlatedHole(params: DrawPcbPlatedHoleParams): void {
|
|
|
56
56
|
width: hole.hole_width,
|
|
57
57
|
height: hole.hole_height,
|
|
58
58
|
fill: colorMap.drill,
|
|
59
|
-
|
|
59
|
+
realToCanvasMat,
|
|
60
60
|
rotation: hole.ccw_rotation,
|
|
61
61
|
})
|
|
62
62
|
return
|
|
@@ -70,7 +70,7 @@ export function drawPcbPlatedHole(params: DrawPcbPlatedHoleParams): void {
|
|
|
70
70
|
width: hole.outer_width,
|
|
71
71
|
height: hole.outer_height,
|
|
72
72
|
fill: colorMap.copper.top,
|
|
73
|
-
|
|
73
|
+
realToCanvasMat,
|
|
74
74
|
rotation: hole.ccw_rotation,
|
|
75
75
|
})
|
|
76
76
|
|
|
@@ -81,7 +81,7 @@ export function drawPcbPlatedHole(params: DrawPcbPlatedHoleParams): void {
|
|
|
81
81
|
width: hole.hole_width,
|
|
82
82
|
height: hole.hole_height,
|
|
83
83
|
fill: colorMap.drill,
|
|
84
|
-
|
|
84
|
+
realToCanvasMat,
|
|
85
85
|
rotation: hole.ccw_rotation,
|
|
86
86
|
})
|
|
87
87
|
return
|
|
@@ -95,7 +95,7 @@ export function drawPcbPlatedHole(params: DrawPcbPlatedHoleParams): void {
|
|
|
95
95
|
width: hole.rect_pad_width,
|
|
96
96
|
height: hole.rect_pad_height,
|
|
97
97
|
fill: colorMap.copper.top,
|
|
98
|
-
|
|
98
|
+
realToCanvasMat,
|
|
99
99
|
borderRadius: (hole as any).rect_border_radius ?? 0,
|
|
100
100
|
})
|
|
101
101
|
|
|
@@ -107,7 +107,7 @@ export function drawPcbPlatedHole(params: DrawPcbPlatedHoleParams): void {
|
|
|
107
107
|
center: { x: holeX, y: holeY },
|
|
108
108
|
radius: hole.hole_diameter / 2,
|
|
109
109
|
fill: colorMap.drill,
|
|
110
|
-
|
|
110
|
+
realToCanvasMat,
|
|
111
111
|
})
|
|
112
112
|
return
|
|
113
113
|
}
|
|
@@ -120,7 +120,7 @@ export function drawPcbPlatedHole(params: DrawPcbPlatedHoleParams): void {
|
|
|
120
120
|
width: hole.rect_pad_width,
|
|
121
121
|
height: hole.rect_pad_height,
|
|
122
122
|
fill: colorMap.copper.top,
|
|
123
|
-
|
|
123
|
+
realToCanvasMat,
|
|
124
124
|
borderRadius: (hole as any).rect_border_radius ?? 0,
|
|
125
125
|
})
|
|
126
126
|
|
|
@@ -133,7 +133,7 @@ export function drawPcbPlatedHole(params: DrawPcbPlatedHoleParams): void {
|
|
|
133
133
|
width: hole.hole_width,
|
|
134
134
|
height: hole.hole_height,
|
|
135
135
|
fill: colorMap.drill,
|
|
136
|
-
|
|
136
|
+
realToCanvasMat,
|
|
137
137
|
})
|
|
138
138
|
return
|
|
139
139
|
}
|
|
@@ -146,7 +146,7 @@ export function drawPcbPlatedHole(params: DrawPcbPlatedHoleParams): void {
|
|
|
146
146
|
width: hole.rect_pad_width,
|
|
147
147
|
height: hole.rect_pad_height,
|
|
148
148
|
fill: colorMap.copper.top,
|
|
149
|
-
|
|
149
|
+
realToCanvasMat,
|
|
150
150
|
borderRadius: (hole as any).rect_border_radius ?? 0,
|
|
151
151
|
rotation: hole.rect_ccw_rotation,
|
|
152
152
|
})
|
|
@@ -160,7 +160,7 @@ export function drawPcbPlatedHole(params: DrawPcbPlatedHoleParams): void {
|
|
|
160
160
|
width: hole.hole_width,
|
|
161
161
|
height: hole.hole_height,
|
|
162
162
|
fill: colorMap.drill,
|
|
163
|
-
|
|
163
|
+
realToCanvasMat,
|
|
164
164
|
rotation: hole.hole_ccw_rotation,
|
|
165
165
|
})
|
|
166
166
|
return
|
|
@@ -16,35 +16,35 @@ import { drawPath } from "../shapes/path"
|
|
|
16
16
|
export interface DrawPcbSilkscreenTextParams {
|
|
17
17
|
ctx: CanvasContext
|
|
18
18
|
text: PcbSilkscreenText
|
|
19
|
-
|
|
19
|
+
realToCanvasMat: Matrix
|
|
20
20
|
colorMap: PcbColorMap
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
export interface DrawPcbSilkscreenRectParams {
|
|
24
24
|
ctx: CanvasContext
|
|
25
25
|
rect: PcbSilkscreenRect
|
|
26
|
-
|
|
26
|
+
realToCanvasMat: Matrix
|
|
27
27
|
colorMap: PcbColorMap
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
export interface DrawPcbSilkscreenCircleParams {
|
|
31
31
|
ctx: CanvasContext
|
|
32
32
|
circle: PcbSilkscreenCircle
|
|
33
|
-
|
|
33
|
+
realToCanvasMat: Matrix
|
|
34
34
|
colorMap: PcbColorMap
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
export interface DrawPcbSilkscreenLineParams {
|
|
38
38
|
ctx: CanvasContext
|
|
39
39
|
line: PcbSilkscreenLine
|
|
40
|
-
|
|
40
|
+
realToCanvasMat: Matrix
|
|
41
41
|
colorMap: PcbColorMap
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
export interface DrawPcbSilkscreenPathParams {
|
|
45
45
|
ctx: CanvasContext
|
|
46
46
|
path: PcbSilkscreenPath
|
|
47
|
-
|
|
47
|
+
realToCanvasMat: Matrix
|
|
48
48
|
colorMap: PcbColorMap
|
|
49
49
|
}
|
|
50
50
|
|
|
@@ -66,15 +66,15 @@ function mapAnchorAlignment(
|
|
|
66
66
|
export function drawPcbSilkscreenText(
|
|
67
67
|
params: DrawPcbSilkscreenTextParams,
|
|
68
68
|
): void {
|
|
69
|
-
const { ctx, text,
|
|
69
|
+
const { ctx, text, realToCanvasMat, colorMap } = params
|
|
70
70
|
|
|
71
71
|
const color = layerToSilkscreenColor(text.layer, colorMap)
|
|
72
|
-
const [x, y] = applyToPoint(
|
|
72
|
+
const [x, y] = applyToPoint(realToCanvasMat, [
|
|
73
73
|
text.anchor_position.x,
|
|
74
74
|
text.anchor_position.y,
|
|
75
75
|
])
|
|
76
76
|
|
|
77
|
-
const fontSize = (text.font_size ?? 1) * Math.abs(
|
|
77
|
+
const fontSize = (text.font_size ?? 1) * Math.abs(realToCanvasMat.a)
|
|
78
78
|
const rotation = text.ccw_rotation ?? 0
|
|
79
79
|
|
|
80
80
|
ctx.save()
|
|
@@ -95,7 +95,7 @@ export function drawPcbSilkscreenText(
|
|
|
95
95
|
export function drawPcbSilkscreenRect(
|
|
96
96
|
params: DrawPcbSilkscreenRectParams,
|
|
97
97
|
): void {
|
|
98
|
-
const { ctx, rect,
|
|
98
|
+
const { ctx, rect, realToCanvasMat, colorMap } = params
|
|
99
99
|
|
|
100
100
|
const color = layerToSilkscreenColor(rect.layer, colorMap)
|
|
101
101
|
|
|
@@ -105,14 +105,14 @@ export function drawPcbSilkscreenRect(
|
|
|
105
105
|
width: rect.width,
|
|
106
106
|
height: rect.height,
|
|
107
107
|
fill: color,
|
|
108
|
-
|
|
108
|
+
realToCanvasMat,
|
|
109
109
|
})
|
|
110
110
|
}
|
|
111
111
|
|
|
112
112
|
export function drawPcbSilkscreenCircle(
|
|
113
113
|
params: DrawPcbSilkscreenCircleParams,
|
|
114
114
|
): void {
|
|
115
|
-
const { ctx, circle,
|
|
115
|
+
const { ctx, circle, realToCanvasMat, colorMap } = params
|
|
116
116
|
|
|
117
117
|
const color = layerToSilkscreenColor(circle.layer, colorMap)
|
|
118
118
|
|
|
@@ -121,14 +121,14 @@ export function drawPcbSilkscreenCircle(
|
|
|
121
121
|
center: circle.center,
|
|
122
122
|
radius: circle.radius,
|
|
123
123
|
fill: color,
|
|
124
|
-
|
|
124
|
+
realToCanvasMat,
|
|
125
125
|
})
|
|
126
126
|
}
|
|
127
127
|
|
|
128
128
|
export function drawPcbSilkscreenLine(
|
|
129
129
|
params: DrawPcbSilkscreenLineParams,
|
|
130
130
|
): void {
|
|
131
|
-
const { ctx, line,
|
|
131
|
+
const { ctx, line, realToCanvasMat, colorMap } = params
|
|
132
132
|
|
|
133
133
|
const color = layerToSilkscreenColor(line.layer, colorMap)
|
|
134
134
|
|
|
@@ -138,14 +138,14 @@ export function drawPcbSilkscreenLine(
|
|
|
138
138
|
end: { x: line.x2, y: line.y2 },
|
|
139
139
|
strokeWidth: line.stroke_width ?? 0.1,
|
|
140
140
|
stroke: color,
|
|
141
|
-
|
|
141
|
+
realToCanvasMat,
|
|
142
142
|
})
|
|
143
143
|
}
|
|
144
144
|
|
|
145
145
|
export function drawPcbSilkscreenPath(
|
|
146
146
|
params: DrawPcbSilkscreenPathParams,
|
|
147
147
|
): void {
|
|
148
|
-
const { ctx, path,
|
|
148
|
+
const { ctx, path, realToCanvasMat, colorMap } = params
|
|
149
149
|
|
|
150
150
|
const color = layerToSilkscreenColor(path.layer, colorMap)
|
|
151
151
|
|
|
@@ -164,7 +164,7 @@ export function drawPcbSilkscreenPath(
|
|
|
164
164
|
end: { x: end.x, y: end.y },
|
|
165
165
|
strokeWidth: path.stroke_width ?? 0.1,
|
|
166
166
|
stroke: color,
|
|
167
|
-
|
|
167
|
+
realToCanvasMat,
|
|
168
168
|
})
|
|
169
169
|
}
|
|
170
170
|
}
|
|
@@ -9,7 +9,7 @@ import { drawPolygon } from "../shapes/polygon"
|
|
|
9
9
|
export interface DrawPcbSmtPadParams {
|
|
10
10
|
ctx: CanvasContext
|
|
11
11
|
pad: PcbSmtPad
|
|
12
|
-
|
|
12
|
+
realToCanvasMat: Matrix
|
|
13
13
|
colorMap: PcbColorMap
|
|
14
14
|
}
|
|
15
15
|
|
|
@@ -21,7 +21,7 @@ function layerToColor(layer: string, colorMap: PcbColorMap): string {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
export function drawPcbSmtPad(params: DrawPcbSmtPadParams): void {
|
|
24
|
-
const { ctx, pad,
|
|
24
|
+
const { ctx, pad, realToCanvasMat, colorMap } = params
|
|
25
25
|
|
|
26
26
|
const color = layerToColor(pad.layer, colorMap)
|
|
27
27
|
|
|
@@ -32,7 +32,7 @@ export function drawPcbSmtPad(params: DrawPcbSmtPadParams): void {
|
|
|
32
32
|
width: pad.width,
|
|
33
33
|
height: pad.height,
|
|
34
34
|
fill: color,
|
|
35
|
-
|
|
35
|
+
realToCanvasMat,
|
|
36
36
|
borderRadius:
|
|
37
37
|
(pad as { corner_radius?: number }).corner_radius ??
|
|
38
38
|
pad.rect_border_radius ??
|
|
@@ -48,7 +48,7 @@ export function drawPcbSmtPad(params: DrawPcbSmtPadParams): void {
|
|
|
48
48
|
width: pad.width,
|
|
49
49
|
height: pad.height,
|
|
50
50
|
fill: color,
|
|
51
|
-
|
|
51
|
+
realToCanvasMat,
|
|
52
52
|
borderRadius:
|
|
53
53
|
(pad as { corner_radius?: number }).corner_radius ??
|
|
54
54
|
pad.rect_border_radius ??
|
|
@@ -64,7 +64,7 @@ export function drawPcbSmtPad(params: DrawPcbSmtPadParams): void {
|
|
|
64
64
|
center: { x: pad.x, y: pad.y },
|
|
65
65
|
radius: pad.radius,
|
|
66
66
|
fill: color,
|
|
67
|
-
|
|
67
|
+
realToCanvasMat,
|
|
68
68
|
})
|
|
69
69
|
return
|
|
70
70
|
}
|
|
@@ -76,7 +76,7 @@ export function drawPcbSmtPad(params: DrawPcbSmtPadParams): void {
|
|
|
76
76
|
width: pad.width,
|
|
77
77
|
height: pad.height,
|
|
78
78
|
fill: color,
|
|
79
|
-
|
|
79
|
+
realToCanvasMat,
|
|
80
80
|
})
|
|
81
81
|
return
|
|
82
82
|
}
|
|
@@ -88,7 +88,7 @@ export function drawPcbSmtPad(params: DrawPcbSmtPadParams): void {
|
|
|
88
88
|
width: pad.width,
|
|
89
89
|
height: pad.height,
|
|
90
90
|
fill: color,
|
|
91
|
-
|
|
91
|
+
realToCanvasMat,
|
|
92
92
|
rotation: pad.ccw_rotation ?? 0,
|
|
93
93
|
})
|
|
94
94
|
return
|
|
@@ -100,7 +100,7 @@ export function drawPcbSmtPad(params: DrawPcbSmtPadParams): void {
|
|
|
100
100
|
ctx,
|
|
101
101
|
points: pad.points,
|
|
102
102
|
fill: color,
|
|
103
|
-
|
|
103
|
+
realToCanvasMat,
|
|
104
104
|
})
|
|
105
105
|
}
|
|
106
106
|
return
|
|
@@ -6,7 +6,7 @@ import { drawLine } from "../shapes/line"
|
|
|
6
6
|
export interface DrawPcbTraceParams {
|
|
7
7
|
ctx: CanvasContext
|
|
8
8
|
trace: PCBTrace
|
|
9
|
-
|
|
9
|
+
realToCanvasMat: Matrix
|
|
10
10
|
colorMap: PcbColorMap
|
|
11
11
|
}
|
|
12
12
|
|
|
@@ -18,7 +18,7 @@ function layerToColor(layer: string, colorMap: PcbColorMap): string {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
export function drawPcbTrace(params: DrawPcbTraceParams): void {
|
|
21
|
-
const { ctx, trace,
|
|
21
|
+
const { ctx, trace, realToCanvasMat, colorMap } = params
|
|
22
22
|
|
|
23
23
|
if (!trace.route || !Array.isArray(trace.route) || trace.route.length < 2) {
|
|
24
24
|
return
|
|
@@ -52,7 +52,7 @@ export function drawPcbTrace(params: DrawPcbTraceParams): void {
|
|
|
52
52
|
end: { x: end.x, y: end.y },
|
|
53
53
|
strokeWidth: traceWidth,
|
|
54
54
|
stroke: color,
|
|
55
|
-
|
|
55
|
+
realToCanvasMat,
|
|
56
56
|
lineCap: "round",
|
|
57
57
|
})
|
|
58
58
|
}
|
|
@@ -6,12 +6,12 @@ import { drawCircle } from "../shapes/circle"
|
|
|
6
6
|
export interface DrawPcbViaParams {
|
|
7
7
|
ctx: CanvasContext
|
|
8
8
|
via: PCBVia
|
|
9
|
-
|
|
9
|
+
realToCanvasMat: Matrix
|
|
10
10
|
colorMap: PcbColorMap
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export function drawPcbVia(params: DrawPcbViaParams): void {
|
|
14
|
-
const { ctx, via,
|
|
14
|
+
const { ctx, via, realToCanvasMat, colorMap } = params
|
|
15
15
|
|
|
16
16
|
// Draw outer copper ring
|
|
17
17
|
drawCircle({
|
|
@@ -19,7 +19,7 @@ export function drawPcbVia(params: DrawPcbViaParams): void {
|
|
|
19
19
|
center: { x: via.x, y: via.y },
|
|
20
20
|
radius: via.outer_diameter / 2,
|
|
21
21
|
fill: colorMap.copper.top,
|
|
22
|
-
|
|
22
|
+
realToCanvasMat,
|
|
23
23
|
})
|
|
24
24
|
|
|
25
25
|
// Draw inner drill hole
|
|
@@ -28,6 +28,6 @@ export function drawPcbVia(params: DrawPcbViaParams): void {
|
|
|
28
28
|
center: { x: via.x, y: via.y },
|
|
29
29
|
radius: via.hole_diameter / 2,
|
|
30
30
|
fill: colorMap.drill,
|
|
31
|
-
|
|
31
|
+
realToCanvasMat,
|
|
32
32
|
})
|
|
33
33
|
}
|
|
@@ -7,14 +7,14 @@ export interface DrawCircleParams {
|
|
|
7
7
|
center: { x: number; y: number }
|
|
8
8
|
radius: number
|
|
9
9
|
fill: string
|
|
10
|
-
|
|
10
|
+
realToCanvasMat: Matrix
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export function drawCircle(params: DrawCircleParams): void {
|
|
14
|
-
const { ctx, center, radius, fill,
|
|
14
|
+
const { ctx, center, radius, fill, realToCanvasMat } = params
|
|
15
15
|
|
|
16
|
-
const [cx, cy] = applyToPoint(
|
|
17
|
-
const scaledRadius = radius * Math.abs(
|
|
16
|
+
const [cx, cy] = applyToPoint(realToCanvasMat, [center.x, center.y])
|
|
17
|
+
const scaledRadius = radius * Math.abs(realToCanvasMat.a)
|
|
18
18
|
|
|
19
19
|
ctx.beginPath()
|
|
20
20
|
ctx.arc(cx, cy, scaledRadius, 0, Math.PI * 2)
|
|
@@ -8,7 +8,7 @@ export interface DrawLineParams {
|
|
|
8
8
|
end: { x: number; y: number }
|
|
9
9
|
strokeWidth: number
|
|
10
10
|
stroke: string
|
|
11
|
-
|
|
11
|
+
realToCanvasMat: Matrix
|
|
12
12
|
lineCap?: "butt" | "round" | "square"
|
|
13
13
|
}
|
|
14
14
|
|
|
@@ -19,13 +19,13 @@ export function drawLine(params: DrawLineParams): void {
|
|
|
19
19
|
end,
|
|
20
20
|
strokeWidth,
|
|
21
21
|
stroke,
|
|
22
|
-
|
|
22
|
+
realToCanvasMat,
|
|
23
23
|
lineCap = "round",
|
|
24
24
|
} = params
|
|
25
25
|
|
|
26
|
-
const [x1, y1] = applyToPoint(
|
|
27
|
-
const [x2, y2] = applyToPoint(
|
|
28
|
-
const scaledStrokeWidth = strokeWidth * Math.abs(
|
|
26
|
+
const [x1, y1] = applyToPoint(realToCanvasMat, [start.x, start.y])
|
|
27
|
+
const [x2, y2] = applyToPoint(realToCanvasMat, [end.x, end.y])
|
|
28
|
+
const scaledStrokeWidth = strokeWidth * Math.abs(realToCanvasMat.a)
|
|
29
29
|
|
|
30
30
|
ctx.beginPath()
|
|
31
31
|
ctx.moveTo(x1, y1)
|
|
@@ -8,16 +8,24 @@ export interface DrawOvalParams {
|
|
|
8
8
|
width: number
|
|
9
9
|
height: number
|
|
10
10
|
fill: string
|
|
11
|
-
|
|
11
|
+
realToCanvasMat: Matrix
|
|
12
12
|
rotation?: number
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
export function drawOval(params: DrawOvalParams): void {
|
|
16
|
-
const {
|
|
16
|
+
const {
|
|
17
|
+
ctx,
|
|
18
|
+
center,
|
|
19
|
+
width,
|
|
20
|
+
height,
|
|
21
|
+
fill,
|
|
22
|
+
realToCanvasMat,
|
|
23
|
+
rotation = 0,
|
|
24
|
+
} = params
|
|
17
25
|
|
|
18
|
-
const [cx, cy] = applyToPoint(
|
|
19
|
-
const scaledWidth = width * Math.abs(
|
|
20
|
-
const scaledHeight = height * Math.abs(
|
|
26
|
+
const [cx, cy] = applyToPoint(realToCanvasMat, [center.x, center.y])
|
|
27
|
+
const scaledWidth = width * Math.abs(realToCanvasMat.a)
|
|
28
|
+
const scaledHeight = height * Math.abs(realToCanvasMat.a)
|
|
21
29
|
|
|
22
30
|
ctx.save()
|
|
23
31
|
ctx.translate(cx, cy)
|
|
@@ -8,7 +8,7 @@ export interface DrawPathParams {
|
|
|
8
8
|
fill?: string
|
|
9
9
|
stroke?: string
|
|
10
10
|
strokeWidth?: number
|
|
11
|
-
|
|
11
|
+
realToCanvasMat: Matrix
|
|
12
12
|
closePath?: boolean
|
|
13
13
|
}
|
|
14
14
|
|
|
@@ -19,7 +19,7 @@ export function drawPath(params: DrawPathParams): void {
|
|
|
19
19
|
fill,
|
|
20
20
|
stroke,
|
|
21
21
|
strokeWidth = 1,
|
|
22
|
-
|
|
22
|
+
realToCanvasMat,
|
|
23
23
|
closePath = false,
|
|
24
24
|
} = params
|
|
25
25
|
|
|
@@ -27,17 +27,17 @@ export function drawPath(params: DrawPathParams): void {
|
|
|
27
27
|
|
|
28
28
|
ctx.beginPath()
|
|
29
29
|
|
|
30
|
-
const
|
|
31
|
-
applyToPoint(
|
|
30
|
+
const canvasPoints = points.map((p) =>
|
|
31
|
+
applyToPoint(realToCanvasMat, [p.x, p.y]),
|
|
32
32
|
)
|
|
33
33
|
|
|
34
|
-
const firstPoint =
|
|
34
|
+
const firstPoint = canvasPoints[0]
|
|
35
35
|
if (!firstPoint) return
|
|
36
36
|
const [firstX, firstY] = firstPoint
|
|
37
37
|
ctx.moveTo(firstX, firstY)
|
|
38
38
|
|
|
39
|
-
for (let i = 1; i <
|
|
40
|
-
const point =
|
|
39
|
+
for (let i = 1; i < canvasPoints.length; i++) {
|
|
40
|
+
const point = canvasPoints[i]
|
|
41
41
|
if (!point) continue
|
|
42
42
|
const [x, y] = point
|
|
43
43
|
ctx.lineTo(x, y)
|
|
@@ -53,7 +53,7 @@ export function drawPath(params: DrawPathParams): void {
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
if (stroke) {
|
|
56
|
-
const scaledStrokeWidth = strokeWidth * Math.abs(
|
|
56
|
+
const scaledStrokeWidth = strokeWidth * Math.abs(realToCanvasMat.a)
|
|
57
57
|
ctx.strokeStyle = stroke
|
|
58
58
|
ctx.lineWidth = scaledStrokeWidth
|
|
59
59
|
ctx.stroke()
|
|
@@ -8,16 +8,24 @@ export interface DrawPillParams {
|
|
|
8
8
|
width: number
|
|
9
9
|
height: number
|
|
10
10
|
fill: string
|
|
11
|
-
|
|
11
|
+
realToCanvasMat: Matrix
|
|
12
12
|
rotation?: number
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
export function drawPill(params: DrawPillParams): void {
|
|
16
|
-
const {
|
|
16
|
+
const {
|
|
17
|
+
ctx,
|
|
18
|
+
center,
|
|
19
|
+
width,
|
|
20
|
+
height,
|
|
21
|
+
fill,
|
|
22
|
+
realToCanvasMat,
|
|
23
|
+
rotation = 0,
|
|
24
|
+
} = params
|
|
17
25
|
|
|
18
|
-
const [cx, cy] = applyToPoint(
|
|
19
|
-
const scaledWidth = width * Math.abs(
|
|
20
|
-
const scaledHeight = height * Math.abs(
|
|
26
|
+
const [cx, cy] = applyToPoint(realToCanvasMat, [center.x, center.y])
|
|
27
|
+
const scaledWidth = width * Math.abs(realToCanvasMat.a)
|
|
28
|
+
const scaledHeight = height * Math.abs(realToCanvasMat.a)
|
|
21
29
|
|
|
22
30
|
ctx.save()
|
|
23
31
|
ctx.translate(cx, cy)
|
|
@@ -6,27 +6,27 @@ export interface DrawPolygonParams {
|
|
|
6
6
|
ctx: CanvasContext
|
|
7
7
|
points: Array<{ x: number; y: number }>
|
|
8
8
|
fill: string
|
|
9
|
-
|
|
9
|
+
realToCanvasMat: Matrix
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export function drawPolygon(params: DrawPolygonParams): void {
|
|
13
|
-
const { ctx, points, fill,
|
|
13
|
+
const { ctx, points, fill, realToCanvasMat } = params
|
|
14
14
|
|
|
15
15
|
if (points.length < 3) return
|
|
16
16
|
|
|
17
17
|
ctx.beginPath()
|
|
18
18
|
|
|
19
|
-
const
|
|
20
|
-
applyToPoint(
|
|
19
|
+
const canvasPoints = points.map((p) =>
|
|
20
|
+
applyToPoint(realToCanvasMat, [p.x, p.y]),
|
|
21
21
|
)
|
|
22
22
|
|
|
23
|
-
const firstPoint =
|
|
23
|
+
const firstPoint = canvasPoints[0]
|
|
24
24
|
if (!firstPoint) return
|
|
25
25
|
const [firstX, firstY] = firstPoint
|
|
26
26
|
ctx.moveTo(firstX, firstY)
|
|
27
27
|
|
|
28
|
-
for (let i = 1; i <
|
|
29
|
-
const point =
|
|
28
|
+
for (let i = 1; i < canvasPoints.length; i++) {
|
|
29
|
+
const point = canvasPoints[i]
|
|
30
30
|
if (!point) continue
|
|
31
31
|
const [x, y] = point
|
|
32
32
|
ctx.lineTo(x, y)
|
|
@@ -8,7 +8,7 @@ export interface DrawRectParams {
|
|
|
8
8
|
width: number
|
|
9
9
|
height: number
|
|
10
10
|
fill?: string
|
|
11
|
-
|
|
11
|
+
realToCanvasMat: Matrix
|
|
12
12
|
borderRadius?: number
|
|
13
13
|
rotation?: number
|
|
14
14
|
stroke?: string
|
|
@@ -23,7 +23,7 @@ export function drawRect(params: DrawRectParams): void {
|
|
|
23
23
|
width,
|
|
24
24
|
height,
|
|
25
25
|
fill,
|
|
26
|
-
|
|
26
|
+
realToCanvasMat,
|
|
27
27
|
borderRadius = 0,
|
|
28
28
|
rotation = 0,
|
|
29
29
|
stroke,
|
|
@@ -31,12 +31,12 @@ export function drawRect(params: DrawRectParams): void {
|
|
|
31
31
|
isStrokeDashed = false,
|
|
32
32
|
} = params
|
|
33
33
|
|
|
34
|
-
const [cx, cy] = applyToPoint(
|
|
35
|
-
const scaledWidth = width * Math.abs(
|
|
36
|
-
const scaledHeight = height * Math.abs(
|
|
37
|
-
const scaledRadius = borderRadius * Math.abs(
|
|
34
|
+
const [cx, cy] = applyToPoint(realToCanvasMat, [center.x, center.y])
|
|
35
|
+
const scaledWidth = width * Math.abs(realToCanvasMat.a)
|
|
36
|
+
const scaledHeight = height * Math.abs(realToCanvasMat.a)
|
|
37
|
+
const scaledRadius = borderRadius * Math.abs(realToCanvasMat.a)
|
|
38
38
|
const scaledStrokeWidth = strokeWidth
|
|
39
|
-
? strokeWidth * Math.abs(
|
|
39
|
+
? strokeWidth * Math.abs(realToCanvasMat.a)
|
|
40
40
|
: undefined
|
|
41
41
|
|
|
42
42
|
ctx.save()
|
|
@@ -153,7 +153,7 @@ export interface DrawTextParams {
|
|
|
153
153
|
y: number
|
|
154
154
|
fontSize: number
|
|
155
155
|
color: string
|
|
156
|
-
|
|
156
|
+
realToCanvasMat: Matrix
|
|
157
157
|
anchorAlignment: AnchorAlignment
|
|
158
158
|
rotation?: number
|
|
159
159
|
}
|
|
@@ -166,21 +166,21 @@ export function drawText(params: DrawTextParams): void {
|
|
|
166
166
|
y,
|
|
167
167
|
fontSize,
|
|
168
168
|
color,
|
|
169
|
-
|
|
169
|
+
realToCanvasMat,
|
|
170
170
|
anchorAlignment,
|
|
171
171
|
rotation = 0,
|
|
172
172
|
} = params
|
|
173
173
|
|
|
174
174
|
if (!text) return
|
|
175
175
|
|
|
176
|
-
const [
|
|
177
|
-
const scale = Math.abs(
|
|
176
|
+
const [canvasX, canvasY] = applyToPoint(realToCanvasMat, [x, y])
|
|
177
|
+
const scale = Math.abs(realToCanvasMat.a)
|
|
178
178
|
const scaledFontSize = fontSize * scale
|
|
179
179
|
const layout = getAlphabetLayout(text, scaledFontSize)
|
|
180
180
|
const startPos = getTextStartPosition(anchorAlignment, layout)
|
|
181
181
|
|
|
182
182
|
ctx.save()
|
|
183
|
-
ctx.translate(
|
|
183
|
+
ctx.translate(canvasX, canvasY)
|
|
184
184
|
|
|
185
185
|
if (rotation !== 0) {
|
|
186
186
|
ctx.rotate(-rotation * (Math.PI / 180))
|
package/lib/drawer/types.ts
CHANGED
package/package.json
CHANGED