Canvacord

Font

Creates and registers a new Font instance for both canvas and builder apis.

new Font(data, [alias])
ParameterTypeDescriptionOptional
data

The font data

alias

The font alias. If not provided, a random UUID will be used.

const data = await readFile('path/to/font.ttf');
const font = new Font(data, 'my-font');

Properties

alias

The font alias. If not provided, a random UUID will be used.

const data = await readFile('path/to/font.ttf');
const font = new Font(data, 'my-font');

Type:string

data

The font data

Type:Buffer

name

The alias for this font.

Type:string

Methods

getData();

Returns the font data that includes information such as the font name, weight, data, and style.

Returns:FontOptions

toJSON();

JSON representation of this font.

Returns:FontOptions

toString();

String representation of this font.

Returns:string

unloadAll();

Unloads the font from the canvas and builder apis.

Returns:void

static fromBuffer(buffer, [alias]);

Creates a new Font instance from a buffer.

ParameterTypeDescriptionOptional
buffer

The buffer containing the font data

alias

The font alias. If not provided, a random UUID will be used.

const buffer = await readFile('path/to/font.ttf');
const font = Font.fromBuffer(buffer, 'my-font');

Returns:Font

static fromFile(path, [alias]);

Creates a new Font instance from a file.

ParameterTypeDescriptionOptional
path

The path to the font file

alias

The font alias. If not provided, a random UUID will be used.

const font = await Font.fromFile('path/to/font.ttf', 'my-font');

Returns:Promise<Font>

static fromFileSync(path, [alias]);

Creates a new Font instance from a file synchronously.

ParameterTypeDescriptionOptional
path

The path to the font file

alias

The font alias. If not provided, a random UUID will be used.

const font = Font.fromFileSync('path/to/font.ttf', 'my-font');

Returns:Font

static loadDefault();

Loads the default font bundled with this package.

const font = Font.loadDefault();

Returns:Font