|
@@ -1,4 +1,5 @@
|
|
|
let JV = require('../jpc_value_define');
|
|
|
+let stringUtil = require('../../../../public/stringUtil');
|
|
|
|
|
|
let JpcCommonHelper = {
|
|
|
commonConstant: {},
|
|
@@ -134,7 +135,15 @@ let JpcCommonHelper = {
|
|
|
},
|
|
|
getStringLinesInArea: function(area, strVal, pdfDoc) {
|
|
|
let areaWidth = area[JV.PROP_RIGHT] - area[JV.PROP_LEFT] - JV.OUTPUT_OFFSET[JV.OFFSET_IDX_RIGHT] - JV.OUTPUT_OFFSET[JV.OFFSET_IDX_LEFT] - 2;
|
|
|
- let txtWidth = pdfDoc.widthOfString(strVal);
|
|
|
+ // let re = /[\u4E00-\u9FA5]/g;
|
|
|
+ let re = /[^\x00-\xff]/ig; //普通ASCII以外的字符
|
|
|
+ let cStr = strVal.match(re);
|
|
|
+ let chnAmt = (cStr)?cStr.length:0;
|
|
|
+ let chnW = pdfDoc.widthOfString('一'), otherW = pdfDoc.widthOfString('_');
|
|
|
+ //备注: 因后台的pdfDoc判断字符串长度与前端的不一样,需要做些调整,不一次性地判断字符串长度。
|
|
|
+ // 分2种字符:中文与非中文,按照各种字符的数量分别乘以相关一个字符的宽度再累计。
|
|
|
+ // let txtWidth = pdfDoc.widthOfString(strVal);
|
|
|
+ let txtWidth = chnAmt * chnW + (strVal.length - chnAmt) * otherW;
|
|
|
let rst = parseInt(txtWidth / areaWidth);
|
|
|
if (txtWidth % areaWidth > 0) {
|
|
|
rst++;
|
|
@@ -145,10 +154,19 @@ let JpcCommonHelper = {
|
|
|
},
|
|
|
splitString: function (area, strVal, pdfDoc) {
|
|
|
let rst = [];
|
|
|
+ // let re = /[\u4E00-\u9FA5]/g;
|
|
|
+ let re = /[^\x00-\xff]/ig; //普通ASCII以外的字符
|
|
|
+ let chnW = pdfDoc.widthOfString('一'), otherW = pdfDoc.widthOfString('_');
|
|
|
let areaWidth = area[JV.PROP_RIGHT] - area[JV.PROP_LEFT] - JV.OUTPUT_OFFSET[JV.OFFSET_IDX_RIGHT] - JV.OUTPUT_OFFSET[JV.OFFSET_IDX_LEFT] - 2;
|
|
|
let preSIdx = 0, txtWidth = 0;
|
|
|
+
|
|
|
for (let sIdx = 1; sIdx <= strVal.length; sIdx++) {
|
|
|
- txtWidth = pdfDoc.widthOfString(strVal.substr(preSIdx, sIdx - preSIdx));
|
|
|
+ let tmpStr = strVal.substr(preSIdx, sIdx - preSIdx);
|
|
|
+ let cStr = tmpStr.match(re);
|
|
|
+ let chnAmt = (cStr)?cStr.length:0;
|
|
|
+ // let chnAmt = tmpStr.match(re).length;
|
|
|
+ // txtWidth = pdfDoc.widthOfString(strVal.substr(preSIdx, sIdx - preSIdx));
|
|
|
+ txtWidth = chnAmt * chnW + (tmpStr.length - chnAmt) * otherW;
|
|
|
if (txtWidth > areaWidth) {
|
|
|
rst.push(strVal.substr(preSIdx, sIdx - preSIdx - 1));
|
|
|
preSIdx = sIdx - 1;
|