Skip to main content

VectorTextBuilder

Class

A mutable builder for an immutable VectorText run.

  • Snapchat: not supported
  • SPECS: fully supported
  • Camera Kit Web: not supported
  • Camera Kit Mobile: not supported
  • SnapchatNot supported — Available on SPECS only
  • SPECSFully supported
  • Camera Kit WebNot supported — Available on SPECS only
  • Camera Kit MobileNot supported — Available on SPECS only

Platform details

  • Snapchat — Not supported — Available on SPECS only.

  • SPECS — Fully supported.

  • Camera Kit Web — Not supported — Available on SPECS only.

  • Camera Kit Mobile — Not supported — Available on SPECS only.

Since Lens Scripting v374

A mutable builder for an immutable VectorText run. Start one with VectorTextBuilder.create, optionally refine with VectorTextBuilder#setWeight, VectorTextBuilder#setItalic, VectorTextBuilder#setLetterSpacing, and VectorTextBuilder#setHorizontalAlignment, then call VectorTextBuilder#build to produce the text run. The builder remains usable after build(). The font is the composite's font source (see VectorCompositeBuilder#setFontSource), not a per-run family.

Index

Example

var tb = VectorTextBuilder.create("Hello", 48);
tb.setWeight(700);
tb.setHorizontalAlignment(HorizontalAlignment.Center);
var text = tb.build();

Extends

Methods

build()

build(): VectorText

SPECS

Returns a new immutable VectorText that snapshots the current builder state. The builder remains usable afterward; the returned text run is an independent snapshot.

Returns

VectorText

Since

Lens Scripting Version 374


create()

static create(text, size): VectorTextBuilder

SPECS

Creates a builder for a text run with the given text content and font size. Throws if size is not greater than 0, or if size is not finite.

Parameters

ParameterTypeDescription
textstringThe text content (String).
sizenumberThe font size (Number, must be > 0), in canvas pixels.

Returns

VectorTextBuilder

Since

Lens Scripting Version 374


getTypeName()

static getTypeName(): TypeName<VectorTextBuilder>

SPECS

Returns the fully-qualified JavaScript type name for this class (for example, "Component.Camera"). This is a static accessor (no instance required) and returns the same value as the instance getTypeName().

Returns

TypeName<VectorTextBuilder>

Since

Lens Scripting Version 374

Overrides

ScriptObject.getTypeName


getTypeName()

getTypeName(): string

Returns the name of this object's type.

Returns

string

Inherited from

ScriptObject.getTypeName


isOfType()

isOfType(type): boolean

Returns true if the object matches or derives from the passed in type.

Parameters

ParameterType
typestring

Returns

boolean

Inherited from

ScriptObject.isOfType


isSame()

isSame(other): boolean

Returns true if this object is the same as other. Useful for checking if two references point to the same thing.

Parameters

ParameterType
otherScriptObject

Returns

boolean

Inherited from

ScriptObject.isSame


setHorizontalAlignment()

setHorizontalAlignment(horizontalAlignment): void

SPECS

Sets the HorizontalAlignment — where this run sits relative to its baseline position. Defaults to Left (the SVG start default).

Parameters

ParameterTypeDescription
horizontalAlignmentHorizontalAlignmentThe horizontal anchor.

Returns

void

Since

Lens Scripting Version 374


setItalic()

setItalic(italic): void

SPECS

Sets whether the run is italicized. Defaults to false.

Parameters

ParameterTypeDescription
italicbooleanWhether the run is italicized (Boolean).

Returns

void

Since

Lens Scripting Version 374


setLetterSpacing()

setLetterSpacing(spacing): void

SPECS

Sets additional spacing between characters, in canvas pixels. Must be finite. Defaults to 0. Throws if spacing is not finite.

Parameters

ParameterTypeDescription
spacingnumberThe letter spacing (Number, finite).

Returns

void

Since

Lens Scripting Version 374


setWeight()

setWeight(weight): void

SPECS

Sets the font weight. Must be between 100 and 900, inclusive. Defaults to 400 (normal). Throws if weight is outside [100, 900].

Parameters

ParameterTypeDescription
weightnumberThe font weight (Number, must be in [100, 900]).

Returns

void

Since

Lens Scripting Version 374