rpt_pdf_util.ts 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  1. // /**
  2. // * Created by Tony on 2019/9/10.
  3. // */
  4. // import { IArea, ICell, IControlCollection, IFontCollection, IFontSubCollection, IMergeBand, IPreviewPage, IRptTpl, IStyleCollection, IStyles } from '../interface/basic';
  5. // import { jsPDF as JsPDF } from 'jspdf';
  6. // import { Canvas } from 'canvas';
  7. // import JV from '../core/jpc_value_define';
  8. // const PDF_SCALE = 0.75;
  9. // // const DPI = getScreenDPI();
  10. // export default class JpcJsPDFHelper {
  11. // doc: JsPDF;
  12. // initialize(
  13. // orientation: string ,
  14. // unit: 'pt' | 'px' | 'in' | 'mm' | 'cm' | 'ex' | 'em' | 'pc',
  15. // format: string | number[]
  16. // ) {
  17. // this.doc = new JsPDF(orientation, unit, format);
  18. // }
  19. // outputAsPdf(pageData:IPreviewPage, paperSize:string, pdfName:string) {
  20. // const me = this;
  21. // const offsetX = 0;
  22. // const offsetY = 0;
  23. // const newName = pdfName;
  24. // const pageObj = pageData;
  25. // const paperSizeIdx = JV.PAGES_SIZE_STR.indexOf(paperSize);
  26. // const size = JV.PAGES_SIZE[paperSizeIdx];
  27. // let orientation = '';
  28. // if (pageData.打印页面_信息.纸张宽高[0] > pageData.打印页面_信息.纸张宽高[1]) {
  29. // orientation = 'landscape';
  30. // } else {
  31. // orientation = 'portrait';
  32. // }
  33. // this.doc = me.initialize(orientation, 'pt', paperSize.toLowerCase());
  34. // const {doc}=this;
  35. // doc.setFont('SmartSimsun', 'normal'); // 目前只考虑宋体
  36. // const privateDrawCell=(doc:JsPDF, ctx:Canvas, cell:ICell, fonts:IFontCollection, styles:IStyles, controls:IControlCollection, mergedBand:IMergeBand) =>{
  37. // ctx.beginPath();
  38. // const style = styles[cell.style];
  39. // if (style) {
  40. // const isNeedMergeBand = private_chkIfInMergedBand(mergedBand, cell);
  41. // private_drawLine(
  42. // cell,
  43. // doc,
  44. // ctx,
  45. // style,
  46. // 'Top',
  47. // ['Left', 'Top'],
  48. // ['Right', 'Top'],
  49. // mergedBand,
  50. // styles,
  51. // isNeedMergeBand
  52. // );
  53. // private_drawLine(
  54. // cell,
  55. // doc,
  56. // ctx,
  57. // style,
  58. // 'Right',
  59. // ['Right', 'Top'],
  60. // ['Right', 'Bottom'],
  61. // mergedBand,
  62. // styles,
  63. // isNeedMergeBand
  64. // );
  65. // private_drawLine(
  66. // cell,
  67. // doc,
  68. // ctx,
  69. // style,
  70. // 'Bottom',
  71. // ['Right', 'Bottom'],
  72. // ['Left', 'Bottom'],
  73. // mergedBand,
  74. // styles,
  75. // isNeedMergeBand
  76. // );
  77. // private_drawLine(
  78. // cell,
  79. // doc,
  80. // ctx,
  81. // style,
  82. // 'Left',
  83. // ['Left', 'Bottom'],
  84. // ['Left', 'Top'],
  85. // mergedBand,
  86. // styles,
  87. // isNeedMergeBand
  88. // );
  89. // }
  90. // private_drawCellText(doc, ctx, cell, fonts, controls);
  91. // ctx.closePath();
  92. // }
  93. // const private_chkIfInMergedBand=(mergedBand:IMergeBand, cell:ICell)=> {
  94. // let rst = false;
  95. // if (mergedBand && cell) {
  96. // rst =
  97. // mergedBand.Top <= cell.area.Top&&
  98. // mergedBand.Bottom >= cell.area.Bottom &&
  99. // mergedBand.Left<= cell.area.Left &&
  100. // mergedBand.Right >= cell.area.Right;
  101. // }
  102. // return rst;
  103. // }
  104. // const private_drawLine=(
  105. // cell:ICell,
  106. // doc:JsPDF,
  107. // ctx:Canvas,
  108. // style:IStyles,
  109. // styleBorderDest:'Top'|'Left'|'Right'|'Bottom',
  110. // startP:['Top'|'Left'|'Right'|'Bottom','Top'|'Left'|'Right'|'Bottom'],
  111. // destP:['Top'|'Left'|'Right'|'Bottom','Top'|'Left'|'Right'|'Bottom'],
  112. // mergedBand:IMergeBand,
  113. // styles:Record<string,IStyleCollection>,
  114. // isNeedMergeBand:boolean
  115. // ) =>{
  116. // let destStyle = style;
  117. // if (mergedBand) {
  118. // if (
  119. // isNeedMergeBand &&
  120. // parseFloat(`${mergedBand[styleBorderDest]}`) === parseFloat(`${cell.area[styleBorderDest]}`)
  121. // ) {
  122. // Object.assign(destStyle, styles[mergedBand.style.ID])
  123. // }
  124. // }
  125. // if (destStyle[styleBorderDest] && parseFloat(destStyle[styleBorderDest][JV.PROP_LINE_WEIGHT]) !== 0) {
  126. // doc.setDrawColor(destStyle[styleBorderDest][JV.PROP_COLOR]);
  127. // if (parseInt(destStyle[styleBorderDest][JV.PROP_LINE_WEIGHT]) === 2) {
  128. // doc.setLineWidth(1 * destStyle[styleBorderDest][JV.PROP_LINE_WEIGHT]);
  129. // } else {
  130. // doc.setLineWidth(0.1);
  131. // }
  132. // doc.line(
  133. // (cell.area[startP[0]] + offsetX) * PDF_SCALE,
  134. // (cell.area[startP[1]] + offsetY) * PDF_SCALE,
  135. // (cell.area[destP[0]] + offsetX) * PDF_SCALE,
  136. // (cell.area[destP[1]] + offsetY) * PDF_SCALE
  137. // );
  138. // }
  139. // }
  140. // const private_drawCellText=(doc:JsPDF, ctx:Canvas, cell:ICell, fonts:IFontCollection, controls:IControlCollection)=> {
  141. // if (cell.Value !== undefined && cell.Value !== null) {
  142. // const values = `${cell.Value}`.split('|');
  143. // // let font = fonts[cell[JV.PROP_FONT]];
  144. // let font = null;
  145. // if (typeof cell.font === 'string') {
  146. // font = fonts[cell.font];
  147. // } else {
  148. // font = cell.font;
  149. // }
  150. // if (font[JV.FONT_PROPS[JV.FONT_PROP_IDX_BOLD]] === 'T') {
  151. // doc.setFont('SmartSimsun', 'bold');
  152. // // doc.setFontStyle("bold");
  153. // } else {
  154. // doc.setFont('SmartSimsun', 'normal');
  155. // }
  156. // // let control = controls[cell[JV.PROP_CONTROL]];
  157. // let control = null;
  158. // if (typeof cell.control === 'string') {
  159. // control = controls[cell.control];
  160. // } else {
  161. // control = cell.control;
  162. // }
  163. // const height = cell.area.Bottom - cell.area.Top;
  164. // const area = [
  165. // cell.area.Left + offsetX,
  166. // cell.area.Top + offsetY,
  167. // cell.area.Right+ offsetX,
  168. // cell.area.Bottom + offsetY,
  169. // ];
  170. // let ah = height;
  171. // let restTopH = 0;
  172. // let restBottomH = 0;
  173. // if (control.CloseOutput === 'T') {
  174. // ah =
  175. // (parseFloat(`${font.FontHeight}`) +
  176. // JV.OUTPUT_OFFSET[JV.OFFSET_IDX_TOP] +
  177. // JV.OUTPUT_OFFSET[JV.OFFSET_IDX_BOTTOM]) *
  178. // values.length;
  179. // const restH = height - ah;
  180. // if (control.Vertical === 'center') {
  181. // restTopH = restH / 2;
  182. // restBottomH = restH / 2;
  183. // } else if (control.Vertical === 'bottom') {
  184. // restBottomH = restH;
  185. // } else {
  186. // restTopH = restH;
  187. // }
  188. // }
  189. // let spaceIdxArr = [];
  190. // for (let i = 0; i < values.length; i++) {
  191. // area[JV.IDX_TOP] = cell.area.Top + i * (ah / values.length) + offsetY + restTopH;
  192. // area[JV.IDX_BOTTOM] =
  193. // cell.area.Top + (i + 1) * (ah / values.length) + offsetY + restBottomH;
  194. // if (values[i] === null || values[i] === undefined || values[i] === 'null') {
  195. // values[i] = '';
  196. // }
  197. // // 因pdfkit输出空格只有浏览器的一半宽度,需要额外加空格补上,jspdf也有这个情况 -----------------------------
  198. // if (typeof values[i] === 'string') {
  199. // for (let j = 0; j < values[i].length; j++) {
  200. // if (values[i][j] === ' ') spaceIdxArr.push(j);
  201. // }
  202. // }
  203. // for (let j = spaceIdxArr.length - 1; j >= 0; j--) {
  204. // values[i] = `${values[i].slice(0, spaceIdxArr[j])} ${values[i].slice(spaceIdxArr[j])}`;
  205. // }
  206. // // -----------------------------
  207. // private_drawText(doc, ctx, values[i], area, font, control);
  208. // spaceIdxArr = [];
  209. // }
  210. // }
  211. // }
  212. // const private_drawText=(doc:JsPDF, ctx:Canvas, val:string, area:number[], font:IFontSubCollection, control:IControlCollection)=> {
  213. // let dftFontHeight = 12;
  214. // const output:any = [];
  215. // if (font) {
  216. // dftFontHeight = 1 * font.FontHeight;
  217. // doc.setFontSize(dftFontHeight);
  218. // }
  219. // // doc.font(fontFile);
  220. // const options = {};
  221. // const inner_setupControl = (outVal: string, inArea: IArea, inFontHeight: number, inOutput: any[])=> {
  222. // if (control) {
  223. // private_setupAreaH(outVal, inArea, control.Horizon, font.FontAngle, inFontHeight, inOutput, options);
  224. // private_setupAreaV(outVal, inArea, control.Vertical, font.FontAngle, inFontHeight, inOutput);
  225. // } else {
  226. // private_setupAreaH(outVal, inArea, 'left', parseInt(`${font.FontAngle}`), inFontHeight, inOutput, options);
  227. // private_setupAreaV(outVal, inArea, 'bottom', parseInt(`${font.FontAngle}`), inFontHeight, inOutput);
  228. // }
  229. // };
  230. // inner_setupControl(val, area, dftFontHeight, output);
  231. // let validAreaTxtWidth =
  232. // area[JV.IDX_RIGHT] -
  233. // JV.OUTPUT_OFFSET[JV.OFFSET_IDX_RIGHT] -
  234. // area[JV.IDX_LEFT] -
  235. // JV.OUTPUT_OFFSET[JV.OFFSET_IDX_RIGHT];
  236. // let validTxtLines = Math.floor(
  237. // (area[JV.IDX_BOTTOM] - area[JV.IDX_TOP]) /
  238. // (dftFontHeight + JV.OUTPUT_OFFSET[JV.OFFSET_IDX_BOTTOM] + JV.OUTPUT_OFFSET[JV.OFFSET_IDX_TOP] + 4)
  239. // );
  240. // if (parseInt(`${font.FontAngle}`) !== 0) {
  241. // validAreaTxtWidth =
  242. // area[JV.IDX_BOTTOM] -
  243. // JV.OUTPUT_OFFSET[JV.OFFSET_IDX_BOTTOM] -
  244. // area[JV.IDX_TOP] -
  245. // JV.OUTPUT_OFFSET[JV.OFFSET_IDX_TOP];
  246. // validTxtLines = Math.floor(
  247. // (area[JV.IDX_RIGHT] - area[JV.IDX_LEFT]) /
  248. // (dftFontHeight + JV.OUTPUT_OFFSET[JV.OFFSET_IDX_RIGHT] + JV.OUTPUT_OFFSET[JV.OFFSET_IDX_LEFT] + 4)
  249. // );
  250. // }
  251. // const private_drawUnderline=(underLineVal, underLineArea)=> {
  252. // // A. 暂不支持角度; B. PDF输出时,坐标没有translate
  253. // // let ctx = doc;
  254. // // 1. 计算下划线的相关坐标
  255. // let width = doc.getTextWidth(underLineVal);
  256. // if (width > underLineArea[JV.IDX_RIGHT] - underLineArea[JV.IDX_LEFT]) {
  257. // width = underLineArea[JV.IDX_RIGHT] - underLineArea[JV.IDX_LEFT];
  258. // }
  259. // const height = dftFontHeight;
  260. // let startX = underLineArea[JV.IDX_LEFT];
  261. // let startY = underLineArea[JV.IDX_TOP];
  262. // let endX = underLineArea[JV.IDX_RIGHT];
  263. // let endY = underLineArea[JV.IDX_BOTTOM];
  264. // // let startX = 0, startY = 0, endX = width, endY = startY;
  265. // if (control.Horizon === 'left') {
  266. // startX = Math.round(underLineArea[JV.IDX_LEFT] + JV.OUTPUT_OFFSET[JV.IDX_LEFT]);
  267. // } else if (control.Horizon === 'right') {
  268. // startX = Math.round(underLineArea[JV.IDX_RIGHT] - width - JV.OUTPUT_OFFSET[JV.IDX_RIGHT]);
  269. // } else {
  270. // startX = Math.round(
  271. // underLineArea[JV.IDX_LEFT] + (underLineArea[JV.IDX_RIGHT] - underLineArea[JV.IDX_LEFT] - width) / 2
  272. // );
  273. // }
  274. // endX = Math.round(startX + width);
  275. // if (control.Vertical === 'top') {
  276. // startY = Math.round(
  277. // underLineArea[JV.IDX_TOP] + JV.OUTPUT_OFFSET[JV.IDX_TOP] + JV.OUTPUT_OFFSET[JV.IDX_BOTTOM] + height
  278. // );
  279. // } else if (control.Vertical === 'bottom') {
  280. // startY = Math.round(underLineArea[JV.IDX_BOTTOM] + JV.OUTPUT_OFFSET[JV.IDX_BOTTOM]);
  281. // } else {
  282. // startY =
  283. // Math.round(
  284. // underLineArea[JV.IDX_TOP] + (underLineArea[JV.IDX_BOTTOM] - underLineArea[JV.IDX_TOP] + height) / 2
  285. // ) +
  286. // JV.OUTPUT_OFFSET[JV.IDX_TOP] +
  287. // JV.OUTPUT_OFFSET[JV.IDX_BOTTOM];
  288. // }
  289. // endY = Math.round(startY);
  290. // // 2. 画线
  291. // // ctx.save();
  292. // if (output[1] !== Math.round(output[1])) {
  293. // ctx.translate(0, 0.5);
  294. // }
  295. // doc.setDrawColor('BLACK');
  296. // doc.setLineWidth(0.1);
  297. // doc.line(startX * PDF_SCALE, startY * PDF_SCALE, endX * PDF_SCALE, endY * PDF_SCALE);
  298. // }
  299. // let rotateOptions;
  300. // if (parseInt(font.FontAngle) !== 0) {
  301. // if (control) {
  302. // rotateOptions = private_setupAreaRotateOption(
  303. // area,
  304. // validAreaTxtWidth,
  305. // control.Vertical,
  306. // dftFontHeight,
  307. // output
  308. // );
  309. // } else {
  310. // rotateOptions = private_setupAreaRotateOption(area, validAreaTxtWidth, 'bottom', dftFontHeight, output);
  311. // }
  312. // doc.rotate(font.FontAngle, rotateOptions);
  313. // }
  314. // if (
  315. // validAreaTxtWidth >= doc.getTextWidth(val) ||
  316. // (control && control.Shrink !== 'T' && validTxtLines < private_splitString(val, validAreaTxtWidth, doc))
  317. // ) {
  318. // options.width = validAreaTxtWidth * PDF_SCALE;
  319. // options.height = dftFontHeight * PDF_SCALE;
  320. // doc.setFontSize(dftFontHeight);
  321. // if (font[JV.FONT_PROPS[5]] === 'T' && parseInt(font.FontAngle) === 0) {
  322. // private_drawUnderline(val, area);
  323. // }
  324. // doc.setFontSize(dftFontHeight * PDF_SCALE);
  325. // doc.text(output[0] * PDF_SCALE, output[1] * PDF_SCALE, val);
  326. // } else {
  327. // while (true) {
  328. // let lines = Math.floor(
  329. // (area[JV.IDX_BOTTOM] - area[JV.IDX_TOP]) /
  330. // (dftFontHeight + JV.OUTPUT_OFFSET[JV.OFFSET_IDX_BOTTOM] + JV.OUTPUT_OFFSET[JV.OFFSET_IDX_TOP] + 4)
  331. // );
  332. // lines = lines === 0 || (control.Shrink === 'T' && control.ShrinkFirst === 'T') ? 1 : lines;
  333. // const actLines = private_splitString(val, validAreaTxtWidth, doc);
  334. // if (actLines.length > lines && dftFontHeight >= 6) {
  335. // dftFontHeight--;
  336. // doc.setFontSize(dftFontHeight);
  337. // options.width = validAreaTxtWidth * PDF_SCALE;
  338. // options.height = dftFontHeight * PDF_SCALE;
  339. // } else {
  340. // const aH = dftFontHeight + JV.OUTPUT_OFFSET[JV.OFFSET_IDX_BOTTOM] + JV.OUTPUT_OFFSET[JV.OFFSET_IDX_TOP] + 4;
  341. // if (
  342. // aH * actLines.length < area[JV.IDX_BOTTOM] - area[JV.IDX_TOP] &&
  343. // control &&
  344. // control.Vertical !== 'top'
  345. // ) {
  346. // if (control.Vertical === 'bottom') {
  347. // area[JV.IDX_TOP] = area[JV.IDX_BOTTOM] - aH * actLines.length;
  348. // } else {
  349. // area[JV.IDX_TOP] = (area[JV.IDX_TOP] + area[JV.IDX_BOTTOM]) / 2 - (aH * actLines.length) / 2;
  350. // area[JV.IDX_BOTTOM] = area[JV.IDX_TOP] + aH * actLines.length;
  351. // }
  352. // }
  353. // const newArea = [];
  354. // const baseTop = area[JV.IDX_TOP];
  355. // for (let ai = 0; ai < area.length; ai++) {
  356. // newArea[ai] = area[ai];
  357. // }
  358. // options.width = validAreaTxtWidth * PDF_SCALE;
  359. // options.height = dftFontHeight * PDF_SCALE;
  360. // for (let lIdx = 0; lIdx < actLines.length; lIdx++) {
  361. // newArea[JV.IDX_TOP] = Math.round(aH * lIdx + baseTop);
  362. // newArea[JV.IDX_BOTTOM] = Math.round(aH * (lIdx + 1) + baseTop);
  363. // doc.setFontSize(dftFontHeight);
  364. // inner_setupControl(actLines[lIdx], newArea, dftFontHeight, output);
  365. // if (font[JV.FONT_PROPS[5]] === 'T' && parseInt(font.FontAngle) === 0) {
  366. // private_drawUnderline(actLines[lIdx], newArea);
  367. // }
  368. // doc.setFontSize(dftFontHeight * PDF_SCALE);
  369. // doc.text(output[0] * PDF_SCALE, output[1] * PDF_SCALE, actLines[lIdx]);
  370. // }
  371. // break;
  372. // }
  373. // }
  374. // }
  375. // }
  376. // const private_setupAreaH=(outVal, area, type, fontAngle, dftFontHeight, outputPoint, options)=> {
  377. // // jspdf输出方式不同(但与H5的canvas处理方式有所不同,因为没有相关alignment属性,需要自己算,而且角度还暂时不支持)-------------------------------------------
  378. // let lType = type;
  379. // if (type !== 'left' && type !== 'right' && type !== 'center') lType = 'left';
  380. // switch (lType) {
  381. // case 'left':
  382. // if (fontAngle === JV.VERTICAL_ANGLE_INT) {
  383. // // outputPoint[1] = 1 * area[JV.IDX_TOP] + JV.OUTPUT_OFFSET[JV.OFFSET_IDX_LEFT];
  384. // } else if (fontAngle === JV.ANTI_VERTICAL_ANGLE_INT) {
  385. // // outputPoint[1] = 1 * area[JV.IDX_BOTTOM] - JV.OUTPUT_OFFSET[JV.OFFSET_IDX_LEFT];
  386. // } else {
  387. // outputPoint[0] = 1 * area[JV.IDX_LEFT] + JV.OUTPUT_OFFSET[JV.OFFSET_IDX_LEFT];
  388. // }
  389. // // ctx.textAlign="start";
  390. // break;
  391. // case 'right':
  392. // if (fontAngle === JV.VERTICAL_ANGLE_INT) {
  393. // outputPoint[1] = 1 * area[JV.IDX_BOTTOM] - JV.OUTPUT_OFFSET[JV.OFFSET_IDX_RIGHT];
  394. // } else if (fontAngle === JV.ANTI_VERTICAL_ANGLE_INT) {
  395. // outputPoint[1] = 1 * area[JV.IDX_TOP] + JV.OUTPUT_OFFSET[JV.OFFSET_IDX_RIGHT];
  396. // } else {
  397. // const width = doc.getTextWidth(outVal);
  398. // outputPoint[0] = 1 * area[JV.IDX_RIGHT] - JV.OUTPUT_OFFSET[JV.OFFSET_IDX_RIGHT] - width;
  399. // }
  400. // // ctx.textAlign="end";
  401. // break;
  402. // case 'center':
  403. // if (fontAngle === JV.VERTICAL_ANGLE_INT || fontAngle === JV.ANTI_VERTICAL_ANGLE_INT) {
  404. // outputPoint[1] = (1 * area[JV.IDX_TOP] + 1 * area[JV.IDX_BOTTOM]) / 2;
  405. // } else {
  406. // const width = doc.getTextWidth(outVal);
  407. // outputPoint[0] = (1 * area[JV.IDX_LEFT] + 1 * area[JV.IDX_RIGHT]) / 2 - width / 2;
  408. // }
  409. // // ctx.textAlign="center";
  410. // break;
  411. // }
  412. // }
  413. // const private_setupAreaV=(outVal, area, type, fontAngle, dftFontHeight, outputPoint)=> {
  414. // // jspdf输出方式不同(与H5的canvas一样处理)-------------------------------------------
  415. // let lType = type;
  416. // if (type !== 'top' && type !== 'bottom' && type !== 'center') lType = 'top';
  417. // switch (lType) {
  418. // case 'top':
  419. // if (fontAngle === JV.VERTICAL_ANGLE_INT) {
  420. // outputPoint[0] = 1 * area[JV.IDX_RIGHT] - dftFontHeight - JV.OUTPUT_OFFSET[JV.OFFSET_IDX_TOP];
  421. // } else if (fontAngle === JV.ANTI_VERTICAL_ANGLE_INT) {
  422. // outputPoint[0] = 1 * area[JV.IDX_LEFT] + dftFontHeight + JV.OUTPUT_OFFSET[JV.OFFSET_IDX_TOP];
  423. // } else outputPoint[1] = 1 * area[JV.IDX_TOP] + dftFontHeight + JV.OUTPUT_OFFSET[JV.OFFSET_IDX_TOP];
  424. // break;
  425. // case 'bottom':
  426. // if (fontAngle === JV.VERTICAL_ANGLE_INT) {
  427. // outputPoint[0] = 1 * area[JV.IDX_LEFT] + JV.OUTPUT_OFFSET[JV.OFFSET_IDX_BOTTOM];
  428. // } else if (fontAngle === JV.ANTI_VERTICAL_ANGLE_INT) {
  429. // outputPoint[0] = 1 * area[JV.IDX_RIGHT] - JV.OUTPUT_OFFSET[JV.OFFSET_IDX_BOTTOM];
  430. // } else {
  431. // outputPoint[1] = 1 * area[JV.IDX_BOTTOM] - JV.OUTPUT_OFFSET[JV.OFFSET_IDX_BOTTOM];
  432. // // if (fontName === "宋体") outputPoint[1] = outputPoint[1] - 1;
  433. // outputPoint[1] -= 1; // 宋体需要提上一个像素点
  434. // }
  435. // break;
  436. // case 'center':
  437. // if (fontAngle === JV.VERTICAL_ANGLE_INT) {
  438. // outputPoint[0] = (1 * area[JV.IDX_LEFT] + 1 * area[JV.IDX_RIGHT] - dftFontHeight) / 2;
  439. // } else if (fontAngle === JV.ANTI_VERTICAL_ANGLE_INT) {
  440. // outputPoint[0] = (1 * area[JV.IDX_LEFT] + 1 * area[JV.IDX_RIGHT] + dftFontHeight) / 2;
  441. // } else {
  442. // outputPoint[1] = (1 * area[JV.IDX_TOP] + 1 * area[JV.IDX_BOTTOM] + dftFontHeight) / 2;
  443. // // if (fontName === "宋体") outputPoint[1] = outputPoint[1] - 1;
  444. // outputPoint[1] -= 1; // 宋体需要提上一个像素点
  445. // }
  446. // break;
  447. // }
  448. // }
  449. // const private_splitString=(strVal, areaWidth, doc) =>{
  450. // const rst = [];
  451. // if (strVal) {
  452. // let preSIdx = 0;
  453. // let txtWidth = 0;
  454. // let currentW = 0;
  455. // const chnW = doc.getTextWidth('一');
  456. // const otherW = doc.getTextWidth('_');
  457. // for (let sIdx = 0; sIdx < strVal.length; sIdx++) {
  458. // currentW = strVal.charCodeAt(sIdx) > 127 ? chnW : otherW;
  459. // txtWidth += currentW;
  460. // if (txtWidth > areaWidth) {
  461. // if (preSIdx < sIdx) {
  462. // rst.push(strVal.substr(preSIdx, sIdx - preSIdx));
  463. // preSIdx = sIdx;
  464. // } else {
  465. // rst.push(strVal.substr(preSIdx, 1));
  466. // preSIdx = sIdx + 1;
  467. // }
  468. // txtWidth = currentW;
  469. // }
  470. // if (sIdx === strVal.length - 1) {
  471. // rst.push(strVal.substr(preSIdx, strVal.length - preSIdx));
  472. // }
  473. // }
  474. // }
  475. // if (rst.length === 0) rst.push(''); // 什么都没有,也得整个空串
  476. // return rst;
  477. // }
  478. // const private_setupAreaRotateOption=(area, w, type = 'top', dftFontHeight, outputPoint)=> {
  479. // const x = (area[JV.IDX_RIGHT] - area[JV.IDX_LEFT]) / 2 + area[JV.IDX_LEFT];
  480. // const y = (area[JV.IDX_BOTTOM] - area[JV.IDX_TOP]) / 2 + area[JV.IDX_TOP];
  481. // const rotateOptions = { origin: [x, y] };
  482. // const h = area[JV.IDX_RIGHT] - area[JV.IDX_LEFT];
  483. // outputPoint[0] = x - w / 2 + JV.OUTPUT_OFFSET[JV.OFFSET_IDX_LEFT];
  484. // switch (type) {
  485. // case 'top':
  486. // outputPoint[1] = y - h / 2 + JV.OUTPUT_OFFSET[JV.OFFSET_IDX_TOP];
  487. // break;
  488. // case 'bottom':
  489. // outputPoint[1] = y + h / 2 - JV.OUTPUT_OFFSET[JV.OFFSET_IDX_BOTTOM] - dftFontHeight;
  490. // break;
  491. // case 'center':
  492. // outputPoint[1] = y + dftFontHeight / 2;
  493. // break;
  494. // }
  495. // return rotateOptions;
  496. // }
  497. // const newPageMergeBand = {...pageObj.MergeBand};
  498. // if (pageObj && pageObj.items.length > 0) {
  499. // for (let i = 0; i < pageObj.items.length; i++) {
  500. // if (i > 0) {
  501. // doc.addPage(paperSize.toLowerCase(), orientation);
  502. // }
  503. // const ctx = doc.canvas.getContext();
  504. // const page = pageObj.items[i];
  505. // const fonts = pageObj.control_collection;
  506. // const styles = pageObj.style_collection;
  507. // const controls = pageObj.control_collection;
  508. // if (page.page_merge_border) {
  509. // Object.assign(newPageMergeBand,page.page_merge_border);
  510. // }
  511. // for (let j = 0; j < page.cells.length; j++) {
  512. // const cell = page.cells[j];
  513. // privateDrawCell(doc, ctx, cell, fonts, styles, controls, newPageMergeBand);
  514. // }
  515. // }
  516. // }
  517. // doc.save(`${newName}.pdf`);
  518. // },
  519. // }