Skip to content

Commit

Permalink
feat: added color attribute for U220 printer
Browse files Browse the repository at this point in the history
  • Loading branch information
nikunj-15 committed Jan 16, 2024
1 parent 265d349 commit ffe67c3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/buffer-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/nodes/text-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(/&nbsp;/g, ' ').replace(/&lt;tab&gt;/g, ' ').replace(/&amp;/g, '&').replace(/&#x3D;/g, '=').replace(/&#x2F;/g, '/').replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&#39;/g, "'").replace(/&quot;/g, '"');

bufferBuilder.printText(text);
Expand Down

0 comments on commit ffe67c3

Please sign in to comment.