Skip to content

Commit

Permalink
[-] Fixed error with logo printing
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitaly Kravtsov committed Feb 1, 2022
1 parent c23be57 commit 6662d29
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 16 deletions.
7 changes: 7 additions & 0 deletions History.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
Company : SHTRIH-M www.shtrih-m.ru (495) 787-6090
Url : https://github.com/shtrih-m/javapos_shtrih

********************************************************************************

01.02.2022
deviceServiceVersion = 1013640

[-] Fixed error with logo printing

********************************************************************************

27.01.2022
Expand Down
35 changes: 21 additions & 14 deletions Source/Core/src/com/shtrih/fiscalprinter/SMFiscalPrinterImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,8 @@ public void setCurrentDateTime() {
LongPrinterStatus status = readLongStatus();
FSReadStatus fsStatus = null;

if (!status.getDate().isEqual(currentDate))
{
if (fsStatus == null){
if (!status.getDate().isEqual(currentDate)) {
if (fsStatus == null) {
fsStatus = fsReadStatus();
}
if ((fsStatus.getDocNumber() == 0) || (fsStatus.getDate().before(currentDate))) {
Expand All @@ -308,10 +307,10 @@ public void setCurrentDateTime() {
if (timeDiffInSecs > params.validTimeDiffInSecs) {
logger.debug(
String.format("FP time: %s, system time: %s",
status.getTime().toString(),
status.getTime().toString(),
currentTime.toString()));

if (fsStatus == null){
if (fsStatus == null) {
fsStatus = fsReadStatus();
}
if ((fsStatus.getDocNumber() == 0)
Expand Down Expand Up @@ -1337,8 +1336,7 @@ public void checkItemCode(CheckCodeRequest request) throws Exception {
checkTag2106(acceptCommand.getErrorCode());
}

private void checkTag2106(int errorCode) throws Exception
{
private void checkTag2106(int errorCode) throws Exception {
boolean isMCChecked = BitUtils.testBit(errorCode, 0);
boolean isMCCRCChecked = BitUtils.testBit(errorCode, 1);
boolean isMSChecked = BitUtils.testBit(errorCode, 2);
Expand All @@ -1350,7 +1348,7 @@ private void checkTag2106(int errorCode) throws Exception
throw new Exception("Планируемый статус товара некорректен");
}
}

public void printSale(PriceItem item) throws Exception {
logger.debug("printSale");
String text = getRecItemText(item.getText());
Expand Down Expand Up @@ -2962,6 +2960,11 @@ public int getMaxGraphicsHeight() throws Exception {
}

public int getMaxGraphicsWidth() throws Exception {
int width = Math.min(getPaperWidth(), getMaxGraphicCommandWidth());
return width;
}

public int getMaxGraphicCommandWidth() throws Exception {
if (capModelParameters()) {
return modelParameters.getGraphics512Width();
} else if (getCapLoadGraphics3()) {
Expand All @@ -2971,6 +2974,10 @@ public int getMaxGraphicsWidth() throws Exception {
}
}

public int getPaperWidth() throws Exception {
return getModel().getFonts().itemByNumber(FontNumber.getNormalFont()).getPaperWidth();
}

public int getMaxGraphicsLineWidth() throws Exception {
if (capModelParameters()) {
return modelParameters.getGraphicsLineWidthInDots();
Expand Down Expand Up @@ -5129,15 +5136,15 @@ public int mcClearBuffer() throws Exception {
return fsAcceptMC(command);
}

public int getCommandTimeout(int code)
{
public int getCommandTimeout(int code) {
Integer timeout = getParams().commandTimeouts.get(code);
if (timeout != null) return timeout;
if (timeout != null) {
return timeout;
}
return PrinterCommand.getDefaultTimeout(code);
}

public void setCommandTimeout(int code, int timeout)
{

public void setCommandTimeout(int code, int timeout) {
getParams().commandTimeouts.put(code, timeout);
}
}
12 changes: 11 additions & 1 deletion Source/FiscalPrinterService/src/com/shtrih/util/ImageRender.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.shtrih.util;

import com.shtrih.jpos.fiscalprinter.PrinterImage;
import java.awt.RenderingHints;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.awt.image.Raster;
Expand Down Expand Up @@ -51,10 +52,19 @@ public void render(String fileName, int maxWidth, int maxHeight) throws Exceptio
if (height > maxHeight){
height = maxHeight;
}

double scaleX = ((double) width) / (double)image.getWidth();
double scaleY = ((double) height) / (double)image.getHeight();
double scale = Math.min(scaleX, scaleY);
width = (int) (scale * image.getWidth());
height = (int) (scale * image.getHeight());

BufferedImage img = new BufferedImage(width, height,
BufferedImage.TYPE_BYTE_BINARY);
Graphics2D g2 = img.createGraphics();
g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);

try {
g2.drawImage(image, 0, 0, width, height, Color.WHITE, null);
} finally {
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 = "639";
public static final String VERSION = "639-1-gc23be57";
}
Binary file modified Source/FiscalPrinterTest/Res/Logo.bmp
Binary file not shown.

0 comments on commit 6662d29

Please sign in to comment.