diff --git a/src/main/java/com/peanut/modules/common/service/impl/UserCertificateServiceImpl.java b/src/main/java/com/peanut/modules/common/service/impl/UserCertificateServiceImpl.java index c371fd72..69e506a7 100644 --- a/src/main/java/com/peanut/modules/common/service/impl/UserCertificateServiceImpl.java +++ b/src/main/java/com/peanut/modules/common/service/impl/UserCertificateServiceImpl.java @@ -307,26 +307,26 @@ public class UserCertificateServiceImpl extends ServiceImpl700){//换行画 + String str = ""; + int nowIndex = 0; //目前一行的长度 + for (int i = 0; i < des.length(); i++) { //9 + String tempStr = ""; + str = str + des.charAt(i); + int strWidth = dess.stringWidth(str.substring(nowIndex)); //获取字符的长度 + if (strWidth>700) {//换行 + int index = str.lastIndexOf(" ")+1; + tempStr = str.substring(nowIndex,index); + int writeY = 700 + alreadyWriteLine * (dess.getHeight()+10);//10是行间距 + g.drawString(tempStr, 155, writeY); alreadyWriteLine++; + nowIndex = index; + } + if (i==des.length()-1){ + tempStr = str.substring(nowIndex); int writeY = 700 + alreadyWriteLine * (dess.getHeight()+10);//10是行间距 - g.drawString(des.charAt(i) + "", 155, writeY); - nowWidth = 0; - space = false; - nowWidth += oneWordWidth; - }else {//一字一字画 - int writeY = 700 + alreadyWriteLine * (dess.getHeight()+10);//10是行间距 - if (nowWidth==0&&space){//首行空一格 - g.drawString(des.charAt(i)+"", 155+oneWordWidth, writeY); - nowWidth += oneWordWidth*2; - }else { - g.drawString(des.charAt(i)+"", 155+nowWidth, writeY); - nowWidth += oneWordWidth; - } + g.drawString(tempStr, 155, writeY); } } // 释放资源