Commit 8f2d9b23 by 胡懿

调整二维码生成

parent 5240d608
...@@ -252,12 +252,12 @@ public class DrawQrcodeUtil { ...@@ -252,12 +252,12 @@ public class DrawQrcodeUtil {
, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); , RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
g2.setRenderingHints(rh); g2.setRenderingHints(rh);
Font font = new Font("黑体",Font.BOLD,16 * qRcodeSize.getInitfontSize()); Font font = new Font("黑体",Font.BOLD,12 * qRcodeSize.getInitfontSize());
g2.setFont(font); //设置字体:字体、字号、大小 g2.setFont(font); //设置字体:字体、字号、大小
g2.setColor(qRcodeSize.color);//设置背景颜色 g2.setColor(qRcodeSize.color);//设置背景颜色
// g2.setBackground(c); // g2.setBackground(c);
int contentX = qRcodeSize.getInitContentX(); int contentX = qRcodeSize.getInitContentX();
int contentY = qRcodeSize.getInitContentY() + 200; int contentY = qRcodeSize.getInitContentY() + 150;
//写二维码 //写二维码
g2.drawImage(qrcodeImage,qRcodeSize.getQrcodeX(),qRcodeSize.getQrcodeY(),qRcodeSize.getQrcodeWidth(),qRcodeSize.getQrcodeHeight(),null,null); g2.drawImage(qrcodeImage,qRcodeSize.getQrcodeX(),qRcodeSize.getQrcodeY(),qRcodeSize.getQrcodeWidth(),qRcodeSize.getQrcodeHeight(),null,null);
...@@ -273,26 +273,48 @@ public class DrawQrcodeUtil { ...@@ -273,26 +273,48 @@ public class DrawQrcodeUtil {
//写入货品类型 //写入货品类型
String contentTitle2 = "货品类型:"; String contentTitle2 = "货品类型:";
int contentTitle2Width = g2.getFontMetrics().stringWidth(contentTitle2); int contentTitle2Width = g2.getFontMetrics().stringWidth(contentTitle2);
g2.drawString(contentTitle2,contentX,contentY+200); g2.drawString(contentTitle2,contentX,contentY+150);
String typeName = formatContent(goodsInfo.getType().getName(),10); String typeName = goodsInfo.getType().getName();
as = new AttributedString(typeName); if (typeName.length() > 15) {
as.addAttribute(TextAttribute.FONT, font); String str1 = typeName.substring(0, 9);
as.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_LOW_DASHED, 0, typeName.length()); str1 = formatContent(str1,9);
g2.drawString(as.getIterator(),contentX+contentTitle2Width,contentY+200); as = new AttributedString(str1);
as.addAttribute(TextAttribute.FONT, font);
as.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_LOW_DASHED, 0, str1.length());
g2.drawString(as.getIterator(),contentX+contentTitle2Width,contentY+150);
String str2 = typeName.substring(9, typeName.length());
str2 = formatContent(str2,9);
as = new AttributedString(str2);
as.addAttribute(TextAttribute.FONT, font);
as.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_LOW_DASHED, 0, str2.length());
g2.drawString(as.getIterator(),contentX+contentTitle2Width,contentY+300);
} else {
typeName = formatContent(goodsInfo.getType().getName(),10);
as = new AttributedString(typeName);
as.addAttribute(TextAttribute.FONT, font);
as.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_LOW_DASHED, 0, typeName.length());
g2.drawString(as.getIterator(),contentX+contentTitle2Width,contentY+150);
}
//写入物资编码 //写入物资编码
String contentTitle4 = "物资编码:"; String contentTitle4 = "物资编码:";
int contentTitle4Width = g2.getFontMetrics().stringWidth(contentTitle4); int contentTitle4Width = g2.getFontMetrics().stringWidth(contentTitle4);
g2.drawString(contentTitle4,contentX,contentY+400); g2.drawString(contentTitle4,contentX,contentY+450);
String code = qrCode.getCode(); String code = qrCode.getCode();
if (code.length() > 10) { if (code.length() > 15) {
String str1 = code.substring(0, 9); String str1 = code.substring(0, 14);
str1 = formatContent(str1,10); str1 = formatContent(str1,15);
as = new AttributedString(str1); as = new AttributedString(str1);
as.addAttribute(TextAttribute.FONT, font); as.addAttribute(TextAttribute.FONT, font);
as.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_LOW_DASHED, 0, str1.length()); as.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_LOW_DASHED, 0, str1.length());
g2.drawString(as.getIterator(),contentX+contentTitle4Width,contentY+400); g2.drawString(as.getIterator(),contentX+contentTitle4Width,contentY+450);
String str2 = code.substring(9, code.length()); String str2 = code.substring(14, code.length());
str2 = formatContent(str2,10); str2 = formatContent(str2,15);
as = new AttributedString(str2); as = new AttributedString(str2);
as.addAttribute(TextAttribute.FONT, font); as.addAttribute(TextAttribute.FONT, font);
as.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_LOW_DASHED, 0, str2.length()); as.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_LOW_DASHED, 0, str2.length());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment