Class: TextStyle

PIXI.TextStyle

A TextStyle Object contains information to decorate a Text objects.

An instance can be shared between multiple Text objects; then changing the style will update all text objects using it.

A tool can be used to generate a text style here.

new PIXI.TextStyle (style)

Name Type Attributes Description
style Partial<PIXI.ITextStyle> <optional>

TextStyle properties to be set on the text. See PIXI.TextStyle.defaultStyle for the default values.

Example

import { TextStyle } from 'pixi.js';
const style = new TextStyle({
  fontFamily: ['Helvetica', 'Arial', 'sans-serif'],
  fontSize: 36,
});

Implements

Members

PIXI.TextStyle.defaultStyle PIXI.ITextStyle static

Default style options used for all TextStyle instances.

Properties:
Name Type Default Description
align 'left' | 'center' | 'right' | 'justify' "left"

See PIXI.TextStyle.align

breakWords boolean false

See PIXI.TextStyle.breakWords

dropShadow boolean false

See PIXI.TextStyle.dropShadow

dropShadowAlpha number 1

See PIXI.TextStyle.dropShadowAlpha

dropShadowAngle number Math.PI / 6

See PIXI.TextStyle.dropShadowAngle

dropShadowBlur number 0

See PIXI.TextStyle.dropShadowBlur

dropShadowColor string | number "black"

See PIXI.TextStyle.dropShadowColor

dropShadowDistance number 5

See PIXI.TextStyle.dropShadowDistance

fill string | Array<string> | number | Array<number> | CanvasGradient | CanvasPattern "black"

See PIXI.TextStyle.fill

fillGradientStops Array<number> []

See PIXI.TextStyle.fillGradientStops

fillGradientType PIXI.TEXT_GRADIENT PIXI.TEXT_GRADIENT.LINEAR_VERTICAL

See PIXI.TextStyle.fillGradientType

fontFamily string | Array<string> "Arial"

See PIXI.TextStyle.fontFamily

fontSize number | string 26

See PIXI.TextStyle.fontSize

fontStyle 'normal' | 'italic' | 'oblique' "normal"

See PIXI.TextStyle.fontStyle

fontVariant 'normal' | 'small-caps' "normal"

See PIXI.TextStyle.fontVariant

fontWeight 'normal' | 'bold' | 'bolder' | 'lighter' | '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900' "normal"

See PIXI.TextStyle.fontWeight

leading number 0

See PIXI.TextStyle.leading

letterSpacing number 0

See PIXI.TextStyle.letterSpacing

lineHeight number 0

See PIXI.TextStyle.lineHeight

lineJoin 'miter' | 'round' | 'bevel' "miter"

See PIXI.TextStyle.lineJoin

miterLimit number 10

See PIXI.TextStyle.miterLimit

padding number 0

See PIXI.TextStyle.padding

stroke string | number "black"

See PIXI.TextStyle.stroke

strokeThickness number 0

See PIXI.TextStyle.strokeThickness

textBaseline 'alphabetic' | 'top' | 'hanging' | 'middle' | 'ideographic' | 'bottom' "alphabetic"

See PIXI.TextStyle.textBaseline

trim boolean false

See PIXI.TextStyle.trim

whiteSpace 'normal' | 'pre' | 'pre-line' "pre"

See PIXI.TextStyle.whiteSpace

wordWrap boolean false

See PIXI.TextStyle.wordWrap

wordWrapWidth number 100

See PIXI.TextStyle.wordWrapWidth

align 'left' | 'center' | 'right' | 'justify'

Alignment for multiline text, does not affect single line text.

breakWords boolean

Indicates if lines can be wrapped within words, it needs wordWrap to be set to true.

dropShadow boolean

Set a drop shadow for the text.

dropShadowAlpha number

Set alpha for the drop shadow.

dropShadowAngle number

Set a angle of the drop shadow.

dropShadowBlur number

Set a shadow blur radius.

dropShadowColor number | string

A fill style to be used on the dropshadow e.g., 'red', '#00FF00'.

dropShadowDistance number

Set a distance of the drop shadow.

fill string | Array<string> | number | Array<number> | CanvasGradient | CanvasPattern

A canvas fillstyle that will be used on the text e.g., 'red', '#00FF00'.

Can be an array to create a gradient e.g., ['#000000','#FFFFFF'] MDN

fillGradientStops number[]

If fill is an array of colours to create a gradient, this array can set the stop points (numbers between 0 and 1) for the color, overriding the default behaviour of evenly spacing them.

fillGradientType PIXI.TEXT_GRADIENT

If fill is an array of colours to create a gradient, this can change the type/direction of the gradient.

fontFamily string | string[]

The font family, can be a single font name, or a list of names where the first is the preferred font.

fontSize number | string

The font size (as a number it converts to px, but as a string, equivalents are '26px','20pt','160%' or '1.6em')

fontStyle 'normal' | 'italic' | 'oblique'

The font style.

fontVariant 'normal' | 'small-caps'

The font variant.

fontWeight 'normal' | 'bold' | 'bolder' | 'lighter' | '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900'

The font weight.

leading number

The space between lines.

letterSpacing number

The amount of spacing between letters, default is 0.

lineHeight number

The line height, a number that represents the vertical space that a letter uses.

lineJoin 'miter' | 'round' | 'bevel'

The lineJoin property sets the type of corner created, it can resolve spiked text issues. Default is 'miter' (creates a sharp corner).

miterLimit number

The miter limit to use when using the 'miter' lineJoin mode.

This can reduce or increase the spikiness of rendered text.

padding number

Occasionally some fonts are cropped. Adding some padding will prevent this from happening by adding padding to all sides of the text.

stroke string | number

A canvas fillstyle that will be used on the text stroke, e.g., 'blue', '#FCFF00'

strokeThickness number

A number that represents the thickness of the stroke.

Default Value:
  • 0

textBaseline 'alphabetic' | 'top' | 'hanging' | 'middle' | 'ideographic' | 'bottom'

The baseline of the text that is rendered.

trim boolean

Trim transparent borders.

whiteSpace 'normal' | 'pre' | 'pre-line'

How newlines and spaces should be handled. Default is 'pre' (preserve, preserve).

value New lines Spaces
'normal' Collapse Collapse
'pre' Preserve Preserve
'pre-line' Preserve Collapse

wordWrap boolean

Indicates if word wrap should be used.

wordWrapWidth number

The width at which text will wrap, it needs wordWrap to be set to true.

Methods

Creates a new TextStyle object with the same values as this one. Note that the only the properties of the object are cloned.

Returns:
Type Description
PIXI.TextStyle New cloned TextStyle object

reset () void

Resets all properties to the defaults specified in TextStyle.prototype._default

toFontString () string

Generates a font style string to use for TextMetrics.measureFont().

Returns:
Type Description
string Font style string, for passing to TextMetrics.measureFont()