tspl-generator
Version:
A TypeScript library for generating TSPL/TSPL2 commands for thermal label printers
154 lines (153 loc) • 5.88 kB
TypeScript
import { LabelConfig, MeasurementSystem, TextOptions, Font, Rotation, BarcodeType } from "./types";
/**
* TSPL Printer class for generating TSPL commands
*/
export declare class TSPLPrinter {
private buffer;
private measurementSystem;
/**
* Create a new TSPL printer instance
* @param measurementSystem - The measurement system to use
*/
constructor(measurementSystem?: MeasurementSystem);
/**
* Initialize the printer with basic settings
* @param config - Label configuration
* @returns The printer instance for method chaining
*/
initialize(config: LabelConfig): this;
/**
* Set the gap between labels
* @param gap - Gap distance
* @param offset - Offset distance
* @returns The printer instance for method chaining
*/
setGap(gap: number, offset?: number): this;
/**
* Add text to the label
* @param options - Text options
* @returns The printer instance for method chaining
*/
addText(options: TextOptions): this;
/**
* Add a text block to the label
* @param x - X coordinate
* @param y - Y coordinate
* @param width - Width of the block
* @param height - Height of the block
* @param font - Font name or number
* @param text - Text content
* @param rotation - Rotation angle
* @param xMultiplier - Horizontal multiplier
* @param yMultiplier - Vertical multiplier
* @param lineSpacing - Line spacing
* @param alignment - Text alignment
* @returns The printer instance for method chaining
*/
addTextBlock(x: number, y: number, width: number, height: number, font: Font | string, text: string, rotation?: Rotation, xMultiplier?: number, yMultiplier?: number, lineSpacing?: number, alignment?: "L" | "C" | "R" | "J"): this;
/**
* Add a barcode to the label
* @param x - X coordinate
* @param y - Y coordinate
* @param barcodeType - Type of barcode
* @param height - Height of barcode
* @param content - Barcode content
* @param readable - Human readable text
* @param rotation - Rotation angle
* @param narrow - Narrow bar width
* @param wide - Wide bar width
* @returns The printer instance for method chaining
*/
addBarcode(x: number, y: number, barcodeType: BarcodeType | string, height: number, content: string, readable?: 0 | 1, rotation?: Rotation, narrow?: number, wide?: number): this;
/**
* Add a QR code to the label
* @param x - X coordinate
* @param y - Y coordinate
* @param content - QR code content
* @param eccLevel - Error correction level
* @param cellWidth - Cell width
* @param mode - Mode
* @param rotation - Rotation angle
* @returns The printer instance for method chaining
*/
addQRCode(x: number, y: number, content: string, eccLevel?: "L" | "M" | "Q" | "H", cellWidth?: number, mode?: "A" | "M", rotation?: Rotation): this;
/**
* Add a box to the label
* @param x - X coordinate of top-left corner
* @param y - Y coordinate of top-left corner
* @param xEnd - X coordinate of bottom-right corner
* @param yEnd - Y coordinate of bottom-right corner
* @param thickness - Line thickness
* @returns The printer instance for method chaining
*/
addBox(x: number, y: number, xEnd: number, yEnd: number, thickness?: number): this;
/**
* Add a line to the label
* @param x - X coordinate of start point
* @param y - Y coordinate of start point
* @param xEnd - X coordinate of end point
* @param yEnd - Y coordinate of end point
* @param thickness - Line thickness
* @returns The printer instance for method chaining
*/
addLine(x: number, y: number, xEnd: number, yEnd: number, thickness?: number): this;
/**
* Add a circle to the label
* @param x - X coordinate of center
* @param y - Y coordinate of center
* @param diameter - Diameter of circle
* @param thickness - Line thickness
* @returns The printer instance for method chaining
*/
addCircle(x: number, y: number, diameter: number, thickness?: number): this;
/**
* Add an ellipse to the label
* @param x - X coordinate of center
* @param y - Y coordinate of center
* @param width - Width of ellipse
* @param height - Height of ellipse
* @param thickness - Line thickness
* @returns The printer instance for method chaining
*/
addEllipse(x: number, y: number, width: number, height: number, thickness?: number): this;
/**
* Add a bitmap image to the label
* @param x - X coordinate
* @param y - Y coordinate
* @param width - Width of bitmap in bytes
* @param height - Height of bitmap in dots
* @param mode - Mode (0: normal, 1: XOR)
* @param bitmap - Bitmap data in hexadecimal format
* @returns The printer instance for method chaining
*/
addBitmap(x: number, y: number, width: number, height: number, bitmap: string, mode?: 0 | 1): this;
/**
* Add a BMP image to the label
* @param x - X coordinate
* @param y - Y coordinate
* @param filename - BMP filename
* @returns The printer instance for method chaining
*/
addBMP(x: number, y: number, filename: string): this;
/**
* Print the label
* @param copies - Number of copies to print
* @returns The printer instance for method chaining
*/
print(copies?: number): this;
/**
* Clear the image buffer
* @returns The printer instance for method chaining
*/
clear(): this;
/**
* Get the generated TSPL code
* @returns The complete TSPL code
*/
getBuffer(): string;
/**
* Reset the buffer
* @returns The printer instance for method chaining
*/
reset(): this;
}