package com.gk.firework.Domain.Vo;
|
|
import java.io.File;
|
import java.io.FileInputStream;
|
import java.io.UnsupportedEncodingException;
|
|
/**
|
* @author : jingjy
|
* @date : 2021/7/27 16:41
|
* @Description: 用于ZPL把文字转换为图片,但是生成数据太大,废弃
|
* @deprecated
|
*/
|
public class ZplUtil {
|
private byte[] dotFont;
|
private String sPrt = "";
|
private String sPrtBuffer ="";
|
|
public String getCharPicture(String str, int x, int y, int h, int w, int b){
|
printChineseChar(str,x,y,h,w,b);
|
return sPrtBuffer+sPrt;
|
}
|
|
public ZplUtil() throws Exception {
|
String path = "E:\\ts24.lib";
|
File file = new File(path);
|
FileInputStream fis = new FileInputStream(file);
|
dotFont = new byte[fis.available()];
|
fis.read(dotFont);
|
fis.close();
|
}
|
|
private void printChineseChar(String str, int x, int y, int h, int w, int b) {
|
byte[] ch = str2bytes(str);
|
for (int off = 0; off < ch.length;) {
|
if (((int) ch[off] & 0x00ff) >= 0xA0) {
|
int qcode = ch[off] & 0xff;
|
int wcode = ch[off + 1] & 0xff;
|
sPrtBuffer = sPrtBuffer
|
+ String.format("^FO%d,%d^XG0000%01X%01X,%d,%d^FS", x,
|
y, qcode, wcode,b,b);
|
sPrt += String.format("~DG0000%02X%02X,00072,003,", qcode,
|
wcode);
|
qcode = (qcode + 128 - 32) & 0x00ff;
|
wcode = (wcode + 128 - 32) & 0x00ff;
|
int offset = (qcode - 16) * 94 * 72 + (wcode - 1)
|
* 72;
|
for (int j = 0; j < 72; j += 3) {
|
qcode = (int) dotFont[j + offset] & 0x00ff;
|
wcode = (int) dotFont[j + offset + 1] & 0x00ff;
|
int qcode1 = (int) dotFont[j + offset + 2] & 0x00ff;
|
sPrt += String.format("%02X%02X%02X", qcode, wcode,
|
qcode1);
|
}
|
x = x + 25*b;
|
off = off + 2;
|
} else if (((int) ch[off] & 0x00FF) < 0xA0) {
|
;
|
printChar(String.format("%c",ch[off]), x, y, h, w);
|
x = x + 15;
|
off++;
|
}
|
}
|
}
|
|
private void printChar(String str, int x, int y, int h, int w) {
|
sPrtBuffer +="^FO"+x+","+y+"^A0,"+h+","+w+"^FD"+str+"^FS";
|
}
|
|
private byte[] str2bytes(String s) {
|
if (null == s || "".equals(s)) {
|
return null;
|
}
|
byte[] abytes = null;
|
try {
|
abytes = s.getBytes("gb2312");
|
} catch (UnsupportedEncodingException ex) {
|
|
}
|
return abytes;
|
}
|
}
|