diff --git a/packages/core/src/kiwi/node-change/convert.ts b/packages/core/src/kiwi/node-change/convert.ts index c4df4608f..76efe79cb 100644 --- a/packages/core/src/kiwi/node-change/convert.ts +++ b/packages/core/src/kiwi/node-change/convert.ts @@ -252,6 +252,12 @@ function convertCornerProps( } } +function importedTextLineHeight(nc: NodeChange): number | null { + const derivedLineHeight = nc.derivedTextData?.baselines?.[0]?.lineHeight + if (derivedLineHeight !== undefined && Number.isFinite(derivedLineHeight)) return derivedLineHeight + return convertLineHeight(nc.lineHeight, nc.fontSize) +} + function convertTextProps( nc: NodeChange ): Pick< @@ -288,7 +294,7 @@ function convertTextProps( textAutoResize: (nc.textAutoResize ?? 'NONE') as TextAutoResize, textCase: (nc.textCase ?? 'ORIGINAL') as TextCase, textDecoration: mapTextDecoration(nc.textDecoration as string), - lineHeight: convertLineHeight(nc.lineHeight, nc.fontSize), + lineHeight: importedTextLineHeight(nc), letterSpacing: convertLetterSpacing(nc.letterSpacing, nc.fontSize), maxLines: (nc.maxLines ?? null) as number | null, styleRuns: importStyleRuns(nc), diff --git a/tests/engine/io/fig/import/legacy/text.test.ts b/tests/engine/io/fig/import/legacy/text.test.ts index 065a96914..8f8352715 100644 --- a/tests/engine/io/fig/import/legacy/text.test.ts +++ b/tests/engine/io/fig/import/legacy/text.test.ts @@ -21,6 +21,34 @@ describe('fig-import: text properties', () => { expect(n.textAlignHorizontal).toBe('CENTER') }) + test('uses derived line metrics for imported Figma text rendering', () => { + const graph = importNodeChanges([ + doc(), + canvas(), + node('TEXT', 10, 1, { + textData: { characters: 'Default' }, + fontSize: 14, + lineHeight: { value: 36, units: 'PIXELS' }, + derivedTextData: { + layoutSize: { x: 49, y: 14 }, + baselines: [ + { + firstCharacter: 0, + endCharacter: 7, + position: { x: 0, y: 12.09 }, + width: 48.25, + lineY: 0, + lineHeight: 16.94, + lineAscent: 13 + } + ] + } + } as Partial) + ]) + const n = graph.getChildren(graph.getPages()[0].id)[0] + expect(n.lineHeight).toBe(16.94) + }) + test('font weight mapping', () => { const cases = [ ['Bold', 700],