Skip to content
This repository has been archived by the owner on Mar 28, 2024. It is now read-only.

Commit

Permalink
fix(bug): bug
Browse files Browse the repository at this point in the history
  • Loading branch information
jerry-f committed Dec 25, 2020
1 parent 94022a4 commit deb3a96
Showing 1 changed file with 164 additions and 154 deletions.
318 changes: 164 additions & 154 deletions src/global/getRowlen.js
Original file line number Diff line number Diff line change
Expand Up @@ -893,187 +893,156 @@ function getCellTextInfo(cell , ctx, option){
}
else{
value = value.toString();
let splitValue = value.replace(/\r\n/g, "_x000D_").replace(/
/g, "_x000D_").replace(/\r/g, "_x000D_").replace(/\n/g, "_x000D_");
let splitArr = splitValue.split("_x000D_");
for(let x=0, len=splitArr.length;x<len;x++){
value = splitArr[x];
anchor = 0;
preStr = undefined;
preTextHeight = undefined;
preTextWidth = undefined;
preMeasureText = undefined;
i=1;
spaceOrTwoByte=null;
while(i <= value.length){
let str = value.substring(anchor, i);
let measureText = getMeasureText(str, ctx);
let textWidth = measureText.width;
let textHeight = measureText.actualBoundingBoxAscent+measureText.actualBoundingBoxDescent;

let width = textWidth * Math.cos(rt*Math.PI/180) + textHeight * Math.sin(rt*Math.PI/180);//consider text box wdith and line height

let height = textWidth * Math.sin(rt*Math.PI/180) + textHeight * Math.cos(rt*Math.PI/180);//consider text box wdith and line height
let lastWord = str.substr(str.length-1,1);
if(lastWord==" " || checkWordByteLength(lastWord)==2){
if(preMeasureText!=null){
spaceOrTwoByte = {
index:i,
str:preStr,
width:preTextWidth,
height:preTextHeight,
asc:preMeasureText.actualBoundingBoxAscent,
desc:preMeasureText.actualBoundingBoxDescent,
};
}

}
// textW_all += textW;
// console.log(str,anchor,i);
if(rt!=0){//rotate
// console.log("all",anchor, i , str);
if((height+space_height)>cellHeight && text_all_split[splitIndex]!=null && i!= value.length){
// console.log("cut",anchor, i , str);

if(spaceOrTwoByte!=null && spaceOrTwoByte.index<i){

anchor = spaceOrTwoByte.index;
while(i <= value.length){
let str = value.substring(anchor, i);
let measureText = getMeasureText(str, ctx);
let textWidth = measureText.width;
let textHeight = measureText.actualBoundingBoxAscent+measureText.actualBoundingBoxDescent;

i = spaceOrTwoByte.index + 1;
let width = textWidth * Math.cos(rt*Math.PI/180) + textHeight * Math.sin(rt*Math.PI/180);//consider text box wdith and line height

text_all_split[splitIndex].push({
content:spaceOrTwoByte.str,
style:fontset,
width:spaceOrTwoByte.width,
height:spaceOrTwoByte.height,
left:0,
top:0,
splitIndex:splitIndex,
asc:spaceOrTwoByte.asc,
desc:spaceOrTwoByte.desc,
fs:fontSize,
});
let height = textWidth * Math.sin(rt*Math.PI/180) + textHeight * Math.cos(rt*Math.PI/180);//consider text box wdith and line height
let lastWord = str.substr(str.length-1,1);
let isSpace = false;
if(checkWordByteLength(lastWord)===1 && lastWord !== ' ' && !/^.$/.test(lastWord) && !/^.$/u.test(lastWord)) {
isSpace = lastWord.replace(/\r\n/g, "_x000D_").replace(/&#13;&#10;/g, "_x000D_").replace(/\r/g, "_x000D_").replace(/\n/g, "_x000D_") === '_x000D_';
}
if(lastWord==" " || checkWordByteLength(lastWord)==2){
if(preMeasureText!=null){
spaceOrTwoByte = {
index:i,
str:preStr,
width:preTextWidth,
height:preTextHeight,
asc:preMeasureText.actualBoundingBoxAscent,
desc:preMeasureText.actualBoundingBoxDescent,
};
}

// console.log(1,anchor,i,splitIndex , spaceOrTwoByte.str);
}
// textW_all += textW;
// console.log(str,anchor,i);
if(rt!=0){//rotate
// console.log("all",anchor, i , str);
if((height+space_height)>cellHeight && text_all_split[splitIndex]!=null && i!= value.length){
// console.log("cut",anchor, i , str);

splitIndex +=1;
if(spaceOrTwoByte!=null && spaceOrTwoByte.index<i){

spaceOrTwoByte = null;
anchor = spaceOrTwoByte.index;

i = spaceOrTwoByte.index + 1;

text_all_split[splitIndex].push({
content:spaceOrTwoByte.str,
style:fontset,
width:spaceOrTwoByte.width,
height:spaceOrTwoByte.height,
left:0,
top:0,
splitIndex:splitIndex,
asc:spaceOrTwoByte.asc,
desc:spaceOrTwoByte.desc,
fs:fontSize,
});

}
else{
anchor = i-1;
// console.log(1,anchor,i,splitIndex , spaceOrTwoByte.str);

text_all_split[splitIndex].push({
content:preStr,
style:fontset,
left:0,
top:0,
splitIndex:splitIndex,
height:preTextHeight,
width:preTextWidth,
asc:measureText.actualBoundingBoxAscent,
desc:measureText.actualBoundingBoxDescent,
fs:fontSize,
});
splitIndex +=1;

// console.log(2,anchor,i, splitIndex, preStr);
spaceOrTwoByte = null;

splitIndex +=1;


}
}
else if(i== value.length){
// console.log("last",anchor, i , str);
if(text_all_split[splitIndex]==null){
text_all_split[splitIndex]= [];
}
else{
anchor = i-1;

text_all_split[splitIndex].push({
content:str,
content:preStr,
style:fontset,
left:0,
top:0,
splitIndex:splitIndex,
height:textHeight,
width:textWidth,
height:preTextHeight,
width:preTextWidth,
asc:measureText.actualBoundingBoxAscent,
desc:measureText.actualBoundingBoxDescent,
fs:fontSize,
});
break;
}
else{
if(text_all_split[splitIndex]==null){
text_all_split[splitIndex]= [];
}
i++;
}
}
else{//plain
if((width+space_width)>cellWidth && text_all_split[splitIndex]!=null && i!= value.length){
// console.log(spaceOrTwoByte, i, anchor);
if(spaceOrTwoByte!=null && spaceOrTwoByte.index<i){

anchor = spaceOrTwoByte.index;
// console.log(2,anchor,i, splitIndex, preStr);

i = spaceOrTwoByte.index + 1;
splitIndex +=1;

text_all_split[splitIndex].push({
content:spaceOrTwoByte.str,
style:fontset,
width:spaceOrTwoByte.width,
height:spaceOrTwoByte.height,
left:0,
top:0,
splitIndex:splitIndex,
asc:spaceOrTwoByte.asc,
desc:spaceOrTwoByte.desc,
fs:fontSize,
});

splitIndex +=1;
}
}
else if(i== value.length){
// console.log("last",anchor, i , str);
if(text_all_split[splitIndex]==null){
text_all_split[splitIndex]= [];
}
text_all_split[splitIndex].push({
content:str,
style:fontset,
left:0,
top:0,
splitIndex:splitIndex,
height:textHeight,
width:textWidth,
asc:measureText.actualBoundingBoxAscent,
desc:measureText.actualBoundingBoxDescent,
fs:fontSize,
});
break;
}
else{
if(text_all_split[splitIndex]==null){
text_all_split[splitIndex]= [];
}
i++;
}
}
else{//plain
if((width+space_width)>cellWidth && text_all_split[splitIndex]!=null && i!= value.length){
// console.log(spaceOrTwoByte, i, anchor);
if(spaceOrTwoByte!=null && spaceOrTwoByte.index<i){

spaceOrTwoByte = null;
anchor = spaceOrTwoByte.index;

i = spaceOrTwoByte.index + 1;

text_all_split[splitIndex].push({
content:spaceOrTwoByte.str,
style:fontset,
width:spaceOrTwoByte.width,
height:spaceOrTwoByte.height,
left:0,
top:0,
splitIndex:splitIndex,
asc:spaceOrTwoByte.asc,
desc:spaceOrTwoByte.desc,
fs:fontSize,
});

}
else{
splitIndex +=1;

spaceOrTwoByte = null;
anchor = i-1;
spaceOrTwoByte = null;

text_all_split[splitIndex].push({
content:preStr,
style:fontset,
width:preTextWidth,
height:preTextHeight,
left:0,
top:0,
splitIndex:splitIndex,
asc:measureText.actualBoundingBoxAscent,
desc:measureText.actualBoundingBoxDescent,
fs:fontSize,
});

// console.log(2);

}
else{

spaceOrTwoByte = null;
anchor = i-1;

splitIndex +=1;
}
}
else if(i== value.length){
if(text_all_split[splitIndex]==null){
text_all_split[splitIndex]= [];
}
text_all_split[splitIndex].push({
content:str,
content:preStr,
style:fontset,
width:textWidth,
height:textHeight,
width:preTextWidth,
height:preTextHeight,
left:0,
top:0,
splitIndex:splitIndex,
Expand All @@ -1082,23 +1051,64 @@ function getCellTextInfo(cell , ctx, option){
fs:fontSize,
});

break;
}
else{
if(text_all_split[splitIndex]==null){
text_all_split[splitIndex]= [];
}
i++;
// console.log(2);



splitIndex +=1;
}
}
else if(isSpace && text_all_split[splitIndex]!=null && i!= value.length) {

preStr = str;
preTextHeight = textHeight;
preTextWidth = textWidth;
preMeasureText = measureText;
spaceOrTwoByte = null;
anchor = i;

text_all_split[splitIndex].push({
content:str,
style:fontset,
width:preTextWidth,
height:preTextHeight,
left:0,
top:0,
splitIndex:splitIndex,
asc:measureText.actualBoundingBoxAscent,
desc:measureText.actualBoundingBoxDescent,
fs:fontSize,
});
splitIndex +=1;
}
else if(i== value.length){
if(text_all_split[splitIndex]==null){
text_all_split[splitIndex]= [];
}
text_all_split[splitIndex].push({
content:str,
style:fontset,
width:textWidth,
height:textHeight,
left:0,
top:0,
splitIndex:splitIndex,
asc:measureText.actualBoundingBoxAscent,
desc:measureText.actualBoundingBoxDescent,
fs:fontSize,
});

break;
}
else{
if(text_all_split[splitIndex]==null){
text_all_split[splitIndex]= [];
}
i++;
}
}
splitIndex +=1;

preStr = str;
preTextHeight = textHeight;
preTextWidth = textWidth;
preMeasureText = measureText;

}

// console.log(text_all_split)
Expand Down

0 comments on commit deb3a96

Please sign in to comment.