diff --git a/src/main/java/cokr/xit/fims/cmmn/pdf/DefaultOtptArtclStng.java b/src/main/java/cokr/xit/fims/cmmn/pdf/DefaultOtptArtclStng.java index 1b256dc7..96009a21 100644 --- a/src/main/java/cokr/xit/fims/cmmn/pdf/DefaultOtptArtclStng.java +++ b/src/main/java/cokr/xit/fims/cmmn/pdf/DefaultOtptArtclStng.java @@ -24,6 +24,8 @@ public class DefaultOtptArtclStng { this.fontStyle="FILL"; this.textSort = "left"; + this.lineChgYn = "N"; + this.forPost = false; this.unique = false; } @@ -124,6 +126,7 @@ public class DefaultOtptArtclStng { private float widthSz; //영역크기 길이 private float heightSz; //영역크기 높이 private String textSort; //텍스트정렬 + private String lineChgYn; private String fontNm; //글꼴명 private int fontSz; //글자크기 private String fontColor; //글자색 diff --git a/src/main/java/cokr/xit/fims/cmmn/pdf/PDFPrintUtil.java b/src/main/java/cokr/xit/fims/cmmn/pdf/PDFPrintUtil.java index f9386e24..86899e59 100644 --- a/src/main/java/cokr/xit/fims/cmmn/pdf/PDFPrintUtil.java +++ b/src/main/java/cokr/xit/fims/cmmn/pdf/PDFPrintUtil.java @@ -3,6 +3,7 @@ package cokr.xit.fims.cmmn.pdf; import java.io.File; import java.io.IOException; import java.text.SimpleDateFormat; +import java.util.ArrayList; import java.util.Date; import java.util.Map; @@ -67,41 +68,77 @@ public class PDFPrintUtil extends PrintUtil { } // - public void writeText(PDPageContentStream contentStream, String text, - float[] XYmm, float textAreaWidth_mm, String align, + public void writeText(PDPageContentStream contentStream, String allText, + float[] XYmm, float textAreaWidth_mm, String align, String newLineYn, PDType0Font font, int fontSize, RenderingMode fontStyle, PDColor fontColor) { try { - if(text == null) { - text = ""; + if(allText == null) { + allText = ""; } + if(newLineYn == null || newLineYn.equals("")) { + newLineYn = "N"; + } + float[] xyAbsolute = this.toPDFCoordinate(XYmm).absolute(); float textAreaWidth_pt = mmToPt(textAreaWidth_mm); - float textWidth = (font.getStringWidth(text) / 1000.0f) * fontSize; - float textAreaHalfWidth_pt = textAreaWidth_pt / 2; - float textHalfWidth = textWidth / 2; + float allTextWidth = calcTextWidth(font, fontSize, allText); + + String textArr[]; + if(allText.equals("") || allText.length() == 1 || textAreaWidth_pt == 0 + || (allTextWidth <= textAreaWidth_pt) + || newLineYn.equals("N")) { + + textArr = new String[] { allText }; + + } else { + + textArr = splitByLineForLargeText(font, fontSize, allText, textAreaWidth_pt); + + } + + String firstLine = textArr[0]; + float firstLineWidth = calcTextWidth(font, fontSize, firstLine); contentStream.beginText(); contentStream.setFont(font, fontSize); - contentStream.setRenderingMode(fontStyle); - contentStream.setNonStrokingColor(fontColor); float resultY = xyAbsolute[1] - fontSize; - float resultX; + + float firstLineAlignCorrection = 0; if(align.equals("right")) { - resultX = xyAbsolute[0] - textWidth + textAreaWidth_pt; - } else if(align.equals("center")){ - resultX = xyAbsolute[0] - textHalfWidth + textAreaHalfWidth_pt; - } else { - resultX = xyAbsolute[0]; + firstLineAlignCorrection = textAreaWidth_pt - firstLineWidth; + } else if(align.equals("center")) { + firstLineAlignCorrection = (textAreaWidth_pt - firstLineWidth)/2; } + float resultX = xyAbsolute[0] + firstLineAlignCorrection; + contentStream.newLineAtOffset(resultX, resultY); + contentStream.showText(textArr[0]); + + if(textArr.length > 1) { + + for(int i = 1; i < textArr.length; i++) { + String thisLine = textArr[i]; + float thisLineWidth = this.calcTextWidth(font, fontSize, thisLine); + float alignCorrection = 0; + + if(align.equals("right")) { + alignCorrection = firstLineWidth - thisLineWidth; + } if(align.equals("center")) { + alignCorrection = (firstLineWidth - thisLineWidth)/2; + } + + contentStream.newLineAtOffset(alignCorrection, -(fontSize + 1)); + contentStream.showText(thisLine); + } - contentStream.showText(text); + + } contentStream.endText(); @@ -111,6 +148,57 @@ public class PDFPrintUtil extends PrintUtil { } + + public float calcTextWidth(PDType0Font font, int fontSize, String text) { + try { + return (font.getStringWidth(text) / 1000.0f) * fontSize; + } catch (IOException e) { + throw new RuntimeException("PDF 파일 출력 중 오류가 발생하였습니다."); + } + } + + public String[] splitByLineForLargeText(PDType0Font font, int fontSize, String allText, float textAreaWidth_pt) { + + float allTextWidth = calcTextWidth(font, fontSize, allText); + + if(allText.equals("") || allText.length() == 1 || textAreaWidth_pt == 0 + || (allTextWidth <= textAreaWidth_pt) + ) { + return new String[] { allText }; + } + + ArrayList textList = new ArrayList(); + + while(!allText.equals("")) { + int lengthForLine = this.getLengthForLine(font, fontSize, allText, textAreaWidth_pt); + String newLine = allText.substring(0,lengthForLine); + textList.add(newLine); + allText = allText.substring(lengthForLine); + } + + return textList.toArray(new String[textList.size()]); + } + + private int getLengthForLine(PDType0Font font, int fontSize, String allText, float textAreaWidth_pt) { + int forLine = allText.length(); + if(forLine <= 1) { + return forLine; + }; + + for( ; ; forLine--) { + if(forLine == 1) { + break; + } + + boolean hit = ( this.calcTextWidth(font, fontSize, allText.substring(0, forLine)) <= textAreaWidth_pt ); + if(hit) { + break; + } + } + + return forLine; + } + public void insertImage(PDDocument doc, PDPageContentStream contentStream, String imagePath, float[] XYmm, float[] SIZEmm) { @@ -240,6 +328,14 @@ public class PDFPrintUtil extends PrintUtil { } } + public String getLineChgYn(DefaultOtptArtclStng prototypeStng, DataObject sggStng) { + if(!sggStng.string("LINE_CHG_YN").equals("")) { + return sggStng.string("LINE_CHG_YN"); + } else { + return prototypeStng.getLineChgYn(); + } + } + public Map getFontMap(PDDocument doc) { try { Map fontMap = Map.of( diff --git a/src/main/java/cokr/xit/fims/sprt/OtptArtclStng.java b/src/main/java/cokr/xit/fims/sprt/OtptArtclStng.java index 90a89f76..e4d9dbea 100644 --- a/src/main/java/cokr/xit/fims/sprt/OtptArtclStng.java +++ b/src/main/java/cokr/xit/fims/sprt/OtptArtclStng.java @@ -14,6 +14,7 @@ public class OtptArtclStng extends AbstractEntity { private String widthSz; //영역크기 길이 private String heightSz; //영역크기 높이 private String textSort; //텍스트정렬 + private String lineChgYn; private String fontNm; //글꼴명 private String fontSz; //글자크기 private String fontColor; //글자색 diff --git a/src/main/java/cokr/xit/fims/sprt/service/bean/Sprt01ServiceBean.java b/src/main/java/cokr/xit/fims/sprt/service/bean/Sprt01ServiceBean.java index f4f27d1c..9d6aa22f 100644 --- a/src/main/java/cokr/xit/fims/sprt/service/bean/Sprt01ServiceBean.java +++ b/src/main/java/cokr/xit/fims/sprt/service/bean/Sprt01ServiceBean.java @@ -404,6 +404,7 @@ public class Sprt01ServiceBean extends AbstractServiceBean implements Sprt01Serv if(prototypeStng.getComponentType().equals("text")) { String align = pdfPrintUtil.getAlign(prototypeStng, otptArtclStng); + String lineChgYn = pdfPrintUtil.getLineChgYn(prototypeStng, otptArtclStng); PDType0Font font = pdfPrintUtil.getFontType(prototypeStng, otptArtclStng, fontMap); int fontSz = pdfPrintUtil.getFontSize(prototypeStng, otptArtclStng); RenderingMode fontStyle = pdfPrintUtil.getFontStyle(prototypeStng, otptArtclStng); @@ -411,7 +412,8 @@ public class Sprt01ServiceBean extends AbstractServiceBean implements Sprt01Serv String textValue = pdfFormat.getMappingValue(otptArtclNm,defaultValue,forPost,dataObject,printOption,pdfPrintUtil); - pdfPrintUtil.writeText(contentStream, textValue, pstn, size[0], align, font, fontSz, fontStyle, fontColor); + pdfPrintUtil.writeText(contentStream, textValue, pstn, size[0], align, lineChgYn + , font, fontSz, fontStyle, fontColor); } else if(prototypeStng.getComponentType().equals("image")) { diff --git a/src/main/resources/sql/mapper/fims/sprt/otptStng-mapper.xml b/src/main/resources/sql/mapper/fims/sprt/otptStng-mapper.xml index c7df5812..8b768402 100644 --- a/src/main/resources/sql/mapper/fims/sprt/otptStng-mapper.xml +++ b/src/main/resources/sql/mapper/fims/sprt/otptStng-mapper.xml @@ -95,6 +95,7 @@ SELECT OTPT_FORM_ID , FONT_COLOR , FONT_STYLE , TEXT_SORT + , LINE_CHG_YN , OTPT_ARTCL_ORDR FROM TB_OTPT_FORM_STNG WHERE USE_YN = 'Y' @@ -126,6 +127,7 @@ INSERT , WIDTH_SZ , HEIGHT_SZ , TEXT_SORT + , LINE_CHG_YN , FONT_NM , FONT_SZ , FONT_COLOR @@ -146,6 +148,7 @@ INSERT , #{widthSz} , #{heightSz} , #{textSort} + , #{lineChgYn} , #{fontNm} , #{fontSz} , #{fontColor} @@ -166,6 +169,7 @@ UPDATE TB_OTPT_FORM_STNG , WIDTH_SZ = #{widthSz} , HEIGHT_SZ = #{heightSz} , TEXT_SORT = #{textSort} + , LINE_CHG_YN = #{lineChgYn} , FONT_NM = #{fontNm} , FONT_SZ = #{fontSz} , FONT_COLOR = #{fontColor} diff --git a/src/main/webapp/WEB-INF/jsp/fims/sprt/sprt01200-main.jsp b/src/main/webapp/WEB-INF/jsp/fims/sprt/sprt01200-main.jsp index 5bf07c49..6854a009 100644 --- a/src/main/webapp/WEB-INF/jsp/fims/sprt/sprt01200-main.jsp +++ b/src/main/webapp/WEB-INF/jsp/fims/sprt/sprt01200-main.jsp @@ -121,8 +121,9 @@ 영역(좌우) 영역(상하) 텍스트정렬 - 글꼴 - 글자크기 + 줄바꿈 + 글꼴 + 글자크기 글자색 글자스타일 @@ -137,7 +138,7 @@ - + + + + - @@ -181,7 +185,7 @@ - +