Text
Draw Text
The drawtext function is used to draw text on the canvas with specified parameters.
| Parameters | Type | Description | Default Value |
|---|---|---|---|
| text | string |
The text to be drawn. | "undefined" |
| [x, y] | number[] |
The coordinates [x, y] where the text will be drawn. | [0, 0] |
| fontSize | number |
The size of the font in pixels. | 24 |
| fontFamily | string |
The font family to use. | "sans-serif" |
| baseline | string |
The text baseline: "top", "middle", "bottom", or "alphabetic". |
"top" |
| textAlign | string |
The text alignment: "start", "end", "left", "right", or "center". |
"start" |
| angle | number |
The rotation angle of the text in degrees. | 0 |
| alpha | number |
The global alpha (transparency) value, between 0.0 and 1.0. |
1.0 |
Example

Load Font
The loadFont function asynchronously downloads a font from a provided URL and adds it to the document's fonts using the specified font family.
| Parameters | Type | Description | Default Value |
|---|---|---|---|
| fontFamily | string |
The font family name to assign to the loaded font. | "undefined" |
| fontURL | string |
The URL pointing to the font file to be downloaded and used. | "undefined" |
Example

Fit Text
Failure
Doens't properly fit text in some cases.
Tries to fit a text with the sepecified width, height and other parameters.
Returns the fontSize tha will fit with the provided data.
| Parameters | Type | Description | Default Value |
|---|---|---|---|
| text | string |
The text . | - |
| width | number |
The size of the max width the text can be in. | - |
| height | number |
The size of the max height the text can be in. | - |
| fontFamily | string |
The font family used for measuring the text. | - |
Measure Text Width
The measureTextWidth function calculates the width of a provided text string with a specified font size and font family.
| Parameters | Type | Description | Default Value |
|---|---|---|---|
| text | string |
The text to be measured. | "undefined" |
| fontSize | number |
The size of the font in pixels. | 24 |
| fontFamily | string |
The font family used for measuring the text. | "sans-serif" |