123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- /**
- * Created by Tony on 2018/4/24.
- */
- let rptPrintHelper = {
- preview: function () {
- if (zTreeOprObj.currentRptPageRst) {
- // window.location.href = '/rpt_print';
- sessionStorage.currentPageData = JSON.stringify(zTreeOprObj.currentRptPageRst);
- sessionStorage.pageSize = rptControlObj.getCurrentPageSize();
- sessionStorage.orientation = rptControlObj.getCurrentOrientation();
- sessionStorage.scaleFactor = 1;
- window.open('/rpt_print');
- } else {
- sessionStorage.currentPageData = null;
- }
- },
- print: function () {
- //
- },
- buildSvgArr: function (pagesData, offsetX, offsetY) {
- let styles = pagesData[JV.NODE_STYLE_COLLECTION],
- fonts = pagesData[JV.NODE_FONT_COLLECTION],
- controls = pagesData[JV.NODE_CONTROL_COLLECTION]
- ;
- let rst = [];
- for (let page of pagesData.items) {
- let svgPageArr = [], pixelSize = getPixelSize(pagesData);
- svgPageArr.push("<svg width='" + pixelSize[0] + "' height='" + pixelSize[1] + "'>");
- for (let cell of page.cells) {
- svgPageArr.push(buildCellSvg(cell, fonts, styles, controls, page[JV.PROP_PAGE_MERGE_BORDER], pagesData[JV.BAND_PROP_MERGE_BAND], offsetX, offsetY));
- }
- svgPageArr.push("</svg>");
- rst.push(svgPageArr);
- }
- return rst;
- }
- };
- function buildCellSvg(cell, fonts, styles, controls, pageMergeBorder, rptMergeBorder, offsetX, offsetY) {
- let rst = [];
- let style = styles[cell[JV.PROP_STYLE]];
- let mergeBandStyle = null;
- if (rptMergeBorder) {
- mergeBandStyle = styles[rptMergeBorder[JV.PROP_STYLE]];
- }
- let left = parseInt(cell[JV.PROP_AREA][JV.PROP_LEFT]) + offsetX + 0.5,
- right = parseInt(cell[JV.PROP_AREA][JV.PROP_RIGHT]) + offsetX + 0.5,
- top = parseInt(cell[JV.PROP_AREA][JV.PROP_TOP]) + offsetY + 0.5,
- bottom = parseInt(cell[JV.PROP_AREA][JV.PROP_BOTTOM]) + offsetY + 0.5,
- x = left, y = top,
- text_anchor = "start"
- ;
- if (style) {
- if (style[JV.PROP_LEFT] && parseFloat(style[JV.PROP_LEFT][JV.PROP_LINE_WEIGHT]) > 0) {
- rst.push("<line x1='" + left + "' y1='" + top +
- "' x2='" + left + "' y2='" + bottom +
- "' style='stroke:rgb(0,0,0);stroke-width:1'/>")
- }
- if (style[JV.PROP_RIGHT] && parseFloat(style[JV.PROP_RIGHT][JV.PROP_LINE_WEIGHT]) > 0) {
- rst.push("<line x1='" + right + "' y1='" + top +
- "' x2='" + right + "' y2='" + bottom +
- "' style='stroke:rgb(0,0,0);stroke-width:1'/>")
- }
- if (style[JV.PROP_TOP] && parseFloat(style[JV.PROP_TOP][JV.PROP_LINE_WEIGHT]) > 0) {
- rst.push("<line x1='" + left + "' y1='" + top +
- "' x2='" + right + "' y2='" + top +
- "' style='stroke:rgb(0,0,0);stroke-width:1'/>")
- }
- if (style[JV.PROP_BOTTOM] && parseFloat(style[JV.PROP_BOTTOM][JV.PROP_LINE_WEIGHT]) > 0) {
- rst.push("<line x1='" + left + "' y1='" + bottom +
- "' x2='" + right + "' y2='" + bottom +
- "' style='stroke:rgb(0,0,0);stroke-width:1'/>")
- }
- }
- let font = cell[JV.PROP_FONT];
- if (typeof font === 'string') {
- font = fonts[cell[JV.PROP_FONT]];
- }
- let fontsize = Math.round(parseInt(font[JV.FONT_PROPS[JV.FONT_PROP_IDX_HEIGHT]]) * 3 / 4);
- let fontWeight = (font[JV.FONT_PROPS[JV.FONT_PROP_IDX_BOLD]] === 'T')?"bold":"normal";
- let control = controls[cell[JV.PROP_CONTROL]];
- if (control) {
- if (control[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_HORIZON]] === "left") {
- text_anchor = "start";
- x = left + JV.OUTPUT_OFFSET[JV.OFFSET_IDX_LEFT];
- } else if (control[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_HORIZON]] === "right") {
- text_anchor = "end";
- x = right - JV.OUTPUT_OFFSET[JV.OFFSET_IDX_RIGHT];
- } else if (control[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_HORIZON]] === "center") {
- text_anchor = "middle";
- x = Math.round((left + right) / 2);
- }
- if (control[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_VERTICAL]] === "top") {
- y = top + JV.OUTPUT_OFFSET[JV.OFFSET_IDX_TOP];
- } else if (control[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_VERTICAL]] === "bottom") {
- y = bottom - JV.OUTPUT_OFFSET[JV.OFFSET_IDX_BOTTOM];
- } else if (control[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_VERTICAL]] === "center") {
- y = Math.round((top + bottom + fontsize) / 2 );
- }
- }
- rst.push("<text style='fill:black;font-family:" + font[JV.PROP_NAME] +
- ";font-weight:" + fontWeight +
- ";font-size:" + fontsize + "pt' x='" +
- x +"' y='" + y + "' text-anchor='" + text_anchor + "'>" + cell[JV.PROP_VALUE] + "</text>");
- return rst.join("");
- }
- function getPixelSize(pagesData) {
- let rst = [793,1122];
- let SCREEN_DPI = [96,96];
- if (pagesData[JV.NODE_PAGE_INFO] && pagesData[JV.NODE_PAGE_INFO][JV.NODE_PAGE_SIZE]) {
- rst[0] = Math.round(SCREEN_DPI[0] * pagesData[JV.NODE_PAGE_INFO][JV.NODE_PAGE_SIZE][0]);
- rst[1] = Math.round(SCREEN_DPI[1] * pagesData[JV.NODE_PAGE_INFO][JV.NODE_PAGE_SIZE][1]);
- }
- return rst;
- }
|