Skip to content

Commit

Permalink
[-] Fixed error with graphics wider than 512 pixels
Browse files Browse the repository at this point in the history
  • Loading branch information
VitalyKravtsov2016 committed Oct 8, 2021
1 parent 4b19c70 commit 69d8a7b
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 29 deletions.
2 changes: 1 addition & 1 deletion History.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
********************************************************************************

08.10.2021
deviceServiceVersion = 1013632
deviceServiceVersion = 1013633

[-] Fixed error with graphics wider than 512 pixels

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2689,7 +2689,7 @@ public boolean getSwapGraphicsLine() throws Exception {

public void printBarcode1D(PrinterBarcode barcode) throws Exception {
SmBarcodeEncoder encoder = new ZXingEncoder(
getMaxGraphicsWidth(), barcode.getBarWidth(), barcode.getHeight());
getMaxGraphicsLineWidth(), barcode.getBarWidth(), barcode.getHeight());
SmBarcode bc = encoder.encode(barcode);
if (bc == null) {
throw new Exception("Barcode type is not supported");
Expand All @@ -2709,7 +2709,7 @@ public void printBarcode1D(PrinterBarcode barcode) throws Exception {
bc.setFirstLine(getImageFirstLine());
bc.setHScale(1);
bc.setVScale(1);
bc.centerBarcode(getMaxGraphicsWidth());
bc.centerBarcode(getMaxGraphicsLineWidth());
printSmBarcode(bc);
}
}
Expand Down Expand Up @@ -2891,18 +2891,20 @@ public int getMaxGraphicsHeight() throws Exception {
}
return height - 1;
}

public int getMaxGraphicsWidth() throws Exception {
if (capModelParameters()) {
return modelParameters.getGraphicsWidth();
return modelParameters.getGraphics512Width();
} else if (getCapLoadGraphics3()) {
return 512;
} else {
return getModel().getFonts().itemByNumber(FontNumber.getNormalFont()).getPaperWidth();
return 320;
}
}

public int getMaxGraphicsLineWidth() throws Exception {
if (capModelParameters()) {
return modelParameters.getGraphicsWidth();
return modelParameters.getGraphicsLineWidthInDots();
} else if (getCapLoadGraphics3()) {
return 512;
} else {
Expand Down Expand Up @@ -3169,7 +3171,7 @@ public void loadImage(PrinterImage image, boolean addImage) throws Exception {
return;
}

image.render(getMaxGraphicsLineWidth(), getMaxGraphicsHeight(), getParams().centerImage);
image.render(getMaxGraphicsWidth(), getMaxGraphicsHeight(), getParams().centerImage);
image.setStartPos(getPrinterImages().getTotalSize() + 1);
// check max image width
if (image.getWidth() > getMaxGraphicsWidth()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public class PrinterModelParameters implements PrinterConst {
private final int maxCommandLength;

// Ширина произвольной графической линии в байтах (печать одномерного штрих-кода) (1 байт)
private final int graphicsWidthBytes;
private final int graphicsLineWidthBytes;

// Ширина графической линии в буфере графики-512 (1 байт)
private final int graphics512WidthBytes;
Expand Down Expand Up @@ -216,20 +216,25 @@ public PrinterModelParameters(CommandInputStream in) throws Exception {
bluethoothSettingsTableNumber = in.readByte();
taxModeFieldNumber = in.readByte();
maxCommandLength = in.readShort();
graphicsWidthBytes = in.readByte();
graphicsLineWidthBytes = in.readByte();
graphics512WidthBytes = readByteIfAvailable(in);

if (in.size() >= 2) {
if (in.size() >= 2)
{
maxGraphics512Height = in.readShort();
fsTableNumber = readByteIfAvailable(in);
ofdTableNumber = readByteIfAvailable(in);
embeddableAndInternetDeviceTableNumber = readByteIfAvailable(in);
ffdTableNumber = readByteIfAvailable(in);
ffdColumnNumber = readByteIfAvailable(in);

} else {
maxGraphics512Height = 0;
fsTableNumber = 0;
ofdTableNumber = 0;
embeddableAndInternetDeviceTableNumber = 0;
ffdTableNumber = 0;
ffdColumnNumber = 0;
}

fsTableNumber = readByteIfAvailable(in);
ofdTableNumber = readByteIfAvailable(in);
embeddableAndInternetDeviceTableNumber = readByteIfAvailable(in);
ffdTableNumber = readByteIfAvailable(in);
ffdColumnNumber = readByteIfAvailable(in);
}

private int readByteIfAvailable(CommandInputStream in) throws Exception {
Expand All @@ -240,8 +245,8 @@ private int readByteIfAvailable(CommandInputStream in) throws Exception {
}
}

public int getGraphicsWidth() {
return getGraphicsWidthBytes() * 8;
public int getGraphicsLineWidthInDots() {
return getGraphicsLineWidthBytes() * 8;
}

public boolean isGraphics512Supported() {
Expand Down Expand Up @@ -348,10 +353,10 @@ public int getMaxCommandLength() {
}

/**
* @return the graphicsWidthBytes
* @return the graphicsLineWidthBytes
*/
public int getGraphicsWidthBytes() {
return graphicsWidthBytes;
public int getGraphicsLineWidthBytes() {
return graphicsLineWidthBytes;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.shtrih.util;

public class ServiceVersion {
public static final String VERSION = "631-1-g973807a";
public static final String VERSION = "632";
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
import static com.shtrih.util.ByteUtils.byteArray;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;

/**
* @author P.Zhirkov
Expand Down Expand Up @@ -39,7 +45,7 @@ public void should_deserialize_response() throws Exception {
PrinterModelParameters status = cmd.getParameters();

assertEquals(true, status.isGraphics512Supported());
assertEquals(256, status.getGraphicsWidth());
assertEquals(256, status.getGraphicsLineWidthInDots());
assertEquals(256, status.getGraphics512Width());
}

Expand All @@ -59,7 +65,7 @@ public void should_deserialize_response2() throws Exception {
PrinterModelParameters status = cmd.getParameters();

assertEquals(true, status.isGraphics512Supported());
assertEquals(512, status.getGraphicsWidth());
assertEquals(512, status.getGraphicsLineWidthInDots());
assertEquals(512, status.getGraphics512Width());
assertEquals(false, status.capFsTableNumber());
assertEquals(false, status.capOfdTableNumber());
Expand Down
7 changes: 4 additions & 3 deletions Source/FiscalPrinterTest/src/PrinterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,6 @@ public void setTrailerLines() {

public void setHeaderLines3() {
try {
//String text = getHeaderLine(1) + getLoadImageCommand("Logo.bmp");
//printer.setHeaderLine(1, text, false);
int count = printer.getNumHeaderLines();
for (int i = 1; i <= count; i++) {
printer.setHeaderLine(i, getHeaderLine(i), false);
Expand Down Expand Up @@ -1000,7 +998,10 @@ public void writeCashierName() {

public void printFiscalReceipt() {
try {
printCorrectionReceipt2();
String text = getHeaderLine(1) + getLoadImageCommand("Logo.bmp");
printer.setHeaderLine(1, text, false);

//printCorrectionReceipt2();

//printZeroFiscalReceipt();
//printFiscalReceipt145_9();
Expand Down

0 comments on commit 69d8a7b

Please sign in to comment.