@chemicalluck/canvas-txt
Version:
Render multiline textboxes in HTML5 canvas with auto line breaks and better alignment system
38 lines (34 loc) • 1 kB
TypeScript
interface SplitTextProps {
ctx: CanvasRenderingContext2D;
text: string;
justify: boolean;
width: number;
}
declare function splitText({ ctx, text, justify, width, }: SplitTextProps): string[];
interface GetTextHeightProps {
ctx: CanvasRenderingContext2D;
text: string;
style: string;
}
declare function getTextHeight({ ctx, text, style, }: GetTextHeightProps): number;
interface CanvasTextConfig {
width: number;
height: number;
x: number;
y: number;
debug?: boolean;
align?: 'left' | 'center' | 'right';
vAlign?: 'top' | 'middle' | 'bottom';
drawStyle?: 'fill' | 'outline';
fontSize?: number;
fontWeight?: string;
fontStyle?: string;
fontVariant?: string;
font?: string;
lineHeight?: number;
justify?: boolean;
}
declare function drawText(ctx: CanvasRenderingContext2D, myText: string, inputConfig: CanvasTextConfig): {
height: number;
};
export { CanvasTextConfig, drawText, getTextHeight, splitText };