From a8ab78e5176018992d7f9714350e56b7a310630e Mon Sep 17 00:00:00 2001 From: wuchunlei Date: Wed, 10 Sep 2025 14:29:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=94=9F=E6=88=90=E8=8B=B1?= =?UTF-8?q?=E6=96=87=E8=AF=81=E4=B9=A6=E6=97=B6=E8=8B=B1=E6=96=87=E5=AE=8C?= =?UTF-8?q?=E6=95=B4=E6=8D=A2=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/UserCertificateServiceImpl.java | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) 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); } } // 释放资源