fix(fig): apply derived glyph override patches

This commit is contained in:
Danila Poyarkov 2026-05-18 01:23:35 +03:00
parent 142a973193
commit 2fd28fbbc5
4 changed files with 27 additions and 18 deletions

View file

@ -1,4 +1,5 @@
import { convertLetterSpacing, convertLineHeight } from '#core/kiwi/node-change/convert'
import { convertFigmaDerivedTextGlyphs } from '#core/kiwi/node-change/derived-text-glyphs'
import type { DerivedSymbolOverride, OverrideContext } from '#core/kiwi/instance-overrides/types'
import type { SceneNode } from '#core/scene-graph'
@ -26,11 +27,13 @@ function resolveSizeOnlyPosition(
return withinParent ? { x: source.x, y: source.y } : { x: 0, y: 0 }
}
function buildDsdTextUpdates(d: DerivedSymbolOverride): Partial<SceneNode> {
function buildDsdTextUpdates(d: DerivedSymbolOverride, blobs: Uint8Array[]): Partial<SceneNode> {
const updates: Partial<SceneNode> = {}
if (d.fontSize !== undefined) updates.fontSize = d.fontSize
if (d.lineHeight !== undefined) updates.lineHeight = convertLineHeight(d.lineHeight, d.fontSize)
if (d.letterSpacing !== undefined) updates.letterSpacing = convertLetterSpacing(d.letterSpacing, d.fontSize)
const figmaDerivedTextGlyphs = convertFigmaDerivedTextGlyphs(d.derivedTextData, blobs)
if (figmaDerivedTextGlyphs.length > 0) updates.figmaDerivedTextGlyphs = figmaDerivedTextGlyphs
return updates
}
@ -40,7 +43,7 @@ export function buildDsdLayoutUpdates(
d: DerivedSymbolOverride,
target: SceneNode
): { updates: Partial<SceneNode>; hasSize: boolean } {
const updates: Partial<SceneNode> = buildDsdTextUpdates(d)
const updates: Partial<SceneNode> = buildDsdTextUpdates(d, ctx.blobs)
const figmaDerivedLayout: NonNullable<SceneNode['figmaDerivedLayout']> = {}
if (d.size) {

View file

@ -50,6 +50,7 @@ export interface DerivedSymbolOverride {
fontSize?: number
lineHeight?: NodeChange['lineHeight']
letterSpacing?: NodeChange['letterSpacing']
derivedTextData?: NodeChange['derivedTextData']
fillGeometry?: Array<{ windingRule?: string; commandsBlob?: number }>
strokeGeometry?: Array<{ windingRule?: string; commandsBlob?: number }>
}

View file

@ -7,6 +7,7 @@ import { guidToString } from './guid'
import { convertEffects, convertFills, convertStrokes } from './paint'
import { importStyleRuns } from './style-runs'
export { importStyleRuns } from './style-runs'
import { convertFigmaDerivedTextGlyphs } from './derived-text-glyphs'
import { convertLetterSpacing, convertLineHeight, mapTextDecoration } from './text-values'
export { convertEffects, convertFills, convertStrokes, setVariableColorResolver } from './paint'
export { convertLetterSpacing, convertLineHeight, mapTextDecoration } from './text-values'
@ -258,21 +259,6 @@ function importedTextLineHeight(nc: NodeChange): number | null {
return convertLineHeight(nc.lineHeight, nc.fontSize)
}
function convertFigmaDerivedTextGlyphs(nc: NodeChange, blobs: Uint8Array[]) {
return (nc.derivedTextData?.glyphs ?? [])
.map((glyph) => {
const blob = glyph.commandsBlob === undefined ? undefined : blobs[glyph.commandsBlob]
if (!blob) return null
return {
commandsBlob: blob,
x: glyph.position.x,
y: glyph.position.y,
fontSize: glyph.fontSize
}
})
.filter((glyph): glyph is NonNullable<typeof glyph> => !!glyph)
}
function convertTextProps(
nc: NodeChange,
blobs: Uint8Array[]
@ -320,7 +306,7 @@ function convertTextProps(
(getOpenPencilPluginValue(nc, TEXT_DIRECTION_PLUGIN_KEY) as
| SceneNode['textDirection']
| null) || 'AUTO',
figmaDerivedTextGlyphs: convertFigmaDerivedTextGlyphs(nc, blobs)
figmaDerivedTextGlyphs: convertFigmaDerivedTextGlyphs(nc.derivedTextData, blobs)
}
}

View file

@ -0,0 +1,19 @@
import type { NodeChange } from '#core/kiwi/binary/codec'
import type { FigmaDerivedTextGlyph } from '#core/scene-graph'
export function convertFigmaDerivedTextGlyphs(
derivedTextData: NodeChange['derivedTextData'],
blobs: Uint8Array[]
): FigmaDerivedTextGlyph[] {
return (derivedTextData?.glyphs ?? [])
.map((glyph) => {
if (glyph.commandsBlob === undefined) return null
return {
commandsBlob: blobs[glyph.commandsBlob],
x: glyph.position.x,
y: glyph.position.y,
fontSize: glyph.fontSize
}
})
.filter((glyph): glyph is NonNullable<typeof glyph> => !!glyph)
}