Browse Source

gbk改utf8

dev
zxc 3 years ago
parent
commit
930ed68e29
  1. 10
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/BarcodeUtils.java

10
epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/BarcodeUtils.java

@ -106,7 +106,7 @@ public class BarcodeUtils {
g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
g.setBackground(Color.white); g.setBackground(Color.white);
// 获取文字数量 按照字节展示 // 获取文字数量 按照字节展示
int size = pressText.getBytes("GBK").length; int size = pressText.getBytes("UTF-8").length;
// 获取一行最多能容纳多少文字 按照文字字节展示 // 获取一行最多能容纳多少文字 按照文字字节展示
int maxSize = (WIDTH / FONTSIZE - 2) * 2; int maxSize = (WIDTH / FONTSIZE - 2) * 2;
if (size > maxSize) { if (size > maxSize) {
@ -121,7 +121,7 @@ public class BarcodeUtils {
g.drawString(pressText, (WIDTH - (FONTSIZE * v)) / 2, startY); g.drawString(pressText, (WIDTH - (FONTSIZE * v)) / 2, startY);
} }
} else { } else {
g.drawString(pressText, (WIDTH - ((pressText.getBytes("GBK").length) / 2) * FONTSIZE) / 2, startY); g.drawString(pressText, (WIDTH - ((pressText.getBytes("UTF-8").length) / 2) * FONTSIZE) / 2, startY);
} }
g.dispose(); g.dispose();
@ -153,7 +153,7 @@ public class BarcodeUtils {
private static String outStringByByte(String str, int len) throws IOException { private static String outStringByByte(String str, int len) throws IOException {
byte[] btf = str.getBytes("gbk"); byte[] btf = str.getBytes("UTF-8");
int count = 0; int count = 0;
for (int j = len - 1; j >= 0; j--) { for (int j = len - 1; j >= 0; j--) {
@ -165,9 +165,9 @@ public class BarcodeUtils {
} }
if (count % 2 == 0) { if (count % 2 == 0) {
return new String(btf, 0, len, "gbk"); return new String(btf, 0, len, "UTF-8");
} else { } else {
return new String(btf, 0, len - 1, "gbk"); return new String(btf, 0, len - 1, "UTF-8");
} }
} }

Loading…
Cancel
Save