UNPKG

lazy-widgets

Version:

Typescript retained mode GUI for the HTML canvas API

35 lines (34 loc) 1.47 kB
import { type FillStyle } from '../theme/FillStyle.js'; import { AsyncImageBitmap } from './AsyncImageBitmap.js'; export interface TextImageBitmapOptions { resolution?: number; } /** * Renders text as an ImageBitmap, which can then be used in widgets that * consume a {@link BackingMediaSource}, like {@link Icon}. Useful for using * font icons instead of images. * * Height is retreived by measuring the fontBoundingBoxAscent and * fontBoundingBoxDescent (falling back to actualBoundingBoxAscent and * actualBoundingBoxDescent), as well as the hangingBaseline (falling back to * the actualBoundingBoxAscent of the `M` character). Width is measured from the * text being rendered, however, it's set to be the same as the height if it's * smaller than the height to avoid issues with thin font icons (such as * vertical ellipsis). The font is assumed to already be loaded by the time this * class is instantiated. * * Throws if a scratch canvas can't be created. */ export declare class TextImageBitmap extends AsyncImageBitmap { readonly text: string; readonly font: string; readonly fillStyle: FillStyle; private _bitmap; private _presentationHash; readonly width: number; readonly height: number; readonly resolution: number; constructor(text: string, font: string, fillStyle: FillStyle, options?: Readonly<TextImageBitmapOptions>); get bitmap(): ImageBitmap | null; get presentationHash(): number; }