Skip to content

Commit

Permalink
feat: added support for U220
Browse files Browse the repository at this point in the history
  • Loading branch information
XGaneshkumar committed Nov 28, 2022
1 parent 4783dd9 commit ab06eef
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 6 deletions.
35 changes: 29 additions & 6 deletions src/buffer-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ import { MutableBuffer } from "mutable-buffer";
import Image from "./image";
export class BufferBuilder {
private buffer: MutableBuffer;
private hasGSCommand: boolean;
private doEmphasise: boolean;

constructor(private defaultSettings: boolean = true) {
this.buffer = new MutableBuffer();

this.hasGSCommand = true;
this.doEmphasise = false;
if (this.defaultSettings) {
this.resetCharacterSize();
this.resetCharacterEncoding();
Expand All @@ -26,13 +29,33 @@ export class BufferBuilder {
width: number = 0,
height: number = 0
): BufferBuilder {
let size = (width << 4) + height;
this.buffer.write(Command.GS_exclamation(size));
if(this.hasGSCommand)
{
let size = (width << 4) + height;
this.buffer.write(Command.GS_exclamation(size));
}
else{
let mode = (width>0?(1<<5):0)+(height>0?(1<<4):0)+(this.doEmphasise?(1<<3):0)+1;
this.buffer.write(Command.ESC_exclamation(mode));
}

return this;
}

public setPrintMode(setting:boolean): BufferBuilder {
this.hasGSCommand = setting;
return this;
}

public resetCharacterSize(): BufferBuilder {
this.buffer.write(Command.GS_exclamation(0));
if(this.hasGSCommand)
{
this.buffer.write(Command.GS_exclamation(0));
}
else
{
this.buffer.write(Command.ESC_exclamation(1));
}
return this;
}

Expand All @@ -52,12 +75,12 @@ export class BufferBuilder {
}

public startBold(): BufferBuilder {
this.buffer.write(Command.ESC_E(1));
this.hasGSCommand? this.buffer.write(Command.ESC_E(1)):this.doEmphasise=true;
return this;
}

public endBold(): BufferBuilder {
this.buffer.write(Command.ESC_E(0));
this.hasGSCommand? this.buffer.write(Command.ESC_E(0)):this.doEmphasise=false;
return this;
}

Expand Down
2 changes: 2 additions & 0 deletions src/node-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import WhiteModeNode from './nodes/white-mode-node';
import PaperCutNode from './nodes/paper-cut-node';
import ImageNode from './nodes/image-node';
import OpenCashDrawerNode from './nodes/open-cash-drawer-node';
import PrintModeNode from './nodes/print-mode';

export class NodeFactory {

Expand All @@ -33,6 +34,7 @@ export class NodeFactory {
case 'paper-cut': return new PaperCutNode(node);
case 'open-cash-drawer': return new OpenCashDrawerNode(node);
case 'image': return new ImageNode(node);
case 'print-mode': return new PrintModeNode(node);

default: return null;
}
Expand Down
27 changes: 27 additions & 0 deletions src/nodes/print-mode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { XMLNode } from '../xml-node';
import { BufferBuilder } from '../buffer-builder';

export default class PrintModeNode extends XMLNode {

constructor(node: any) {
super(node);
}

public open(bufferBuilder: BufferBuilder): BufferBuilder {
if(this.attributes.mode === 'U220')
{
bufferBuilder.setPrintMode(false);
}
else
{
bufferBuilder.setPrintMode(true);
}
return bufferBuilder;
}

public close(bufferBuilder: BufferBuilder): BufferBuilder {
bufferBuilder.resetAlign();
return bufferBuilder;
}

}

0 comments on commit ab06eef

Please sign in to comment.