commit 986cc071902bf3b126daf40d4942fec88877cbf6 Author: xuenhua Date: Sun Dec 15 18:25:59 2024 +0800 点阵字 diff --git a/HZK16 b/HZK16 new file mode 100644 index 0000000..27f10c9 Binary files /dev/null and b/HZK16 differ diff --git a/Word.java b/Word.java new file mode 100644 index 0000000..dc00b05 --- /dev/null +++ b/Word.java @@ -0,0 +1,273 @@ +import java.io.File; +import java.io.FileInputStream; +import java.io.PrintStream; + +public class Word { + public final static String ZK_PATH = "/HZK16"; + public final static String ENCODE = "GB2312"; + private int[] unit = new int[32]; + private String yes = "$";// "¡ö"; + private String no = " "; + private PrintStream print = null; + public Word() { + // String str = "ÎÒ"; + // + // try { + // + // byte[] b = str.getBytes("GB2312"); + // + // for (int i = 0; i < b.length; i++) { + // + // System.out.println(Integer.toHexString(b[i])); + // + // } + // + // } catch (Exception ex) { + // + // } + + } + + public void setYes(String str) { + yes = str; + } + + public void setNo(String str) { + no = str; + } + + private int negativeToPlus(byte b) { + return b & 0xFF; + } + + public void setOutputFile(String filename) throws Exception { + print = new PrintStream(filename); + } + + public void colseFileStream() { + print.close(); + } + + private void readChina(char ch) { // ÐèÒªµÃµ½µãÕóµÄºº×Ö + byte[] buf = new byte[32]; + FileInputStream input = null; + try { + if (ch < 0x80) { + long offset = (ch + 155) * 32; // »ñµÃÆ«ÒÆÁ¿ + File file = new File("HZK16"); + input = new FileInputStream(file); + input.skip(offset); + input.read(buf, 0, 32); + for (int i = 0; i < 32; i++) + unit[i] = negativeToPlus(buf[i]); + input.close(); + } + if (ch > 0x80) { + String string = Character.toString(ch); + byte[] bt = string.getBytes("GBK"); // »ñµÃ¹ú±êÂë + int a1 = negativeToPlus(bt[0]); // תΪÎÞ·ûºÅÕûÊý + int a2 = negativeToPlus(bt[1]); + int qh = a1 - 0xA0; // µÃµ½ÇøÎ»Âë + int wh = a2 - 0xA0; + long offset = (94 * (qh - 1) + (wh - 1)) * 32; // »ñµÃÆ«ÒÆÁ¿ + + File file = new File("HZK16"); + input = new FileInputStream(file); + input.skip(offset); + input.read(buf, 0, 32); + for (int i = 0; i < 32; i++) + unit[i] = negativeToPlus(buf[i]); + input.close(); + } + // String string = Character.toString(ch); + // byte[] bt = string.getBytes("GBK"); // »ñµÃ¹ú±êÂë + // int a1 = negativeToPlus(bt[0]); // תΪÎÞ·ûºÅÕûÊý + // int a2 = negativeToPlus(bt[1]); + // int qh = a1 - 0xA0; // µÃµ½ÇøÎ»Âë + // int wh = a2 - 0xA0; + // long offset = (94 * (qh - 1) + (wh - 1)) * 32; // »ñµÃÆ«ÒÆÁ¿ + // + // File file = new File("HZK16"); + // input = new FileInputStream(file); + // input.skip(offset); + // input.read(buf, 0, 32); + // for (int i = 0; i < 32; i++) + // unit[i] = negativeToPlus(buf[i]); + // input.close(); + } catch (Exception e) { + System.out.println("ÎļþÒì³£"); + e.printStackTrace(); + } + } + + public void writeChina(char ch) { // ²ÎÊý: yesÊÇÓе㴦ÏÔʾ noÊÇÎ޵㴦ÏÔʾ + int i, j, k; + readChina(ch); + for (j = 0; j < 16; j++) { + for (i = 0; i < 2; i++) + for (k = 0; k < 8; k++) + if ((unit[j * 2 + i] & (0x80 >> k)) >= 1) // È¡bitλֵ + { + System.out.print(yes); + } else { + System.out.print(no); + } + System.out.println(); + } + } + + public void writeChinaToFile_V(String str) { + try { + int i, j, k; + for (int x = 0; x < str.length(); x++) { + readChina(str.charAt(x)); + for (j = 0; j < 16; j++) { + for (i = 0; i < 2; i++) { + for (k = 0; k < 8; k++) { + if ((unit[j * 2 + i] & (0x80 >> k)) >= 1) // È¡bitλֵ + { + print.print(yes); + } else { + print.print(no); + } + } + } + print.println(); + } + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void writeChinaToFile_H(String str) { + try { + int i, j, k; + { + for (j = 0; j < 16; j++) { + print.print(" "); + // Êä³öÿ¸ö×ÖµÄͬһÐÐ/////////////// + for (int x = 0; x < str.length(); x++) { + readChina(str.charAt(x)); + + for (i = 0; i < 2; i++) { + for (k = 0; k < 8; k++) { + if ((unit[j * 2 + i] & (0x80 >> k)) >= 1) // È¡bitλֵ + { + print.print(yes); + } else { + print.print(no); + } + } + } + print.print(" "); + } + print.println(); + // ////////////////////////////////// + } + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + public static void main(String[] args) throws Exception { + Word charcode = new Word(); + String str = "ALIPAY¡ú¡Þ"; + String str2 = "Ö§¸¶ÃÎÏëÈÎÄã·ÉÏè"; + charcode.setOutputFile("output.txt"); // È·¶¨Êä³ö ÎļþÁ÷ + charcode.writeChinaToFile_H(str); + charcode.writeChinaToFile_H(str2); // ҪдµÄ×Ö·û´® + + + charcode.colseFileStream(); // ¹Ø±ÕÁ÷ + + + + + // int code[] = null; + // byte data[] = null; + // Word getcode = new Word(); + // code = getcode.getByteCode("ÎÒ"); + // data = getcode.read(code[0], code[1]); + // for (int i = 0; i < 32; i++) { + // System.out.println(data[i]); + // } + + } +} +// public int[] getByteCode(String str) { +// +// int[] byteCode = new int[2]; +// +// try { +// +// byte[] data = str.getBytes(ENCODE); +// +// byteCode[0] = data[0] < 0 ? 256 + data[0] : data[0]; +// +// byteCode[1] = data[1] < 0 ? 256 + data[1] : data[1]; +// +// } catch (Exception ex) { +// +// } +// +// return byteCode; +// +// } +// +// public byte[] read(int areaCode, int posCode) { +// +// byte[] data = null; +// try { +// int area = areaCode - 0xa0;// »ñµÃÕæÊµÇøÂë +// int pos = posCode - 0xa0;// »ñµÃÕæÊµÎ»Âë +// InputStream in = getClass().getResourceAsStream(ZK_PATH); +// long offset = 32 * ((area - 1) * 94 + pos - 1); +// in.skip(offset); +// data = new byte[32]; +// in.read(data, 0, 32); +// in.close(); +// } catch (Exception ex) { +// +// } +// +// return data; +// +// } + +// protected void drawString(Graphics g, String str, int x, int y, int +// color) { +// +// byte[] data = null; +// int[] code = null; +// int byteCount;// µ½µãÕóÊý¾ÝµÄµÚ¼¸¸ö×Ö½ÚÁË +// int lCount;// ¿ØÖÆÁÐ +// g.setColor(color); +// for (int i = 0; i < str.length(); i++) { +// if (str.charAt(i) < 0x80) {// ·ÇÖÐÎÄ +// g.drawString(str.substring(i, i + 1), x + (i << 4), y, 0); +// continue; +// } +// +// code = getByteCode(str.substring(i, i + 1)); +// data = read(code[0], code[1]); +// byteCount = 0; +// for (int line = 0; line < 16; line++) { +// lCount = 0; +// for (int k = 0; k < 2; k++) { +// for (int j = 0; j < 8; j++) { +// if ((data[byteCount] & mask[j]) == mask[j]) { +// g.drawLine(x + lCount + (i << 4), y + line, x +// + lCount + (i << 4), y + line); +// } +// +// lCount++; +// +// } +// byteCount++; +// } +// } +// } +// } +