From ffe67c3495a19f72ca151244ef590fcac5c7c53f Mon Sep 17 00:00:00 2001 From: nikunj-15 Date: Tue, 16 Jan 2024 17:44:00 +0530 Subject: [PATCH] feat: added color attribute for U220 printer --- src/buffer-builder.ts | 5 +++++ src/command.ts | 2 ++ src/nodes/text-node.ts | 2 ++ 3 files changed, 9 insertions(+) diff --git a/src/buffer-builder.ts b/src/buffer-builder.ts index 03e71ab..2b083dc 100644 --- a/src/buffer-builder.ts +++ b/src/buffer-builder.ts @@ -22,6 +22,11 @@ export class BufferBuilder { return this; } + public setPrintColor(color: 'black' | 'red' = 'black'): BufferBuilder { + this.buffer.write(Command.ESC_r(color === 'red' ? 1 : 0)); + return this; + } + public setCharacterSize( width: number = 0, height: number = 0 diff --git a/src/command.ts b/src/command.ts index a6d8d78..df58ff6 100644 --- a/src/command.ts +++ b/src/command.ts @@ -25,6 +25,8 @@ export class Command { public static ESC_M = (n: number): number[] => [Command.ESC, 0x4D, n]; // ESCMn public static ESC_t = (n: number): number[] => [Command.ESC, 0x07, n]; // ESCtn public static ESC_Z = (m: number, n: number, k: number): number[] => [Command.ESC, 0x5A, m, n, k]; // ESCZmnk + public static ESC_r = (n: number): number[] => [Command.ESC, 0x72, n]; // ESCR + public static FS_and: number[] = [Command.FS, 0x40]; //ESC@ public static FS_ob_C_fe_utf = [Command.FS, 0x28, 0x43, 0x02, 0x00, 0x30, 0x02]; //UTF-8 encoding diff --git a/src/nodes/text-node.ts b/src/nodes/text-node.ts index f7f5c1d..bb85635 100644 --- a/src/nodes/text-node.ts +++ b/src/nodes/text-node.ts @@ -14,6 +14,8 @@ export default class TextNode extends XMLNode { bufferBuilder.setCharacterSize(size[0], size[1]); } + bufferBuilder.setPrintColor(this.attributes.color); + let text = this.getContent().replace(/ /g, ' ').replace(/<tab>/g, ' ').replace(/&/g, '&').replace(/=/g, '=').replace(///g, '/').replace(/</g, '<').replace(/>/g, '>').replace(/'/g, "'").replace(/"/g, '"'); bufferBuilder.printText(text);