import { ImageDimensions, JsonRenderOptions } from '../types/index.js'; import { Logger } from './logger.js'; /** * Canvas configuration interface */ interface CanvasConfig { width: number; height: number; scaleFactor: number; adjustedFontSize: number; } /** * Image processor for creating printer-ready bitmap data from text and graphics. * * This class handles the complete pipeline of: * 1. Canvas setup with DPI awareness * 2. Font registration and text rendering * 3. Graphics drawing (stripes, patterns) * 4. Image data conversion to printer format * 5. Debug image generation * * @example * ```typescript * const dimensions = { width: 384, height: 32, dpi: 203 }; * const logger = new Logger(); * const processor = new ImageProcessor(dimensions, logger); * * const options = { * firstLine: "Hello", * secondLine: "World", * fontFamily: "Arial", * fontSize: 12 * }; * * const imageData = await processor.createImage(options); * ``` */ export declare class ImageProcessor { private readonly dimensions; private readonly logger; constructor(dimensions: ImageDimensions, logger: Logger); /** * Converts an 8-bit array to a byte value */ private bitArrayToByte; /** * Calculates canvas configuration based on options */ private getCanvasConfig; /** * Registers the custom font safely */ private registerCustomFont; /** * Configures canvas context with appropriate settings */ private configureContext; /** * Sets up and configures the canvas for printing */ private setupCanvas; /** * Draws text lines on the canvas */ private drawText; /** * Processes variable substitution in content */ private processVariables; /** * Renders a text element on the canvas */ private renderTextElement; /** * Renders a line element on the canvas */ private renderLineElement; /** * Renders a rectangle element on the canvas */ private renderRectangleElement; /** * Renders a circle element on the canvas */ private renderCircleElement; /** * Renders a stripe element on the canvas */ private renderStripeElement; /** * Renders a grid element on the canvas */ private renderGridElement; /** * Renders a single element based on its type */ private renderElement; /** * Renders all elements from a JSON template */ private renderFromTemplate; /** * Draws alternating horizontal stripes on the canvas */ private drawStripes; /** * Converts canvas to printer-ready byte array */ private canvasToImageData; /** * Creates debug metadata text lines */ private createDebugMetadata; /** * Draws debug metadata on canvas */ private drawDebugMetadata; /** * Generates a timestamp for unique filenames */ private generateTimestamp; /** * Saves debug images for development purposes */ private saveDebugImage; /** * Saves the original printer image */ private saveOriginalImage; /** * Saves the enhanced debug image with metadata */ private saveEnhancedDebugImage; /** * Validates print options before processing */ private validatePrintOptions; /** * Creates a printer-ready image from a JSON template */ createImageFromJson(options: JsonRenderOptions): Promise<{ imageData: number[]; config: CanvasConfig; }>; /** * Saves debug images for JSON template rendering */ private saveJsonDebugImage; } export {};