Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/pcb/pcb_silkscreen_text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const pcb_silkscreen_text = z
ccw_rotation: z.number().optional(),
layer: layer_ref,
is_mirrored: z.boolean().default(false).optional(),
keep_upright: z.boolean().default(false).optional(),
anchor_position: point.default({ x: 0, y: 0 }),
anchor_alignment: ninePointAnchor.default("center"),
})
Expand Down Expand Up @@ -66,6 +67,12 @@ export interface PcbSilkscreenText {
ccw_rotation?: number
layer: LayerRef
is_mirrored?: boolean
/**
* When true, a renderer should keep the text readable ("keep upright",
* like KiCad) by flipping any ccw_rotation that would render it upside-down,
* rather than drawing the raw rotation. Defaults to false.
*/
keep_upright?: boolean
anchor_position: Point
anchor_alignment: NinePointAnchor
}
Expand Down
20 changes: 20 additions & 0 deletions tests/pcb_silkscreen_text.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { test, expect } from "bun:test"
import { pcb_silkscreen_text } from "../src/pcb/pcb_silkscreen_text"

test("pcb_silkscreen_text carries an optional keep_upright flag", () => {
const base = {
type: "pcb_silkscreen_text" as const,
pcb_component_id: "pcb_component_0",
text: "R1",
layer: "top" as const,
ccw_rotation: 180,
}

const withFlag = pcb_silkscreen_text.parse({ ...base, keep_upright: true })
expect(withFlag.keep_upright).toBe(true)

// Absent behaves like the sibling is_mirrored flag: undefined (falsy), so a
// renderer honors the raw ccw_rotation unless keep_upright is explicitly set.
const withoutFlag = pcb_silkscreen_text.parse(base)
expect(withoutFlag.keep_upright).toBeUndefined()
})
Loading