Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added color attribute for U220 printer #34

Merged
merged 1 commit into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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