circuit-to-canvas 0.0.54 → 0.0.55
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.js
CHANGED
|
@@ -407,7 +407,7 @@ function getAlphabetLayout(text, fontSize) {
|
|
|
407
407
|
const spaceWidth = glyphWidth * SPACE_WIDTH_RATIO;
|
|
408
408
|
const strokeWidth = Math.max(fontSize * STROKE_WIDTH_RATIO, 0.35);
|
|
409
409
|
const lineHeight = fontSize * LINE_HEIGHT_RATIO;
|
|
410
|
-
const lines = text.split("\n");
|
|
410
|
+
const lines = text.replace(/\\n/g, "\n").split("\n");
|
|
411
411
|
const lineWidths = [];
|
|
412
412
|
let maxWidth = 0;
|
|
413
413
|
for (const line of lines) {
|
|
@@ -26,7 +26,7 @@ export function getAlphabetLayout(
|
|
|
26
26
|
const strokeWidth = Math.max(fontSize * STROKE_WIDTH_RATIO, 0.35)
|
|
27
27
|
const lineHeight = fontSize * LINE_HEIGHT_RATIO
|
|
28
28
|
|
|
29
|
-
const lines = text.split("\n")
|
|
29
|
+
const lines = text.replace(/\\n/g, "\n").split("\n")
|
|
30
30
|
const lineWidths: number[] = []
|
|
31
31
|
|
|
32
32
|
let maxWidth = 0
|
package/package.json
CHANGED
|
Binary file
|
|
@@ -3,27 +3,41 @@ import { createCanvas } from "@napi-rs/canvas"
|
|
|
3
3
|
import type { PcbSilkscreenText } from "circuit-json"
|
|
4
4
|
import { CircuitToCanvasDrawer } from "../../lib/drawer"
|
|
5
5
|
|
|
6
|
-
test("draw silkscreen text
|
|
7
|
-
const
|
|
6
|
+
test("draw multiline silkscreen text", async () => {
|
|
7
|
+
const SCALE = 4
|
|
8
|
+
const canvas = createCanvas(150 * SCALE, 100 * SCALE)
|
|
8
9
|
const ctx = canvas.getContext("2d")
|
|
10
|
+
ctx.scale(SCALE, SCALE)
|
|
9
11
|
const drawer = new CircuitToCanvasDrawer(ctx)
|
|
10
12
|
|
|
11
13
|
ctx.fillStyle = "#1a1a1a"
|
|
12
|
-
ctx.fillRect(0, 0,
|
|
14
|
+
ctx.fillRect(0, 0, canvas.width / SCALE, canvas.height / SCALE)
|
|
13
15
|
|
|
14
|
-
const
|
|
16
|
+
const text1: PcbSilkscreenText = {
|
|
15
17
|
type: "pcb_silkscreen_text",
|
|
16
|
-
pcb_silkscreen_text_id: "
|
|
18
|
+
pcb_silkscreen_text_id: "silkscreen-text-1",
|
|
17
19
|
pcb_component_id: "component1",
|
|
18
20
|
layer: "top",
|
|
19
|
-
text: "
|
|
20
|
-
anchor_position: { x:
|
|
21
|
+
text: "Top\\nLeft",
|
|
22
|
+
anchor_position: { x: 40, y: 50 },
|
|
21
23
|
anchor_alignment: "center",
|
|
22
24
|
font: "tscircuit2024",
|
|
23
|
-
font_size:
|
|
25
|
+
font_size: 4,
|
|
24
26
|
}
|
|
25
27
|
|
|
26
|
-
|
|
28
|
+
const text2: PcbSilkscreenText = {
|
|
29
|
+
type: "pcb_silkscreen_text",
|
|
30
|
+
pcb_silkscreen_text_id: "silkscreen-text-2",
|
|
31
|
+
pcb_component_id: "component1",
|
|
32
|
+
layer: "top",
|
|
33
|
+
text: "Top\nLeft",
|
|
34
|
+
anchor_position: { x: 110, y: 50 },
|
|
35
|
+
anchor_alignment: "center",
|
|
36
|
+
font: "tscircuit2024",
|
|
37
|
+
font_size: 4,
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
drawer.drawElements([text1, text2])
|
|
27
41
|
|
|
28
42
|
await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
|
|
29
43
|
import.meta.path,
|