Skip to content

Commit

Permalink
Merge pull request #102 from wangstar/js
Browse files Browse the repository at this point in the history
perf:减少非必要text标签构建
  • Loading branch information
DLTech21 authored Nov 15, 2023
2 parents 6ca1f9c + 42e73b1 commit 8ff1343
Showing 1 changed file with 24 additions and 17 deletions.
41 changes: 24 additions & 17 deletions src/utils/ofd/ofd_util.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const convertPathAbbreviatedDatatoPoint = abbreviatedData => {
let pointList = [];
let i = 0;
while (i < array.length) {
if (array[i] === 'M'|| array[i] === 'S') {
if (array[i] === 'M' || array[i] === 'S') {
let point = {
'type': 'M',
'x': parseFloat(array[i + 1]),
Expand Down Expand Up @@ -102,28 +102,28 @@ const millimetersToPixel = function (mm, dpi) {

let MaxScale = 10;

let Scale = MaxScale ;
let Scale = MaxScale;

export const setMaxPageScal = function (scale) {
MaxScale = scale > 5 ? 5 : scale;
}

export const setPageScal = function (scale) {
// scale = Math.ceil(scale);
Scale = scale > 1 ? scale: 1;
Scale = Scale > MaxScale ? MaxScale: Scale;
Scale = scale > 1 ? scale : 1;
Scale = Scale > MaxScale ? MaxScale : Scale;
}

export const getPageScal = function () {
return Scale;
}

export const converterDpi = function (width) {
return millimetersToPixel(width, Scale*25.4);
return millimetersToPixel(width, Scale * 25.4);
}

export const deltaFormatter = function (delta) {
if(delta.indexOf("g") === -1) {
if (delta.indexOf("g") === -1) {
let floatList = [];
for (let f of delta.split(' ')) {
floatList.push(parseFloat(f));
Expand Down Expand Up @@ -202,8 +202,15 @@ export const calTextPoint = function (textCodes) {
y += deltaYList[(i - 1)];
}
let text = textStr.substring(i, i + 1);
let textCodePoint = {'x': converterDpi(x), 'y': converterDpi(y), 'text': text};
textCodePointList.push(textCodePoint);
let filterPointY = textCodePointList.filter((textCodePoint) => {
return textCodePoint.y == converterDpi(y)
});
if (filterPointY && filterPointY.length) { // Y坐标相同,无需再创建text标签
filterPointY[0].text += text;
} else {
let textCodePoint = { 'x': converterDpi(x), 'y': converterDpi(y), 'text': text };
textCodePointList.push(textCodePoint);
}
}
}
}
Expand All @@ -228,27 +235,27 @@ export const getExtensionByPath = function (path) {
let REGX_HTML_DECODE = /&\w+;|&#(\d+);/g;

let HTML_DECODE = {
"&lt;" : "<",
"&gt;" : ">",
"&amp;" : "&",
"&lt;": "<",
"&gt;": ">",
"&amp;": "&",
"&nbsp;": " ",
"&quot;": "\"",
"&copy;": "",
"&apos;": "'",
// Add more
};

export const decodeHtml = function(s){
export const decodeHtml = function (s) {
s = (s != undefined) ? s : this.toString();
return (typeof s != "string") ? s :
s.replace(REGX_HTML_DECODE,
function($0, $1){
function ($0, $1) {
var c = HTML_DECODE[$0];
if(c == undefined){
if (c == undefined) {
// Maybe is Entity Number
if(!isNaN($1)){
c = String.fromCharCode(($1 == 160) ? 32:$1);
}else{
if (!isNaN($1)) {
c = String.fromCharCode(($1 == 160) ? 32 : $1);
} else {
c = $0;
}
}
Expand Down

0 comments on commit 8ff1343

Please sign in to comment.