fix(fig): use derived text line metrics
This commit is contained in:
parent
2072f2e916
commit
ff0f072aef
|
|
@ -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),
|
||||
|
|
|
|||
|
|
@ -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<NodeChange>)
|
||||
])
|
||||
const n = graph.getChildren(graph.getPages()[0].id)[0]
|
||||
expect(n.lineHeight).toBe(16.94)
|
||||
})
|
||||
|
||||
test('font weight mapping', () => {
|
||||
const cases = [
|
||||
['Bold', 700],
|
||||
|
|
|
|||
Loading…
Reference in a new issue