Skip to main content

Editor.Assets.CustomVariationStyle

Class

A user-defined named style on a variable Editor.Assets.Font.

A user-defined named style on a variable Editor.Assets.Font. Holds the standard variation axis values (weight, width, slant, italic, opticalSize) plus any custom axes the font exposes (e.g. GRAD, YOPQ). Create one with Font.createVariationStyle() and apply it by setting preferredStyle on a Text component to its name.

Index

Example

// Add a heavy, narrow headline style to a variable font and use it on a Text component.
// Only the axes the font defines take effect.
export function applyHeadlineStyle(
font: Editor.Assets.Font,
text: Editor.Components.Text,
name: string,
): Editor.Assets.CustomVariationStyle {
if (!font.isVariableFont) {
throw new Error(`${font.name} is not a variable font`);
}
const style = font.createVariationStyle(name);
if (Editor.isNull(style)) {
throw new Error(`"${name}" is already a style name on ${font.name}`);
}
style.weight = 850;
style.width = 85;
text.fontSource = font;
text.preferredStyle = style.name;
console.log(`Text now uses ${font.name} ${style.name}`);
return style;
}

Extends

Properties

id

readonly id: Uuid

The unique id of the entity.

Inherited from

EntityStructure.id


italic

italic: boolean

Italic axis value (ital). If the font has no ital axis, the slant axis (slnt) changes instead.


meta

readonly meta: Meta

Metadata associated with this entity, providing access to its unique identifier and other descriptive properties.

Inherited from

EntityStructure.meta


name

readonly name: string

Name of the custom variation style. Assign it to Text.preferredStyle to change to this style.


opticalSize

opticalSize: number

Optical size axis value (opsz).


slant

slant: number

Slant axis value (slnt), in degrees.


type

readonly type: string

The entity's type.

Inherited from

EntityStructure.type


weight

weight: number

Weight axis value (wght).


width

width: number

Width axis value (wdth).

Methods

getDirectlyReferencedEntities()

getDirectlyReferencedEntities(): Entity[]

A list of entities which this entity has a reference to.

Returns

Entity[]

Inherited from

EntityStructure.getDirectlyReferencedEntities


getMeta()

static getMeta(): Meta

Returns metadata about this type.

Returns

Meta

Overrides

EntityStructure.getMeta


getOwnedEntities()

getOwnedEntities(): Entity[]

A list of entities which has a reference to this entity.

Returns

Entity[]

Inherited from

EntityStructure.getOwnedEntities


getTypeName()

static getTypeName(): string

Returns the type name of this class.

Returns

string

Overrides

EntityStructure.getTypeName


getTypeName()

getTypeName(): string

Returns the name of this object's type.

Returns

string

Inherited from

EntityStructure.getTypeName


isOfType()

isOfType(type): boolean

Returns true if the object is of the specified type.

Parameters

ParameterType
typestring

Returns

boolean

Inherited from

EntityStructure.isOfType


isSame()

isSame(other): boolean

Returns true if this object refers to the same instance as the given object.

Parameters

ParameterType
otherScriptObject

Returns

boolean

Inherited from

EntityStructure.isSame