circuit-to-svg 0.0.125 → 0.0.126

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
@@ -578,7 +578,8 @@ function createSvgObjectsFromPcbSilkscreenText(pcbSilkscreenText, transform) {
578
578
  text,
579
579
  font_size = 1,
580
580
  layer = "top",
581
- ccw_rotation = 0
581
+ ccw_rotation = 0,
582
+ anchor_alignment = "center"
582
583
  } = pcbSilkscreenText;
583
584
  if (!anchor_position || typeof anchor_position.x !== "number" || typeof anchor_position.y !== "number") {
584
585
  console.error("Invalid anchor_position:", anchor_position);
@@ -589,6 +590,33 @@ function createSvgObjectsFromPcbSilkscreenText(pcbSilkscreenText, transform) {
589
590
  anchor_position.y
590
591
  ]);
591
592
  const transformedFontSize = font_size * Math.abs(transform.a);
593
+ let textAnchor = "middle";
594
+ let dominantBaseline = "central";
595
+ let dx = 0;
596
+ let dy = 0;
597
+ switch (anchor_alignment) {
598
+ case "top_left":
599
+ textAnchor = "start";
600
+ dominantBaseline = "text-before-edge";
601
+ break;
602
+ case "top_right":
603
+ textAnchor = "end";
604
+ dominantBaseline = "text-before-edge";
605
+ break;
606
+ case "bottom_left":
607
+ textAnchor = "start";
608
+ dominantBaseline = "text-after-edge";
609
+ break;
610
+ case "bottom_right":
611
+ textAnchor = "end";
612
+ dominantBaseline = "text-after-edge";
613
+ break;
614
+ case "center":
615
+ default:
616
+ textAnchor = "middle";
617
+ dominantBaseline = "central";
618
+ break;
619
+ }
592
620
  const textTransform = compose2(
593
621
  translate2(transformedX, transformedY),
594
622
  rotate2(ccw_rotation * Math.PI / 180),
@@ -601,11 +629,13 @@ function createSvgObjectsFromPcbSilkscreenText(pcbSilkscreenText, transform) {
601
629
  attributes: {
602
630
  x: "0",
603
631
  y: "0",
632
+ dx: dx.toString(),
633
+ dy: dy.toString(),
604
634
  fill: color,
605
635
  "font-family": "Arial, sans-serif",
606
636
  "font-size": transformedFontSize.toString(),
607
- "text-anchor": "middle",
608
- "dominant-baseline": "central",
637
+ "text-anchor": textAnchor,
638
+ "dominant-baseline": dominantBaseline,
609
639
  transform: matrixToString2(textTransform),
610
640
  class: `pcb-silkscreen-text pcb-silkscreen-${layer}`,
611
641
  "data-pcb-silkscreen-text-id": pcbSilkscreenText.pcb_component_id,