diff --git a/bun.lockb b/bun.lockb index 778d5b6..6fb5786 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/lib/sch/svg-object-fns/create-svg-objects-from-sch-component-with-symbol.ts b/lib/sch/svg-object-fns/create-svg-objects-from-sch-component-with-symbol.ts index 22f13df..88fadf8 100644 --- a/lib/sch/svg-object-fns/create-svg-objects-from-sch-component-with-symbol.ts +++ b/lib/sch/svg-object-fns/create-svg-objects-from-sch-component-with-symbol.ts @@ -181,33 +181,19 @@ export const createSvgObjectsFromSchematicComponentWithSymbol = ({ textValue = schComponent.symbol_display_value ?? "" } - const getTextOffset = ( - bounds: { minX: number; maxX: number; minY: number; maxY: number }, - anchor: TextPrimitive["anchor"], - transform: Matrix, - ) => { - const symbolHeight = Math.abs(bounds.maxY - bounds.minY) - const offsetFactor = 0.1 + const symbolHeight = Math.abs(bounds.maxY - bounds.minY) + const offsetFactor = 0.1 + const baseOffset = symbolHeight * offsetFactor + const transformScale = Math.abs(transformFromSymbolToReal.a) - const baseOffset = symbolHeight * offsetFactor + let verticalOffset = 0 - const transformScale = Math.abs(transform.a) - - if (anchor.includes("bottom")) { - return baseOffset * transformScale - } - if (anchor.includes("top")) { - return -baseOffset * transformScale - } - return 0 + if (text.anchor.includes("bottom")) { + verticalOffset = baseOffset * transformScale + } else if (text.anchor.includes("top")) { + verticalOffset = -baseOffset * transformScale } - const verticalOffset = getTextOffset( - bounds, - text.anchor, - transformFromSymbolToReal, - ) - const dominantBaseline = text.anchor.includes("bottom") ? "auto" : text.anchor.includes("top") diff --git a/package.json b/package.json index 60cd91a..c3719b6 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "@types/bun": "^1.1.9", "biome": "^0.3.3", "bun-match-svg": "^0.0.6", - "circuit-json": "^0.0.111", + "circuit-json": "^0.0.119", "esbuild": "^0.20.2", "performance-now": "^2.1.0", "react": "^18.3.1", diff --git a/tests/sch/transform-attribute.test.tsx b/tests/sch/transform-attribute.test.tsx index 5b2204a..f7c065b 100644 --- a/tests/sch/transform-attribute.test.tsx +++ b/tests/sch/transform-attribute.test.tsx @@ -1,7 +1,7 @@ import { test, expect } from "bun:test" import { convertCircuitJsonToSchematicSvg } from "lib" -test.skip("svg should have data-real-to-screen-transform attribute", () => { +test("svg should have data-real-to-screen-transform attribute", () => { const svg = convertCircuitJsonToSchematicSvg([ { type: "schematic_box",