UOCL-244: receipts added to main code base
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
<groupId>com.unicenta</groupId>
|
<groupId>com.unicenta</groupId>
|
||||||
<artifactId>unicentaopos</artifactId>
|
<artifactId>unicentaopos</artifactId>
|
||||||
<version>5.0.1</version>
|
<version>5.0.2-SNAPSHOT</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ import java.util.ArrayList;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author JG uniCenta
|
* @author JG uniCenta
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@@ -50,72 +49,89 @@ public abstract class BasicTicket implements PrintItem {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
protected int m_iBodyHeight;
|
protected int m_iBodyHeight;
|
||||||
|
|
||||||
/** Creates a new instance of AbstractTicket */
|
|
||||||
public BasicTicket() {
|
|
||||||
// JG 16 May 12 use diamond inference
|
|
||||||
m_aCommands = new ArrayList<>();
|
|
||||||
pil = null;
|
|
||||||
m_iBodyHeight = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Creates a new instance of AbstractTicket
|
||||||
|
*/
|
||||||
|
public BasicTicket() {
|
||||||
|
// JG 16 May 12 use diamond inference
|
||||||
|
m_aCommands = new ArrayList<>();
|
||||||
|
pil = null;
|
||||||
|
m_iBodyHeight = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
protected abstract Font getBaseFont();
|
protected abstract Font getBaseFont();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
protected abstract int getFontHeight();
|
protected abstract int getFontHeight();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
protected abstract double getImageScale();
|
protected abstract double getImageScale();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int getHeight() {
|
public int getHeight() {
|
||||||
return m_iBodyHeight;
|
return m_iBodyHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @param g2d
|
* @param g2d
|
||||||
* @param x
|
* @param x
|
||||||
* @param y
|
* @param y
|
||||||
* @param width
|
* @param width
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void draw(Graphics2D g2d, int x, int y, int width) {
|
public void draw(Graphics2D g2d, int x, int y, int width) {
|
||||||
|
|
||||||
BufferedImage image = new BufferedImage(width + 10, 10, 1);
|
int currenty = y;
|
||||||
|
for (PrintItem pi : m_aCommands) {
|
||||||
|
pi.draw(g2d, x, currenty, width);
|
||||||
|
currenty += pi.getHeight();
|
||||||
|
}
|
||||||
|
|
||||||
|
saveTicket(g2d, x, y, width);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void saveTicket(Graphics2D g2d, int x, int y, int width) {
|
||||||
|
|
||||||
|
int receiptHeight = 5;
|
||||||
|
|
||||||
|
PrintItem pi;
|
||||||
|
for(Iterator i$ = m_aCommands.iterator(); i$.hasNext(); receiptHeight += pi.getHeight()) {
|
||||||
|
pi = (PrintItem)i$.next();
|
||||||
|
}
|
||||||
|
|
||||||
|
BufferedImage image = new BufferedImage(width + 10, receiptHeight, 1);
|
||||||
g2d = image.createGraphics();
|
g2d = image.createGraphics();
|
||||||
|
int currenty = y;
|
||||||
|
|
||||||
int currenty = y;
|
for(Iterator i$ = this.m_aCommands.iterator(); i$.hasNext(); currenty += pi.getHeight()) {
|
||||||
for (PrintItem pi : m_aCommands) {
|
pi = (PrintItem)i$.next();
|
||||||
pi.draw(g2d, x, currenty, width);
|
pi.draw(g2d, x, currenty, width);
|
||||||
currenty += pi.getHeight();
|
}
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ImageIO.write(this.negative(image), "png", new File(System.getProperty("user.home") + "/test.png"));
|
ImageIO.write(this.negative(image), "png", new File(System.getProperty("user.home") + "/test.png"));
|
||||||
} catch (Exception var10) {
|
}
|
||||||
System.out.println("Error serialising receipt image !!! : " + var10);
|
catch (Exception e) {
|
||||||
|
System.out.println("Error serialising receipt image !!! : " + e);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public BufferedImage negative(BufferedImage img) {
|
public BufferedImage negative(BufferedImage img) {
|
||||||
for(int x = 0; x < img.getWidth(); ++x) {
|
for (int x = 0; x < img.getWidth(); ++x) {
|
||||||
for(int y = 0; y < img.getHeight(); ++y) {
|
for (int y = 0; y < img.getHeight(); ++y) {
|
||||||
int RGBA = img.getRGB(x, y);
|
int RGBA = img.getRGB(x, y);
|
||||||
Color col = new Color(RGBA, true);
|
Color col = new Color(RGBA, true);
|
||||||
col = new Color(Math.abs(col.getRed() - 255), Math.abs(col.getGreen() - 255), Math.abs(col.getBlue() - 255));
|
col = new Color(Math.abs(col.getRed() - 255), Math.abs(col.getGreen() - 255), Math.abs(col.getBlue() - 255));
|
||||||
@@ -127,66 +143,61 @@ public abstract class BasicTicket implements PrintItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public java.util.List<PrintItem> getCommands() {
|
public java.util.List<PrintItem> getCommands() {
|
||||||
return m_aCommands;
|
return m_aCommands;
|
||||||
}
|
}
|
||||||
|
|
||||||
// INTERFAZ PRINTER 2
|
// INTERFAZ PRINTER 2
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @param image
|
* @param image
|
||||||
*/
|
*/
|
||||||
public void printImage(BufferedImage image) {
|
public void printImage(BufferedImage image) {
|
||||||
|
|
||||||
PrintItem pi = new PrintItemImage(image, getImageScale());
|
PrintItem pi = new PrintItemImage(image, getImageScale());
|
||||||
m_aCommands.add(pi);
|
m_aCommands.add(pi);
|
||||||
m_iBodyHeight += pi.getHeight();
|
m_iBodyHeight += pi.getHeight();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @param type
|
* @param type
|
||||||
* @param position
|
* @param position
|
||||||
* @param code
|
* @param code
|
||||||
*/
|
*/
|
||||||
public void printBarCode(String type, String position, String code) {
|
public void printBarCode(String type, String position, String code) {
|
||||||
|
|
||||||
PrintItem pi = new PrintItemBarcode(type, position, code, getImageScale());
|
PrintItem pi = new PrintItemBarcode(type, position, code, getImageScale());
|
||||||
m_aCommands.add(pi);
|
m_aCommands.add(pi);
|
||||||
m_iBodyHeight += pi.getHeight();
|
m_iBodyHeight += pi.getHeight();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @param iTextSize
|
* @param iTextSize
|
||||||
*/
|
*/
|
||||||
public void beginLine(int iTextSize) {
|
public void beginLine(int iTextSize) {
|
||||||
pil = new PrintItemLine(iTextSize, getBaseFont(), getFontHeight());
|
pil = new PrintItemLine(iTextSize, getBaseFont(), getFontHeight());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @param iStyle
|
* @param iStyle
|
||||||
* @param sText
|
* @param sText
|
||||||
*/
|
*/
|
||||||
public void printText(int iStyle, String sText) {
|
public void printText(int iStyle, String sText) {
|
||||||
if (pil != null) {
|
if (pil != null) {
|
||||||
pil.addText(iStyle, sText);
|
pil.addText(iStyle, sText);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public void endLine() {
|
public void endLine() {
|
||||||
if (pil != null) {
|
if (pil != null) {
|
||||||
m_aCommands.add(pil);
|
m_aCommands.add(pil);
|
||||||
m_iBodyHeight += pil.getHeight();
|
m_iBodyHeight += pil.getHeight();
|
||||||
pil = null;
|
pil = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user