@@ -268,7 +268,7 @@ void Adafruit_Thermal::printBarcode(const char *text, uint8_t type) {
268
268
}
269
269
270
270
// === Character commands ===
271
-
271
+ # define FONT_MASK ( 1 << 0 ) // !< Select character font A or B
272
272
#define INVERSE_MASK \
273
273
(1 << 1 ) // !< Turn on/off white/black reverse printing mode. Not in 2.6.8
274
274
// !< firmware (see inverseOn())
@@ -278,18 +278,43 @@ void Adafruit_Thermal::printBarcode(const char *text, uint8_t type) {
278
278
#define DOUBLE_WIDTH_MASK (1 << 5 ) // !< Turn on/off double-width printing mode
279
279
#define STRIKE_MASK (1 << 6 ) // !< Turn on/off deleteline mode
280
280
281
+ void Adafruit_Thermal::adjustCharValues (uint8_t printMode) {
282
+ uint8_t charWidth;
283
+ if (printMode & FONT_MASK) {
284
+ // FontB
285
+ charHeight = 17 ;
286
+ charWidth = 9 ;
287
+ } else {
288
+ // FontA
289
+ charHeight = 24 ;
290
+ charWidth = 12 ;
291
+ }
292
+ // Double Width Mode
293
+ if (printMode & DOUBLE_WIDTH_MASK) {
294
+ maxColumn /= 2 ;
295
+ charWidth *= 2 ;
296
+ }
297
+ // Double Height Mode
298
+ if (printMode & DOUBLE_HEIGHT_MASK) {
299
+ charHeight *= 2 ;
300
+ }
301
+ maxColumn = (384 / charWidth);
302
+ }
303
+
281
304
void Adafruit_Thermal::setPrintMode (uint8_t mask) {
282
305
printMode |= mask;
283
306
writePrintMode ();
284
- charHeight = (printMode & DOUBLE_HEIGHT_MASK) ? 48 : 24 ;
285
- maxColumn = (printMode & DOUBLE_WIDTH_MASK) ? 16 : 32 ;
307
+ adjustCharValues (printMode);
308
+ // charHeight = (printMode & DOUBLE_HEIGHT_MASK) ? 48 : 24;
309
+ // maxColumn = (printMode & DOUBLE_WIDTH_MASK) ? 16 : 32;
286
310
}
287
311
288
312
void Adafruit_Thermal::unsetPrintMode (uint8_t mask) {
289
313
printMode &= ~mask;
290
314
writePrintMode ();
291
- charHeight = (printMode & DOUBLE_HEIGHT_MASK) ? 48 : 24 ;
292
- maxColumn = (printMode & DOUBLE_WIDTH_MASK) ? 16 : 32 ;
315
+ adjustCharValues (printMode);
316
+ // charHeight = (printMode & DOUBLE_HEIGHT_MASK) ? 48 : 24;
317
+ // maxColumn = (printMode & DOUBLE_WIDTH_MASK) ? 16 : 32;
293
318
}
294
319
295
320
void Adafruit_Thermal::writePrintMode () {
@@ -395,24 +420,30 @@ void Adafruit_Thermal::setSize(char value) {
395
420
396
421
switch (toupper (value)) {
397
422
default : // Small: standard width and height
398
- size = 0x00 ;
399
- charHeight = 24 ;
400
- maxColumn = 32 ;
423
+ // size = 0x00;
424
+ // charHeight = 24;
425
+ // maxColumn = 32;
426
+ doubleWidthOff ();
427
+ doubleHeightOff ();
401
428
break ;
402
429
case ' M' : // Medium: double height
403
- size = 0x01 ;
404
- charHeight = 48 ;
405
- maxColumn = 32 ;
430
+ // size = 0x01;
431
+ // charHeight = 48;
432
+ // maxColumn = 32;
433
+ doubleHeightOn ();
434
+ doubleWidthOff ();
406
435
break ;
407
436
case ' L' : // Large: double width and height
408
- size = 0x11 ;
409
- charHeight = 48 ;
410
- maxColumn = 16 ;
437
+ // size = 0x11;
438
+ // charHeight = 48;
439
+ // maxColumn = 16;
440
+ doubleHeightOn ();
441
+ doubleWidthOn ();
411
442
break ;
412
443
}
413
444
414
- writeBytes (ASCII_GS, ' !' , size);
415
- prevByte = ' \n ' ; // Setting the size adds a linefeed
445
+ // writeBytes(ASCII_GS, '!', size);
446
+ // prevByte = '\n'; // Setting the size adds a linefeed
416
447
}
417
448
418
449
// ESC 7 n1 n2 n3 Setting Control Parameter Command
@@ -654,6 +685,17 @@ void Adafruit_Thermal::tab() {
654
685
column = (column + 4 ) & 0b11111100 ;
655
686
}
656
687
688
+ void Adafruit_Thermal::setFont (char font) {
689
+ switch (toupper (font)) {
690
+ case ' B' :
691
+ setPrintMode (FONT_MASK);
692
+ break ;
693
+ case ' A' :
694
+ default :
695
+ unsetPrintMode (FONT_MASK);
696
+ }
697
+ }
698
+
657
699
void Adafruit_Thermal::setCharSpacing (int spacing) {
658
700
writeBytes (ASCII_ESC, ' ' , spacing);
659
701
}
0 commit comments