Administrator
2023-06-19 49588f5a462ae7425e7eb030438a35fd80c246fa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
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;
    }
}