rpt_print.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. /**
  2. * Created by Tony on 2018/4/24.
  3. */
  4. let rptPrintHelper = {
  5. preview: async function () {
  6. if (zTreeOprObj.checkedRptTplNodes && zTreeOprObj.checkedRptTplNodes.length > 0) {
  7. let rptIds = [], flags = [], compare_ids = [];
  8. let params = {};
  9. params.pageSize = rptControlObj.getCurrentPageSize();
  10. params.orientation = ((zTreeOprObj.checkedRptTplNodes.length > 1)?null:rptControlObj.getCurrentOrientation());
  11. params.custCfg = zTreeOprObj.reportPageCfg;
  12. params.prj_id = projectObj.project.projectInfo.ID;
  13. for (let tplNode of zTreeOprObj.checkedRptTplNodes) {
  14. rptIds.push(tplNode.refId);
  15. let flag = null;
  16. if (tplNode.hasOwnProperty('flags')) {
  17. flag = tplNode.flags;
  18. params.prj_ids = rptTplObj.getAllPrjIds();
  19. if (flag.auditType === 'audit_compare') {
  20. let pids = [];
  21. let comp_pid = await compareObject.getCompareID(); //返回单个对应的project ID
  22. if (comp_pid !== null) {
  23. pids.push(projectObj.project.projectInfo.ID);
  24. pids.push(comp_pid);
  25. }
  26. compare_ids.push(pids);
  27. } else {
  28. compare_ids.push([]);
  29. }
  30. } else {
  31. compare_ids.push([]);
  32. }
  33. flags.push(flag);
  34. }
  35. params.rpt_ids = rptIds.join(",");
  36. params.compare_ids = compare_ids;
  37. params.flags = flags;
  38. CommonAjax.postEx("report_api/getMultiReports", params, 10000, true,
  39. function(result){
  40. //sessionStorage.currentPageData = JSON.stringify(zTreeOprObj.currentRptPageRst);
  41. sessionStorage.multiRptsData = JSON.stringify(result);
  42. sessionStorage.pageSize = rptControlObj.getCurrentPageSize();
  43. sessionStorage.orientation = rptControlObj.getCurrentOrientation();
  44. sessionStorage.scaleFactor = 1;
  45. window.open('/printReport/' + sessionStorage.pageSize);
  46. },
  47. function(failRst){
  48. sessionStorage.currentPageData = null;
  49. console.log(failRst);
  50. },
  51. function(exceptionRst){
  52. sessionStorage.currentPageData = null;
  53. console.log(exceptionRst);
  54. }
  55. );
  56. } else {
  57. //不可能的branch
  58. }
  59. // if (zTreeOprObj.currentRptPageRst) {
  60. // sessionStorage.currentPageData = JSON.stringify(zTreeOprObj.currentRptPageRst);
  61. // sessionStorage.pageSize = rptControlObj.getCurrentPageSize();
  62. // sessionStorage.orientation = rptControlObj.getCurrentOrientation();
  63. // sessionStorage.scaleFactor = 1;
  64. // window.open('/rpt_print');
  65. // } else {
  66. // sessionStorage.currentPageData = null;
  67. // }
  68. },
  69. previewSvgData: function() {
  70. //
  71. },
  72. buildSvgArr: function (pagesData, actAreaArr, offsetX, offsetY) {
  73. let styles = pagesData[JV.NODE_STYLE_COLLECTION],
  74. fonts = pagesData[JV.NODE_FONT_COLLECTION],
  75. controls = pagesData[JV.NODE_CONTROL_COLLECTION]
  76. ;
  77. let rst = [];
  78. let canvas = document.getElementById("chkCanvas");
  79. let pixelSize = getPixelSize(pagesData);
  80. let isHtoV = false;
  81. if (pixelSize[0] > pixelSize[1]) {
  82. // changeHtoV(pagesData, pixelSize);
  83. isHtoV = true;
  84. }
  85. for (let idx = 0; idx < pagesData.items.length; idx++) {
  86. let page = pagesData.items[idx];
  87. let actAreaOffsetX = 0, actAreaOffsetY = 0;
  88. if (actAreaArr) {
  89. actAreaOffsetX = actAreaArr[idx].Left;
  90. actAreaOffsetY = actAreaArr[idx].Top;
  91. if (pixelSize[0] > pixelSize[1]) {
  92. }
  93. }
  94. let svgPageArr = [];
  95. svgPageArr.push("<svg width='" + pixelSize[0] + "' height='" + pixelSize[1] + "'>");
  96. // let adjustY = 0.5 * ((idx + 1) % 2);
  97. let adjustY = 0.5;
  98. for (let cell of page.cells) {
  99. svgPageArr.push(buildCellSvg(cell, fonts, styles, controls, page[JV.PROP_PAGE_MERGE_BORDER], pagesData[JV.BAND_PROP_MERGE_BAND],
  100. offsetX - actAreaOffsetX, offsetY - actAreaOffsetY, adjustY, canvas, isHtoV, pixelSize, actAreaArr[idx]));
  101. }
  102. svgPageArr.push("</svg>");
  103. rst.push(svgPageArr);
  104. }
  105. return rst;
  106. }
  107. };
  108. function getActualBorderStyle(cell, styles, mergeBorderStyle, pageBorderArea, borderStr) {
  109. let rst = styles[cell[JV.PROP_STYLE]][borderStr];
  110. if (rst && parseFloat(rst[JV.PROP_LINE_WEIGHT]) === 1) {
  111. rst[JV.PROP_LINE_WEIGHT] = 0.5;
  112. }
  113. if (mergeBorderStyle) {
  114. if (parseFloat(cell[JV.PROP_AREA][borderStr]) === parseFloat(pageBorderArea[borderStr])) {
  115. if (borderStr === JV.PROP_LEFT || borderStr === JV.PROP_RIGHT) {
  116. if (parseFloat(cell[JV.PROP_AREA][JV.PROP_TOP]) >= parseFloat(pageBorderArea[JV.PROP_TOP]) &&
  117. parseFloat(cell[JV.PROP_AREA][JV.PROP_BOTTOM]) <= parseFloat(pageBorderArea[JV.PROP_BOTTOM])) {
  118. rst = mergeBorderStyle[borderStr];
  119. }
  120. } else if (borderStr === JV.PROP_TOP || borderStr === JV.PROP_BOTTOM) {
  121. if (parseFloat(cell[JV.PROP_AREA][JV.PROP_LEFT]) >= parseFloat(pageBorderArea[JV.PROP_LEFT]) &&
  122. parseFloat(cell[JV.PROP_AREA][JV.PROP_RIGHT]) <= parseFloat(pageBorderArea[JV.PROP_RIGHT])) {
  123. rst = mergeBorderStyle[borderStr];
  124. }
  125. }
  126. }
  127. }
  128. return rst;
  129. }
  130. function buildCellSvg(cell, fonts, styles, controls, pageMergeBorder, rptMergeBorder, offsetX, offsetY, adjustY, canvas, isHtoV, pixelSize, actArea) {
  131. let rst = [];
  132. let style = styles[cell[JV.PROP_STYLE]];
  133. let mergeBandStyle = null;
  134. if (rptMergeBorder) {
  135. mergeBandStyle = styles[rptMergeBorder[JV.PROP_STYLE][JV.PROP_ID]];
  136. }
  137. let font = cell[JV.PROP_FONT];
  138. if (typeof font === 'string') {
  139. font = fonts[cell[JV.PROP_FONT]];
  140. }
  141. let left = parseInt(cell[JV.PROP_AREA][JV.PROP_LEFT]) + offsetX + 0.5,
  142. right = parseInt(cell[JV.PROP_AREA][JV.PROP_RIGHT]) + offsetX + 0.5,
  143. top = parseInt(cell[JV.PROP_AREA][JV.PROP_TOP]) + offsetY + adjustY,
  144. bottom = parseInt(cell[JV.PROP_AREA][JV.PROP_BOTTOM]) + offsetY + adjustY
  145. ;
  146. let HtoVStr = "";
  147. if (isHtoV) {
  148. // HtoVStr = ` transform="translate(`+ (actArea.Bottom - actArea.Top + 5) + `,0) rotate(90)"`;
  149. //引用了padding后,top坐标不用考虑offset了
  150. HtoVStr = ` transform="translate(${(actArea.Bottom - actArea.Top + 2)},0) rotate(90)"`;
  151. }
  152. if (style) {
  153. let leftBS = getActualBorderStyle(cell, styles, mergeBandStyle, (pageMergeBorder)?pageMergeBorder:rptMergeBorder[JV.PROP_AREA], JV.PROP_LEFT);
  154. // if (style[JV.PROP_LEFT] && parseFloat(style[JV.PROP_LEFT][JV.PROP_LINE_WEIGHT]) > 0) {
  155. if (leftBS && parseFloat(leftBS[JV.PROP_LINE_WEIGHT]) > 0) {
  156. rst.push("<line x1='" + left + "' y1='" + top +
  157. "' x2='" + left + "' y2='" + bottom +
  158. "' style='stroke:rgb(0,0,0);stroke-width:" + leftBS[JV.PROP_LINE_WEIGHT] + "'" + HtoVStr + "/>")
  159. }
  160. let rightBS = getActualBorderStyle(cell, styles, mergeBandStyle, (pageMergeBorder)?pageMergeBorder:rptMergeBorder[JV.PROP_AREA], JV.PROP_RIGHT);
  161. // if (style[JV.PROP_RIGHT] && parseFloat(style[JV.PROP_RIGHT][JV.PROP_LINE_WEIGHT]) > 0) {
  162. if (rightBS && parseFloat(rightBS[JV.PROP_LINE_WEIGHT]) > 0) {
  163. rst.push("<line x1='" + right + "' y1='" + top +
  164. "' x2='" + right + "' y2='" + bottom +
  165. "' style='stroke:rgb(0,0,0);stroke-width:" + rightBS[JV.PROP_LINE_WEIGHT] +"'" + HtoVStr + "/>")
  166. }
  167. let topBS = getActualBorderStyle(cell, styles, mergeBandStyle, (pageMergeBorder)?pageMergeBorder:rptMergeBorder[JV.PROP_AREA], JV.PROP_TOP);
  168. // if (style[JV.PROP_TOP] && parseFloat(style[JV.PROP_TOP][JV.PROP_LINE_WEIGHT]) > 0) {
  169. if (topBS && parseFloat(topBS[JV.PROP_LINE_WEIGHT]) > 0) {
  170. rst.push("<line x1='" + left + "' y1='" + top +
  171. "' x2='" + right + "' y2='" + top +
  172. "' style='stroke:rgb(0,0,0);stroke-width:" + topBS[JV.PROP_LINE_WEIGHT] +"'" + HtoVStr + "/>")
  173. }
  174. let bottomBS = getActualBorderStyle(cell, styles, mergeBandStyle, (pageMergeBorder)?pageMergeBorder:rptMergeBorder[JV.PROP_AREA], JV.PROP_BOTTOM);
  175. // if (style[JV.PROP_BOTTOM] && parseFloat(style[JV.PROP_BOTTOM][JV.PROP_LINE_WEIGHT]) > 0) {
  176. if (bottomBS && parseFloat(bottomBS[JV.PROP_LINE_WEIGHT]) > 0) {
  177. rst.push("<line x1='" + left + "' y1='" + bottom +
  178. "' x2='" + right + "' y2='" + bottom +
  179. "' style='stroke:rgb(0,0,0);stroke-width:" + bottomBS[JV.PROP_LINE_WEIGHT] +"'" + HtoVStr + "/>")
  180. }
  181. }
  182. let control = cell[JV.PROP_CONTROL];
  183. if (typeof control === 'string') {
  184. control = controls[cell[JV.PROP_CONTROL]];
  185. }
  186. buildText(rst, cell, font, control, offsetX, offsetY, adjustY, canvas, isHtoV, HtoVStr);
  187. return rst.join("");
  188. }
  189. function _splitValues(cell, control, orgValues, ctx2D) {
  190. //根据control的 自动折行 及 缩放优先 这俩属性 来分解cell value
  191. if (control[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_WRAP]] === 'T' && control[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_SHRINK_FIRST]] !== 'T') {
  192. let vals = [];
  193. let validAreaTxtWidth = cell[JV.PROP_AREA][JV.PROP_RIGHT] - JV.OUTPUT_OFFSET[JV.OFFSET_IDX_RIGHT] - cell[JV.PROP_AREA][JV.PROP_LEFT] - JV.OUTPUT_OFFSET[JV.OFFSET_IDX_LEFT] - 1;
  194. for (let val of orgValues) {
  195. let actW = ctx2D.measureText(val).width;
  196. if (actW > (validAreaTxtWidth - 4)) {
  197. //减4个像素是考虑到导出excel的情况
  198. vals = vals.concat(private_splitString(val, validAreaTxtWidth, ctx2D));
  199. } else {
  200. vals.push(val);
  201. }
  202. }
  203. if (vals.length > orgValues.length) {
  204. for (let idx = 0; idx < vals.length; idx++) {
  205. orgValues[idx] = vals[idx];
  206. }
  207. }
  208. }
  209. }
  210. const strReplaceReg1 = new RegExp('\n\r', 'gm'),
  211. strReplaceReg2 = new RegExp('\r\n', 'gm'),
  212. strReplaceReg3 = new RegExp('\n', 'gm'),
  213. strReplaceReg4 = new RegExp('\r', 'gm')
  214. ;
  215. function _preHandleSpliter(orgVal) {
  216. let rst = orgVal;
  217. if (rst !== null && rst !== '') {
  218. rst = rst.replace(strReplaceReg1, '|').replace(strReplaceReg2, '|').replace(strReplaceReg3, '|').replace(strReplaceReg4, '|');
  219. }
  220. return rst;
  221. }
  222. function buildText(destRst, cell, font, control, offsetX, offsetY, adjustY, canvas, isHtoV, HtoVStr) {
  223. let orgFontHeight = parseInt(font[JV.FONT_PROPS[JV.FONT_PROP_IDX_HEIGHT]]);
  224. let fontWeight = (font[JV.FONT_PROPS[JV.FONT_PROP_IDX_BOLD]] === 'T')?"bold":"normal";
  225. let fontStyle = (font[JV.FONT_PROPS[JV.FONT_PROP_IDX_ITALIC]] === 'T')?"italic":"normal";
  226. let fontUnderline = (font[JV.FONT_PROPS[JV.FONT_PROP_IDX_UNDERLINE]] === 'T')?"underline":"normal";
  227. let left = parseInt(cell[JV.PROP_AREA][JV.PROP_LEFT]) + offsetX + 0.5,
  228. right = parseInt(cell[JV.PROP_AREA][JV.PROP_RIGHT]) + offsetX + 0.5,
  229. top = parseInt(cell[JV.PROP_AREA][JV.PROP_TOP]) + offsetY + adjustY,
  230. bottom = parseInt(cell[JV.PROP_AREA][JV.PROP_BOTTOM]) + offsetY + adjustY,
  231. x = left, y = top,
  232. text_anchor = "start"
  233. ;
  234. let value = cell[JV.PROP_VALUE];
  235. if (value === undefined || value === null) {
  236. value = "";
  237. }
  238. let values = null;
  239. if (typeof value === "string") {
  240. // values = value.split("|");
  241. values = _preHandleSpliter(value).split('|');
  242. } else {
  243. values = [value];
  244. }
  245. // let stepHeight = (parseInt(cell[JV.PROP_AREA][JV.PROP_BOTTOM]) - parseInt(cell[JV.PROP_AREA][JV.PROP_TOP])) / values.length;
  246. if (control) {
  247. if (control[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_HORIZON]] === "left") {
  248. text_anchor = "start";
  249. x = left + JV.OUTPUT_OFFSET[JV.OFFSET_IDX_LEFT];
  250. } else if (control[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_HORIZON]] === "right") {
  251. text_anchor = "end";
  252. x = right - JV.OUTPUT_OFFSET[JV.OFFSET_IDX_RIGHT];
  253. } else if (control[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_HORIZON]] === "center") {
  254. text_anchor = "middle";
  255. x = Math.round((left + right) / 2);
  256. }
  257. }
  258. let area = [0,0,0,0];
  259. area[JV.IDX_TOP] = top;
  260. area[JV.IDX_BOTTOM] = bottom;
  261. area[JV.IDX_LEFT] = left;
  262. area[JV.IDX_RIGHT] = right;
  263. let height = bottom - top;
  264. let ctx = canvas.getContext("2d");
  265. ctx.font = ((font[JV.FONT_PROPS[JV.FONT_PROP_IDX_BOLD]] === 'T')?"bold ":"") + ((font[JV.FONT_PROPS[JV.FONT_PROP_IDX_ITALIC]] === 'T')?"italic":"") + orgFontHeight + "px " + font[JV.PROP_NAME];
  266. _splitValues(cell, control, values, ctx);
  267. let inner_draw_text = function (textValue) {
  268. let dftFontHeight = orgFontHeight;
  269. ctx.font = ((font[JV.FONT_PROPS[JV.FONT_PROP_IDX_BOLD]] === 'T')?"bold ":"") + ((font[JV.FONT_PROPS[JV.FONT_PROP_IDX_ITALIC]] === 'T')?"italic":"") + dftFontHeight + "px " + font[JV.PROP_NAME];
  270. function inner_build_text(innerTxt, innerArea) {
  271. let innerDftFontHeight = (dftFontHeight * 3 / 4); //SVG的字体与canvas的字体大小的切换, 不用考虑取整
  272. if (control) {
  273. if (control[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_VERTICAL]] === "top") {
  274. y = innerArea[JV.IDX_TOP] + JV.OUTPUT_OFFSET[JV.IDX_TOP];
  275. } else if (control[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_VERTICAL]] === "bottom") {
  276. y = innerArea[JV.IDX_BOTTOM] - JV.OUTPUT_OFFSET[JV.IDX_BOTTOM];
  277. } else if (control[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_VERTICAL]] === "center") {
  278. y = Math.round((innerArea[JV.IDX_TOP] + innerArea[JV.IDX_BOTTOM] + innerDftFontHeight) / 2 );
  279. }
  280. } else {
  281. y = innerArea[JV.IDX_TOP] + JV.OUTPUT_OFFSET[JV.IDX_TOP];
  282. }
  283. if (font[JV.PROP_NAME] === "宋体") {
  284. y--;
  285. }
  286. destRst.push("<text style='fill:black;font-family:" + font[JV.PROP_NAME] +
  287. ";font-weight:" + fontWeight +
  288. ";font-style:" + fontStyle +
  289. ";text-decoration:" + fontUnderline +
  290. // ";text-decoration:normal" +
  291. ";font-size:" + innerDftFontHeight + "pt' x='" +
  292. x +"' y='" + y + "' text-anchor='" + text_anchor + "' xml:space='preserve'" + HtoVStr + ">" + innerTxt + "</text>");
  293. }
  294. let actLines = private_splitString(textValue, (area[JV.IDX_RIGHT] - area[JV.IDX_LEFT]), ctx);
  295. let validTxtLines = 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));
  296. if (actLines.length === 1 || (control && control.Shrink !== 'T' && validTxtLines < actLines)) {
  297. inner_build_text(textValue, area);
  298. } else {
  299. while (true) {
  300. let lines = Math.floor((area[JV.IDX_BOTTOM] - area[JV.IDX_TOP]) / (dftFontHeight + JV.OUTPUT_OFFSET[JV.IDX_BOTTOM] + JV.OUTPUT_OFFSET[JV.IDX_TOP] + 4));
  301. lines = (lines === 0 || (control.Shrink === 'T' && control.ShrinkFirst === 'T'))?1:lines;
  302. actLines = private_splitString(textValue, (area[JV.IDX_RIGHT] - area[JV.IDX_LEFT] - JV.OUTPUT_OFFSET[JV.IDX_LEFT] - JV.OUTPUT_OFFSET[JV.IDX_RIGHT]), ctx);
  303. if (actLines.length > lines && dftFontHeight >= 6) {
  304. dftFontHeight--;
  305. ctx.font = ((font[JV.FONT_PROPS[JV.FONT_PROP_IDX_BOLD]] === 'T')?"bold ":"") + ((font[JV.FONT_PROPS[JV.FONT_PROP_IDX_ITALIC]] === 'T')?"italic":"") + dftFontHeight + "px " + font[JV.PROP_NAME];
  306. } else {
  307. let aH = dftFontHeight + JV.OUTPUT_OFFSET[JV.IDX_BOTTOM] + JV.OUTPUT_OFFSET[JV.IDX_TOP] + 4;
  308. if ((aH * actLines.length) < (area[JV.IDX_BOTTOM] - area[JV.IDX_TOP]) && (control && control.Vertical !== 'top')) {
  309. if (control.Vertical === 'bottom') {
  310. area[JV.IDX_TOP] = area[JV.IDX_BOTTOM] - (aH * actLines.length);
  311. } else {
  312. area[JV.IDX_TOP] = (area[JV.IDX_TOP] + area[JV.IDX_BOTTOM]) / 2 - (aH * actLines.length) / 2
  313. area[JV.IDX_BOTTOM] = area[JV.IDX_TOP] + (aH * actLines.length);
  314. }
  315. }
  316. let newArea = [], baseTop = area[JV.IDX_TOP];
  317. for (let ai = 0; ai < area.length; ai++) {
  318. newArea[ai] = area[ai];
  319. }
  320. for (let lIdx = 0; lIdx < actLines.length; lIdx++) {
  321. newArea[JV.IDX_TOP] = Math.round(aH * lIdx + baseTop);
  322. newArea[JV.IDX_BOTTOM] = Math.round(aH * (lIdx + 1) + baseTop);
  323. inner_build_text(actLines[lIdx], newArea);
  324. }
  325. break;
  326. }
  327. }
  328. }
  329. };
  330. const isCloseOutput = _chkIfCloseOutput(control, values.length, area, orgFontHeight);
  331. let closeTopOffset = 0;
  332. if (isCloseOutput) {
  333. closeTopOffset = (height - (orgFontHeight + 4) * values.length) / 2;
  334. }
  335. for (let vidx = 0; vidx < values.length; vidx++) {
  336. if (isCloseOutput) {
  337. area[JV.IDX_TOP] = top + closeTopOffset + vidx *(orgFontHeight + 4);
  338. area[JV.IDX_BOTTOM] = top + closeTopOffset + (vidx + 1) *(orgFontHeight + 4);
  339. } else {
  340. area[JV.IDX_TOP] = top + vidx * (height / values.length);
  341. area[JV.IDX_BOTTOM] = top + (vidx + 1) * (height / values.length);
  342. }
  343. inner_draw_text(values[vidx]);
  344. }
  345. }
  346. function _chkIfCloseOutput(control, actLines, area, fontHeight) {
  347. let rst = false;
  348. if (control.CloseOutput === 'T' && actLines > 1) {
  349. rst = true;
  350. }
  351. return rst;
  352. }
  353. function private_splitString(strVal, areaWidth, ctx) {
  354. let rst = [];
  355. if (strVal) {
  356. let preSIdx = 0, txtWidth = 0;
  357. let currentW = 0;
  358. let chnW = ctx.measureText('一').width, otherW = ctx.measureText('_').width;
  359. for (let sIdx = 0; sIdx < strVal.length; sIdx++) {
  360. currentW = (strVal.charCodeAt(sIdx) > 127)?chnW:otherW;
  361. txtWidth += currentW;
  362. if (txtWidth > areaWidth) {
  363. if (preSIdx < sIdx) {
  364. rst.push(strVal.substr(preSIdx, sIdx - preSIdx));
  365. preSIdx = sIdx;
  366. } else {
  367. rst.push(strVal.substr(preSIdx, 1));
  368. preSIdx = sIdx + 1;
  369. }
  370. txtWidth = currentW;
  371. }
  372. if (sIdx === strVal.length - 1) {
  373. rst.push(strVal.substr(preSIdx, strVal.length - preSIdx));
  374. }
  375. }
  376. }
  377. if (rst.length === 0) rst.push(''); //什么都没有,也得整个空串
  378. return rst;
  379. }
  380. function getPixelSize(pagesData) {
  381. let rst = [793,1122];
  382. let SCREEN_DPI = [96,96];
  383. if (pagesData[JV.NODE_PAGE_INFO] && pagesData[JV.NODE_PAGE_INFO][JV.NODE_PAGE_SIZE]) {
  384. rst[0] = Math.round(SCREEN_DPI[0] * pagesData[JV.NODE_PAGE_INFO][JV.NODE_PAGE_SIZE][0]);
  385. rst[1] = Math.round(SCREEN_DPI[1] * pagesData[JV.NODE_PAGE_INFO][JV.NODE_PAGE_SIZE][1]);
  386. }
  387. return rst;
  388. }