/** * Text Formatter * * Provides text formatting capabilities for ESC/POS thermal printers. * Supports alignment, font scaling, bold, underline, and inverse printing. * * @example * ```typescript * const formatter = new TextFormatter(); * const commands = [ * ...formatter.setStyle({ align: TextAlign.CENTER, bold: true }), * ...formatter.format('Title', { heightScale: 2, widthScale: 2 }), * ...formatter.resetStyle() * ]; * ``` */ /** * Text alignment options */ export declare enum TextAlign { LEFT = "left", CENTER = "center", RIGHT = "right" } /** * Text style configuration */ export interface TextStyle { /** Text alignment */ align?: TextAlign; /** Width scale factor (1-8) */ widthScale?: number; /** Height scale factor (1-8) */ heightScale?: number; /** Bold text */ bold?: boolean; /** Underline text */ underline?: boolean; /** Inverse printing (white on black) */ inverse?: boolean; } /** * Text formatter interface */ export interface ITextFormatter { /** Set text style */ setStyle(style: TextStyle): Uint8Array[]; /** Reset style to default */ resetStyle(): Uint8Array[]; /** Format text with optional style */ format(text: string, style?: TextStyle): Uint8Array[]; } /** * Text Formatter class * Generates ESC/POS formatting commands for thermal printers */ export declare class TextFormatter implements ITextFormatter { private currentStyle; /** * Set text style * * Generates ESC/POS commands to apply the specified text style. * Only generates commands for style properties that differ from current state. * * @param style - Text style to apply * @returns Array of ESC/POS command buffers * * @example * ```typescript * formatter.setStyle({ align: TextAlign.CENTER, bold: true }); * ``` */ setStyle(style: TextStyle): Uint8Array[]; /** * Reset text style to default * * Generates ESC/POS commands to reset all formatting to default values. * This ensures clean state for subsequent print operations. * * @returns Array of ESC/POS command buffers * * @example * ```typescript * formatter.resetStyle(); * ``` */ resetStyle(): Uint8Array[]; /** * Format text with optional style * * Applies the specified style, encodes the text, and optionally resets style. * This is a convenience method that combines setStyle + text encoding. * * @param text - Text content to format * @param style - Optional text style to apply * @returns Array of ESC/POS command buffers * * @example * ```typescript * formatter.format('Hello World', { bold: true, align: TextAlign.CENTER }); * ``` */ format(text: string, style?: TextStyle): Uint8Array[]; /** * Generate alignment command * * @param align - Text alignment * @returns ESC/POS alignment command */ align(align: TextAlign): Uint8Array[]; /** * Generate character size command * * @param width - Width scale (1-8) * @param height - Height scale (1-8) * @returns ESC/POS size command */ setSize(width: number, height: number): Uint8Array[]; /** * Generate bold command * * @param enabled - Enable or disable bold * @returns ESC/POS bold command */ setBold(enabled: boolean): Uint8Array[]; /** * Generate underline command * * @param enabled - Enable or disable underline * @returns ESC/POS underline command */ setUnderline(enabled: boolean): Uint8Array[]; /** * Generate inverse command * * @param enabled - Enable or disable inverse printing * @returns ESC/POS inverse command */ setInverse(enabled: boolean): Uint8Array[]; /** * Get current style state * * @returns Current text style */ getCurrentStyle(): Required; /** * Convert TextAlign enum to ESC/POS value */ private getAlignValue; /** * Clamp scale value to valid range (1-8) */ private clampScale; } export declare const textFormatter: TextFormatter;