瀏覽代碼

code sync + tuning

TonyKang 6 年之前
父節點
當前提交
99531d6578

+ 94 - 24
modules/reports/util/rpt_pdf_util.js

@@ -152,33 +152,21 @@ function export_pdf_file (pageData, paperSize, fName, callback) {
         }
         doc.font(fontFile);
         let options={};
-        if (control) {
-            private_setupAreaH(area, control.Horizon, font.FontAngle, dftFontHeight, output,options);
-            private_setupAreaV(area, control.Vertical, font.FontAngle, dftFontHeight, output);
-        } else {
-            private_setupAreaH(area, "left", font.FontAngle, dftFontHeight, output,options);
-            private_setupAreaV(area, "bottom", font.FontAngle, dftFontHeight, output);
-        }
+        let inner_setupControl = function (inArea, inFontHeight, inOutput) {
+            if (control) {
+                private_setupAreaH(inArea, control.Horizon, font.FontAngle, inFontHeight, inOutput, options);
+                private_setupAreaV(inArea, control.Vertical, font.FontAngle, inFontHeight, inOutput);
+            } else {
+                private_setupAreaH(inArea, "left", parseInt(font.FontAngle), inFontHeight, inOutput, options);
+                private_setupAreaV(inArea, "bottom", parseInt(font.FontAngle), inFontHeight, inOutput);
+            }
+        };
+        inner_setupControl(area, dftFontHeight, output);
         let w = area[JV.IDX_RIGHT] - JV.OUTPUT_OFFSET[JV.OFFSET_IDX_RIGHT] - area[JV.IDX_LEFT] - JV.OUTPUT_OFFSET[JV.OFFSET_IDX_RIGHT];
         if (parseInt(font.FontAngle) !== 0) {
             w = area[JV.IDX_BOTTOM] - JV.OUTPUT_OFFSET[JV.OFFSET_IDX_BOTTOM] - area[JV.IDX_TOP] - JV.OUTPUT_OFFSET[JV.OFFSET_IDX_TOP];
         }
-        // doc.save();
-        //doc.translate(output[0], output[1]);
-        if (w >= doc.widthOfString(val)) {
-            options.width = w;
-            options.height = dftFontHeight;
-        } else {
-            while (true) {
-                dftFontHeight--;
-                doc.fontSize(dftFontHeight);
-                if (w >= doc.widthOfString(val) || dftFontHeight < 6) {
-                    options.width = w;
-                    options.height = dftFontHeight;
-                    break;
-                }
-            }
-        }
+
         function private_drawUnderline() {
             //A. 暂不支持角度; B. PDF输出时,坐标没有translate
             let ctx = doc;
@@ -230,7 +218,61 @@ function export_pdf_file (pageData, paperSize, fName, callback) {
             }
             doc.rotate(font.FontAngle,rotateOptions);
         }
-        doc.text(val,output[0], output[1], options);
+        if (w >= doc.widthOfString(val) || (control && control.Shrink !== 'T')) {
+            options.width = w;
+            options.height = dftFontHeight;
+            doc.text(val,output[0], output[1], options);
+            doc.font(__dirname + '/pdf_base_files/simhei_bold_italic.ttf');
+        } else {
+            while (true) {
+                //*/
+                let lines = Math.floor((area[JV.IDX_BOTTOM] - area[JV.IDX_TOP]) / (dftFontHeight + JV.OUTPUT_OFFSET[JV.OFFSET_IDX_BOTTOM] + JV.OUTPUT_OFFSET[JV.OFFSET_IDX_TOP] + 4));
+                lines = (lines === 0)?1:lines;
+                let actLines = private_splitString(val, w, doc);
+                if (actLines.length > lines && dftFontHeight >= 6) {
+                    dftFontHeight--;
+                    doc.fontSize(dftFontHeight);
+                    options.width = w;
+                    options.height = dftFontHeight;
+                    doc.text(val,output[0], output[1], options);
+                } else {
+                    let aH = dftFontHeight + JV.OUTPUT_OFFSET[JV.OFFSET_IDX_BOTTOM] + JV.OUTPUT_OFFSET[JV.OFFSET_IDX_TOP] + 4;
+                    if ((aH * actLines.length) < (area[JV.IDX_BOTTOM] - area[JV.IDX_TOP]) && (control && control.Vertical !== 'top')) {
+                        if (control.Vertical === 'bottom') {
+                            area[JV.IDX_TOP] = area[JV.IDX_BOTTOM] - (aH * actLines.length);
+                        } else {
+                            area[JV.IDX_TOP] = (area[JV.IDX_TOP] + area[JV.IDX_BOTTOM]) / 2 - (aH * actLines.length) / 2
+                            area[JV.IDX_BOTTOM] = area[JV.IDX_TOP] + (aH * actLines.length);
+                        }
+                    }
+                    let newArea = [], baseTop = area[JV.IDX_TOP];
+                    for (let ai = 0; ai < area.length; ai++) {
+                        newArea[ai] = area[ai];
+                    }
+                    options.width = w;
+                    options.height = dftFontHeight;
+                    for (let lIdx = 0; lIdx < actLines.length; lIdx++) {
+                        newArea[JV.IDX_TOP] = Math.round(aH * lIdx + baseTop);
+                        newArea[JV.IDX_BOTTOM] = Math.round(aH * (lIdx + 1) + baseTop);
+                        inner_setupControl(newArea, dftFontHeight, output);
+                        doc.text(actLines[lIdx], output[0], output[1], options);
+                    }
+                    break;
+                }
+                /*/
+                dftFontHeight--;
+                doc.fontSize(dftFontHeight);
+                if (w >= doc.widthOfString(val) || dftFontHeight < 6) {
+                    options.width = w;
+                    options.height = dftFontHeight;
+                    doc.text(val,output[0], output[1], options);
+                    doc.font(__dirname + '/pdf_base_files/simhei_bold_italic.ttf');
+                    break;
+                }
+                //*/
+            }
+        }
+        // doc.text(val,output[0], output[1], options);
         doc.font(__dirname + '/pdf_base_files/simhei_bold_italic.ttf');
         // doc.restore();
     }
