FontName
interface Font {
fontName: FontName
}
interface FontName {
readonly family: string
readonly style: string
readonly variationSettings?: FontVariationSettings
}
Describes a font used by a text node. For example, the default font is { family: "Inter", style: "Regular" }.
Reads always include family and style. For variable fonts, they also include variationSettings with every axis the family defines. Static fonts omit variationSettings.
variationSettings
The variable font axis values applied to the text, for example { wght: 600, slnt: -10 }. Absent for a static font.
Reading reports every axis the family defines. When setting, an omitted axis keeps the value of the named instance style refers to, so { wght: 900 } on Inter Regular changes only the weight and leaves slant at Regular's default. Setting an axis the family does not define throws; use figma.getFontFamilyVariationAxes to discover the valid tags.
FontVariationSettings
interface FontVariationSettings {
readonly [axis: string]: number
}
Variable font axis values keyed by OpenType variation axis tag, mirroring the CSS font-variation-settings property. A tag is always four ASCII characters, for example "wght", "wdth", "slnt", or "opsz".
(async () => {
const text = figma.createText()
await figma.loadFontAsync({ family: 'Inter', style: 'Regular' })
text.fontName = {
family: 'Inter',
style: 'Regular',
variationSettings: { wght: 600, slnt: -5 },
}
text.characters = 'Hello, variable fonts!'
})()
FontNameInput
interface FontNameInput {
readonly family: string
readonly style?: string
readonly variationSettings?: FontVariationSettings
}
A font to apply where style can be inferred rather than named. Unlike FontName, style may be omitted, in which case Figma resolves the named instance that most closely matches variationSettings. Reads always return a fully populated FontName.
Accepted by figma.loadFontAsync, setRangeFontName, and when assigning fontName.
Omitting style in loadFontAsync loads every style of the family (variable or static). Omitting style when setting a font lets Figma pick the named instance closest to variationSettings. for example { family: 'Inter', variationSettings: { wght: 900 } } resolves to Inter Black.
(async () => {
await figma.loadFontAsync({ family: 'Inter' })
const text = figma.createText()
text.characters = 'Hello'
text.setRangeFontName(0, text.characters.length, {
family: 'Inter',
variationSettings: { wght: 900 },
})
// Read back: { family: 'Inter', style: 'Black', variationSettings: { wght: 900, slnt: 0 } }
console.log(text.fontName)
})()