Skip to content

@mbtech-nl/bitmap / renderText

Function: renderText()

ts
function renderText(text: string, options?: TextRenderOptions): LabelBitmap;

Defined in: font/render.ts:53

Render an ASCII string into a packed 1bpp bitmap using the bundled font.

Each character is rasterised left-to-right with letterSpacing pixels of gap between glyphs. Code points outside 0x20..0x7F are replaced with a space (0x20).

Parameters

ParameterTypeDescription
textstringString to render. Must be non-empty.
optionsTextRenderOptionsFont, scale factors, letter spacing, and invert flag. See TextRenderOptions.

Returns

LabelBitmap

A 1bpp LabelBitmap sized to fit the rendered text.

Throws

If text is empty, or if scaleX/scaleY is not a positive integer, or if letterSpacing is not a non-negative integer.

Example

ts
const banner = renderText('HELLO', { scaleX: 2, scaleY: 2 });

Released under the MIT License.