AI-native design editor. Open-source Figma alternative.
fix(io): include text decoration export bounds
Danila Poyarkov4861b37e6462
diff --git a/packages/core/src/geometry.ts b/packages/core/src/geometry.tsindex 8ca104033..4150c7a6a 100644--- a/packages/core/src/geometry.ts+++ b/packages/core/src/geometry.ts@@ -226,6 +226,10 @@ export interface VisualBoundsNode {visible?: booleantype?: stringclipsContent?: boolean+ fontSize?: number+ textDecoration?: string+ textUnderlineOffset?: number | null+ textDecorationThickness?: number | null}export function unionVisualBounds(@@ -333,6 +337,13 @@ export function nodeVisualBounds(bounds = unionVisualBounds(bounds, transformedLocalBounds(node, localGeometry, abs)) ?? bounds}+ if (node.type === 'TEXT' && node.textDecoration && node.textDecoration !== 'NONE') {+ const fontSize = node.fontSize ?? 14+ const underlineOffset = node.textUnderlineOffset ?? fontSize * 0.18+ const thickness = node.textDecorationThickness ?? Math.max(1, fontSize / 16)+ bounds.maxY += underlineOffset + thickness + fontSize * 0.35+ }+return bounds}diff --git a/packages/docs/development/roadmap.md b/packages/docs/development/roadmap.mdindex 91786c2cb..12b5bb028 100644--- a/packages/docs/development/roadmap.md+++ b/packages/docs/development/roadmap.md@@ -195,7 +195,7 @@ OpenPencil deliberately preserves many Figma/Kiwi fields even when they are not| Version/sort/publish/library metadata | ↩ | — | ◐ | Assets UI shows a subset; publish/update workflow is missing. || Variable and parameter consumption maps | ✅ | ◐ | ◐ | Filtered/preserved for safe round-trip; normalized bindings cover common cases. || Page fields: background, page type, guides | ↩ | ◐ | — | Background color and background paints round-trip for imported pages; page type/guides mostly round-trip. Guides are not rendered/editable. |-| Text internals: `textData`, layout versions, font version, derived data | ✅ | ✅ | — | Important for text fidelity; most internals are not editable. Imported derived text data, leading trim, decoration style, underline decoration paint/offset/thickness/skip-ink, semantic font metadata, and raw OpenType feature toggles are preserved for round-trip when safe; decoration style/thickness/color and leading trim now render through CanvasKit. |+| Text internals: `textData`, layout versions, font version, derived data | ✅ | ✅ | — | Important for text fidelity; most internals are not editable. Imported derived text data, leading trim, decoration style, underline decoration paint/offset/thickness/skip-ink, semantic font metadata, and raw OpenType feature toggles are preserved for round-trip when safe; decoration style/thickness/color and leading trim now render through CanvasKit, and raster export bounds account for decoration overflow. || `fontVariations` | ✅ | ✅ | — | Variable font axes are imported, rendered, and exported for text nodes and style runs. || Raw paint/effect/vector/geometry payloads | ✅ | ✅ | ◐ | Converted fields render; raw payloads preserve Figma import/export details, including mask, background paint, layout grid, export setting, and prototype interaction metadata where safe. |diff --git a/tests/engine/geometry/text-visual-bounds.test.ts b/tests/engine/geometry/text-visual-bounds.test.tsnew file mode 100644index 000000000..f3621f6c3--- /dev/null+++ b/tests/engine/geometry/text-visual-bounds.test.ts@@ -0,0 +1,37 @@+import { describe, expect, test } from 'bun:test'++import { nodeVisualBounds } from '#core/geometry'+import type { SceneNode } from '#core/scene-graph'++describe('text visual bounds', () => {+ test('includes decoration overflow below text nodes', () => {+ const base = {+ id: 'text',+ type: 'TEXT',+ visible: true,+ width: 100,+ height: 23,+ rotation: 0,+ flipX: false,+ flipY: false,+ strokes: [],+ effects: [],+ fillGeometry: [],+ strokeGeometry: [],+ childIds: [],+ fontSize: 32,+ textDecoration: 'NONE',+ textUnderlineOffset: null,+ textDecorationThickness: null+ } as SceneNode++ const normal = nodeVisualBounds(base, () => ({ x: 10, y: 20 }))+ const decorated = nodeVisualBounds(+ { ...base, textDecoration: 'UNDERLINE', textUnderlineOffset: 5, textDecorationThickness: 2 },+ () => ({ x: 10, y: 20 })+ )++ expect(normal.maxY).toBe(43)+ expect(decorated.maxY).toBeGreaterThan(normal.maxY)+ })+})diff --git a/tests/fixtures/figma-oracles/visual-comparison-report.json b/tests/fixtures/figma-oracles/visual-comparison-report.jsonindex c58377f31..654e00eb1 100644--- a/tests/fixtures/figma-oracles/visual-comparison-report.json+++ b/tests/fixtures/figma-oracles/visual-comparison-report.json@@ -21,14 +21,15 @@{"name": "rich-text-decorations","nodeId": "296488:2238",- "output": "/tmp/open-pencil-oracles/rich-text/decorations-norm",+ "output": "/tmp/open-pencil-oracles/rich-text/decorations-bounds-derived","figmaSize": "493x41",- "openPencilSize": "493x23",+ "openPencilSize": "493x42","normalization": "Padded/cropped without scaling before diff",- "differentPixels": 6881,- "differentPercent": 34.04,- "rmseNormalized": 0.243701,- "finding": "OpenPencil imports style-run decoration metadata, but exact Figma text height/line metrics still differ substantially."+ "differentPixels": 7568,+ "differentPercent": 37.44,+ "rmseNormalized": 0.22616,+ "previousOpenPencilSize": "493x23",+ "finding": "Text export bounds now include decoration overflow so underlines are not clipped, but derived glyph rendering still approximates rich decoration style/color poorly."},{"name": "nested-luminance-mask",@@ -65,6 +66,6 @@"nextActions": ["Continue tuning pattern row spacing and tile origin against pattern-visible-source-frame.","Use perceptual/color-tolerant image diff for mask comparisons instead of raw absolute-error counts.",- "Tune rich text line metrics before treating underline placement diffs as actionable."+ "Render rich decoration styles/colors for Figma-derived glyph paths or reliably fall back to paragraph text when fonts are available."]}