@lightningjs/renderer
Version:
Lightning 3 Renderer
92 lines (91 loc) • 3.09 kB
TypeScript
import type { NormalizedFontMetrics } from '../../../font-face-types/TrFontFace.js';
import type { WebTrFontFace } from '../../../font-face-types/WebTrFontFace.js';
import { type TextBaseline } from './types.js';
/**
* Returns CSS font setting string for use in canvas context.
*
* @param fontFace
* @param fontStyle
* @param fontSize
* @param precision
* @param defaultFontFace
* @returns
*/
export declare function getFontSetting(fontFace: string | string[], fontStyle: string, fontSize: number, precision: number, defaultFontFace: string): string;
/**
* Returns true if the given character is a zero-width space.
*
* @param space
*/
export declare function isZeroWidthSpace(space: string): boolean;
/**
* Returns true if the given character is a zero-width space or a regular space.
*
* @param space
*/
export declare function isSpace(space: string): boolean;
/**
* Converts a string into an array of tokens and the words between them.
*
* @param tokenRegex
* @param text
*/
export declare function tokenizeString(tokenRegex: RegExp, text: string): string[];
/**
* Measure the width of a string accounting for letter spacing.
*
* @param context
* @param word
* @param space
*/
export declare function measureText(word: string, space: number | undefined, context: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D): number;
/**
* Get the font metrics for a font face.
*
* @remarks
* This function will attempt to grab the explicitly defined metrics from the
* font face first. If the font face does not have metrics defined, it will
* attempt to calculate the metrics using the browser's measureText method.
*
* If the browser does not support the font metrics API, it will use some
* default values.
*
* @param context
* @param fontFace
* @param fontSize
* @returns
*/
export declare function getWebFontMetrics(context: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D, fontFace: WebTrFontFace, fontSize: number): NormalizedFontMetrics;
export interface WrapTextResult {
l: string[];
n: number[];
}
/**
* Applies newlines to a string to have it optimally fit into the horizontal
* bounds set by the Text object's wordWrapWidth property.
*
* @param text
* @param wordWrapWidth
* @param suffix
* @param context
*/
export declare function wrapWord(word: string, wordWrapWidth: number, suffix: string, context: CanvasRenderingContext2D): string;
/**
* Applies newlines to a string to have it optimally fit into the horizontal
* bounds set by the Text object's wordWrapWidth property.
*/
export declare function wrapText(text: string, wordWrapWidth: number, letterSpacing: number, indent: number | undefined, context: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D): {
l: string[];
n: number[];
};
/**
* Calculate height for the canvas
*
* @param textBaseline
* @param fontSize
* @param lineHeight
* @param numLines
* @param offsetY
* @returns
*/
export declare function calcHeight(textBaseline: TextBaseline, fontSize: number, lineHeight: number, numLines: number): number;