Skip to content

Commit

Permalink
bug fix issue #44 printing large QR Code
Browse files Browse the repository at this point in the history
  • Loading branch information
Franck ALARY committed Aug 20, 2020
1 parent 55bc488 commit 983aa75
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ public AsyncEscPosPrinter getAsyncEscPosPrinter(DeviceConnection printerConnecti
"[L]Tel : +33801201456\n" +
"[L]\n" +
"[C]<barcode type='ean13' height='10'>831254784551</barcode>\n" +
"[C]<qrcode size='20'>http://www.developpeur-web.dantsu.com/</qrcode>"
"[C]<qrcode size='20'>http://www.developpeur-web.dantsu.com/</qrcode>\n"
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,15 @@ public class EscPosPrinterCommands {
private EscPosCharsetEncoding charsetEncoding;


private static byte[] initImageCommand(int bytesByLine, int bitmapHeight) {
public static byte[] initImageCommand(int bytesByLine, int bitmapHeight) {
int
xH = bytesByLine / 256,
xL = bytesByLine - (xH * 256),
yH = bitmapHeight / 256,
yL = bitmapHeight - (yH * 256);

byte[] imageBytes = new byte[8 + bytesByLine * bitmapHeight];
System.arraycopy(new byte[]{0x1D, 0x76, 0x30, 0x00, (byte) bytesByLine, 0x00, (byte) bitmapHeight, 0x00}, 0, imageBytes, 0, 8);
System.arraycopy(new byte[]{0x1D, 0x76, 0x30, 0x00, (byte) xL, (byte) xH, (byte) yL, (byte) yH}, 0, imageBytes, 0, 8);
return imageBytes;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,10 @@ public PrinterTextParserImg(PrinterTextParserColumn printerTextParserColumn, Str
public PrinterTextParserImg(PrinterTextParserColumn printerTextParserColumn, String textAlign, byte[] image) {
EscPosPrinter printer = printerTextParserColumn.getLine().getTextParser().getPrinter();

int byteWidth = ((int) image[4] & 0xFF),
int
byteWidth = ((int) image[4] & 0xFF) + ((int) image[5] & 0xFF) * 256,
width = byteWidth * 8,
height = ((int) image[6] & 0xFF),
height = ((int) image[6] & 0xFF) + ((int) image[7] & 0xFF) * 256,
nbrByteDiff = (int) Math.floor(((float) (printer.getPrinterWidthPx() - width)) / 8f),
nbrWhiteByteToInsert = 0;

Expand All @@ -123,16 +124,14 @@ public PrinterTextParserImg(PrinterTextParserColumn printerTextParserColumn, Str

if (nbrWhiteByteToInsert > 0) {
int newByteWidth = byteWidth + nbrWhiteByteToInsert;
byte[] newImage = new byte[newByteWidth * height + 8];
System.arraycopy(image, 0, newImage, 0, 8);
newImage[4] = (byte) newByteWidth;
byte[] newImage = EscPosPrinterCommands.initImageCommand(newByteWidth, height);
for (int i = 0; i < height; i++) {
System.arraycopy(image, (byteWidth * i + 8), newImage, (newByteWidth * i + nbrWhiteByteToInsert + 8), byteWidth);
}
image = newImage;
}

this.length = (int) Math.ceil(((float) (((int) image[4] & 0xFF) * 8)) / ((float) printer.getPrinterCharSizeWidthPx()));
this.length = (int) Math.ceil(((float) byteWidth * 8) / ((float) printer.getPrinterCharSizeWidthPx()));
this.image = image;
}

Expand Down

0 comments on commit 983aa75

Please sign in to comment.