출력요소 줄바꿈 기능 추가

main
이범준 11 months ago
parent f8b6fd7505
commit ce9fabf400

@ -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; //글자색

@ -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<String> textList = new ArrayList<String>();
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<String, PDType0Font> getFontMap(PDDocument doc) {
try {
Map<String, PDType0Font> fontMap = Map.of(

@ -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; //글자색

@ -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")) {

@ -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}

@ -121,8 +121,9 @@
<th style="width:110px">영역(좌우)</th>
<th style="width:110px">영역(상하)</th>
<th style="width:140px">텍스트정렬</th>
<th style="width:110px">글꼴</th>
<th style="width:110px">글자크기</th>
<th style="width:70px">줄바꿈</th>
<th style="width:100px">글꼴</th>
<th style="width:80px">글자크기</th>
<th style="width:80px">글자색</th>
<th style="width:110px">글자스타일</th>
<th class="dummy-th"></th>
@ -137,7 +138,7 @@
<button type="button">▼</button>
</td>
<td data-col="checkbox" class="text-center">
<input type="checkbox" class="form-check-input" />
<input type="checkbox" name="del" class="form-check-input" />
</td>
<td data-col="otptArtclNm" class="text-center">
<select class="form-select" onchange="pageObject['${pageName}'].fnChangeComponent(this);">
@ -168,8 +169,11 @@
</select>
<button type="button" class="btn btn-xs btn-outline-dark h-px-25 px-1">▶</button>
</td>
<td data-col="lineChgYn" class="text-center">
<input type="checkbox" value="Y" class="form-check-input" />
</td>
<td data-col="fontNm" class="text-center">
<select class="form-select no-bgi">
<select class="form-select no-bgi w-automin">
<option value="gulimche">굴림체</option>
<option value="gulim">굴림</option>
<option value="batangche">바탕체</option>
@ -181,7 +185,7 @@
</select>
</td>
<td data-col="fontSz" class="text-center">
<input type="number" class="form-control w-px-90" min="8" max="25" />
<input type="number" class="form-control w-px-60" min="8" max="25" />
</td>
<td data-col="fontColor" class="text-center">
<select class="form-select no-bgi w-automin">
@ -344,9 +348,11 @@ $(document).ready(function(){
$("#otptGlobalStng--${pageName}").append(document.getElementById("bcrnTemplate--${pageName}").innerHTML);
if(otptGlobalStng.BCRN_IMG_PATH == null || otptGlobalStng.BCRN_IMG_PATH == ""){
$("#fileStatus--${pageName}").text("없음");
$("#fileStatus--${pageName}").attr("title","");
$("#btnBgDown--${pageName}").attr("hidden","hidden");
} else {
$("#fileStatus--${pageName}").text(otptGlobalStng.BCRN_IMG_FILE_NM);
$("#fileStatus--${pageName}").text("있음");
$("#fileStatus--${pageName}").attr("title",otptGlobalStng.BCRN_IMG_FILE_NM);
$("#btnBgDown--${pageName}").removeAttr("hidden");
}
@ -396,6 +402,8 @@ $(document).ready(function(){
$($P.fnGetElement(lastTr,"textSort"))
.set(!isEmpty(data.TEXT_SORT) ? data.TEXT_SORT : $P.fnGetProto(prototypeList, data.OTPT_ARTCL_NM, "textSort"));
$($P.fnGetElement(lastTr,"lineChgYn"))
.set(!isEmpty(data.LINE_CHG_YN) ? data.LINE_CHG_YN : $P.fnGetProto(prototypeList, data.OTPT_ARTCL_NM, "lineChgYn"));
$($P.fnGetElement(lastTr,"fontNm"))
.set(!isEmpty(data.FONT_NM) ? data.FONT_NM : $P.fnGetProto(prototypeList, data.OTPT_ARTCL_NM, "fontNm"));
$($P.fnGetElement(lastTr,"fontSz"))
@ -467,7 +475,7 @@ $(document).ready(function(){
var prototypeList = $P.otptArtclStngMap.unique.prototypeList;
var existArr = [];
$("#tbodyUnique--sprt01200-main tr").each(function(){
$("#tbodyUnique--${pageName} tr").each(function(){
var el = $P.fnGetElement(this,"otptArtclNm");
existArr.push($(el).val());
});
@ -548,6 +556,8 @@ $(document).ready(function(){
$($P.fnGetElement(lastTr,"textSort"))
.set($P.fnGetProto(prototypeList, otptArtclNm, "textSort"));
$($P.fnGetElement(lastTr,"lineChgYn"))
.set($P.fnGetProto(prototypeList, otptArtclNm, "lineChgYn"));
$($P.fnGetElement(lastTr,"fontNm"))
.set($P.fnGetProto(prototypeList, otptArtclNm, "fontNm"));
$($P.fnGetElement(lastTr,"fontSz"))
@ -592,13 +602,13 @@ $(document).ready(function(){
return;
}
if($("#"+tbodyId).find("input[type='checkbox']:checked").length <= 0){
if($("#"+tbodyId).find("input[name='del'][type='checkbox']:checked").length <= 0){
alert('체크된 항목이 없습니다.');
return;
}
$("#"+tbodyId).find("tr").filter(function(index, selector){
if($(selector).find(":checkbox").is(":checked")){
if($(selector).find("input[name='del'][type='checkbox']").is(":checked")){
$(selector).remove();
}
});
@ -615,27 +625,30 @@ $(document).ready(function(){
var prototypeList = $P.otptArtclStngMap.multiple.prototypeList;
$($P.fnGetElement(tr,"componentType"))
.val($P.fnGetProto(prototypeList, otptArtclNm, "componentType"));
.set($P.fnGetProto(prototypeList, otptArtclNm, "componentType"));
$($P.fnGetElement(tr,"leftPstn"))
.val($P.fnGetProto(prototypeList, otptArtclNm, "leftPstn"));
.set($P.fnGetProto(prototypeList, otptArtclNm, "leftPstn"));
$($P.fnGetElement(tr,"topPstn"))
.val($P.fnGetProto(prototypeList, otptArtclNm, "topPstn"));
.set($P.fnGetProto(prototypeList, otptArtclNm, "topPstn"));
$($P.fnGetElement(tr,"widthSz"))
.val($P.fnGetProto(prototypeList, otptArtclNm, "widthSz"));
.set($P.fnGetProto(prototypeList, otptArtclNm, "widthSz"));
$($P.fnGetElement(tr,"heightSz"))
.val($P.fnGetProto(prototypeList, otptArtclNm, "heightSz"));
.set($P.fnGetProto(prototypeList, otptArtclNm, "heightSz"));
$($P.fnGetElement(tr,"textSort"))
.val($P.fnGetProto(prototypeList, otptArtclNm, "textSort"));
.set($P.fnGetProto(prototypeList, otptArtclNm, "textSort"));
$($P.fnGetElement(tr,"lineChgYn"))
.set($P.fnGetProto(prototypeList, otptArtclNm, "lineChgYn"));
$($P.fnGetElement(tr,"fontNm"))
.val($P.fnGetProto(prototypeList, otptArtclNm, "fontNm"));
.set($P.fnGetProto(prototypeList, otptArtclNm, "fontNm"));
$($P.fnGetElement(tr,"fontSz"))
.val($P.fnGetProto(prototypeList, otptArtclNm, "fontSz"));
.set($P.fnGetProto(prototypeList, otptArtclNm, "fontSz"));
$($P.fnGetElement(tr,"fontColor"))
.val($P.fnGetProto(prototypeList, otptArtclNm, "fontColor"));
.set($P.fnGetProto(prototypeList, otptArtclNm, "fontColor"));
$($P.fnGetElement(tr,"fontStyle"))
.val($P.fnGetProto(prototypeList, otptArtclNm, "fontStyle"));
.set($P.fnGetProto(prototypeList, otptArtclNm, "fontStyle"));
}
@ -651,7 +664,16 @@ $(document).ready(function(){
row.topPstn = $($P.fnGetElement(this,"topPstn")).val();
row.widthSz = $($P.fnGetElement(this,"widthSz")).val();
row.heightSz = $($P.fnGetElement(this,"heightSz")).val();
row.textSort = $($P.fnGetElement(this,"textSort")).val();
var lineChgYnEl = $P.fnGetElement(this,"lineChgYn");
if($(lineChgYnEl).is(":checked")){
row.lineChgYn = "Y";
} else {
row.lineChgYn = "N";
}
row.fontNm = $($P.fnGetElement(this,"fontNm")).val();
row.fontSz = $($P.fnGetElement(this,"fontSz")).val();
row.fontColor = $($P.fnGetElement(this,"fontColor")).val();
@ -673,7 +695,7 @@ $(document).ready(function(){
$P.fnSave = () => {
//출력물 전역설정
var formData = new FormData(document.getElementById("frmEdit--sprt01200-main"));
var formData = new FormData(document.getElementById("frmEdit--${pageName}"));
//출력 요소 설정
var rowArr1 = $P.getRowData("tbodyUnique--${pageName}", formData);
@ -784,14 +806,17 @@ $(document).ready(function(){
$P.fnBgUpload = (fileElement) => {
if(fileElement.files == null || fileElement.files.length == 0){
if($P.otptGlobalStng.BCRN_IMG_PATH == null || $P.otptGlobalStng.BCRN_IMG_PATH == ""){
$("#fileStatus--sprt01200-main").text("없음");
$("#fileStatus--${pageName}").text("없음");
$("#fileStatus--${pageName}").attr("title","");
$("#btnBgDown--${pageName}").attr("hidden","hidden");
} else {
$("#fileStatus--sprt01200-main").text($P.otptGlobalStng.BCRN_IMG_FILE_NM);
$("#fileStatus--${pageName}").text("있음");
$("#fileStatus--${pageName}").attr("title", $P.otptGlobalStng.BCRN_IMG_FILE_NM);
$("#btnBgDown--${pageName}").removeAttr("hidden");
}
} else {
$("#fileStatus--sprt01200-main").text("이미지 변경됨");
$("#fileStatus--${pageName}").text("이미지 변경됨");
$("#fileStatus--${pageName}").attr("title","");
$("#btnBgDown--${pageName}").attr("hidden","hidden");
}
}

@ -12,6 +12,12 @@ $.fn.set = function(value) {
} else if($(this).hasClass('option-style-select')){
$(this).val(value);
this.changeUI();
} else if(this.type == "checkbox" || this.type == "radio"){
if(this.value == value){
$(this).prop("checked", true);
} else {
$(this).prop("checked", false);
}
} else {
$(this).val(value);
}

Loading…
Cancel
Save