Skip to content

Commit 34c7b5e

Browse files
authored
Merge pull request #40 from pcapanna/master
Correcting barcode width and height functionality.
2 parents be377c9 + 4abb8af commit 34c7b5e

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

commands.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,18 @@ _.BARCODE_FORMAT = {
134134
BARCODE_FONT_A : '\x1d\x66\x00' , // Font type A for HRI barcode chars
135135
BARCODE_FONT_B : '\x1d\x66\x01' , // Font type B for HRI barcode chars
136136

137-
BARCODE_HEIGHT : '\x1d\x68\x64' , // Barcode Height [1-255]
138-
BARCODE_WIDTH : '\x1d\x77\x03' , // Barcode Width [2-6]
137+
BARCODE_HEIGHT : function(height){ // Barcode Height [1-255]
138+
return '\x1d\x68'+String.fromCharCode(height);
139+
},
140+
BARCODE_WIDTH : { // Barcode Width [2-6]
141+
1: '\x1d\x77\x02',
142+
2: '\x1d\x77\x03',
143+
3: '\x1d\x77\x04',
144+
4: '\x1d\x77\x05',
145+
5: '\x1d\x77\x06'
146+
},
147+
BARCODE_HEIGHT_DEFAULT : '\x1d\x77\x64', // Barcode height default:100
148+
BARCODE_WIDTH_DEFAULT : '\x1d\x77\x03', // Barcode width default:3
139149

140150
BARCODE_UPC_A : '\x1d\x6b\x00' , // Barcode type UPC-A
141151
BARCODE_UPC_E : '\x1d\x6b\x01' , // Barcode type UPC-E

printer.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,11 +290,15 @@ Printer.prototype.hardware = function(hw){
290290
* @return printer instance
291291
*/
292292
Printer.prototype.barcode = function(code, type, width, height, position, font){
293-
if(width >= 1 || width <= 255){
294-
this.buffer.write(_.BARCODE_FORMAT.BARCODE_WIDTH);
293+
if(width >= 2 || width <= 6){
294+
this.buffer.write(_.BARCODE_FORMAT.BARCODE_WIDTH[width]);
295+
}else{
296+
this.buffer.write(_.BARCODE_FORMAT.BARCODE_WIDTH_DEFAULT);
295297
}
296-
if(height >=2 || height <= 6){
297-
this.buffer.write(_.BARCODE_FORMAT.BARCODE_HEIGHT);
298+
if(height >=1 || height <= 255){
299+
this.buffer.write(_.BARCODE_FORMAT.BARCODE_HEIGHT(height));
300+
}else{
301+
this.buffer.write(_.BARCODE_FORMAT.BARCODE_HEIGHT_DEFAULT);
298302
}
299303
this.buffer.write(_.BARCODE_FORMAT[
300304
'BARCODE_FONT_' + (font || 'A').toUpperCase()

0 commit comments

Comments
 (0)