import { Point } from '../geom/point.js'; import { Rectangle } from '../geom/rectangle.js'; import { Image } from './image.js'; import type { Game } from '../core/game.js'; import type { Matrix } from '../geom/matrix.js'; import type { RenderSession } from './render_session.js'; /** The font shorthand split into its CSS parts. */ export type FontComponents = { font?: string; fontStyle?: string; fontVariant?: string; fontWeight?: string | number; fontSize?: string | number; fontFamily?: string; }; /** Style accepted by Text, as supplied by callers; setStyle fills in every default. */ export type TextStyle = FontComponents & { align?: string; backgroundColor?: string | null; boundsAlignH?: string; boundsAlignV?: string; fill?: string; maxLines?: number; shadowBlur?: number; shadowColor?: string; shadowFill?: boolean; shadowOffsetX?: number; shadowOffsetY?: number; shadowStroke?: boolean; stroke?: string; strokeThickness?: number; tabs?: number | number[]; wordWrap?: boolean; wordWrapWidth?: number; }; /** The same style once setStyle has applied every default. */ export type ResolvedTextStyle = Required> & TextStyle & { backgroundColor: string | null; }; export declare class Text extends Image { type: number; canvas: HTMLCanvasElement; context: CanvasRenderingContext2D; padding: Point; textBounds: Rectangle | null; style: ResolvedTextStyle; colors: (string | null)[]; strokeColors: (string | null)[]; fontStyles: (string | null)[]; fontWeights: (string | null)[]; autoRound: boolean; useAdvancedWrap: boolean; _res: number; _text: string; _fontComponents: FontComponents; _lineSpacing: number; _charCount: number; _width: number; _height: number; dirty: boolean; /** * Creates a new Text object. * @param {Game} game - The game instance this text belongs to. * @param {number} x - The x position of the text. * @param {number} y - The y position of the text. * @param {string | number} text - The text content to display. * @param {object} style - The style settings for the text. */ constructor(game: Game, x: number, y: number, text?: string | number, style?: TextStyle); /** * Destroys this text object and cleans up resources. */ destroy(): void; /** * Sets the drop shadow properties for this text. * @param {number} x - The horizontal offset of the shadow. * @param {number} y - The vertical offset of the shadow. * @param {string} color - The color of the shadow. * @param {number} blur - The blur radius of the shadow. * @param {boolean} shadowStroke - Whether to apply the shadow to the stroke. * @param {boolean} shadowFill - Whether to apply the shadow to the fill. * @returns {Text} This Text object for chaining. */ setShadow(x?: number, y?: number, color?: string, blur?: number, shadowStroke?: boolean, shadowFill?: boolean): this; /** * Sets the style properties for this text. * @param {object} style - The style settings to apply. * @param {boolean} update - Whether to update the text immediately. * @returns {Text} This Text object for chaining. */ setStyle(style?: TextStyle | null, update?: boolean): this; /** * Updates the text content and renders it to the canvas. */ updateText(): void; /** * Renders a tabbed line of text to the canvas. * @param {string} line - The line of text to render. * @param {number} x - The x position to start rendering from. * @param {number} y - The y position to start rendering from. * @param {boolean} fill - True to fill the text, false to stroke it. */ renderTabLine(line: string, x: number, y: number, fill: boolean): void; /** * Updates the shadow properties for this text. * @param {string} state - The shadow state to update ('stroke' or 'fill'). */ updateShadow(state: boolean): void; /** * Reports whether any per-character style has been set, which forces the slower per-glyph path. * @returns {boolean} True when a colour, weight or style has been assigned to a character. */ hasCharacterStyles(): boolean; /** * Measures the width of a line of text. * @param {string} line - The line of text to measure. * @returns {number} The width of the line in pixels. */ measureLine(line: string): number; /** * Updates a line of text to the canvas. * @param {string} line - The line of text to update. * @param {number} x - The x position to start updating from. * @param {number} y - The y position to start updating from. */ updateLine(line: string, x: number, y: number): void; /** * Clears all color values from this text object. * @returns {Text} This Text object for chaining. */ clearColors(): this; /** * Clears all font style values from this text object. * @returns {Text} This Text object for chaining. */ clearFontValues(): this; /** * Adds a color to this text object at the specified position. * @param {string} color - The color to apply. * @param {number} position - The character position to apply the color at. * @returns {Text} This Text object for chaining. */ addColor(color: string, position: number): this; /** * Adds a stroke color to this text object at the specified position. * @param {number} color - The stroke color to apply. * @param {number} position - The character position to apply the stroke color at. * @returns {Text} This Text object for chaining. */ addStrokeColor(color: string, position: number): this; /** * Adds a font style to this text object at the specified position. * @param {object} style - The font style to apply. * @param {number} position - The character position to apply the font style at. * @returns {Text} This Text object for chaining. */ addFontStyle(style: string, position: number): this; /** * Adds a font weight to this text object at the specified position. * @param {number} weight - The font weight to apply. * @param {number} position - The character position to apply the font weight at. * @returns {Text} This Text object for chaining. */ addFontWeight(weight: string, position: number): this; /** * Precalculates word wrap for the given text. * @param {string} text - The text to precalculate word wrap for. * @returns {string[]} The wrapped lines of text. */ precalculateWordWrap(text: string): string[]; /** * Runs word wrap on the given text. * @param {string} text - The text to run word wrap on. * @returns {string} The wrapped text. */ runWordWrap(text: string): string; /** * Runs advanced word wrap on the given text. * @param {string} text - The text to run advanced word wrap on. * @returns {string} The wrapped text. * @throws {Error} If the wordWrapWidth setting is less than a single character. */ advancedWordWrap(text: string): string; /** * Runs basic word wrap on the given text. * @param {string} text - The text to run basic word wrap on. * @returns {string} The wrapped text. */ basicWordWrap(text: string): string; /** * Updates the font properties based on the given components. * @param {object} components - The font components to update from. */ updateFont(components: FontComponents): void; /** * Converts a font string to components. * @param {string} font - The font string to convert. * @returns {{ font: string, fontStyle?: string, fontVariant?: string, fontWeight?: string, fontSize?: string, fontFamily?: string }} The font components. */ fontToComponents(font: string): FontComponents; /** * Converts font components to a font string. * @param {object} components - The font components to convert. * @returns {string} The font string. */ componentsToFont(components: FontComponents): string; /** * Sets the text content of this object. * @param {string} text - The new text to set. * @param {boolean} immediate - If true, updates the text immediately. * @returns {Text} This Text object for chaining. */ setText(text: string | number, immediate?: boolean): this; /** * Parses a list of text into this object. * @param {string[]|string[][]} list - The list of text to parse. * @returns {Text} This Text object for chaining. */ parseList(list: string[] | string[][]): this; /** * Sets the text bounds for this object. * @param {number} x - The x position of the bounds. * @param {number} y - The y position of the bounds. * @param {number} width - The width of the bounds. * @param {number} height - The height of the bounds. * @returns {Text} This Text object for chaining. */ setTextBounds(x: number, y: number, width: number, height: number): this; /** * Updates the texture of this object. */ updateTexture(): void; /** * Renders this text object using WebGL. * @param {object} renderSession - The render session to use. */ renderWebGL(renderSession: RenderSession): void; /** * Renders this text object using Canvas. * @param {object} renderSession - The render session to use. */ renderCanvas(renderSession: RenderSession): void; /** * Gets the font properties cache object. * @returns {{[key: string]: {ascent: number, descent: number, fontSize: number}}} The font properties cache. */ getFontPropertiesCache(): Record; /** * Gets the font properties canvas element. * @returns {HTMLCanvasElement} The font properties canvas element. */ getFontPropertiesCanvas(): HTMLCanvasElement; /** * Gets the font properties canvas context. * @returns {CanvasRenderingContext2D} The font properties canvas context. */ getFontPropertiesContext(): CanvasRenderingContext2D; /** * Determines the font properties for a given font. * @param {string} font - The font to determine properties for. * @returns {object} The font properties. */ determineFontProperties(font: string): FontProperties; /** * Determines font properties using a fallback method. * @param {string} fontStyle - The font style to determine properties for. * @returns {{ascent: number, descent: number, fontSize: number}} The font properties. */ determineFontPropertiesFallback(fontStyle: string): FontProperties; /** * Gets the bounds of this text object. * @param {Matrix} matrix - The transformation matrix to use. * @returns {Rectangle} The bounds of this text object. */ getBounds(matrix?: Matrix | null): Rectangle; /** * Gets the text content of this object. * @returns {string} The current text content. */ get text(): string; /** * Sets the text content of this object. * @param {string | number | boolean | Date} value - The new text content to set. */ set text(value: string | number); /** * Gets the CSS font string for this object. * @returns {string} The CSS font string. */ get cssFont(): string; /** * Sets the CSS font string for this object. * @param {string} value - The new CSS font string to set. */ set cssFont(value: string); /** * Gets the font family of this object. * @returns {number} The font family. */ get font(): string; /** * Sets the font family of this object. * @param {string} value - The new font family to set. */ set font(value: string); /** * Gets the font size of this object. * @returns {number} The font size. */ get fontSize(): number; /** * Sets the font size of this object. * @param {number} value - The new font size to set. */ set fontSize(value: number); /** * Gets the font weight of this object. * @returns {string} The font weight. */ get fontWeight(): string; /** * Sets the font weight of this object. * @param {string} value - The new font weight to set. */ set fontWeight(value: string); /** * Gets the font style of this object. * @returns {string} The font style. */ get fontStyle(): string; /** * Sets the font style of this object. * @param {string} value - The new font style to set. */ set fontStyle(value: string); /** * Gets the font variant of this object. * @returns {string} The font variant. */ get fontVariant(): string; /** * Sets the font variant of this object. * @param {string} value - The new font variant to set. */ set fontVariant(value: string); /** * Gets the fill color of this object. * @returns {number} The fill color. */ get fill(): string; /** * Sets the fill color of this object. * @param {string} value - The new fill color to set. */ set fill(value: string); /** * Gets the alignment of this object. * @returns {string} The text alignment. */ get align(): string; /** * Sets the alignment of this object. * @param {string} value - The new text alignment to set. */ set align(value: string); /** * Gets the resolution of this object. * @returns {number} The resolution. */ get resolution(): number; /** * Sets the resolution of this object. * @param {number} value - The new resolution to set. */ set resolution(value: number); /** * Gets the tabs setting of this object. * @returns {number} The tabs setting. */ get tabs(): number | number[]; /** * Sets the tabs setting of this object. * @param {number} value - The new tabs setting to set. */ set tabs(value: number | number[]); /** * Gets the horizontal bounds alignment of this object. * @returns {number} The horizontal bounds alignment. */ get boundsAlignH(): string; /** * Sets the horizontal bounds alignment of this object. * @param {number} value - The new horizontal bounds alignment to set. */ set boundsAlignH(value: string); /** * Gets the vertical bounds alignment of this object. * @returns {number} The vertical bounds alignment. */ get boundsAlignV(): string; /** * Sets the vertical bounds alignment of this object. * @param {number} value - The new vertical bounds alignment to set. */ set boundsAlignV(value: string); /** * Gets the stroke color of this object. * @returns {number} The stroke color. */ get stroke(): string; /** * Sets the stroke color of this object. * @param {string} value - The new stroke color to set. */ set stroke(value: string); /** * Gets the stroke thickness of this object. * @returns {number} The stroke thickness. */ get strokeThickness(): number; /** * Sets the stroke thickness of this object. * @param {number} value - The new stroke thickness to set. */ set strokeThickness(value: number); /** * Gets the word wrap setting of this object. * @returns {number} The word wrap setting. */ get wordWrap(): boolean; /** * Sets the word wrap setting of this object. * @param {boolean} value - The new word wrap setting to set. */ set wordWrap(value: boolean); /** * Gets the word wrap width of this object. * @returns {number} The word wrap width. */ get wordWrapWidth(): number; /** * Sets the word wrap width of this object. * @param {number} value - The new word wrap width to set. */ set wordWrapWidth(value: number); /** * Gets the line spacing of this object. * @returns {number} The line spacing. */ get lineSpacing(): number; /** * Sets the line spacing of this object. * @param {number} value - The new line spacing to set. */ set lineSpacing(value: number); /** * Gets the shadow offset X of this object. * @returns {number} The shadow offset X. */ get shadowOffsetX(): number; /** * Sets the shadow offset X of this object. * @param {number} value - The new shadow offset X to set. */ set shadowOffsetX(value: number); /** * Gets the shadow offset Y of this object. * @returns {number} The shadow offset Y. */ get shadowOffsetY(): number; /** * Sets the shadow offset Y of this object. * @param {number} value - The new shadow offset Y to set. */ set shadowOffsetY(value: number); /** * Gets the shadow color of this object. * @returns {number} The shadow color. */ get shadowColor(): string; /** * Sets the shadow color of this object. * @param {string} value - The new shadow color to set. */ set shadowColor(value: string); /** * Gets the shadow blur of this object. * @returns {number} The shadow blur. */ get shadowBlur(): number; /** * Sets the shadow blur of this object. * @param {number} value - The new shadow blur to set. */ set shadowBlur(value: number); /** * Gets the shadow stroke setting of this object. * @returns {number} The shadow stroke setting. */ get shadowStroke(): boolean; /** * Sets the shadow stroke setting of this object. * @param {boolean} value - The new shadow stroke setting to set. */ set shadowStroke(value: boolean); /** * Gets the shadow fill setting of this object. * @returns {number} The shadow fill setting. */ get shadowFill(): boolean; /** * Sets the shadow fill setting of this object. * @param {boolean} value - The new shadow fill setting to set. */ set shadowFill(value: boolean); /** * Gets the width of this object. * @returns {number} The width in pixels. */ get width(): number; /** * Sets the width of this object. * @param {number} value - The new width to set in pixels. */ set width(value: number); /** * Gets the height of this object. * @returns {number} The height in pixels. */ get height(): number; /** * Sets the height of this object. * @param {number} value - The new height to set in pixels. */ set height(value: number); } //# sourceMappingURL=text.d.ts.map