circuit-to-canvas 0.0.22 → 0.0.23
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 +8 -4
- package/dist/index.js +26 -6
- package/lib/drawer/CircuitToCanvasDrawer.ts +5 -7
- package/lib/drawer/elements/index.ts +17 -5
- package/lib/drawer/elements/pcb-silkscreen-circle.ts +33 -0
- package/lib/drawer/elements/pcb-silkscreen-line.ts +34 -0
- package/lib/drawer/elements/pcb-silkscreen-path.ts +44 -0
- package/lib/drawer/elements/pcb-silkscreen-rect.ts +34 -0
- package/lib/drawer/elements/pcb-silkscreen-text.ts +71 -0
- package/package.json +1 -1
- package/lib/drawer/elements/pcb-silkscreen.ts +0 -186
package/dist/index.d.ts
CHANGED
|
@@ -300,34 +300,38 @@ interface DrawPcbSilkscreenTextParams {
|
|
|
300
300
|
realToCanvasMat: Matrix;
|
|
301
301
|
colorMap: PcbColorMap;
|
|
302
302
|
}
|
|
303
|
+
declare function drawPcbSilkscreenText(params: DrawPcbSilkscreenTextParams): void;
|
|
304
|
+
|
|
303
305
|
interface DrawPcbSilkscreenRectParams {
|
|
304
306
|
ctx: CanvasContext;
|
|
305
307
|
rect: PcbSilkscreenRect;
|
|
306
308
|
realToCanvasMat: Matrix;
|
|
307
309
|
colorMap: PcbColorMap;
|
|
308
310
|
}
|
|
311
|
+
declare function drawPcbSilkscreenRect(params: DrawPcbSilkscreenRectParams): void;
|
|
312
|
+
|
|
309
313
|
interface DrawPcbSilkscreenCircleParams {
|
|
310
314
|
ctx: CanvasContext;
|
|
311
315
|
circle: PcbSilkscreenCircle;
|
|
312
316
|
realToCanvasMat: Matrix;
|
|
313
317
|
colorMap: PcbColorMap;
|
|
314
318
|
}
|
|
319
|
+
declare function drawPcbSilkscreenCircle(params: DrawPcbSilkscreenCircleParams): void;
|
|
320
|
+
|
|
315
321
|
interface DrawPcbSilkscreenLineParams {
|
|
316
322
|
ctx: CanvasContext;
|
|
317
323
|
line: PcbSilkscreenLine;
|
|
318
324
|
realToCanvasMat: Matrix;
|
|
319
325
|
colorMap: PcbColorMap;
|
|
320
326
|
}
|
|
327
|
+
declare function drawPcbSilkscreenLine(params: DrawPcbSilkscreenLineParams): void;
|
|
328
|
+
|
|
321
329
|
interface DrawPcbSilkscreenPathParams {
|
|
322
330
|
ctx: CanvasContext;
|
|
323
331
|
path: PcbSilkscreenPath;
|
|
324
332
|
realToCanvasMat: Matrix;
|
|
325
333
|
colorMap: PcbColorMap;
|
|
326
334
|
}
|
|
327
|
-
declare function drawPcbSilkscreenText(params: DrawPcbSilkscreenTextParams): void;
|
|
328
|
-
declare function drawPcbSilkscreenRect(params: DrawPcbSilkscreenRectParams): void;
|
|
329
|
-
declare function drawPcbSilkscreenCircle(params: DrawPcbSilkscreenCircleParams): void;
|
|
330
|
-
declare function drawPcbSilkscreenLine(params: DrawPcbSilkscreenLineParams): void;
|
|
331
335
|
declare function drawPcbSilkscreenPath(params: DrawPcbSilkscreenPathParams): void;
|
|
332
336
|
|
|
333
337
|
interface DrawPcbCutoutParams {
|
package/dist/index.js
CHANGED
|
@@ -647,7 +647,7 @@ function drawPcbBoard(params) {
|
|
|
647
647
|
}
|
|
648
648
|
}
|
|
649
649
|
|
|
650
|
-
// lib/drawer/elements/pcb-silkscreen.ts
|
|
650
|
+
// lib/drawer/elements/pcb-silkscreen-text.ts
|
|
651
651
|
import { applyToPoint as applyToPoint9 } from "transformation-matrix";
|
|
652
652
|
|
|
653
653
|
// lib/drawer/shapes/text/text.ts
|
|
@@ -765,7 +765,7 @@ function drawText(params) {
|
|
|
765
765
|
ctx.restore();
|
|
766
766
|
}
|
|
767
767
|
|
|
768
|
-
// lib/drawer/elements/pcb-silkscreen.ts
|
|
768
|
+
// lib/drawer/elements/pcb-silkscreen-text.ts
|
|
769
769
|
function layerToSilkscreenColor(layer, colorMap) {
|
|
770
770
|
return layer === "bottom" ? colorMap.silkscreen.bottom : colorMap.silkscreen.top;
|
|
771
771
|
}
|
|
@@ -803,9 +803,14 @@ function drawPcbSilkscreenText(params) {
|
|
|
803
803
|
strokeAlphabetText(ctx, content, layout, startPos.x, startPos.y);
|
|
804
804
|
ctx.restore();
|
|
805
805
|
}
|
|
806
|
+
|
|
807
|
+
// lib/drawer/elements/pcb-silkscreen-rect.ts
|
|
808
|
+
function layerToSilkscreenColor2(layer, colorMap) {
|
|
809
|
+
return layer === "bottom" ? colorMap.silkscreen.bottom : colorMap.silkscreen.top;
|
|
810
|
+
}
|
|
806
811
|
function drawPcbSilkscreenRect(params) {
|
|
807
812
|
const { ctx, rect, realToCanvasMat, colorMap } = params;
|
|
808
|
-
const color =
|
|
813
|
+
const color = layerToSilkscreenColor2(rect.layer, colorMap);
|
|
809
814
|
drawRect({
|
|
810
815
|
ctx,
|
|
811
816
|
center: rect.center,
|
|
@@ -815,9 +820,14 @@ function drawPcbSilkscreenRect(params) {
|
|
|
815
820
|
realToCanvasMat
|
|
816
821
|
});
|
|
817
822
|
}
|
|
823
|
+
|
|
824
|
+
// lib/drawer/elements/pcb-silkscreen-circle.ts
|
|
825
|
+
function layerToSilkscreenColor3(layer, colorMap) {
|
|
826
|
+
return layer === "bottom" ? colorMap.silkscreen.bottom : colorMap.silkscreen.top;
|
|
827
|
+
}
|
|
818
828
|
function drawPcbSilkscreenCircle(params) {
|
|
819
829
|
const { ctx, circle, realToCanvasMat, colorMap } = params;
|
|
820
|
-
const color =
|
|
830
|
+
const color = layerToSilkscreenColor3(circle.layer, colorMap);
|
|
821
831
|
drawCircle({
|
|
822
832
|
ctx,
|
|
823
833
|
center: circle.center,
|
|
@@ -826,9 +836,14 @@ function drawPcbSilkscreenCircle(params) {
|
|
|
826
836
|
realToCanvasMat
|
|
827
837
|
});
|
|
828
838
|
}
|
|
839
|
+
|
|
840
|
+
// lib/drawer/elements/pcb-silkscreen-line.ts
|
|
841
|
+
function layerToSilkscreenColor4(layer, colorMap) {
|
|
842
|
+
return layer === "bottom" ? colorMap.silkscreen.bottom : colorMap.silkscreen.top;
|
|
843
|
+
}
|
|
829
844
|
function drawPcbSilkscreenLine(params) {
|
|
830
845
|
const { ctx, line, realToCanvasMat, colorMap } = params;
|
|
831
|
-
const color =
|
|
846
|
+
const color = layerToSilkscreenColor4(line.layer, colorMap);
|
|
832
847
|
drawLine({
|
|
833
848
|
ctx,
|
|
834
849
|
start: { x: line.x1, y: line.y1 },
|
|
@@ -838,9 +853,14 @@ function drawPcbSilkscreenLine(params) {
|
|
|
838
853
|
realToCanvasMat
|
|
839
854
|
});
|
|
840
855
|
}
|
|
856
|
+
|
|
857
|
+
// lib/drawer/elements/pcb-silkscreen-path.ts
|
|
858
|
+
function layerToSilkscreenColor5(layer, colorMap) {
|
|
859
|
+
return layer === "bottom" ? colorMap.silkscreen.bottom : colorMap.silkscreen.top;
|
|
860
|
+
}
|
|
841
861
|
function drawPcbSilkscreenPath(params) {
|
|
842
862
|
const { ctx, path, realToCanvasMat, colorMap } = params;
|
|
843
|
-
const color =
|
|
863
|
+
const color = layerToSilkscreenColor5(path.layer, colorMap);
|
|
844
864
|
if (!path.route || path.route.length < 2) return;
|
|
845
865
|
for (let i = 0; i < path.route.length - 1; i++) {
|
|
846
866
|
const start = path.route[i];
|
|
@@ -38,13 +38,11 @@ import { drawPcbHole } from "./elements/pcb-hole"
|
|
|
38
38
|
import { drawPcbSmtPad } from "./elements/pcb-smtpad"
|
|
39
39
|
import { drawPcbTrace } from "./elements/pcb-trace"
|
|
40
40
|
import { drawPcbBoard } from "./elements/pcb-board"
|
|
41
|
-
import {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
drawPcbSilkscreenPath,
|
|
47
|
-
} from "./elements/pcb-silkscreen"
|
|
41
|
+
import { drawPcbSilkscreenText } from "./elements/pcb-silkscreen-text"
|
|
42
|
+
import { drawPcbSilkscreenRect } from "./elements/pcb-silkscreen-rect"
|
|
43
|
+
import { drawPcbSilkscreenCircle } from "./elements/pcb-silkscreen-circle"
|
|
44
|
+
import { drawPcbSilkscreenLine } from "./elements/pcb-silkscreen-line"
|
|
45
|
+
import { drawPcbSilkscreenPath } from "./elements/pcb-silkscreen-path"
|
|
48
46
|
import { drawPcbCutout } from "./elements/pcb-cutout"
|
|
49
47
|
import { drawPcbCopperPour } from "./elements/pcb-copper-pour"
|
|
50
48
|
import { drawPcbCopperText } from "./elements/pcb-copper-text"
|
|
@@ -15,16 +15,28 @@ export { drawPcbBoard, type DrawPcbBoardParams } from "./pcb-board"
|
|
|
15
15
|
|
|
16
16
|
export {
|
|
17
17
|
drawPcbSilkscreenText,
|
|
18
|
-
drawPcbSilkscreenRect,
|
|
19
|
-
drawPcbSilkscreenCircle,
|
|
20
|
-
drawPcbSilkscreenLine,
|
|
21
|
-
drawPcbSilkscreenPath,
|
|
22
18
|
type DrawPcbSilkscreenTextParams,
|
|
19
|
+
} from "./pcb-silkscreen-text"
|
|
20
|
+
|
|
21
|
+
export {
|
|
22
|
+
drawPcbSilkscreenRect,
|
|
23
23
|
type DrawPcbSilkscreenRectParams,
|
|
24
|
+
} from "./pcb-silkscreen-rect"
|
|
25
|
+
|
|
26
|
+
export {
|
|
27
|
+
drawPcbSilkscreenCircle,
|
|
24
28
|
type DrawPcbSilkscreenCircleParams,
|
|
29
|
+
} from "./pcb-silkscreen-circle"
|
|
30
|
+
|
|
31
|
+
export {
|
|
32
|
+
drawPcbSilkscreenLine,
|
|
25
33
|
type DrawPcbSilkscreenLineParams,
|
|
34
|
+
} from "./pcb-silkscreen-line"
|
|
35
|
+
|
|
36
|
+
export {
|
|
37
|
+
drawPcbSilkscreenPath,
|
|
26
38
|
type DrawPcbSilkscreenPathParams,
|
|
27
|
-
} from "./pcb-silkscreen"
|
|
39
|
+
} from "./pcb-silkscreen-path"
|
|
28
40
|
|
|
29
41
|
export { drawPcbCutout, type DrawPcbCutoutParams } from "./pcb-cutout"
|
|
30
42
|
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { PcbSilkscreenCircle } from "circuit-json"
|
|
2
|
+
import type { Matrix } from "transformation-matrix"
|
|
3
|
+
import type { PcbColorMap, CanvasContext } from "../types"
|
|
4
|
+
import { drawCircle } from "../shapes/circle"
|
|
5
|
+
|
|
6
|
+
export interface DrawPcbSilkscreenCircleParams {
|
|
7
|
+
ctx: CanvasContext
|
|
8
|
+
circle: PcbSilkscreenCircle
|
|
9
|
+
realToCanvasMat: Matrix
|
|
10
|
+
colorMap: PcbColorMap
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function layerToSilkscreenColor(layer: string, colorMap: PcbColorMap): string {
|
|
14
|
+
return layer === "bottom"
|
|
15
|
+
? colorMap.silkscreen.bottom
|
|
16
|
+
: colorMap.silkscreen.top
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function drawPcbSilkscreenCircle(
|
|
20
|
+
params: DrawPcbSilkscreenCircleParams,
|
|
21
|
+
): void {
|
|
22
|
+
const { ctx, circle, realToCanvasMat, colorMap } = params
|
|
23
|
+
|
|
24
|
+
const color = layerToSilkscreenColor(circle.layer, colorMap)
|
|
25
|
+
|
|
26
|
+
drawCircle({
|
|
27
|
+
ctx,
|
|
28
|
+
center: circle.center,
|
|
29
|
+
radius: circle.radius,
|
|
30
|
+
fill: color,
|
|
31
|
+
realToCanvasMat,
|
|
32
|
+
})
|
|
33
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { PcbSilkscreenLine } from "circuit-json"
|
|
2
|
+
import type { Matrix } from "transformation-matrix"
|
|
3
|
+
import type { PcbColorMap, CanvasContext } from "../types"
|
|
4
|
+
import { drawLine } from "../shapes/line"
|
|
5
|
+
|
|
6
|
+
export interface DrawPcbSilkscreenLineParams {
|
|
7
|
+
ctx: CanvasContext
|
|
8
|
+
line: PcbSilkscreenLine
|
|
9
|
+
realToCanvasMat: Matrix
|
|
10
|
+
colorMap: PcbColorMap
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function layerToSilkscreenColor(layer: string, colorMap: PcbColorMap): string {
|
|
14
|
+
return layer === "bottom"
|
|
15
|
+
? colorMap.silkscreen.bottom
|
|
16
|
+
: colorMap.silkscreen.top
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function drawPcbSilkscreenLine(
|
|
20
|
+
params: DrawPcbSilkscreenLineParams,
|
|
21
|
+
): void {
|
|
22
|
+
const { ctx, line, realToCanvasMat, colorMap } = params
|
|
23
|
+
|
|
24
|
+
const color = layerToSilkscreenColor(line.layer, colorMap)
|
|
25
|
+
|
|
26
|
+
drawLine({
|
|
27
|
+
ctx,
|
|
28
|
+
start: { x: line.x1, y: line.y1 },
|
|
29
|
+
end: { x: line.x2, y: line.y2 },
|
|
30
|
+
strokeWidth: line.stroke_width ?? 0.1,
|
|
31
|
+
stroke: color,
|
|
32
|
+
realToCanvasMat,
|
|
33
|
+
})
|
|
34
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { PcbSilkscreenPath } from "circuit-json"
|
|
2
|
+
import type { Matrix } from "transformation-matrix"
|
|
3
|
+
import type { PcbColorMap, CanvasContext } from "../types"
|
|
4
|
+
import { drawLine } from "../shapes/line"
|
|
5
|
+
|
|
6
|
+
export interface DrawPcbSilkscreenPathParams {
|
|
7
|
+
ctx: CanvasContext
|
|
8
|
+
path: PcbSilkscreenPath
|
|
9
|
+
realToCanvasMat: Matrix
|
|
10
|
+
colorMap: PcbColorMap
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function layerToSilkscreenColor(layer: string, colorMap: PcbColorMap): string {
|
|
14
|
+
return layer === "bottom"
|
|
15
|
+
? colorMap.silkscreen.bottom
|
|
16
|
+
: colorMap.silkscreen.top
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function drawPcbSilkscreenPath(
|
|
20
|
+
params: DrawPcbSilkscreenPathParams,
|
|
21
|
+
): void {
|
|
22
|
+
const { ctx, path, realToCanvasMat, colorMap } = params
|
|
23
|
+
|
|
24
|
+
const color = layerToSilkscreenColor(path.layer, colorMap)
|
|
25
|
+
|
|
26
|
+
if (!path.route || path.route.length < 2) return
|
|
27
|
+
|
|
28
|
+
// Draw each segment of the path
|
|
29
|
+
for (let i = 0; i < path.route.length - 1; i++) {
|
|
30
|
+
const start = path.route[i]
|
|
31
|
+
const end = path.route[i + 1]
|
|
32
|
+
|
|
33
|
+
if (!start || !end) continue
|
|
34
|
+
|
|
35
|
+
drawLine({
|
|
36
|
+
ctx,
|
|
37
|
+
start: { x: start.x, y: start.y },
|
|
38
|
+
end: { x: end.x, y: end.y },
|
|
39
|
+
strokeWidth: path.stroke_width ?? 0.1,
|
|
40
|
+
stroke: color,
|
|
41
|
+
realToCanvasMat,
|
|
42
|
+
})
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { PcbSilkscreenRect } from "circuit-json"
|
|
2
|
+
import type { Matrix } from "transformation-matrix"
|
|
3
|
+
import type { PcbColorMap, CanvasContext } from "../types"
|
|
4
|
+
import { drawRect } from "../shapes/rect"
|
|
5
|
+
|
|
6
|
+
export interface DrawPcbSilkscreenRectParams {
|
|
7
|
+
ctx: CanvasContext
|
|
8
|
+
rect: PcbSilkscreenRect
|
|
9
|
+
realToCanvasMat: Matrix
|
|
10
|
+
colorMap: PcbColorMap
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function layerToSilkscreenColor(layer: string, colorMap: PcbColorMap): string {
|
|
14
|
+
return layer === "bottom"
|
|
15
|
+
? colorMap.silkscreen.bottom
|
|
16
|
+
: colorMap.silkscreen.top
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function drawPcbSilkscreenRect(
|
|
20
|
+
params: DrawPcbSilkscreenRectParams,
|
|
21
|
+
): void {
|
|
22
|
+
const { ctx, rect, realToCanvasMat, colorMap } = params
|
|
23
|
+
|
|
24
|
+
const color = layerToSilkscreenColor(rect.layer, colorMap)
|
|
25
|
+
|
|
26
|
+
drawRect({
|
|
27
|
+
ctx,
|
|
28
|
+
center: rect.center,
|
|
29
|
+
width: rect.width,
|
|
30
|
+
height: rect.height,
|
|
31
|
+
fill: color,
|
|
32
|
+
realToCanvasMat,
|
|
33
|
+
})
|
|
34
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { PcbSilkscreenText } from "circuit-json"
|
|
2
|
+
import type { Matrix } from "transformation-matrix"
|
|
3
|
+
import { applyToPoint } from "transformation-matrix"
|
|
4
|
+
import type { PcbColorMap, CanvasContext } from "../types"
|
|
5
|
+
import {
|
|
6
|
+
getAlphabetLayout,
|
|
7
|
+
strokeAlphabetText,
|
|
8
|
+
getTextStartPosition,
|
|
9
|
+
type AnchorAlignment,
|
|
10
|
+
} from "../shapes/text"
|
|
11
|
+
|
|
12
|
+
export interface DrawPcbSilkscreenTextParams {
|
|
13
|
+
ctx: CanvasContext
|
|
14
|
+
text: PcbSilkscreenText
|
|
15
|
+
realToCanvasMat: Matrix
|
|
16
|
+
colorMap: PcbColorMap
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function layerToSilkscreenColor(layer: string, colorMap: PcbColorMap): string {
|
|
20
|
+
return layer === "bottom"
|
|
21
|
+
? colorMap.silkscreen.bottom
|
|
22
|
+
: colorMap.silkscreen.top
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function mapAnchorAlignment(alignment?: string): AnchorAlignment {
|
|
26
|
+
if (!alignment) return "center"
|
|
27
|
+
return alignment as AnchorAlignment
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function drawPcbSilkscreenText(
|
|
31
|
+
params: DrawPcbSilkscreenTextParams,
|
|
32
|
+
): void {
|
|
33
|
+
const { ctx, text, realToCanvasMat, colorMap } = params
|
|
34
|
+
|
|
35
|
+
const content = text.text ?? ""
|
|
36
|
+
if (!content) return
|
|
37
|
+
|
|
38
|
+
const color = layerToSilkscreenColor(text.layer, colorMap)
|
|
39
|
+
const [x, y] = applyToPoint(realToCanvasMat, [
|
|
40
|
+
text.anchor_position.x,
|
|
41
|
+
text.anchor_position.y,
|
|
42
|
+
])
|
|
43
|
+
const scale = Math.abs(realToCanvasMat.a)
|
|
44
|
+
const fontSize = (text.font_size ?? 1) * scale
|
|
45
|
+
const rotation = text.ccw_rotation ?? 0
|
|
46
|
+
|
|
47
|
+
const layout = getAlphabetLayout(content, fontSize)
|
|
48
|
+
const alignment = mapAnchorAlignment(text.anchor_alignment)
|
|
49
|
+
const startPos = getTextStartPosition(alignment, layout)
|
|
50
|
+
|
|
51
|
+
ctx.save()
|
|
52
|
+
ctx.translate(x, y)
|
|
53
|
+
|
|
54
|
+
// Apply rotation (CCW rotation in degrees)
|
|
55
|
+
if (rotation !== 0) {
|
|
56
|
+
ctx.rotate(-rotation * (Math.PI / 180))
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (text.layer === "bottom") {
|
|
60
|
+
ctx.scale(-1, 1)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
ctx.lineWidth = layout.strokeWidth
|
|
64
|
+
ctx.lineCap = "round"
|
|
65
|
+
ctx.lineJoin = "round"
|
|
66
|
+
ctx.strokeStyle = color
|
|
67
|
+
|
|
68
|
+
strokeAlphabetText(ctx, content, layout, startPos.x, startPos.y)
|
|
69
|
+
|
|
70
|
+
ctx.restore()
|
|
71
|
+
}
|
package/package.json
CHANGED
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
PcbSilkscreenText,
|
|
3
|
-
PcbSilkscreenRect,
|
|
4
|
-
PcbSilkscreenCircle,
|
|
5
|
-
PcbSilkscreenLine,
|
|
6
|
-
PcbSilkscreenPath,
|
|
7
|
-
} from "circuit-json"
|
|
8
|
-
import type { Matrix } from "transformation-matrix"
|
|
9
|
-
import { applyToPoint } from "transformation-matrix"
|
|
10
|
-
import type { PcbColorMap, CanvasContext } from "../types"
|
|
11
|
-
import { drawRect } from "../shapes/rect"
|
|
12
|
-
import { drawCircle } from "../shapes/circle"
|
|
13
|
-
import { drawLine } from "../shapes/line"
|
|
14
|
-
import { drawPath } from "../shapes/path"
|
|
15
|
-
import {
|
|
16
|
-
getAlphabetLayout,
|
|
17
|
-
strokeAlphabetText,
|
|
18
|
-
getTextStartPosition,
|
|
19
|
-
type AnchorAlignment,
|
|
20
|
-
} from "../shapes/text"
|
|
21
|
-
|
|
22
|
-
export interface DrawPcbSilkscreenTextParams {
|
|
23
|
-
ctx: CanvasContext
|
|
24
|
-
text: PcbSilkscreenText
|
|
25
|
-
realToCanvasMat: Matrix
|
|
26
|
-
colorMap: PcbColorMap
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export interface DrawPcbSilkscreenRectParams {
|
|
30
|
-
ctx: CanvasContext
|
|
31
|
-
rect: PcbSilkscreenRect
|
|
32
|
-
realToCanvasMat: Matrix
|
|
33
|
-
colorMap: PcbColorMap
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export interface DrawPcbSilkscreenCircleParams {
|
|
37
|
-
ctx: CanvasContext
|
|
38
|
-
circle: PcbSilkscreenCircle
|
|
39
|
-
realToCanvasMat: Matrix
|
|
40
|
-
colorMap: PcbColorMap
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export interface DrawPcbSilkscreenLineParams {
|
|
44
|
-
ctx: CanvasContext
|
|
45
|
-
line: PcbSilkscreenLine
|
|
46
|
-
realToCanvasMat: Matrix
|
|
47
|
-
colorMap: PcbColorMap
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export interface DrawPcbSilkscreenPathParams {
|
|
51
|
-
ctx: CanvasContext
|
|
52
|
-
path: PcbSilkscreenPath
|
|
53
|
-
realToCanvasMat: Matrix
|
|
54
|
-
colorMap: PcbColorMap
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function layerToSilkscreenColor(layer: string, colorMap: PcbColorMap): string {
|
|
58
|
-
return layer === "bottom"
|
|
59
|
-
? colorMap.silkscreen.bottom
|
|
60
|
-
: colorMap.silkscreen.top
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function mapAnchorAlignment(alignment?: string): AnchorAlignment {
|
|
64
|
-
if (!alignment) return "center"
|
|
65
|
-
return alignment as AnchorAlignment
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export function drawPcbSilkscreenText(
|
|
69
|
-
params: DrawPcbSilkscreenTextParams,
|
|
70
|
-
): void {
|
|
71
|
-
const { ctx, text, realToCanvasMat, colorMap } = params
|
|
72
|
-
|
|
73
|
-
const content = text.text ?? ""
|
|
74
|
-
if (!content) return
|
|
75
|
-
|
|
76
|
-
const color = layerToSilkscreenColor(text.layer, colorMap)
|
|
77
|
-
const [x, y] = applyToPoint(realToCanvasMat, [
|
|
78
|
-
text.anchor_position.x,
|
|
79
|
-
text.anchor_position.y,
|
|
80
|
-
])
|
|
81
|
-
const scale = Math.abs(realToCanvasMat.a)
|
|
82
|
-
const fontSize = (text.font_size ?? 1) * scale
|
|
83
|
-
const rotation = text.ccw_rotation ?? 0
|
|
84
|
-
|
|
85
|
-
const layout = getAlphabetLayout(content, fontSize)
|
|
86
|
-
const alignment = mapAnchorAlignment(text.anchor_alignment)
|
|
87
|
-
const startPos = getTextStartPosition(alignment, layout)
|
|
88
|
-
|
|
89
|
-
ctx.save()
|
|
90
|
-
ctx.translate(x, y)
|
|
91
|
-
|
|
92
|
-
// Apply rotation (CCW rotation in degrees)
|
|
93
|
-
if (rotation !== 0) {
|
|
94
|
-
ctx.rotate(-rotation * (Math.PI / 180))
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if (text.layer === "bottom") {
|
|
98
|
-
ctx.scale(-1, 1)
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
ctx.lineWidth = layout.strokeWidth
|
|
102
|
-
ctx.lineCap = "round"
|
|
103
|
-
ctx.lineJoin = "round"
|
|
104
|
-
ctx.strokeStyle = color
|
|
105
|
-
|
|
106
|
-
strokeAlphabetText(ctx, content, layout, startPos.x, startPos.y)
|
|
107
|
-
|
|
108
|
-
ctx.restore()
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
export function drawPcbSilkscreenRect(
|
|
112
|
-
params: DrawPcbSilkscreenRectParams,
|
|
113
|
-
): void {
|
|
114
|
-
const { ctx, rect, realToCanvasMat, colorMap } = params
|
|
115
|
-
|
|
116
|
-
const color = layerToSilkscreenColor(rect.layer, colorMap)
|
|
117
|
-
|
|
118
|
-
drawRect({
|
|
119
|
-
ctx,
|
|
120
|
-
center: rect.center,
|
|
121
|
-
width: rect.width,
|
|
122
|
-
height: rect.height,
|
|
123
|
-
fill: color,
|
|
124
|
-
realToCanvasMat,
|
|
125
|
-
})
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
export function drawPcbSilkscreenCircle(
|
|
129
|
-
params: DrawPcbSilkscreenCircleParams,
|
|
130
|
-
): void {
|
|
131
|
-
const { ctx, circle, realToCanvasMat, colorMap } = params
|
|
132
|
-
|
|
133
|
-
const color = layerToSilkscreenColor(circle.layer, colorMap)
|
|
134
|
-
|
|
135
|
-
drawCircle({
|
|
136
|
-
ctx,
|
|
137
|
-
center: circle.center,
|
|
138
|
-
radius: circle.radius,
|
|
139
|
-
fill: color,
|
|
140
|
-
realToCanvasMat,
|
|
141
|
-
})
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
export function drawPcbSilkscreenLine(
|
|
145
|
-
params: DrawPcbSilkscreenLineParams,
|
|
146
|
-
): void {
|
|
147
|
-
const { ctx, line, realToCanvasMat, colorMap } = params
|
|
148
|
-
|
|
149
|
-
const color = layerToSilkscreenColor(line.layer, colorMap)
|
|
150
|
-
|
|
151
|
-
drawLine({
|
|
152
|
-
ctx,
|
|
153
|
-
start: { x: line.x1, y: line.y1 },
|
|
154
|
-
end: { x: line.x2, y: line.y2 },
|
|
155
|
-
strokeWidth: line.stroke_width ?? 0.1,
|
|
156
|
-
stroke: color,
|
|
157
|
-
realToCanvasMat,
|
|
158
|
-
})
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
export function drawPcbSilkscreenPath(
|
|
162
|
-
params: DrawPcbSilkscreenPathParams,
|
|
163
|
-
): void {
|
|
164
|
-
const { ctx, path, realToCanvasMat, colorMap } = params
|
|
165
|
-
|
|
166
|
-
const color = layerToSilkscreenColor(path.layer, colorMap)
|
|
167
|
-
|
|
168
|
-
if (!path.route || path.route.length < 2) return
|
|
169
|
-
|
|
170
|
-
// Draw each segment of the path
|
|
171
|
-
for (let i = 0; i < path.route.length - 1; i++) {
|
|
172
|
-
const start = path.route[i]
|
|
173
|
-
const end = path.route[i + 1]
|
|
174
|
-
|
|
175
|
-
if (!start || !end) continue
|
|
176
|
-
|
|
177
|
-
drawLine({
|
|
178
|
-
ctx,
|
|
179
|
-
start: { x: start.x, y: start.y },
|
|
180
|
-
end: { x: end.x, y: end.y },
|
|
181
|
-
strokeWidth: path.stroke_width ?? 0.1,
|
|
182
|
-
stroke: color,
|
|
183
|
-
realToCanvasMat,
|
|
184
|
-
})
|
|
185
|
-
}
|
|
186
|
-
}
|