|
|
@@ -1,492 +1,542 @@
|
|
|
+// /**
|
|
|
+// * Created by Tony on 2019/9/10.
|
|
|
+// */
|
|
|
|
|
|
-// const pdf = require('pdfkit');
|
|
|
-// const fs = require('fs');
|
|
|
-// import jpcCmnHelper from '../core/helper/jpc_helper_common';
|
|
|
-// const PDF_SCALE = 0.75;
|
|
|
-
|
|
|
-// const DPI = jpcCmnHelper.getScreenDPI()[0] * PDF_SCALE;
|
|
|
-
|
|
|
+// import { IArea, ICell, IControlCollection, IFontCollection, IFontSubCollection, IMergeBand, IPreviewPage, IRptTpl, IStyleCollection, IStyles } from '../interface/basic';
|
|
|
+// import { jsPDF as JsPDF } from 'jspdf';
|
|
|
+// import { Canvas } from 'canvas';
|
|
|
// import JV from '../core/jpc_value_define';
|
|
|
-// import { IMergeBand, IPositionProps, IPreviewPage } from '../index';
|
|
|
-// import { ICell, IControlCollection, IControlSubCollection, IFontCollection, IFontSubCollection, IStyleCollection, IStyles } from '../interface/basic';
|
|
|
-
|
|
|
-// import {getActualFont} from './rpt_font_util';
|
|
|
-
|
|
|
+// const PDF_SCALE = 0.75;
|
|
|
+// // const DPI = getScreenDPI();
|
|
|
|
|
|
+// export default class JpcJsPDFHelper {
|
|
|
+// doc: JsPDF;
|
|
|
|
|
|
-// const getNewName=()=>{
|
|
|
-// return (new Date()).getTime();
|
|
|
-// }
|
|
|
-// // 目前不支持下划线
|
|
|
+// initialize(
|
|
|
+// orientation: string ,
|
|
|
+// unit: 'pt' | 'px' | 'in' | 'mm' | 'cm' | 'ex' | 'em' | 'pc',
|
|
|
+// format: string | number[]
|
|
|
+// ) {
|
|
|
+// this.doc = new JsPDF(orientation, unit, format);
|
|
|
+// }
|
|
|
|
|
|
-// export const exportPdfFile=(pageData:IPreviewPage, paperSize:string, fName:string, callback:any) =>{
|
|
|
-// const offsetX = 10;
|
|
|
-// const offsetY = 10;
|
|
|
-// const doc = new pdf({ autoFirstPage: false });
|
|
|
-// const newName = getNewName();
|
|
|
-// const stream = doc.pipe(fs.createWriteStream(`${__dirname.slice(0, __dirname.length - 21)}/tmp/${newName}.pdf`));
|
|
|
-// const pageObj = pageData;
|
|
|
-// // doc.rect(5,5,1190,890).lineWidth(1).strokeColor('black').stroke();//边框
|
|
|
-// const paperSizeIdx = JV.PAGES_SIZE_STR.indexOf(paperSize);
|
|
|
-// const size = JV.PAGES_SIZE[paperSizeIdx];
|
|
|
|
|
|
-// const newPageMergeBand = {...pageObj.MergeBand};
|
|
|
-// const privateDrawLine=(cell:any, doc:any, style:any, styleBorderDest:string, startP:[string,string], destP:[string,string], mergedBand:any, styles:any, isNeedMergeBand:boolean)=> {
|
|
|
-// // doc.beginPath();
|
|
|
-// let destStyle = style;
|
|
|
-// if (mergedBand) {
|
|
|
-// if (
|
|
|
-// isNeedMergeBand &&
|
|
|
-// mergedBand[styleBorderDest] === cell.area[styleBorderDest]
|
|
|
-// ) {
|
|
|
-// destStyle = styles[mergedBand.style.ID];
|
|
|
-// }
|
|
|
-// }
|
|
|
-// // doc.moveTo(cell.area.[startP[0]] + offsetX, cell.area.[startP[1]] + offsetY);
|
|
|
-// doc.moveTo(
|
|
|
-// (cell.area[startP[0]] + offsetX) * PDF_SCALE,
|
|
|
-// (cell.area[startP[1]] + offsetY) * PDF_SCALE
|
|
|
-// );
|
|
|
-// if (destStyle[styleBorderDest] && parseFloat(destStyle[styleBorderDest][JV.PROP_LINE_WEIGHT]) !== 0) {
|
|
|
-// doc.lineWidth(1.0 * destStyle[styleBorderDest][JV.PROP_LINE_WEIGHT]);
|
|
|
-// // doc.lineTo(cell.area.[destP[0]] + offsetX, cell.area.[destP[1]] + offsetY);
|
|
|
-// doc.lineTo(
|
|
|
-// (cell.area[destP[0]] + offsetX) * PDF_SCALE,
|
|
|
-// (cell.area[destP[1]] + offsetY) * PDF_SCALE
|
|
|
-// );
|
|
|
-// doc.strokeColor(destStyle[styleBorderDest][JV.PROP_COLOR]);
|
|
|
-// }
|
|
|
-// doc.stroke();
|
|
|
-// }
|
|
|
-// const privateDrawCell=(cell:ICell, fonts:IFontCollection, styles:IStyleCollection, controls:IControlCollection, mergedBand:IMergeBand)=> {
|
|
|
-// doc.save();
|
|
|
-// // doc.translate(0.5,0.5); //跟H5的canvas不同,不需要这样切换
|
|
|
-// const style = styles[cell.style];
|
|
|
-// if (style) {
|
|
|
-// const isNeedMergeBand = privateChkIfInMergedBand(mergedBand, cell);
|
|
|
-// privateDrawLine(
|
|
|
-// cell,
|
|
|
-// doc,
|
|
|
-// style,
|
|
|
-// 'Top',
|
|
|
-// ['Left', 'Top'],
|
|
|
-// ['Right', 'Top'],
|
|
|
-// mergedBand,
|
|
|
-// styles,
|
|
|
-// isNeedMergeBand
|
|
|
-// );
|
|
|
-// privateDrawLine(
|
|
|
-// cell,
|
|
|
-// doc,
|
|
|
-// style,
|
|
|
-// 'Right',
|
|
|
-// ['Right', 'Top'],
|
|
|
-// ['Right', 'Bottom'],
|
|
|
-// mergedBand,
|
|
|
-// styles,
|
|
|
-// isNeedMergeBand
|
|
|
-// );
|
|
|
-// privateDrawLine(
|
|
|
-// cell,
|
|
|
-// doc,
|
|
|
-// style,
|
|
|
-// 'Bottom',
|
|
|
-// ['Right', 'Bottom'],
|
|
|
-// ['Left','Bottom'],
|
|
|
-// mergedBand,
|
|
|
-// styles,
|
|
|
-// isNeedMergeBand
|
|
|
-// );
|
|
|
-// privateDrawLine(
|
|
|
-// cell,
|
|
|
-// doc,
|
|
|
-// style,
|
|
|
-// 'Left',
|
|
|
-// ['Left', 'Bottom'],
|
|
|
-// ['Left', 'Top'],
|
|
|
-// mergedBand,
|
|
|
-// styles,
|
|
|
-// isNeedMergeBand
|
|
|
-// );
|
|
|
+// outputAsPdf(pageData:IPreviewPage, paperSize:string, pdfName:string) {
|
|
|
+// const me = this;
|
|
|
+// const offsetX = 0;
|
|
|
+// const offsetY = 0;
|
|
|
+// const newName = pdfName;
|
|
|
+// const pageObj = pageData;
|
|
|
+// const paperSizeIdx = JV.PAGES_SIZE_STR.indexOf(paperSize);
|
|
|
+// const size = JV.PAGES_SIZE[paperSizeIdx];
|
|
|
+// let orientation = '';
|
|
|
+// if (pageData.打印页面_信息.纸张宽高[0] > pageData.打印页面_信息.纸张宽高[1]) {
|
|
|
+// orientation = 'landscape';
|
|
|
+// } else {
|
|
|
+// orientation = 'portrait';
|
|
|
// }
|
|
|
-// privateDrawCellText(cell, fonts, controls);
|
|
|
-// doc.restore();
|
|
|
-// }
|
|
|
+// this.doc = me.initialize(orientation, 'pt', paperSize.toLowerCase());
|
|
|
+// const {doc}=this;
|
|
|
+// doc.setFont('SmartSimsun', 'normal'); // 目前只考虑宋体
|
|
|
|
|
|
-// if (pageObj && pageObj.items.length > 0) {
|
|
|
-// for (let i = 0; i < pageObj.items.length; i++) {
|
|
|
-// if (pageData.打印页面_信息.纸张宽高[0] > pageData.打印页面_信息.纸张宽高[1]) {
|
|
|
-// doc.addPage({ size: [size[1] * DPI, size[0] * DPI] });
|
|
|
-// } else {
|
|
|
-// doc.addPage({ size: [size[0] * DPI, size[1] * DPI] });
|
|
|
-// }
|
|
|
-// const page = pageObj.items[i];
|
|
|
-// const fonts = pageObj.font_collection;
|
|
|
-// const styles = pageObj.style_collection;
|
|
|
-// const controls = pageObj.control_collection;
|
|
|
|
|
|
-// if (page.page_merge_border) {
|
|
|
-// Object.assign(newPageMergeBand,page.page_merge_border);
|
|
|
-// }
|
|
|
-// for (let j = 0; j < page.cells.length; j++) {
|
|
|
-// const cell = page.cells[j];
|
|
|
-// privateDrawCell(cell, fonts, styles, controls, newPageMergeBand);
|
|
|
+// const privateDrawCell=(doc:JsPDF, ctx:Canvas, cell:ICell, fonts:IFontCollection, styles:IStyles, controls:IControlCollection, mergedBand:IMergeBand) =>{
|
|
|
+// ctx.beginPath();
|
|
|
+// const style = styles[cell.style];
|
|
|
+// if (style) {
|
|
|
+// const isNeedMergeBand = private_chkIfInMergedBand(mergedBand, cell);
|
|
|
+// private_drawLine(
|
|
|
+// cell,
|
|
|
+// doc,
|
|
|
+// ctx,
|
|
|
+// style,
|
|
|
+// 'Top',
|
|
|
+// ['Left', 'Top'],
|
|
|
+// ['Right', 'Top'],
|
|
|
+// mergedBand,
|
|
|
+// styles,
|
|
|
+// isNeedMergeBand
|
|
|
+// );
|
|
|
+// private_drawLine(
|
|
|
+// cell,
|
|
|
+// doc,
|
|
|
+// ctx,
|
|
|
+// style,
|
|
|
+// 'Right',
|
|
|
+// ['Right', 'Top'],
|
|
|
+// ['Right', 'Bottom'],
|
|
|
+// mergedBand,
|
|
|
+// styles,
|
|
|
+// isNeedMergeBand
|
|
|
+// );
|
|
|
+// private_drawLine(
|
|
|
+// cell,
|
|
|
+// doc,
|
|
|
+// ctx,
|
|
|
+// style,
|
|
|
+// 'Bottom',
|
|
|
+// ['Right', 'Bottom'],
|
|
|
+// ['Left', 'Bottom'],
|
|
|
+// mergedBand,
|
|
|
+// styles,
|
|
|
+// isNeedMergeBand
|
|
|
+// );
|
|
|
+// private_drawLine(
|
|
|
+// cell,
|
|
|
+// doc,
|
|
|
+// ctx,
|
|
|
+// style,
|
|
|
+// 'Left',
|
|
|
+// ['Left', 'Bottom'],
|
|
|
+// ['Left', 'Top'],
|
|
|
+// mergedBand,
|
|
|
+// styles,
|
|
|
+// isNeedMergeBand
|
|
|
+// );
|
|
|
// }
|
|
|
+// private_drawCellText(doc, ctx, cell, fonts, controls);
|
|
|
+// ctx.closePath();
|
|
|
// }
|
|
|
-// }
|
|
|
-// doc.end();
|
|
|
-// stream.on('finish', function () {
|
|
|
-// console.log(`${newName}.pdf was written.`);
|
|
|
-// callback(newName);
|
|
|
-// });
|
|
|
-
|
|
|
-// const privateChkIfInMergedBand=(mergedBand:IMergeBand, cell:ICell)=> {
|
|
|
-// let rst = false;
|
|
|
-// if (mergedBand && cell) {
|
|
|
-// rst =
|
|
|
-// mergedBand.Top <= cell.area.Top &&
|
|
|
-// mergedBand.Bottom >= cell.area.Bottom &&
|
|
|
-// mergedBand.Right <= cell.area.Right &&
|
|
|
-// mergedBand.Left >= cell.area.Left;
|
|
|
+
|
|
|
+// const private_chkIfInMergedBand=(mergedBand:IMergeBand, cell:ICell)=> {
|
|
|
+// let rst = false;
|
|
|
+// if (mergedBand && cell) {
|
|
|
+// rst =
|
|
|
+// mergedBand.Top <= cell.area.Top&&
|
|
|
+// mergedBand.Bottom >= cell.area.Bottom &&
|
|
|
+// mergedBand.Left<= cell.area.Left &&
|
|
|
+// mergedBand.Right >= cell.area.Right;
|
|
|
+// }
|
|
|
+// return rst;
|
|
|
// }
|
|
|
-// return rst;
|
|
|
-// }
|
|
|
-
|
|
|
-
|
|
|
|
|
|
-
|
|
|
-// const privateDrawCellText=(cell:ICell, fonts:IFontCollection, controls:IControlCollection) =>{
|
|
|
-// if (cell.Value) {
|
|
|
-// const values = `${cell.Value}`.split('|');
|
|
|
-// // let font = fonts[cell.font];
|
|
|
-// let font = null;
|
|
|
-// if (typeof cell.font === 'string') {
|
|
|
-// font = fonts[cell.font];
|
|
|
-// } else {
|
|
|
-// font = cell.font;
|
|
|
-// }
|
|
|
-// // let control = controls[cell.control];
|
|
|
-// let control = null;
|
|
|
-// if (typeof cell.control === 'string') {
|
|
|
-// control = controls[cell.control];
|
|
|
-// } else {
|
|
|
-// control = cell.control;
|
|
|
+// const private_drawLine=(
|
|
|
+// cell:ICell,
|
|
|
+// doc:JsPDF,
|
|
|
+// ctx:Canvas,
|
|
|
+// style:IStyles,
|
|
|
+// styleBorderDest:'Top'|'Left'|'Right'|'Bottom',
|
|
|
+// startP:['Top'|'Left'|'Right'|'Bottom','Top'|'Left'|'Right'|'Bottom'],
|
|
|
+// destP:['Top'|'Left'|'Right'|'Bottom','Top'|'Left'|'Right'|'Bottom'],
|
|
|
+// mergedBand:IMergeBand,
|
|
|
+// styles:Record<string,IStyleCollection>,
|
|
|
+// isNeedMergeBand:boolean
|
|
|
+// ) =>{
|
|
|
+// let destStyle = style;
|
|
|
+// if (mergedBand) {
|
|
|
+// if (
|
|
|
+// isNeedMergeBand &&
|
|
|
+// parseFloat(`${mergedBand[styleBorderDest]}`) === parseFloat(`${cell.area[styleBorderDest]}`)
|
|
|
+// ) {
|
|
|
+// Object.assign(destStyle, styles[mergedBand.style.ID])
|
|
|
+// }
|
|
|
// }
|
|
|
-// const height = cell.area.Bottom - cell.area.Top;
|
|
|
-// const area = [
|
|
|
-// cell.area.Left + offsetX,
|
|
|
-// cell.area.Top + offsetY,
|
|
|
-// cell.area.Right + offsetX,
|
|
|
-// cell.area.Bottom + offsetY,
|
|
|
-// ];
|
|
|
-// let ah = height;
|
|
|
-// let restTopH = 0;
|
|
|
-// let restBottomH = 0;
|
|
|
-// if (control.CloseOutput === 'T') {
|
|
|
-// ah =
|
|
|
-// (parseFloat(font.Name) +
|
|
|
-// JV.OUTPUT_OFFSET[JV.OFFSET_IDX_TOP] +
|
|
|
-// JV.OUTPUT_OFFSET[JV.OFFSET_IDX_BOTTOM]) *
|
|
|
-// values.length;
|
|
|
-// const restH = height - ah;
|
|
|
-// if (control.Vertical === 'center') {
|
|
|
-// restTopH = restH / 2;
|
|
|
-// restBottomH = restH / 2;
|
|
|
-// } else if (control.Vertical === 'bottom') {
|
|
|
-// restBottomH = restH;
|
|
|
+// if (destStyle[styleBorderDest] && parseFloat(destStyle[styleBorderDest][JV.PROP_LINE_WEIGHT]) !== 0) {
|
|
|
+// doc.setDrawColor(destStyle[styleBorderDest][JV.PROP_COLOR]);
|
|
|
+// if (parseInt(destStyle[styleBorderDest][JV.PROP_LINE_WEIGHT]) === 2) {
|
|
|
+// doc.setLineWidth(1 * destStyle[styleBorderDest][JV.PROP_LINE_WEIGHT]);
|
|
|
// } else {
|
|
|
-// restTopH = restH;
|
|
|
+// doc.setLineWidth(0.1);
|
|
|
// }
|
|
|
+// doc.line(
|
|
|
+// (cell.area[startP[0]] + offsetX) * PDF_SCALE,
|
|
|
+// (cell.area[startP[1]] + offsetY) * PDF_SCALE,
|
|
|
+// (cell.area[destP[0]] + offsetX) * PDF_SCALE,
|
|
|
+// (cell.area[destP[1]] + offsetY) * PDF_SCALE
|
|
|
+// );
|
|
|
// }
|
|
|
-// let spaceIdxArr = [];
|
|
|
-// for (let i = 0; i < values.length; i++) {
|
|
|
-// // area[JV.IDX_TOP] = cell.area..Top + i * (height / values.length) + offsetY;
|
|
|
-// // area[JV.IDX_BOTTOM] = cell.area..Top + (i + 1) * (height / values.length) + offsetY;
|
|
|
-// area[JV.IDX_TOP] = cell.area.Top + i * (ah / values.length) + offsetY + restTopH;
|
|
|
-// area[JV.IDX_BOTTOM] = cell.area.Top + (i + 1) * (ah / values.length) + offsetY + restBottomH;
|
|
|
-// if (values[i] === null || values[i] === undefined || values[i] === 'null') {
|
|
|
-// values[i] = '';
|
|
|
+// }
|
|
|
+
|
|
|
+// const private_drawCellText=(doc:JsPDF, ctx:Canvas, cell:ICell, fonts:IFontCollection, controls:IControlCollection)=> {
|
|
|
+// if (cell.Value !== undefined && cell.Value !== null) {
|
|
|
+// const values = `${cell.Value}`.split('|');
|
|
|
+// // let font = fonts[cell[JV.PROP_FONT]];
|
|
|
+// let font = null;
|
|
|
+// if (typeof cell.font === 'string') {
|
|
|
+// font = fonts[cell.font];
|
|
|
+// } else {
|
|
|
+// font = cell.font;
|
|
|
// }
|
|
|
-// // 因pdfkit输出空格只有一半宽度,需要额外加空格补上 -----------------------------
|
|
|
-// if (typeof values[i] === 'string') {
|
|
|
-// for (let j = 0; j < values[i].length; j++) {
|
|
|
-// if (values[i][j] === ' ') spaceIdxArr.push(j);
|
|
|
-// }
|
|
|
+// if (font[JV.FONT_PROPS[JV.FONT_PROP_IDX_BOLD]] === 'T') {
|
|
|
+// doc.setFont('SmartSimsun', 'bold');
|
|
|
+// // doc.setFontStyle("bold");
|
|
|
+// } else {
|
|
|
+// doc.setFont('SmartSimsun', 'normal');
|
|
|
// }
|
|
|
-// for (let j = spaceIdxArr.length - 1; j >= 0; j--) {
|
|
|
-// values[i] = `${values[i].slice(0, spaceIdxArr[j])} ${values[i].slice(spaceIdxArr[j])}`;
|
|
|
+// // let control = controls[cell[JV.PROP_CONTROL]];
|
|
|
+// let control = null;
|
|
|
+// if (typeof cell.control === 'string') {
|
|
|
+// control = controls[cell.control];
|
|
|
+// } else {
|
|
|
+// control = cell.control;
|
|
|
// }
|
|
|
-// // -----------------------------
|
|
|
-// privateDrawText(values[i], area, font, control);
|
|
|
-// spaceIdxArr = [];
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// const privateSplitString=(strVal:string, areaWidth:number, doc: { widthOfString: (arg0: string) => any; })=> {
|
|
|
-// const rst = [];
|
|
|
-// if (strVal) {
|
|
|
-// let preSIdx = 0;
|
|
|
-// let txtWidth = 0;
|
|
|
-// let currentW = 0;
|
|
|
-// const chnW = doc.widthOfString('一');
|
|
|
-// const 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;
|
|
|
+// const height = cell.area.Bottom - cell.area.Top;
|
|
|
+// const area = [
|
|
|
+// cell.area.Left + offsetX,
|
|
|
+// cell.area.Top + offsetY,
|
|
|
+// cell.area.Right+ offsetX,
|
|
|
+// cell.area.Bottom + offsetY,
|
|
|
+// ];
|
|
|
+// let ah = height;
|
|
|
+// let restTopH = 0;
|
|
|
+// let restBottomH = 0;
|
|
|
+// if (control.CloseOutput === 'T') {
|
|
|
+// ah =
|
|
|
+// (parseFloat(`${font.FontHeight}`) +
|
|
|
+// JV.OUTPUT_OFFSET[JV.OFFSET_IDX_TOP] +
|
|
|
+// JV.OUTPUT_OFFSET[JV.OFFSET_IDX_BOTTOM]) *
|
|
|
+// values.length;
|
|
|
+// const restH = height - ah;
|
|
|
+// if (control.Vertical === 'center') {
|
|
|
+// restTopH = restH / 2;
|
|
|
+// restBottomH = restH / 2;
|
|
|
+// } else if (control.Vertical === 'bottom') {
|
|
|
+// restBottomH = restH;
|
|
|
// } else {
|
|
|
-// rst.push(strVal.substr(preSIdx, 1));
|
|
|
-// preSIdx = sIdx + 1;
|
|
|
+// restTopH = restH;
|
|
|
// }
|
|
|
-// txtWidth = currentW;
|
|
|
// }
|
|
|
-// if (sIdx === strVal.length - 1) {
|
|
|
-// rst.push(strVal.substr(preSIdx, strVal.length - preSIdx));
|
|
|
+// let spaceIdxArr = [];
|
|
|
+// for (let i = 0; i < values.length; i++) {
|
|
|
+// area[JV.IDX_TOP] = cell.area.Top + i * (ah / values.length) + offsetY + restTopH;
|
|
|
+// area[JV.IDX_BOTTOM] =
|
|
|
+// cell.area.Top + (i + 1) * (ah / values.length) + offsetY + restBottomH;
|
|
|
+// if (values[i] === null || values[i] === undefined || values[i] === 'null') {
|
|
|
+// values[i] = '';
|
|
|
+// }
|
|
|
+// // 因pdfkit输出空格只有浏览器的一半宽度,需要额外加空格补上,jspdf也有这个情况 -----------------------------
|
|
|
+// if (typeof values[i] === 'string') {
|
|
|
+// for (let j = 0; j < values[i].length; j++) {
|
|
|
+// if (values[i][j] === ' ') spaceIdxArr.push(j);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// for (let j = spaceIdxArr.length - 1; j >= 0; j--) {
|
|
|
+// values[i] = `${values[i].slice(0, spaceIdxArr[j])} ${values[i].slice(spaceIdxArr[j])}`;
|
|
|
+// }
|
|
|
+// // -----------------------------
|
|
|
+// private_drawText(doc, ctx, values[i], area, font, control);
|
|
|
+// spaceIdxArr = [];
|
|
|
// }
|
|
|
// }
|
|
|
// }
|
|
|
-// if (rst.length === 0) rst.push(''); // 什么都没有,也得整个空串
|
|
|
-// return rst;
|
|
|
-// }
|
|
|
-// const privateDrawText=(val:string, area:number[], font:IFontSubCollection, control:IControlSubCollection)=> {
|
|
|
-// let dftFontHeight = 12;
|
|
|
-// const output: number[] = [];
|
|
|
-// let fontFile = `${__dirname}/pdf_base_files/simkai.ttf`;
|
|
|
-// if (font) {
|
|
|
-// dftFontHeight = 1 * font.FontHeight;
|
|
|
-// fontFile = `${__dirname}/pdf_base_files/${getActualFont(
|
|
|
-// font.Name,
|
|
|
-// font.FontBold === 'T',
|
|
|
-// font.FontItalic === 'T'
|
|
|
-// )}.ttf`;
|
|
|
-// doc.fontSize(dftFontHeight);
|
|
|
-// }
|
|
|
-// doc.font(fontFile);
|
|
|
-// const options = {
|
|
|
-// width:0,
|
|
|
-// height:0
|
|
|
-// };
|
|
|
-// const innerSetupControl = function (inArea:number[], inFontHeight:number, inOutput: number[]) {
|
|
|
-// if (control) {
|
|
|
-// privateSetupAreaH(inArea, control.Horizon, font.FontAngle, inFontHeight, inOutput, options);
|
|
|
-// privateSetupAreaV(inArea, control.Vertical, font.FontAngle, inFontHeight, inOutput);
|
|
|
-// } else {
|
|
|
-// privateSetupAreaH(inArea, 'left', parseInt(`${font.FontAngle}`), inFontHeight, inOutput, options);
|
|
|
-// privateSetupAreaV(inArea, 'bottom', parseInt(`${font.FontAngle}`), inFontHeight, inOutput);
|
|
|
-// }
|
|
|
-// };
|
|
|
-// innerSetupControl(area, dftFontHeight, output);
|
|
|
-// let validAreaTxtWidth =
|
|
|
-// area[JV.IDX_RIGHT] -
|
|
|
-// JV.OUTPUT_OFFSET[JV.OFFSET_IDX_RIGHT] -
|
|
|
-// area[JV.IDX_LEFT] -
|
|
|
-// JV.OUTPUT_OFFSET[JV.OFFSET_IDX_RIGHT];
|
|
|
-// 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)
|
|
|
-// );
|
|
|
-// if (parseInt(`${font.FontAngle}`) !== 0) {
|
|
|
-// validAreaTxtWidth =
|
|
|
-// area[JV.IDX_BOTTOM] -
|
|
|
-// JV.OUTPUT_OFFSET[JV.OFFSET_IDX_BOTTOM] -
|
|
|
-// area[JV.IDX_TOP] -
|
|
|
-// JV.OUTPUT_OFFSET[JV.OFFSET_IDX_TOP];
|
|
|
-// validTxtLines = Math.floor(
|
|
|
-// (area[JV.IDX_RIGHT] - area[JV.IDX_LEFT]) /
|
|
|
-// (dftFontHeight + JV.OUTPUT_OFFSET[JV.OFFSET_IDX_RIGHT] + JV.OUTPUT_OFFSET[JV.OFFSET_IDX_LEFT] + 4)
|
|
|
-// );
|
|
|
-// }
|
|
|
|
|
|
-// const privateDrawUnderline=(underLineVal:string, underLineArea:number[])=> {
|
|
|
-// // A. 暂不支持角度; B. PDF输出时,坐标没有translate
|
|
|
-// const ctx = doc;
|
|
|
-// // 1. 计算下划线的相关坐标
|
|
|
-// let width = ctx.widthOfString(underLineVal);
|
|
|
-// if (width > underLineArea[JV.IDX_RIGHT] - underLineArea[JV.IDX_LEFT]) {
|
|
|
-// width = underLineArea[JV.IDX_RIGHT] - underLineArea[JV.IDX_LEFT];
|
|
|
+// const private_drawText=(doc:JsPDF, ctx:Canvas, val:string, area:number[], font:IFontSubCollection, control:IControlCollection)=> {
|
|
|
+// let dftFontHeight = 12;
|
|
|
+// const output:any = [];
|
|
|
+// if (font) {
|
|
|
+// dftFontHeight = 1 * font.FontHeight;
|
|
|
+// doc.setFontSize(dftFontHeight);
|
|
|
// }
|
|
|
-// const height = dftFontHeight;
|
|
|
-// let startX = underLineArea[JV.IDX_LEFT];
|
|
|
-// let startY = underLineArea[JV.IDX_TOP];
|
|
|
-// let endX = underLineArea[JV.IDX_RIGHT];
|
|
|
-// let endY = underLineArea[JV.IDX_BOTTOM];
|
|
|
-// // let startX = 0, startY = 0, endX = width, endY = startY;
|
|
|
-// if (control.Horizon === 'left') {
|
|
|
-// startX = Math.round(underLineArea[JV.IDX_LEFT] + JV.OUTPUT_OFFSET[JV.IDX_LEFT]);
|
|
|
-// } else if (control.Horizon === 'right') {
|
|
|
-// startX = Math.round(underLineArea[JV.IDX_RIGHT] - width - JV.OUTPUT_OFFSET[JV.IDX_RIGHT]);
|
|
|
-// } else {
|
|
|
-// startX = Math.round(
|
|
|
-// underLineArea[JV.IDX_LEFT] + (underLineArea[JV.IDX_RIGHT] - underLineArea[JV.IDX_LEFT] - width) / 2
|
|
|
+// // doc.font(fontFile);
|
|
|
+// const options = {};
|
|
|
+// const inner_setupControl = (outVal: string, inArea: IArea, inFontHeight: number, inOutput: any[])=> {
|
|
|
+// if (control) {
|
|
|
+// private_setupAreaH(outVal, inArea, control.Horizon, font.FontAngle, inFontHeight, inOutput, options);
|
|
|
+// private_setupAreaV(outVal, inArea, control.Vertical, font.FontAngle, inFontHeight, inOutput);
|
|
|
+// } else {
|
|
|
+// private_setupAreaH(outVal, inArea, 'left', parseInt(`${font.FontAngle}`), inFontHeight, inOutput, options);
|
|
|
+// private_setupAreaV(outVal, inArea, 'bottom', parseInt(`${font.FontAngle}`), inFontHeight, inOutput);
|
|
|
+// }
|
|
|
+// };
|
|
|
+// inner_setupControl(val, area, dftFontHeight, output);
|
|
|
+// let validAreaTxtWidth =
|
|
|
+// area[JV.IDX_RIGHT] -
|
|
|
+// JV.OUTPUT_OFFSET[JV.OFFSET_IDX_RIGHT] -
|
|
|
+// area[JV.IDX_LEFT] -
|
|
|
+// JV.OUTPUT_OFFSET[JV.OFFSET_IDX_RIGHT];
|
|
|
+// 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)
|
|
|
+// );
|
|
|
+// if (parseInt(`${font.FontAngle}`) !== 0) {
|
|
|
+// validAreaTxtWidth =
|
|
|
+// area[JV.IDX_BOTTOM] -
|
|
|
+// JV.OUTPUT_OFFSET[JV.OFFSET_IDX_BOTTOM] -
|
|
|
+// area[JV.IDX_TOP] -
|
|
|
+// JV.OUTPUT_OFFSET[JV.OFFSET_IDX_TOP];
|
|
|
+// validTxtLines = Math.floor(
|
|
|
+// (area[JV.IDX_RIGHT] - area[JV.IDX_LEFT]) /
|
|
|
+// (dftFontHeight + JV.OUTPUT_OFFSET[JV.OFFSET_IDX_RIGHT] + JV.OUTPUT_OFFSET[JV.OFFSET_IDX_LEFT] + 4)
|
|
|
// );
|
|
|
// }
|
|
|
-// endX = Math.round(startX + width);
|
|
|
|
|
|
-// if (control.Vertical === 'top') {
|
|
|
-// startY = Math.round(
|
|
|
-// underLineArea[JV.IDX_TOP] + JV.OUTPUT_OFFSET[JV.IDX_TOP] + JV.OUTPUT_OFFSET[JV.IDX_BOTTOM] + height
|
|
|
-// );
|
|
|
-// } else if (control.Vertical === 'bottom') {
|
|
|
-// startY = Math.round(underLineArea[JV.IDX_BOTTOM] + JV.OUTPUT_OFFSET[JV.IDX_BOTTOM]);
|
|
|
-// } else {
|
|
|
-// startY =
|
|
|
-// Math.round(
|
|
|
-// underLineArea[JV.IDX_TOP] + (underLineArea[JV.IDX_BOTTOM] - underLineArea[JV.IDX_TOP] + height) / 2
|
|
|
-// ) +
|
|
|
-// JV.OUTPUT_OFFSET[JV.IDX_TOP] +
|
|
|
-// JV.OUTPUT_OFFSET[JV.IDX_BOTTOM];
|
|
|
+// const private_drawUnderline=(underLineVal, underLineArea)=> {
|
|
|
+// // A. 暂不支持角度; B. PDF输出时,坐标没有translate
|
|
|
+// // let ctx = doc;
|
|
|
+// // 1. 计算下划线的相关坐标
|
|
|
+// let width = doc.getTextWidth(underLineVal);
|
|
|
+// if (width > underLineArea[JV.IDX_RIGHT] - underLineArea[JV.IDX_LEFT]) {
|
|
|
+// width = underLineArea[JV.IDX_RIGHT] - underLineArea[JV.IDX_LEFT];
|
|
|
+// }
|
|
|
+// const height = dftFontHeight;
|
|
|
+// let startX = underLineArea[JV.IDX_LEFT];
|
|
|
+// let startY = underLineArea[JV.IDX_TOP];
|
|
|
+// let endX = underLineArea[JV.IDX_RIGHT];
|
|
|
+// let endY = underLineArea[JV.IDX_BOTTOM];
|
|
|
+// // let startX = 0, startY = 0, endX = width, endY = startY;
|
|
|
+// if (control.Horizon === 'left') {
|
|
|
+// startX = Math.round(underLineArea[JV.IDX_LEFT] + JV.OUTPUT_OFFSET[JV.IDX_LEFT]);
|
|
|
+// } else if (control.Horizon === 'right') {
|
|
|
+// startX = Math.round(underLineArea[JV.IDX_RIGHT] - width - JV.OUTPUT_OFFSET[JV.IDX_RIGHT]);
|
|
|
+// } else {
|
|
|
+// startX = Math.round(
|
|
|
+// underLineArea[JV.IDX_LEFT] + (underLineArea[JV.IDX_RIGHT] - underLineArea[JV.IDX_LEFT] - width) / 2
|
|
|
+// );
|
|
|
+// }
|
|
|
+// endX = Math.round(startX + width);
|
|
|
+
|
|
|
+// if (control.Vertical === 'top') {
|
|
|
+// startY = Math.round(
|
|
|
+// underLineArea[JV.IDX_TOP] + JV.OUTPUT_OFFSET[JV.IDX_TOP] + JV.OUTPUT_OFFSET[JV.IDX_BOTTOM] + height
|
|
|
+// );
|
|
|
+// } else if (control.Vertical === 'bottom') {
|
|
|
+// startY = Math.round(underLineArea[JV.IDX_BOTTOM] + JV.OUTPUT_OFFSET[JV.IDX_BOTTOM]);
|
|
|
+// } else {
|
|
|
+// startY =
|
|
|
+// Math.round(
|
|
|
+// underLineArea[JV.IDX_TOP] + (underLineArea[JV.IDX_BOTTOM] - underLineArea[JV.IDX_TOP] + height) / 2
|
|
|
+// ) +
|
|
|
+// JV.OUTPUT_OFFSET[JV.IDX_TOP] +
|
|
|
+// JV.OUTPUT_OFFSET[JV.IDX_BOTTOM];
|
|
|
+// }
|
|
|
+// endY = Math.round(startY);
|
|
|
+// // 2. 画线
|
|
|
+// // ctx.save();
|
|
|
+// if (output[1] !== Math.round(output[1])) {
|
|
|
+// ctx.translate(0, 0.5);
|
|
|
+// }
|
|
|
+
|
|
|
+// doc.setDrawColor('BLACK');
|
|
|
+// doc.setLineWidth(0.1);
|
|
|
+// doc.line(startX * PDF_SCALE, startY * PDF_SCALE, endX * PDF_SCALE, endY * PDF_SCALE);
|
|
|
// }
|
|
|
-// endY = Math.round(startY);
|
|
|
-// // 2. 画线
|
|
|
-// // ctx.save();
|
|
|
-// if (output[1] !== Math.round(output[1])) {
|
|
|
-// ctx.translate(0, 0.5);
|
|
|
+
|
|
|
+// let rotateOptions;
|
|
|
+// if (parseInt(font.FontAngle) !== 0) {
|
|
|
+// if (control) {
|
|
|
+// rotateOptions = private_setupAreaRotateOption(
|
|
|
+// area,
|
|
|
+// validAreaTxtWidth,
|
|
|
+// control.Vertical,
|
|
|
+// dftFontHeight,
|
|
|
+// output
|
|
|
+// );
|
|
|
+// } else {
|
|
|
+// rotateOptions = private_setupAreaRotateOption(area, validAreaTxtWidth, 'bottom', dftFontHeight, output);
|
|
|
+// }
|
|
|
+// doc.rotate(font.FontAngle, rotateOptions);
|
|
|
+// }
|
|
|
+// if (
|
|
|
+// validAreaTxtWidth >= doc.getTextWidth(val) ||
|
|
|
+// (control && control.Shrink !== 'T' && validTxtLines < private_splitString(val, validAreaTxtWidth, doc))
|
|
|
+// ) {
|
|
|
+// options.width = validAreaTxtWidth * PDF_SCALE;
|
|
|
+// options.height = dftFontHeight * PDF_SCALE;
|
|
|
+// doc.setFontSize(dftFontHeight);
|
|
|
+// if (font[JV.FONT_PROPS[5]] === 'T' && parseInt(font.FontAngle) === 0) {
|
|
|
+// private_drawUnderline(val, area);
|
|
|
+// }
|
|
|
+// doc.setFontSize(dftFontHeight * PDF_SCALE);
|
|
|
+// doc.text(output[0] * PDF_SCALE, output[1] * PDF_SCALE, val);
|
|
|
+// } 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 || (control.Shrink === 'T' && control.ShrinkFirst === 'T') ? 1 : lines;
|
|
|
+// const actLines = private_splitString(val, validAreaTxtWidth, doc);
|
|
|
+// if (actLines.length > lines && dftFontHeight >= 6) {
|
|
|
+// dftFontHeight--;
|
|
|
+// doc.setFontSize(dftFontHeight);
|
|
|
+// options.width = validAreaTxtWidth * PDF_SCALE;
|
|
|
+// options.height = dftFontHeight * PDF_SCALE;
|
|
|
+// } else {
|
|
|
+// const 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;
|
|
|
+// }
|
|
|
+// }
|
|
|
+// const newArea = [];
|
|
|
+// const baseTop = area[JV.IDX_TOP];
|
|
|
+// for (let ai = 0; ai < area.length; ai++) {
|
|
|
+// newArea[ai] = area[ai];
|
|
|
+// }
|
|
|
+// options.width = validAreaTxtWidth * PDF_SCALE;
|
|
|
+// options.height = dftFontHeight * PDF_SCALE;
|
|
|
+// 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);
|
|
|
+// doc.setFontSize(dftFontHeight);
|
|
|
+// inner_setupControl(actLines[lIdx], newArea, dftFontHeight, output);
|
|
|
+// if (font[JV.FONT_PROPS[5]] === 'T' && parseInt(font.FontAngle) === 0) {
|
|
|
+// private_drawUnderline(actLines[lIdx], newArea);
|
|
|
+// }
|
|
|
+// doc.setFontSize(dftFontHeight * PDF_SCALE);
|
|
|
+// doc.text(output[0] * PDF_SCALE, output[1] * PDF_SCALE, actLines[lIdx]);
|
|
|
+// }
|
|
|
+// break;
|
|
|
+// }
|
|
|
+// }
|
|
|
// }
|
|
|
-// // ctx.beginPath();
|
|
|
-// // ctx.moveTo(startX, startY);
|
|
|
-// ctx.moveTo(startX * PDF_SCALE, startY * PDF_SCALE);
|
|
|
-// ctx.lineWidth(1);
|
|
|
-// ctx.strokeStyle = 'BLACK';
|
|
|
-// // ctx.lineTo(endX, endY);
|
|
|
-// ctx.lineTo(endX * PDF_SCALE, endY * PDF_SCALE);
|
|
|
-// ctx.stroke();
|
|
|
-// // ctx.restore();
|
|
|
// }
|
|
|
|
|
|
-// let rotateOptions;
|
|
|
-// // if (font[JV.FONT_PROPS[5]] === 'T' && parseInt(font.FontAngle) === 0) {
|
|
|
-// // privateDrawUnderline(val);
|
|
|
-// // }
|
|
|
-// if (parseInt(`${font.FontAngle}`) !== 0) {
|
|
|
-// if (control) {
|
|
|
-// rotateOptions = privateSetupAreaRotateOption(area, validAreaTxtWidth, control.Vertical, dftFontHeight, output);
|
|
|
-// } else {
|
|
|
-// rotateOptions = privateSetupAreaRotateOption(area, validAreaTxtWidth, 'bottom', dftFontHeight, output);
|
|
|
+// const private_setupAreaH=(outVal, area, type, fontAngle, dftFontHeight, outputPoint, options)=> {
|
|
|
+// // jspdf输出方式不同(但与H5的canvas处理方式有所不同,因为没有相关alignment属性,需要自己算,而且角度还暂时不支持)-------------------------------------------
|
|
|
+// let lType = type;
|
|
|
+// if (type !== 'left' && type !== 'right' && type !== 'center') lType = 'left';
|
|
|
+// switch (lType) {
|
|
|
+// case 'left':
|
|
|
+// if (fontAngle === JV.VERTICAL_ANGLE_INT) {
|
|
|
+// // outputPoint[1] = 1 * area[JV.IDX_TOP] + JV.OUTPUT_OFFSET[JV.OFFSET_IDX_LEFT];
|
|
|
+// } else if (fontAngle === JV.ANTI_VERTICAL_ANGLE_INT) {
|
|
|
+// // outputPoint[1] = 1 * area[JV.IDX_BOTTOM] - JV.OUTPUT_OFFSET[JV.OFFSET_IDX_LEFT];
|
|
|
+// } else {
|
|
|
+// outputPoint[0] = 1 * area[JV.IDX_LEFT] + JV.OUTPUT_OFFSET[JV.OFFSET_IDX_LEFT];
|
|
|
+// }
|
|
|
+// // ctx.textAlign="start";
|
|
|
+// break;
|
|
|
+// case 'right':
|
|
|
+// if (fontAngle === JV.VERTICAL_ANGLE_INT) {
|
|
|
+// outputPoint[1] = 1 * area[JV.IDX_BOTTOM] - JV.OUTPUT_OFFSET[JV.OFFSET_IDX_RIGHT];
|
|
|
+// } else if (fontAngle === JV.ANTI_VERTICAL_ANGLE_INT) {
|
|
|
+// outputPoint[1] = 1 * area[JV.IDX_TOP] + JV.OUTPUT_OFFSET[JV.OFFSET_IDX_RIGHT];
|
|
|
+// } else {
|
|
|
+// const width = doc.getTextWidth(outVal);
|
|
|
+// outputPoint[0] = 1 * area[JV.IDX_RIGHT] - JV.OUTPUT_OFFSET[JV.OFFSET_IDX_RIGHT] - width;
|
|
|
+// }
|
|
|
+// // ctx.textAlign="end";
|
|
|
+// break;
|
|
|
+// case 'center':
|
|
|
+// if (fontAngle === JV.VERTICAL_ANGLE_INT || fontAngle === JV.ANTI_VERTICAL_ANGLE_INT) {
|
|
|
+// outputPoint[1] = (1 * area[JV.IDX_TOP] + 1 * area[JV.IDX_BOTTOM]) / 2;
|
|
|
+// } else {
|
|
|
+// const width = doc.getTextWidth(outVal);
|
|
|
+// outputPoint[0] = (1 * area[JV.IDX_LEFT] + 1 * area[JV.IDX_RIGHT]) / 2 - width / 2;
|
|
|
+// }
|
|
|
+// // ctx.textAlign="center";
|
|
|
+// break;
|
|
|
// }
|
|
|
-// doc.rotate(font.FontAngle, rotateOptions);
|
|
|
// }
|
|
|
-// if (
|
|
|
-// validAreaTxtWidth >= doc.widthOfString(val) ||
|
|
|
-// (control && control.Shrink !== 'T' && validTxtLines < privateSplitString(val, validAreaTxtWidth, doc).length)
|
|
|
-// ) {
|
|
|
-// options.width = validAreaTxtWidth * PDF_SCALE;
|
|
|
-// options.height = dftFontHeight * PDF_SCALE;
|
|
|
-// doc.fontSize(dftFontHeight);
|
|
|
-// if (font[JV.FONT_PROPS[5]] === 'T' && parseInt(`${font.FontAngle}`) === 0) {
|
|
|
-// privateDrawUnderline(val, area);
|
|
|
+
|
|
|
+// const private_setupAreaV=(outVal, area, type, fontAngle, dftFontHeight, outputPoint)=> {
|
|
|
+// // jspdf输出方式不同(与H5的canvas一样处理)-------------------------------------------
|
|
|
+// let lType = type;
|
|
|
+// if (type !== 'top' && type !== 'bottom' && type !== 'center') lType = 'top';
|
|
|
+// switch (lType) {
|
|
|
+// case 'top':
|
|
|
+// if (fontAngle === JV.VERTICAL_ANGLE_INT) {
|
|
|
+// outputPoint[0] = 1 * area[JV.IDX_RIGHT] - dftFontHeight - JV.OUTPUT_OFFSET[JV.OFFSET_IDX_TOP];
|
|
|
+// } else if (fontAngle === JV.ANTI_VERTICAL_ANGLE_INT) {
|
|
|
+// outputPoint[0] = 1 * area[JV.IDX_LEFT] + dftFontHeight + JV.OUTPUT_OFFSET[JV.OFFSET_IDX_TOP];
|
|
|
+// } else outputPoint[1] = 1 * area[JV.IDX_TOP] + dftFontHeight + JV.OUTPUT_OFFSET[JV.OFFSET_IDX_TOP];
|
|
|
+// break;
|
|
|
+// case 'bottom':
|
|
|
+// if (fontAngle === JV.VERTICAL_ANGLE_INT) {
|
|
|
+// outputPoint[0] = 1 * area[JV.IDX_LEFT] + JV.OUTPUT_OFFSET[JV.OFFSET_IDX_BOTTOM];
|
|
|
+// } else if (fontAngle === JV.ANTI_VERTICAL_ANGLE_INT) {
|
|
|
+// outputPoint[0] = 1 * area[JV.IDX_RIGHT] - JV.OUTPUT_OFFSET[JV.OFFSET_IDX_BOTTOM];
|
|
|
+// } else {
|
|
|
+// outputPoint[1] = 1 * area[JV.IDX_BOTTOM] - JV.OUTPUT_OFFSET[JV.OFFSET_IDX_BOTTOM];
|
|
|
+// // if (fontName === "宋体") outputPoint[1] = outputPoint[1] - 1;
|
|
|
+// outputPoint[1] -= 1; // 宋体需要提上一个像素点
|
|
|
+// }
|
|
|
+// break;
|
|
|
+// case 'center':
|
|
|
+// if (fontAngle === JV.VERTICAL_ANGLE_INT) {
|
|
|
+// outputPoint[0] = (1 * area[JV.IDX_LEFT] + 1 * area[JV.IDX_RIGHT] - dftFontHeight) / 2;
|
|
|
+// } else if (fontAngle === JV.ANTI_VERTICAL_ANGLE_INT) {
|
|
|
+// outputPoint[0] = (1 * area[JV.IDX_LEFT] + 1 * area[JV.IDX_RIGHT] + dftFontHeight) / 2;
|
|
|
+// } else {
|
|
|
+// outputPoint[1] = (1 * area[JV.IDX_TOP] + 1 * area[JV.IDX_BOTTOM] + dftFontHeight) / 2;
|
|
|
+// // if (fontName === "宋体") outputPoint[1] = outputPoint[1] - 1;
|
|
|
+// outputPoint[1] -= 1; // 宋体需要提上一个像素点
|
|
|
+// }
|
|
|
+// break;
|
|
|
// }
|
|
|
-// doc.fontSize(dftFontHeight * PDF_SCALE);
|
|
|
-// doc.text(val, output[0] * PDF_SCALE, output[1] * PDF_SCALE, 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 || (control.Shrink === 'T' && control.ShrinkFirst === 'T') ? 1 : lines;
|
|
|
-// const actLines = privateSplitString(val, validAreaTxtWidth, doc);
|
|
|
-// if (actLines.length > lines && dftFontHeight >= 6) {
|
|
|
-// dftFontHeight--;
|
|
|
-// doc.fontSize(dftFontHeight);
|
|
|
-// options.width = validAreaTxtWidth * PDF_SCALE;
|
|
|
-// options.height = dftFontHeight * PDF_SCALE;
|
|
|
-// // doc.text(val,output[0], output[1], options);
|
|
|
-// } else {
|
|
|
-// const 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;
|
|
|
+// }
|
|
|
+
|
|
|
+// const private_splitString=(strVal, areaWidth, doc) =>{
|
|
|
+// const rst = [];
|
|
|
+// if (strVal) {
|
|
|
+// let preSIdx = 0;
|
|
|
+// let txtWidth = 0;
|
|
|
+// let currentW = 0;
|
|
|
+// const chnW = doc.getTextWidth('一');
|
|
|
+// const otherW = doc.getTextWidth('_');
|
|
|
+// 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 {
|
|
|
-// 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;
|
|
|
+// rst.push(strVal.substr(preSIdx, 1));
|
|
|
+// preSIdx = sIdx + 1;
|
|
|
// }
|
|
|
+// txtWidth = currentW;
|
|
|
// }
|
|
|
-// const newArea = [];
|
|
|
-// const baseTop = area[JV.IDX_TOP];
|
|
|
-// for (let ai = 0; ai < area.length; ai++) {
|
|
|
-// newArea[ai] = area[ai];
|
|
|
+// if (sIdx === strVal.length - 1) {
|
|
|
+// rst.push(strVal.substr(preSIdx, strVal.length - preSIdx));
|
|
|
// }
|
|
|
-// options.width = validAreaTxtWidth * PDF_SCALE;
|
|
|
-// options.height = dftFontHeight * PDF_SCALE;
|
|
|
-// 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);
|
|
|
-// innerSetupControl(newArea, dftFontHeight, output);
|
|
|
-// doc.fontSize(dftFontHeight);
|
|
|
-// if (font[JV.FONT_PROPS[5]] === 'T' && parseInt(`${font.FontAngle}`) === 0) {
|
|
|
-// privateDrawUnderline(actLines[lIdx], newArea);
|
|
|
-// }
|
|
|
-// doc.fontSize(dftFontHeight * PDF_SCALE);
|
|
|
-// doc.text(actLines[lIdx], output[0] * PDF_SCALE, output[1] * PDF_SCALE, options);
|
|
|
-// }
|
|
|
-// break;
|
|
|
// }
|
|
|
-// /* /
|
|
|
-// dftFontHeight--;
|
|
|
-// doc.fontSize(dftFontHeight);
|
|
|
-// if (validAreaTxtWidth >= doc.widthOfString(val) || dftFontHeight < 6) {
|
|
|
-// options.width = validAreaTxtWidth;
|
|
|
-// options.height = dftFontHeight;
|
|
|
-// doc.text(val,output[0], output[1], options);
|
|
|
-// doc.font(__dirname + '/pdf_base_files/simhei_bold_italic.ttf');
|
|
|
-// break;
|
|
|
-// }
|
|
|
-// // */
|
|
|
// }
|
|
|
+// if (rst.length === 0) rst.push(''); // 什么都没有,也得整个空串
|
|
|
+// return rst;
|
|
|
// }
|
|
|
-// // doc.text(val,output[0], output[1], options);
|
|
|
-// doc.font(`${__dirname}/pdf_base_files/simhei_bold_italic.ttf`);
|
|
|
-// // doc.restore();
|
|
|
-// }
|
|
|
|
|
|
-// const privateSetupAreaH=(area: number[], type: string, fontAngle: string | number | undefined, dftFontHeight: number, outputPoint: number[], options: { width?: number; height?: number; align?: any; })=> {
|
|
|
-// let lType = type;
|
|
|
-// if (type !== 'left' && type !== 'right' && type !== 'center') lType = 'left';
|
|
|
-// options.align = lType;
|
|
|
-// outputPoint[0] = 1 * area[JV.IDX_LEFT] + JV.OUTPUT_OFFSET[JV.OFFSET_IDX_LEFT];
|
|
|
-// }
|
|
|
-
|
|
|
-// const privateSetupAreaV=(area: number[], type: string, fontAngle: string | number | undefined, dftFontHeight: number, outputPoint: number[])=> {
|
|
|
-// let lType = type;
|
|
|
-// if (type !== 'top' && type !== 'bottom' && type !== 'center') lType = 'top';
|
|
|
-// switch (lType) {
|
|
|
-// case 'top':
|
|
|
-// outputPoint[1] = 1 * area[JV.IDX_TOP] + JV.OUTPUT_OFFSET[JV.OFFSET_IDX_TOP];
|
|
|
-// break;
|
|
|
-// case 'bottom':
|
|
|
-// outputPoint[1] = 1 * area[JV.IDX_BOTTOM] - JV.OUTPUT_OFFSET[JV.OFFSET_IDX_BOTTOM] - dftFontHeight;
|
|
|
-// break;
|
|
|
-// case 'center':
|
|
|
-// outputPoint[1] = 1 * area[JV.IDX_TOP] + (1 * area[JV.IDX_BOTTOM] - 1 * area[JV.IDX_TOP] - dftFontHeight) / 2;
|
|
|
-// break;
|
|
|
+// const private_setupAreaRotateOption=(area, w, type = 'top', dftFontHeight, outputPoint)=> {
|
|
|
+// const x = (area[JV.IDX_RIGHT] - area[JV.IDX_LEFT]) / 2 + area[JV.IDX_LEFT];
|
|
|
+// const y = (area[JV.IDX_BOTTOM] - area[JV.IDX_TOP]) / 2 + area[JV.IDX_TOP];
|
|
|
+// const rotateOptions = { origin: [x, y] };
|
|
|
+// const h = area[JV.IDX_RIGHT] - area[JV.IDX_LEFT];
|
|
|
+// outputPoint[0] = x - w / 2 + JV.OUTPUT_OFFSET[JV.OFFSET_IDX_LEFT];
|
|
|
+// switch (type) {
|
|
|
+// case 'top':
|
|
|
+// outputPoint[1] = y - h / 2 + JV.OUTPUT_OFFSET[JV.OFFSET_IDX_TOP];
|
|
|
+// break;
|
|
|
+// case 'bottom':
|
|
|
+// outputPoint[1] = y + h / 2 - JV.OUTPUT_OFFSET[JV.OFFSET_IDX_BOTTOM] - dftFontHeight;
|
|
|
+// break;
|
|
|
+// case 'center':
|
|
|
+// outputPoint[1] = y + dftFontHeight / 2;
|
|
|
+// break;
|
|
|
+// }
|
|
|
+// return rotateOptions;
|
|
|
// }
|
|
|
-// }
|
|
|
-
|
|
|
-
|
|
|
+// const newPageMergeBand = {...pageObj.MergeBand};
|
|
|
+// if (pageObj && pageObj.items.length > 0) {
|
|
|
+// for (let i = 0; i < pageObj.items.length; i++) {
|
|
|
+// if (i > 0) {
|
|
|
+// doc.addPage(paperSize.toLowerCase(), orientation);
|
|
|
+// }
|
|
|
+// const ctx = doc.canvas.getContext();
|
|
|
+// const page = pageObj.items[i];
|
|
|
+// const fonts = pageObj.control_collection;
|
|
|
+// const styles = pageObj.style_collection;
|
|
|
+// const controls = pageObj.control_collection;
|
|
|
|
|
|
-// const privateSetupAreaRotateOption=(area: number[], w: number, type = 'top', dftFontHeight: number, outputPoint: any[]) =>{
|
|
|
-// const x = (area[JV.IDX_RIGHT] - area[JV.IDX_LEFT]) / 2 + area[JV.IDX_LEFT];
|
|
|
-// const y = (area[JV.IDX_BOTTOM] - area[JV.IDX_TOP]) / 2 + area[JV.IDX_TOP];
|
|
|
-// const rotateOptions = { origin: [x, y] };
|
|
|
-// const h = area[JV.IDX_RIGHT] - area[JV.IDX_LEFT];
|
|
|
-// outputPoint[0] = x - w / 2 + JV.OUTPUT_OFFSET[JV.OFFSET_IDX_LEFT];
|
|
|
-// switch (type) {
|
|
|
-// case 'top':
|
|
|
-// outputPoint[1] = y - h / 2 + JV.OUTPUT_OFFSET[JV.OFFSET_IDX_TOP];
|
|
|
-// break;
|
|
|
-// case 'bottom':
|
|
|
-// outputPoint[1] = y + h / 2 - JV.OUTPUT_OFFSET[JV.OFFSET_IDX_BOTTOM] - dftFontHeight;
|
|
|
-// break;
|
|
|
-// case 'center':
|
|
|
-// outputPoint[1] = y + dftFontHeight / 2;
|
|
|
-// break;
|
|
|
+// if (page.page_merge_border) {
|
|
|
+// Object.assign(newPageMergeBand,page.page_merge_border);
|
|
|
+// }
|
|
|
+// for (let j = 0; j < page.cells.length; j++) {
|
|
|
+// const cell = page.cells[j];
|
|
|
+// privateDrawCell(doc, ctx, cell, fonts, styles, controls, newPageMergeBand);
|
|
|
+// }
|
|
|
+// }
|
|
|
// }
|
|
|
-// return rotateOptions;
|
|
|
-// }
|
|
|
+// doc.save(`${newName}.pdf`);
|
|
|
+
|
|
|
+// },
|
|
|
// }
|
|
|
-// export default {}
|
|
|
+
|
|
|
+
|