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