@@ -258,6 +300,34 @@ function export_pdf_file (pageData, paperSize, fName, callback) {
         }
     }
 
+    function private_splitString(strVal, areaWidth, doc) {
+        let rst = [];
+        if (strVal) {
+            let preSIdx = 0, txtWidth = 0;
+            let currentW = 0;
+            let chnW = doc.widthOfString('一'), otherW = doc.widthOfString('_');
+            for (let sIdx = 0; sIdx < strVal.length; sIdx++) {
+                currentW = (strVal.charCodeAt(sIdx) > 127)?chnW:otherW;
+                txtWidth += currentW;
+                if (txtWidth > areaWidth) {
+                    if (preSIdx < sIdx) {
+                        rst.push(strVal.substr(preSIdx, sIdx - preSIdx));
+                        preSIdx = sIdx;
+                    } else {
+                        rst.push(strVal.substr(preSIdx, 1));
+                        preSIdx = sIdx + 1;
+                    }
+                    txtWidth = currentW;
+                }
+                if (sIdx === strVal.length - 1) {
+                    rst.push(strVal.substr(preSIdx, strVal.length - preSIdx));
+                }
+            }
+        }
+        if (rst.length === 0) rst.push(''); //什么都没有,也得整个空串
+        return rst;
+    }
+
     function private_setupAreaRotateOption(area,w, type="top",dftFontHeight,outputPoint){
         let x = (area[JV.IDX_RIGHT] - area[JV.IDX_LEFT])/2+area[JV.IDX_LEFT];
         let y =(area[JV.IDX_BOTTOM] - area[JV.IDX_TOP])/2+ area[JV.IDX_TOP];

+ 0 - 8
web/maintain/report/html/rpt_tpl_dtl_calc.html

@@ -14,14 +14,6 @@
                                 </div>
                             </div>
                         </div>
-                        <div class="row" style="display:none;">
-                            <div class="form-group col-md-5">
-                                <select class="form-control" id="exprTemplatesSelect"></select>
-                            </div>
-                            <div class="form-group col-md-1">
-                                <button class="btn btn-primary" id="expr_tpl_select_btn" onclick="calculationTreeOprObj.setTemplateExpression(this)">套用</button>
-                            </div>
-                        </div>
                         <div class="row">
                             <div class="sub-button p-0">
                                 <button class="btn btn-primary" id="ext_code_tpl_select_btn" onclick="calculationTreeOprObj.setExtCodeTemplate(this)">套用</button>

+ 99 - 59
web/maintain/report/js/jpc_output.js

@@ -4,6 +4,7 @@
 let JpcCanvasOutput = {
     offsetX: 10,
     offsetY: 10,
+    scaleFactor: 1,
     cleanCanvas: function (canvas) {
         let ctx = canvas.getContext("2d");
         ctx.save();
@@ -11,9 +12,18 @@ let JpcCanvasOutput = {
         ctx.clearRect(0,0, canvas.width, canvas.height);
         ctx.restore();
     },
+    resetFonts: function(rptFonts) {
+        let me = JpcCanvasOutput;
+        if (me.scaleFactor !== 1) {
+            for (let key in rptFonts) {
+                rptFonts[key]["FontHeight"] = me.scaleFactor * rptFonts[key]["FontHeight"];
+            }
+        }
+    },
     drawToCanvas : function(pageObj, canvas, pageIdx) {
         let me = this;
         let ctx = canvas.getContext("2d");
+        let floatReg = /^(-?\d+)(\.\d+)?$/;
 
         function private_setupAreaH(area, type, fontAngle, dftFontHeight, outputPoint) {
             let lType = type;
@@ -76,6 +86,33 @@ let JpcCanvasOutput = {
                     break;
             }
         }
+        function private_splitString(strVal, areaWidth, ctx) {
+            let rst = [];
+            if (strVal) {
+                let preSIdx = 0, txtWidth = 0;
+                let currentW = 0;
+                let chnW = ctx.measureText('一').width, otherW = ctx.measureText('_').width;
+                for (let sIdx = 0; sIdx < strVal.length; sIdx++) {
+                    currentW = (strVal.charCodeAt(sIdx) > 127)?chnW:otherW;
+                    txtWidth += currentW;
+                    if (txtWidth > areaWidth) {
+                        if (preSIdx < sIdx) {
+                            rst.push(strVal.substr(preSIdx, sIdx - preSIdx));
+                            preSIdx = sIdx;
+                        } else {
+                            rst.push(strVal.substr(preSIdx, 1));
+                            preSIdx = sIdx + 1;
+                        }
+                        txtWidth = currentW;
+                    }
+                    if (sIdx === strVal.length - 1) {
+                        rst.push(strVal.substr(preSIdx, strVal.length - preSIdx));
+                    }
+                }
+            }
+            if (rst.length === 0) rst.push(''); //什么都没有,也得整个空串
+            return rst;
+        }
         function private_drawText(val, area, font, control) {
             let dftFontHeight = 12;
             let output = [];
@@ -92,13 +129,16 @@ let JpcCanvasOutput = {
                 }
                 ctx.font = dftOthers + dftFontHeight + "px " + font[JV.PROP_NAME];
             }
-            if (control) {
-                private_setupAreaH(area, control.Horizon, parseInt(font.FontAngle), dftFontHeight, output);
-                private_setupAreaV(area, control.Vertical, parseInt(font.FontAngle), font.Name, dftFontHeight, output);
-            } else {
-                private_setupAreaH(area, "left", parseInt(font.FontAngle), dftFontHeight, output);
-                private_setupAreaV(area, "bottom", parseInt(font.FontAngle), font.Name, dftFontHeight, output);
-            }
+            let inner_setupControl = function (inArea, inFontHeight, inOutput) {
+                if (control) {
+                    private_setupAreaH(inArea, control.Horizon, parseInt(font.FontAngle), inFontHeight, inOutput);
+                    private_setupAreaV(inArea, control.Vertical, parseInt(font.FontAngle), font.Name, inFontHeight, inOutput);
+                } else {
+                    private_setupAreaH(inArea, "left", parseInt(font.FontAngle), inFontHeight, inOutput);
+                    private_setupAreaV(inArea, "bottom", parseInt(font.FontAngle), font.Name, inFontHeight, inOutput);
+                }
+            };
+            inner_setupControl(area, dftFontHeight, output);
             let w = area[JV.IDX_RIGHT] - JV.OUTPUT_OFFSET[JV.OFFSET_IDX_RIGHT] - area[JV.IDX_LEFT] - JV.OUTPUT_OFFSET[JV.OFFSET_IDX_RIGHT];
             if ( parseInt(font.FontAngle) !== 0) {
                 w = area[JV.IDX_BOTTOM] - JV.OUTPUT_OFFSET[JV.OFFSET_IDX_BOTTOM] - area[JV.IDX_TOP] - JV.OUTPUT_OFFSET[JV.OFFSET_IDX_TOP];
@@ -154,14 +194,38 @@ let JpcCanvasOutput = {
             } else if (font.FontAngle === JV.ANTI_VERTICAL_ANGLE) {
                 ctx.rotate(-Math.PI/2);
             }
-            if (w >= ctx.measureText(val).width) {
+            if (w >= ctx.measureText(val).width || (control && control.Shrink !== 'T') ) {
                 ctx.fillText(val, 0, 0);
             } else {
                 while (true) {
-                    dftFontHeight--;
-                    ctx.font = "" + dftFontHeight + "px " + font[JV.PROP_NAME];
-                    if (w >=  ctx.measureText(val).width || dftFontHeight < 6) {
-                        ctx.fillText(val, 0, 0);
+                    let lines = Math.floor((area[JV.IDX_BOTTOM] - area[JV.IDX_TOP]) / (dftFontHeight + JV.OUTPUT_OFFSET[JV.OFFSET_IDX_BOTTOM] + JV.OUTPUT_OFFSET[JV.OFFSET_IDX_TOP] + 4));
+                    lines = (lines === 0)?1:lines;
+                    let actLines = private_splitString(val, w, ctx);
+                    if (actLines.length > lines && dftFontHeight >= 6) {
+                        dftFontHeight--;
+                        ctx.font = "" + dftFontHeight + "px " + font[JV.PROP_NAME];
+                    } else {
+                        let aH = dftFontHeight + JV.OUTPUT_OFFSET[JV.OFFSET_IDX_BOTTOM] + JV.OUTPUT_OFFSET[JV.OFFSET_IDX_TOP] + 4;
+                        if ((aH * actLines.length) < (area[JV.IDX_BOTTOM] - area[JV.IDX_TOP]) && (control && control.Vertical !== 'top')) {
+                            if (control.Vertical === 'bottom') {
+                                area[JV.IDX_TOP] = area[JV.IDX_BOTTOM] - (aH * actLines.length);
+                            } else {
+                                area[JV.IDX_TOP] = (area[JV.IDX_TOP] + area[JV.IDX_BOTTOM]) / 2 - (aH * actLines.length) / 2
+                                area[JV.IDX_BOTTOM] = area[JV.IDX_TOP] + (aH * actLines.length);
+                            }
+                        }
+                        let newArea = [], baseTop = area[JV.IDX_TOP];
+                        for (let ai = 0; ai < area.length; ai++) {
+                            newArea[ai] = area[ai];
+                        }
+                        for (let lIdx = 0; lIdx < actLines.length; lIdx++) {
+                            newArea[JV.IDX_TOP] = Math.round(aH * lIdx + baseTop);
+                            newArea[JV.IDX_BOTTOM] = Math.round(aH * (lIdx + 1) + baseTop);
+                            ctx.translate(-output[0], -output[1]);
+                            inner_setupControl(newArea, dftFontHeight, output);
+                            ctx.translate(output[0], output[1]);
+                            ctx.fillText(actLines[lIdx], 0, 0);
+                        }
                         break;
                     }
                 }
@@ -169,7 +233,7 @@ let JpcCanvasOutput = {
             ctx.restore();
         }
         function private_drawCellText(cell, fonts, controls) {
-            if (cell[JV.PROP_VALUE]) {
+            if (cell[JV.PROP_VALUE] !== null && cell[JV.PROP_VALUE] !== undefined) {
                 let values = ("" + cell[JV.PROP_VALUE]).split('|');
                 let font = null;
                 if (typeof cell[JV.PROP_FONT] === "string") {
@@ -185,7 +249,11 @@ let JpcCanvasOutput = {
                     control = cell[JV.PROP_CONTROL];
                 }
                 if (control.ShowZero === "F") {
-                    if (parseFloat(cell[JV.PROP_VALUE]) === 0.0) {
+                    if (typeof cell[JV.PROP_VALUE] === "string") {
+                        if (floatReg.test(cell[JV.PROP_VALUE]) && parseFloat(cell[JV.PROP_VALUE]) === 0.0) {
+                            values = [""];
+                        }
+                    } else if (parseFloat(cell[JV.PROP_VALUE]) === 0.0) {
                         values = [""];
                     }
                 }
@@ -247,6 +315,17 @@ let JpcCanvasOutput = {
             }
             return rst;
         }
+        function private_resetArea(area) {
+            area[JV.PROP_LEFT] = me.scaleFactor * area[JV.PROP_LEFT];
+            area[JV.PROP_RIGHT] = me.scaleFactor * area[JV.PROP_RIGHT];
+            area[JV.PROP_TOP] = me.scaleFactor * area[JV.PROP_TOP];
+            area[JV.PROP_BOTTOM] = me.scaleFactor * area[JV.PROP_BOTTOM];
+        }
+        function private_resetCellFont(cell) {
+            if (typeof cell.font !== "string") {
+                cell.font["FontHeight"] = me.scaleFactor * cell.font["FontHeight"];
+            }
+        }
 
         if (pageObj && pageObj.items.length > 0 && canvas && pageObj.items.length >= pageIdx) {
             let page = pageObj.items[pageIdx - 1],
@@ -261,37 +340,14 @@ let JpcCanvasOutput = {
                 newPageMergeBand[JV.PROP_TOP] = page[JV.PROP_PAGE_MERGE_BORDER][JV.PROP_TOP];
                 newPageMergeBand[JV.PROP_BOTTOM] = page[JV.PROP_PAGE_MERGE_BORDER][JV.PROP_BOTTOM];
             }
+            private_resetArea(newPageMergeBand);
             for (let j = 0; j < page.cells.length; j++) {
                 let cell = page.cells[j];
-                // private_drawCell(cell, fonts, styles, controls, mergedBand);
-                private_drawCell(cell, fonts, styles, controls, newPageMergeBand);
-            }
-        }
-    },
-    highlightConflictArea: function (pageObj, pageIdx) {
-        if (pageObj && pageObj.items.length > 0 && pageObj.items.length >= pageIdx) {
-            let private_create_conflict_line = function () {
-                return {"LineWeight": "1", "DashStyle": "SOLID", "Color": "RED"};
-            };
-            let page = pageObj.items[pageIdx - 1],
-                styleConflict = {"Left": private_create_conflict_line(), "Right": private_create_conflict_line(), "Top": private_create_conflict_line(), "Bottom": private_create_conflict_line()}
-            ;
-            pageObj[JV.NODE_STYLE_COLLECTION]["ConflictCell"] = styleConflict;
-            let conflictIds = [];
-            for (let j = 0; j < page.cells.length; j++) {
-                if (conflictIds.indexOf(j) < 0) {
-                    let cell1 = page.cells[j];
-                    for (let k = j + 1; k < page.cells.length; k++) {
-                        let cell2 = page.cells[k];
-                        //判断area是否有交叉
-                        if (areaConflict(cell1[JV.PROP_AREA], cell2[JV.PROP_AREA])) {
-                            conflictIds.push(j);
-                            conflictIds.push(k);
-                            cell1[JV.PROP_STYLE] = "ConflictCell";
-                            cell2[JV.PROP_STYLE] = "ConflictCell";
-                        }
-                    }
+                if (me.scaleFactor !== 1) {
+                    private_resetCellFont(cell);
+                    private_resetArea(cell[JV.PROP_AREA]);
                 }
+                private_drawCell(cell, fonts, styles, controls, newPageMergeBand);
             }
         }
     },
@@ -322,20 +378,4 @@ let JpcCanvasOutput = {
         rst[1] = Math.round(resolution[0] * rst[1]);
         return rst;
     }
-};
-
-function areaConflict(area1,area2) {
-    let maxX,maxY,minX,minY,
-        w1 = area1[JV.PROP_RIGHT] - area1[JV.PROP_LEFT],
-        w2 = area2[JV.PROP_RIGHT] - area2[JV.PROP_LEFT],
-        h1 = area1[JV.PROP_BOTTOM] - area1[JV.PROP_TOP],
-        h2 = area2[JV.PROP_BOTTOM] - area2[JV.PROP_TOP]
-    ;
-    //1. 求2个矩形的最小外包矩形
-    minX = (area1[JV.PROP_LEFT] <= area2[JV.PROP_LEFT]) ? area1[JV.PROP_LEFT] : area2[JV.PROP_LEFT];
-    minY = (area1[JV.PROP_TOP] <= area2[JV.PROP_TOP]) ? area1[JV.PROP_TOP] : area2[JV.PROP_TOP];
-    maxX = (area1[JV.PROP_RIGHT] >= area2[JV.PROP_RIGHT]) ? area1[JV.PROP_RIGHT] : area2[JV.PROP_RIGHT];
-    maxY = (area1[JV.PROP_BOTTOM] >= area2[JV.PROP_BOTTOM]) ? area1[JV.PROP_BOTTOM] : area2[JV.PROP_BOTTOM];
-    //2. 判断外包矩形与高与宽是否小于俩矩形的高与宽之和(这里的边界条件是小于,等于的话不算;而且是高与宽都得符合条件!)
-    return (maxX - minX < w1 + w2 && maxY - minY < h1 + h2);
-}
+};

文件差異過大導致無法顯示
+ 0 - 18
web/maintain/report/js/rpt_tpl_calculation.js


+ 0 - 1
web/maintain/report/js/rpt_tpl_main.js

@@ -22,7 +22,6 @@ let rptTplObj = {
         selectableFiledTreeOprObj.iniTree();
         preview_util.drawBorder($("#tplCanvas")[0]);
         calculationTreeOprObj.buildRunType();
-        calculationTreeOprObj.buildExprTemplates();
         preHandleObj.buildTypeData();
         calculationTreeOprObj.iniExtCodeTpl();
     }