Skip to content

AI-native design editor. Open-source Figma alternative.

fix(canvas): preserve text OpenType toggles

Danila Poyarkovc337905a020c
diff --git a/packages/core/src/canvas/text.ts b/packages/core/src/canvas/text.ts
index 10bfc2a72..5ea99436e 100644
--- a/packages/core/src/canvas/text.ts
+++ b/packages/core/src/canvas/text.ts
@@ -2,6 +2,7 @@ import type {
CanvasKit,
FontWeight,
Paragraph,
+ TextFontFeatures,
TextFontVariations,
TypefaceFontProvider
} from 'canvaskit-wasm'
@@ -173,6 +174,16 @@ export function textFontVariations(
return variations.map((variation) => ({ axis: variation.axis, value: variation.value }))
}
+export function textFontFeatures(
+ features: SceneNode['fontFeatures'] | undefined
+): TextFontFeatures[] | undefined {
+ if (!features || features.length === 0) return undefined
+ return features.map((feature) => ({
+ name: feature.tag.toLowerCase(),
+ value: feature.enabled ? 1 : 0
+ }))
+}
+
function textDecorationValue(ck: CanvasKit, decoration: string): number {
switch (decoration) {
case 'UNDERLINE':
@@ -228,6 +239,7 @@ function addStyledRuns(
slant: (s.italic ?? node.italic) ? ck.FontSlant.Italic : ck.FontSlant.Upright
},
fontVariations: textFontVariations(s.fontVariations ?? node.fontVariations),
+ fontFeatures: textFontFeatures(s.fontFeatures ?? node.fontFeatures),
letterSpacing: s.letterSpacing ?? (node.letterSpacing || 0),
decoration: textDecorationValue(ck, s.textDecoration ?? node.textDecoration),
heightMultiplier: runLineHeight ? runLineHeight / runFontSize : undefined,
@@ -284,6 +296,7 @@ export function buildParagraph(
slant: node.italic ? ck.FontSlant.Italic : ck.FontSlant.Upright
},
fontVariations: textFontVariations(node.fontVariations),
+ fontFeatures: textFontFeatures(node.fontFeatures),
letterSpacing: node.letterSpacing || 0,
decoration: textDecorationValue(ck, node.textDecoration),
heightMultiplier: node.lineHeight ? node.lineHeight / baseFontSize : undefined,
diff --git a/packages/core/src/kiwi/fig/node-change/convert.ts b/packages/core/src/kiwi/fig/node-change/convert.ts
index 01f2e8224..112e0c6b3 100644
--- a/packages/core/src/kiwi/fig/node-change/convert.ts
+++ b/packages/core/src/kiwi/fig/node-change/convert.ts
@@ -8,6 +8,7 @@ import { convertEffects, convertFills, convertStrokes } from './paint'
import { importStyleRuns } from './style-runs'
export { importStyleRuns } from './style-runs'
import { convertFigmaDerivedTextGlyphs } from './derived-text-glyphs'
+import { convertFontFeatures } from './font-features'
import { convertFontVariations } from './font-variations'
import { convertLetterSpacing, convertLineHeight, mapTextDecoration } from './text-values'
export { convertEffects, convertFills, convertStrokes, setVariableColorResolver } from './paint'
@@ -294,6 +295,7 @@ function convertTextProps(
| 'maxLines'
| 'styleRuns'
| 'fontVariations'
+ | 'fontFeatures'
| 'textTruncation'
| 'textDirection'
| 'figmaDerivedLayout'
@@ -319,6 +321,7 @@ function convertTextProps(
maxLines: (nc.maxLines ?? null) as number | null,
styleRuns: importStyleRuns(nc),
fontVariations: convertFontVariations(nc),
+ fontFeatures: convertFontFeatures(nc),
textTruncation: (nc.textTruncation as string) === 'ENDING' ? 'ENDING' : 'DISABLED',
textDirection:
(getOpenPencilPluginValue(nc, TEXT_DIRECTION_PLUGIN_KEY) as
@@ -775,6 +778,8 @@ export const FIGMA_RAW_NODE_FIELD_KEYS = [
'textUserLayoutVersion',
'textExplicitLayoutVersion',
'fontVariations',
+ 'fontVariantCommonLigatures',
+ 'fontVariantContextualLigatures',
'derivedTextData',
'fillPaints',
'strokePaints',
diff --git a/packages/core/src/kiwi/fig/node-change/font-features.ts b/packages/core/src/kiwi/fig/node-change/font-features.ts
new file mode 100644
index 000000000..b4750a60d
--- /dev/null
+++ b/packages/core/src/kiwi/fig/node-change/font-features.ts
@@ -0,0 +1,23 @@
+import type { NodeChange } from '#core/kiwi/fig/codec'
+import type { FontFeature } from '#core/scene-graph'
+
+const LIGATURE_FEATURES = [
+ ['fontVariantCommonLigatures', 'LIGA'],
+ ['fontVariantContextualLigatures', 'CALT']
+] as const
+
+export function convertFontFeatures(nc: NodeChange): FontFeature[] {
+ const features: FontFeature[] = []
+ for (const [field, tag] of LIGATURE_FEATURES) {
+ const enabled = nc[field]
+ if (enabled !== undefined) features.push({ tag, enabled })
+ }
+ return features
+}
+
+export function applyFontFeaturesToKiwi(nc: NodeChange, features: FontFeature[]): void {
+ for (const feature of features) {
+ if (feature.tag === 'LIGA') nc.fontVariantCommonLigatures = feature.enabled
+ else if (feature.tag === 'CALT') nc.fontVariantContextualLigatures = feature.enabled
+ }
+}
diff --git a/packages/core/src/kiwi/fig/node-change/serialize.ts b/packages/core/src/kiwi/fig/node-change/serialize.ts
index 968a2729c..43a053ae3 100644
--- a/packages/core/src/kiwi/fig/node-change/serialize.ts
+++ b/packages/core/src/kiwi/fig/node-change/serialize.ts
@@ -19,6 +19,7 @@ import type { Color, GUID, Matrix } from '#core/types'
import { guidToString, stringToGuid, VARIABLE_BINDING_FIELDS } from './convert'
import { sceneNodeToKiwiWithContext, type KiwiNodeChange } from './export-node'
+import { applyFontFeaturesToKiwi } from './font-features'
import { stringToFigmaAxisTag } from './font-variations'
import {
BOUND_VARIABLES_PLUGIN_KEY,
@@ -220,6 +221,9 @@ function exportTextData(node: SceneNode): NodeChange['textData'] {
if (style.fontVariations && style.fontVariations.length > 0) {
override.fontVariations = style.fontVariations.map(fontVariationToKiwi)
}
+ if (style.fontFeatures && style.fontFeatures.length > 0) {
+ applyFontFeaturesToKiwi(override as NodeChange, style.fontFeatures)
+ }
if (style.letterSpacing !== undefined) {
override.letterSpacing = { value: style.letterSpacing, units: 'PIXELS' }
}
@@ -327,6 +331,7 @@ function serializeTextProps(
nc.textDecorationSkipInk = true
nc.fontVariantCommonLigatures = true
nc.fontVariantContextualLigatures = true
+ applyFontFeaturesToKiwi(nc, node.fontFeatures)
nc.fontVersion = ''
nc.emojiImageSet = 'APPLE'
if (fontDigestMap) {
diff --git a/packages/core/src/kiwi/fig/node-change/style-runs.ts b/packages/core/src/kiwi/fig/node-change/style-runs.ts
index 18aa6b5e2..1ba31339b 100644
--- a/packages/core/src/kiwi/fig/node-change/style-runs.ts
+++ b/packages/core/src/kiwi/fig/node-change/style-runs.ts
@@ -2,6 +2,7 @@ import type { NodeChange } from '#core/kiwi/fig/codec'
import type { CharacterStyleOverride, StyleRun } from '#core/scene-graph'
import { styleToWeight } from '#core/text/fonts'
+import { convertFontFeatures } from './font-features'
import { convertFontVariations } from './font-variations'
import { convertFills } from './paint'
import { convertLetterSpacing, convertLineHeight, mapTextDecoration } from './text-values'
@@ -19,6 +20,8 @@ function convertStyleOverride(
if (override.fontSize !== undefined) style.fontSize = override.fontSize
const fontVariations = convertFontVariations(override)
if (fontVariations.length > 0) style.fontVariations = fontVariations
+ const fontFeatures = convertFontFeatures(override)
+ if (fontFeatures.length > 0) style.fontFeatures = fontFeatures
if (override.letterSpacing) {
style.letterSpacing = convertLetterSpacing(
override.letterSpacing,
diff --git a/packages/core/src/scene-graph/copy.ts b/packages/core/src/scene-graph/copy.ts
index 31e91389c..42afb8696 100644
--- a/packages/core/src/scene-graph/copy.ts
+++ b/packages/core/src/scene-graph/copy.ts
@@ -41,7 +41,11 @@ export function copyStyleRun(r: StyleRun): StyleRun {
...r,
style: {
...r.style,
- fills: r.style.fills ? r.style.fills.map(copyFill) : undefined
+ fills: r.style.fills ? r.style.fills.map(copyFill) : undefined,
+ fontVariations: r.style.fontVariations
+ ? r.style.fontVariations.map((v) => ({ ...v }))
+ : undefined,
+ fontFeatures: r.style.fontFeatures ? r.style.fontFeatures.map((v) => ({ ...v })) : undefined
}
}
}
diff --git a/packages/core/src/scene-graph/node-defaults.ts b/packages/core/src/scene-graph/node-defaults.ts
index e5e02ed0a..ba947ee5d 100644
--- a/packages/core/src/scene-graph/node-defaults.ts
+++ b/packages/core/src/scene-graph/node-defaults.ts
@@ -87,6 +87,7 @@ export function createDefaultNode(
maxLines: null,
styleRuns: [],
fontVariations: [],
+ fontFeatures: [],
horizontalConstraint: 'MIN',
verticalConstraint: 'MIN',
strokeCap: 'NONE',
diff --git a/packages/core/src/scene-graph/source-metadata.ts b/packages/core/src/scene-graph/source-metadata.ts
index aaa6f8c72..395ab90bc 100644
--- a/packages/core/src/scene-graph/source-metadata.ts
+++ b/packages/core/src/scene-graph/source-metadata.ts
@@ -33,6 +33,7 @@ const RAW_NODE_FIELD_KEYS = new Set([
'maxLines',
'styleRuns',
'fontVariations',
+ 'fontFeatures',
'textTruncation',
'layoutMode',
'itemSpacing',
diff --git a/packages/core/src/scene-graph/types.ts b/packages/core/src/scene-graph/types.ts
index 66dd7b159..15c12ea8e 100644
--- a/packages/core/src/scene-graph/types.ts
+++ b/packages/core/src/scene-graph/types.ts
@@ -178,6 +178,11 @@ export interface FontVariation {
value: number
}
+export interface FontFeature {
+ tag: string
+ enabled: boolean
+}
+
export interface CharacterStyleOverride {
fontWeight?: number
italic?: boolean
@@ -188,6 +193,7 @@ export interface CharacterStyleOverride {
lineHeight?: number | null
fills?: Fill[]
fontVariations?: FontVariation[]
+ fontFeatures?: FontFeature[]
}
export interface StyleRun {
@@ -333,6 +339,7 @@ export interface SceneNode {
styleRuns: StyleRun[]
fontVariations: FontVariation[]
+ fontFeatures: FontFeature[]
horizontalConstraint: ConstraintType
verticalConstraint: ConstraintType
diff --git a/packages/docs/development/roadmap.md b/packages/docs/development/roadmap.md
index 56680045f..296c11192 100644
--- a/packages/docs/development/roadmap.md
+++ b/packages/docs/development/roadmap.md
@@ -157,7 +157,7 @@ Figma's design documentation groups features into these areas:
| Text case | ✅ | ◐ | — | ✅ | ✅ | Model/export/JSX support; UI missing. |
| Vertical text alignment | ✅ | ◐ | — | ✅ | ✅ | Modeled; UI/render parity needs more coverage. |
| Justified text | ✅ | ◐ | — | ✅ | ✅ | Modeled; UI does not expose it. |
-| Font variations / OpenType features | ✅ | ✅ | — | ✅ | — | Imported `fontVariations` are applied to CanvasKit text styles and exported; OpenType feature controls are not exposed. |
+| Font variations / OpenType features | ✅ | ✅ | — | ✅ | — | Imported `fontVariations` and common ligature toggles are applied to CanvasKit text styles and exported; broader OpenType controls are not exposed. |
| Variables: collections/modes/aliases | ✅ | ◐ | ◐ | ✅ | ✅ | Color/number/string/boolean model exists; inspector coverage is still incomplete. |
| Variables bound to fills/strokes | ✅ | ✅ | ✅ | ✅ | ✅ | Common color bindings render and edit. |
| Variables bound to text/layout/visibility/effects | ◐ | ◐ | ◐ | ◐ | ✅ | Some bindings exist; not full Figma property coverage. |
@@ -206,7 +206,7 @@ These are parsed or visible in Figma docs and most likely to cause visible diffe
1. **Masks** — tune remaining exact Figma stack semantics beyond common alpha/vector/luminance and consecutive-mask paths.
2. **Corner smoothing** — expand Figma fixture comparisons and tune remaining stroke/effect edge cases.
3. **Pattern fills/strokes** — support Figma pattern paint objects and transforms beyond image tile fills.
-4. **Variable-font fixtures** — broaden real-file coverage for variable axes and OpenType feature metadata.
+4. **Variable-font fixtures** — broaden real-file coverage for variable axes and additional OpenType feature metadata beyond common ligature toggles.
5. **Boolean operation editing** — improve inspector/tooling workflows for imported boolean-operation nodes.
6. **Layout grids and guides** — render/edit page guides and Figma layout grids, or clearly keep them round-trip-only.
7. **Full component property and slot workflows** — support authoring, not just preserving imported payloads.
diff --git a/tests/engine/io/fig/export/font-variations.test.ts b/tests/engine/io/fig/export/font-variations.test.ts
index b1707adfc..6a2a08934 100644
--- a/tests/engine/io/fig/export/font-variations.test.ts
+++ b/tests/engine/io/fig/export/font-variations.test.ts
@@ -10,11 +10,15 @@ describe('Figma font variation export', () => {
const text = graph.createNode('TEXT', page.id, {
text: 'Axis',
fontVariations: [{ axis: 'wght', value: 650 }],
+ fontFeatures: [{ tag: 'LIGA', enabled: false }],
styleRuns: [
{
start: 0,
length: 2,
- style: { fontVariations: [{ axis: 'wdth', value: 88 }] }
+ style: {
+ fontVariations: [{ axis: 'wdth', value: 88 }],
+ fontFeatures: [{ tag: 'CALT', enabled: false }]
+ }
}
]
})
@@ -25,8 +29,11 @@ describe('Figma font variation export', () => {
expect(nodeChange.fontVariations).toEqual([
{ axisTag: 0x77676874, axisName: 'wght', value: 650 }
])
+ expect(nodeChange.fontVariantCommonLigatures).toBe(false)
+ expect(nodeChange.fontVariantContextualLigatures).toBe(true)
expect(nodeChange.textData?.styleOverrideTable?.[0]?.fontVariations).toEqual([
{ axisTag: 0x77647468, axisName: 'wdth', value: 88 }
])
+ expect(nodeChange.textData?.styleOverrideTable?.[0]?.fontVariantContextualLigatures).toBe(false)
})
})
diff --git a/tests/engine/io/fig/import/font-variations.test.ts b/tests/engine/io/fig/import/font-variations.test.ts
index 4cfa1e2b8..81caa3760 100644
--- a/tests/engine/io/fig/import/font-variations.test.ts
+++ b/tests/engine/io/fig/import/font-variations.test.ts
@@ -23,7 +23,24 @@ describe('Figma font variation import', () => {
])
})
- test('imports styled-run variable font axes', () => {
+ test('imports base text OpenType feature toggles', () => {
+ const props = nodeChangeToProps(
+ {
+ type: 'TEXT',
+ textData: { characters: 'Ligatures' },
+ fontVariantCommonLigatures: false,
+ fontVariantContextualLigatures: true
+ } as NodeChange,
+ []
+ )
+
+ expect(props.fontFeatures).toEqual([
+ { tag: 'LIGA', enabled: false },
+ { tag: 'CALT', enabled: true }
+ ])
+ })
+
+ test('imports styled-run variable font axes and OpenType feature toggles', () => {
const runs = importStyleRuns({
type: 'TEXT',
fontSize: 16,
@@ -33,14 +50,22 @@ describe('Figma font variation import', () => {
styleOverrideTable: [
{
styleID: 1,
- fontVariations: [{ axisName: 'GRAD', value: -50 }]
+ fontVariations: [{ axisName: 'GRAD', value: -50 }],
+ fontVariantCommonLigatures: false
} as NodeChange
]
}
} as NodeChange)
expect(runs).toEqual([
- { start: 0, length: 2, style: { fontVariations: [{ axis: 'GRAD', value: -50 }] } }
+ {
+ start: 0,
+ length: 2,
+ style: {
+ fontVariations: [{ axis: 'GRAD', value: -50 }],
+ fontFeatures: [{ tag: 'LIGA', enabled: false }]
+ }
+ }
])
})
})
diff --git a/tests/engine/render/canvas/text-font-variations.test.ts b/tests/engine/render/canvas/text-font-variations.test.ts
index df3ce67c3..00d6816e8 100644
--- a/tests/engine/render/canvas/text-font-variations.test.ts
+++ b/tests/engine/render/canvas/text-font-variations.test.ts
@@ -1,6 +1,6 @@
import { describe, expect, test } from 'bun:test'
-import { textFontVariations } from '#core/canvas/text'
+import { textFontFeatures, textFontVariations } from '#core/canvas/text'
describe('canvas text font variations', () => {
test('passes imported variable font axes to CanvasKit text styles', () => {
@@ -19,4 +19,21 @@ describe('canvas text font variations', () => {
expect(textFontVariations([])).toBeUndefined()
expect(textFontVariations(undefined)).toBeUndefined()
})
+
+ test('passes imported OpenType feature toggles to CanvasKit text styles', () => {
+ expect(
+ textFontFeatures([
+ { tag: 'LIGA', enabled: false },
+ { tag: 'CALT', enabled: true }
+ ])
+ ).toEqual([
+ { name: 'liga', value: 0 },
+ { name: 'calt', value: 1 }
+ ])
+ })
+
+ test('omits font features when no toggles are set', () => {
+ expect(textFontFeatures([])).toBeUndefined()
+ expect(textFontFeatures(undefined)).toBeUndefined()
+ })
})