Browse Source

fix(bug): 文本自动换行bug

master
break-wave 5 years ago
parent
commit
bc926e5c49
  1. 231
      src/global/getRowlen.js

231
src/global/getRowlen.js

@ -19,7 +19,7 @@ function rowlenByRange(d, r1, r2, cfg) {
let canvas = $("#luckysheetTableContent").get(0).getContext("2d"); let canvas = $("#luckysheetTableContent").get(0).getContext("2d");
canvas.textBaseline = 'top'; //textBaseline以top计算 canvas.textBaseline = 'top'; //textBaseline以top计算
for(let r = r1; r <= r2; r++){ for(let r = r1; r <= r2; r++){
if (cfg_clone["rowhidden"] != null && cfg_clone["rowhidden"][r] != null) { if (cfg_clone["rowhidden"] != null && cfg_clone["rowhidden"][r] != null) {
continue; continue;
@ -50,7 +50,7 @@ function rowlenByRange(d, r1, r2, cfg) {
}); });
let computeRowlen = 0; let computeRowlen = 0;
if(textInfo!=null){ if(textInfo!=null){
computeRowlen = textInfo.textHeightAll+2; computeRowlen = textInfo.textHeightAll+2;
} }
@ -63,7 +63,7 @@ function rowlenByRange(d, r1, r2, cfg) {
} }
currentRowLen = currentRowLen/Store.zoomRatio; currentRowLen = currentRowLen/Store.zoomRatio;
if(currentRowLen != Store.defaultrowlen){ if(currentRowLen != Store.defaultrowlen){
cfg_clone["rowlen"][r] = currentRowLen; cfg_clone["rowlen"][r] = currentRowLen;
} }
@ -79,7 +79,7 @@ function computeRowlenArr(rowHeight, cfg) {
for (let i = 0; i < rowHeight; i++) { for (let i = 0; i < rowHeight; i++) {
let rowlen = Store.defaultrowlen; let rowlen = Store.defaultrowlen;
if (cfg["rowlen"] != null && cfg["rowlen"][i] != null) { if (cfg["rowlen"] != null && cfg["rowlen"][i] != null) {
rowlen = cfg["rowlen"][i]; rowlen = cfg["rowlen"][i];
} }
@ -92,7 +92,7 @@ function computeRowlenArr(rowHeight, cfg) {
else { else {
rh_height += rowlen + 1; rh_height += rowlen + 1;
} }
rowlenArr.push(rh_height);//行的临时长度分布 rowlenArr.push(rh_height);//行的临时长度分布
} }
@ -147,7 +147,7 @@ function getMeasureText(value, ctx, fontset){
// cache.width = measureText.width; // cache.width = measureText.width;
// } // }
// else{ // else{
// //measureText.actualBoundingBoxLeft + // //measureText.actualBoundingBoxLeft +
// cache.width = measureText.actualBoundingBoxRight; // cache.width = measureText.actualBoundingBoxRight;
// } // }
@ -317,7 +317,7 @@ function getCellTextInfo(cell , ctx, option){
let splitArr = v.split("_x000D_"), preNewValue=null; let splitArr = v.split("_x000D_"), preNewValue=null;
for(let x=0;x<splitArr.length;x++){ for(let x=0;x<splitArr.length;x++){
let newValue = splitArr[x]; let newValue = splitArr[x];
if(newValue=="" && x!=splitArr.length-1){ if(newValue=="" && x!=splitArr.length-1){
inlineStringArr.push({ inlineStringArr.push({
fontset:scfontset, fontset:scfontset,
@ -343,7 +343,7 @@ function getCellTextInfo(cell , ctx, option){
si:similarIndex, si:similarIndex,
fs:fs==null?11:fs, fs:fs==null?11:fs,
}); });
} }
if(x!=splitArr.length-1 && preNewValue!="" ){ if(x!=splitArr.length-1 && preNewValue!="" ){
@ -356,15 +356,15 @@ function getCellTextInfo(cell , ctx, option){
fs:fs==null?11:fs, fs:fs==null?11:fs,
}); });
similarIndex++; similarIndex++;
} }
} }
preNewValue = newValue; preNewValue = newValue;
} }
similarIndex++; similarIndex++;
} }
isInline = true; isInline = true;
} }
@ -375,7 +375,7 @@ function getCellTextInfo(cell , ctx, option){
cancelLine = checkstatusByCell(cell ,"cl");//cancelLine cancelLine = checkstatusByCell(cell ,"cl");//cancelLine
underLine = checkstatusByCell(cell ,"un");//underLine underLine = checkstatusByCell(cell ,"un");//underLine
fontSize = checkstatusByCell(cell ,"fs"); fontSize = checkstatusByCell(cell ,"fs");
if(cell instanceof Object){ if(cell instanceof Object){
value = cell.m; value = cell.m;
if(value == null){ if(value == null){
@ -385,16 +385,16 @@ function getCellTextInfo(cell , ctx, option){
else{ else{
value = cell; value = cell;
} }
if(isRealNull(value)){ if(isRealNull(value)){
return null; return null;
} }
} }
// let measureText = getMeasureText(value, ctx);
// let measureText = getMeasureText(value, ctx);
// //luckysheetTableContent.measureText(value); // //luckysheetTableContent.measureText(value);
// let textWidth = measureText.width; // let textWidth = measureText.width;
// let textHeight = measureText.actualBoundingBoxDescent + measureText.actualBoundingBoxAscent; // let textHeight = measureText.actualBoundingBoxDescent + measureText.actualBoundingBoxAscent;
@ -404,7 +404,7 @@ function getCellTextInfo(cell , ctx, option){
let textW_all = 0; //拆分后宽高度合计 let textW_all = 0; //拆分后宽高度合计
let textH_all = 0; let textH_all = 0;
let colIndex=0, textH_all_cache=0, textH_all_Column = {}, textH_all_ColumnHeight=[]; let colIndex=0, textH_all_cache=0, textH_all_Column = {}, textH_all_ColumnHeight=[];
if(isInline){ if(isInline){
let preShareCell = null; let preShareCell = null;
@ -414,8 +414,8 @@ function getCellTextInfo(cell , ctx, option){
if(shareCell.wrap===true){ if(shareCell.wrap===true){
value = "M"; value = "M";
showValue = ""; showValue = "";
if( preShareCell!=null && preShareCell.wrap!==true && (i<inlineStringArr.length-1)){ if( preShareCell!=null && preShareCell.wrap!==true && (i<inlineStringArr.length-1)){
// console.log("wrap",i,colIndex,preShareCell.wrap); // console.log("wrap",i,colIndex,preShareCell.wrap);
textH_all_ColumnHeight.push(textH_all_cache); textH_all_ColumnHeight.push(textH_all_cache);
@ -431,11 +431,11 @@ function getCellTextInfo(cell , ctx, option){
let textW = measureText.width + space_width; let textW = measureText.width + space_width;
let textH = measureText.actualBoundingBoxAscent + measureText.actualBoundingBoxDescent + space_height; let textH = measureText.actualBoundingBoxAscent + measureText.actualBoundingBoxDescent + space_height;
// textW_all += textW; // textW_all += textW;
textH_all_cache += textH; textH_all_cache += textH;
if(tb=="2" && !shareCell.wrap){ if(tb=="2" && !shareCell.wrap){
if(textH_all_cache>cellHeight && textH_all_Column[colIndex]!=null){ if(textH_all_cache>cellHeight && textH_all_Column[colIndex]!=null){
// textW_all += textW; // textW_all += textW;
@ -446,11 +446,11 @@ function getCellTextInfo(cell , ctx, option){
colIndex +=1; colIndex +=1;
} }
} }
if(i== inlineStringArr.length-1){ if(i== inlineStringArr.length-1){
textH_all_ColumnHeight.push(textH_all_cache); textH_all_ColumnHeight.push(textH_all_cache);
} }
if(textH_all_Column[colIndex]==null){ if(textH_all_Column[colIndex]==null){
textH_all_Column[colIndex]= []; textH_all_Column[colIndex]= [];
} }
@ -471,36 +471,36 @@ function getCellTextInfo(cell , ctx, option){
if(shareCell.wrap===true){ if(shareCell.wrap===true){
item.wrap=true; item.wrap=true;
} }
textH_all_Column[colIndex].push(item); textH_all_Column[colIndex].push(item);
console.log("normal",i,colIndex,shareCell, preShareCell, textH_all_Column); console.log("normal",i,colIndex,shareCell, preShareCell, textH_all_Column);
preShareCell = shareCell; preShareCell = shareCell;
} }
} }
else{ else{
let measureText = getMeasureText(value, ctx); let measureText = getMeasureText(value, ctx);
let textHeight = measureText.actualBoundingBoxDescent + measureText.actualBoundingBoxAscent; let textHeight = measureText.actualBoundingBoxDescent + measureText.actualBoundingBoxAscent;
value = value.toString(); value = value.toString();
let vArr = []; let vArr = [];
if(value.length > 1){ if(value.length > 1){
vArr = value.split(""); vArr = value.split("");
} }
else{ else{
vArr.push(value); vArr.push(value);
} }
let oneWordWidth = getMeasureText(vArr[0], ctx).width; let oneWordWidth = getMeasureText(vArr[0], ctx).width;
for(let i = 0; i < vArr.length; i++){ for(let i = 0; i < vArr.length; i++){
let textW = oneWordWidth + space_width; let textW = oneWordWidth + space_width;
let textH = textHeight + space_height; let textH = textHeight + space_height;
// textW_all += textW; // textW_all += textW;
textH_all_cache += textH; textH_all_cache += textH;
if(tb=="2"){ if(tb=="2"){
if(textH_all_cache>cellHeight && textH_all_Column[colIndex]!=null){ if(textH_all_cache>cellHeight && textH_all_Column[colIndex]!=null){
// textW_all += textW; // textW_all += textW;
@ -510,15 +510,15 @@ function getCellTextInfo(cell , ctx, option){
colIndex +=1; colIndex +=1;
} }
} }
if(i== vArr.length-1){ if(i== vArr.length-1){
textH_all_ColumnHeight.push(textH_all_cache); textH_all_ColumnHeight.push(textH_all_cache);
} }
if(textH_all_Column[colIndex]==null){ if(textH_all_Column[colIndex]==null){
textH_all_Column[colIndex]= []; textH_all_Column[colIndex]= [];
} }
textH_all_Column[colIndex].push({ textH_all_Column[colIndex].push({
content:vArr[i], content:vArr[i],
style:fontset, style:fontset,
@ -530,7 +530,7 @@ function getCellTextInfo(cell , ctx, option){
asc:measureText.actualBoundingBoxAscent, asc:measureText.actualBoundingBoxAscent,
desc:measureText.actualBoundingBoxDescent desc:measureText.actualBoundingBoxDescent
}); });
} }
} }
@ -555,7 +555,7 @@ function getCellTextInfo(cell , ctx, option){
// console.log("verticalWrap", textContent,cell, option); // console.log("verticalWrap", textContent,cell, option);
return textContent; return textContent;
} }
let cumColumnWidth = 0; let cumColumnWidth = 0;
for(let i = 0; i < textH_all_ColumnHeight.length; i++){ for(let i = 0; i < textH_all_ColumnHeight.length; i++){
let columnHeight = textH_all_ColumnHeight[i]; let columnHeight = textH_all_ColumnHeight[i];
@ -565,7 +565,7 @@ function getCellTextInfo(cell , ctx, option){
let cumWordHeight = 0; let cumWordHeight = 0;
for(let c=0;c<col.length;c++){ for(let c=0;c<col.length;c++){
let word = col[c]; let word = col[c];
let left = space_width + cumColumnWidth; let left = space_width + cumColumnWidth;
if(horizonAlign == "0"){ if(horizonAlign == "0"){
left = cellWidth / 2 + cumColumnWidth - textW_all/2 + space_width*textH_all_ColumnHeight.length; left = cellWidth / 2 + cumColumnWidth - textW_all/2 + space_width*textH_all_ColumnHeight.length;
@ -588,8 +588,8 @@ function getCellTextInfo(cell , ctx, option){
word.top = top; word.top = top;
drawLineInfo(word, cancelLine, underLine,{ drawLineInfo(word, cancelLine, underLine,{
width:columnWidth, width:columnWidth,
height:word.height, height:word.height,
left:left, left:left,
top:top+word.height-space_height, top:top+word.height-space_height,
asc:word.height, asc:word.height,
@ -616,7 +616,7 @@ function getCellTextInfo(cell , ctx, option){
if(tb=="2" || isInline){//wrap if(tb=="2" || isInline){//wrap
let textW_all = 0; //拆分后宽高度合计 let textW_all = 0; //拆分后宽高度合计
let textH_all = 0; let textH_all = 0;
let textW_all_inner = 0; let textW_all_inner = 0;
// let oneWordWidth = getMeasureText(vArr[0], ctx).width; // let oneWordWidth = getMeasureText(vArr[0], ctx).width;
@ -632,7 +632,7 @@ function getCellTextInfo(cell , ctx, option){
if(shareCells[shareCells.length-1].wrap===true){ if(shareCells[shareCells.length-1].wrap===true){
anchor = i; anchor = i;
if(shareCells.length>1){ if(shareCells.length>1){
for(let s=0;s<shareCells.length-1;s++){ for(let s=0;s<shareCells.length-1;s++){
let sc = shareCells[s]; let sc = shareCells[s];
@ -649,13 +649,13 @@ function getCellTextInfo(cell , ctx, option){
inline:true, inline:true,
fs:sc.fs fs:sc.fs
} }
// if(rt!=0){//rotate // if(rt!=0){//rotate
// item.textHeight = sc.textHeight; // item.textHeight = sc.textHeight;
// item.textWidth = sc.textWidth; // item.textWidth = sc.textWidth;
// } // }
text_all_split[splitIndex].push(item); text_all_split[splitIndex].push(item);
} }
} }
@ -700,11 +700,11 @@ function getCellTextInfo(cell , ctx, option){
textHeight = Math.max(sc.measureText.actualBoundingBoxAscent+sc.measureText.actualBoundingBoxDescent); textHeight = Math.max(sc.measureText.actualBoundingBoxAscent+sc.measureText.actualBoundingBoxDescent);
// console.log(sc.v,sc.measureText.width,sc.measureText.actualBoundingBoxAscent,sc.measureText.actualBoundingBoxDescent); // console.log(sc.v,sc.measureText.width,sc.measureText.actualBoundingBoxAscent,sc.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 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 height = textWidth * Math.sin(rt*Math.PI/180) + textHeight * Math.cos(rt*Math.PI/180);//consider text box wdith and line height
// textW_all += textW; // textW_all += textW;
@ -713,7 +713,7 @@ function getCellTextInfo(cell , ctx, option){
spaceOrTwoByteIndex = i; spaceOrTwoByteIndex = i;
} }
if(rt!=0){//rotate if(rt!=0){//rotate
// console.log("all",anchor, i , str); // console.log("all",anchor, i , str);
console.log(height,space_height, cellHeight, shareCells,(height+space_height)>cellHeight); console.log(height,space_height, cellHeight, shareCells,(height+space_height)>cellHeight);
@ -721,7 +721,7 @@ function getCellTextInfo(cell , ctx, option){
// console.log("cut",anchor, i , str); // console.log("cut",anchor, i , str);
if(spaceOrTwoByteIndex!=null && spaceOrTwoByteIndex<i){ if(spaceOrTwoByteIndex!=null && spaceOrTwoByteIndex<i){
for(let s=0;s<spaceOrTwoByteIndex-anchor;s++){ for(let s=0;s<spaceOrTwoByteIndex-anchor;s++){
let sc = shareCells[s]; let sc = shareCells[s];
text_all_split[splitIndex].push({ text_all_split[splitIndex].push({
@ -745,12 +745,12 @@ function getCellTextInfo(cell , ctx, option){
splitIndex +=1; splitIndex +=1;
spaceOrTwoByteIndex = null; spaceOrTwoByteIndex = null;
} }
else{ else{
anchor = i-1; anchor = i-1;
for(let s=0;s<shareCells.length-1;s++){ for(let s=0;s<shareCells.length-1;s++){
let sc = shareCells[s]; let sc = shareCells[s];
text_all_split[splitIndex].push({ text_all_split[splitIndex].push({
@ -767,7 +767,7 @@ function getCellTextInfo(cell , ctx, option){
fs:sc.fs fs:sc.fs
}); });
} }
splitIndex +=1; splitIndex +=1;
} }
@ -804,10 +804,10 @@ function getCellTextInfo(cell , ctx, option){
} }
else{//plain else{//plain
if((width+space_width)>cellWidth && text_all_split[splitIndex]!=null && tb=="2" && i!= inlineStringArr.length){ if((width+space_width)>cellWidth && text_all_split[splitIndex]!=null && tb=="2" && i!= inlineStringArr.length){
if(spaceOrTwoByteIndex!=null && spaceOrTwoByteIndex<i){ if(spaceOrTwoByteIndex!=null && spaceOrTwoByteIndex<i){
for(let s=0;s<spaceOrTwoByteIndex-anchor;s++){ for(let s=0;s<spaceOrTwoByteIndex-anchor;s++){
let sc = shareCells[s]; let sc = shareCells[s];
text_all_split[splitIndex].push({ text_all_split[splitIndex].push({
@ -831,11 +831,11 @@ function getCellTextInfo(cell , ctx, option){
splitIndex +=1; splitIndex +=1;
spaceOrTwoByteIndex = null; spaceOrTwoByteIndex = null;
} }
else{ else{
anchor = i-1; anchor = i-1;
for(let s=0;s<shareCells.length-1;s++){ for(let s=0;s<shareCells.length-1;s++){
let sc = shareCells[s]; let sc = shareCells[s];
text_all_split[splitIndex].push({ text_all_split[splitIndex].push({
@ -852,7 +852,7 @@ function getCellTextInfo(cell , ctx, option){
fs:sc.fs fs:sc.fs
}); });
} }
splitIndex +=1; splitIndex +=1;
} }
@ -878,7 +878,7 @@ function getCellTextInfo(cell , ctx, option){
fs:sc.fs fs:sc.fs
}); });
} }
break; break;
} }
else{ else{
@ -898,11 +898,13 @@ function getCellTextInfo(cell , ctx, option){
let measureText = getMeasureText(str, ctx); let measureText = getMeasureText(str, ctx);
let textWidth = measureText.width; let textWidth = measureText.width;
let textHeight = measureText.actualBoundingBoxAscent+measureText.actualBoundingBoxDescent; 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 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 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 lastWord = str.substr(str.length-1,1);
let isSpace = lastWord.replace(/\r\n/g, "_x000D_").replace(/&#13;&#10;/g, "_x000D_").replace(/\r/g, "_x000D_").replace(/\n/g, "_x000D_");
isSpace = isSpace === '_x000D_'
if(lastWord==" " || checkWordByteLength(lastWord)==2){ if(lastWord==" " || checkWordByteLength(lastWord)==2){
if(preMeasureText!=null){ if(preMeasureText!=null){
spaceOrTwoByte = { spaceOrTwoByte = {
@ -924,11 +926,11 @@ function getCellTextInfo(cell , ctx, option){
// console.log("cut",anchor, i , str); // console.log("cut",anchor, i , str);
if(spaceOrTwoByte!=null && spaceOrTwoByte.index<i){ if(spaceOrTwoByte!=null && spaceOrTwoByte.index<i){
anchor = spaceOrTwoByte.index; anchor = spaceOrTwoByte.index;
i = spaceOrTwoByte.index + 1; i = spaceOrTwoByte.index + 1;
text_all_split[splitIndex].push({ text_all_split[splitIndex].push({
content:spaceOrTwoByte.str, content:spaceOrTwoByte.str,
style:fontset, style:fontset,
@ -945,15 +947,15 @@ function getCellTextInfo(cell , ctx, option){
// console.log(1,anchor,i,splitIndex , spaceOrTwoByte.str); // console.log(1,anchor,i,splitIndex , spaceOrTwoByte.str);
splitIndex +=1; splitIndex +=1;
spaceOrTwoByte = null; spaceOrTwoByte = null;
} }
else{ else{
anchor = i-1; anchor = i-1;
text_all_split[splitIndex].push({ text_all_split[splitIndex].push({
content:preStr, content:preStr,
style:fontset, style:fontset,
@ -968,10 +970,10 @@ function getCellTextInfo(cell , ctx, option){
}); });
// console.log(2,anchor,i, splitIndex, preStr); // console.log(2,anchor,i, splitIndex, preStr);
splitIndex +=1; splitIndex +=1;
} }
} }
else if(i== value.length){ else if(i== value.length){
@ -1004,11 +1006,11 @@ function getCellTextInfo(cell , ctx, option){
if((width+space_width)>cellWidth && text_all_split[splitIndex]!=null && i!= value.length){ if((width+space_width)>cellWidth && text_all_split[splitIndex]!=null && i!= value.length){
// console.log(spaceOrTwoByte, i, anchor); // console.log(spaceOrTwoByte, i, anchor);
if(spaceOrTwoByte!=null && spaceOrTwoByte.index<i){ if(spaceOrTwoByte!=null && spaceOrTwoByte.index<i){
anchor = spaceOrTwoByte.index; anchor = spaceOrTwoByte.index;
i = spaceOrTwoByte.index + 1; i = spaceOrTwoByte.index + 1;
text_all_split[splitIndex].push({ text_all_split[splitIndex].push({
content:spaceOrTwoByte.str, content:spaceOrTwoByte.str,
style:fontset, style:fontset,
@ -1026,14 +1028,14 @@ function getCellTextInfo(cell , ctx, option){
spaceOrTwoByte = null; spaceOrTwoByte = null;
} }
else{ else{
spaceOrTwoByte = null; spaceOrTwoByte = null;
anchor = i-1; anchor = i-1;
text_all_split[splitIndex].push({ text_all_split[splitIndex].push({
content:preStr, content:preStr,
style:fontset, style:fontset,
@ -1049,11 +1051,30 @@ function getCellTextInfo(cell , ctx, option){
// console.log(2); // console.log(2);
splitIndex +=1; splitIndex +=1;
} }
} }
else if(isSpace && text_all_split[splitIndex]!=null && i!= value.length) {
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){ else if(i== value.length){
if(text_all_split[splitIndex]==null){ if(text_all_split[splitIndex]==null){
text_all_split[splitIndex]= []; text_all_split[splitIndex]= [];
@ -1070,7 +1091,7 @@ function getCellTextInfo(cell , ctx, option){
desc:measureText.actualBoundingBoxDescent, desc:measureText.actualBoundingBoxDescent,
fs:fontSize, fs:fontSize,
}); });
break; break;
} }
else{ else{
@ -1080,12 +1101,12 @@ function getCellTextInfo(cell , ctx, option){
i++; i++;
} }
} }
preStr = str; preStr = str;
preTextHeight = textHeight; preTextHeight = textHeight;
preTextWidth = textWidth; preTextWidth = textWidth;
preMeasureText = measureText; preMeasureText = measureText;
} }
// console.log(text_all_split) // console.log(text_all_split)
@ -1143,8 +1164,8 @@ function getCellTextInfo(cell , ctx, option){
// console.log(textH_all,textW_all,textW_all_inner); // console.log(textH_all,textW_all,textW_all_inner);
// let cumColumnWidth = 0; // let cumColumnWidth = 0;
let cumWordHeight = 0,cumColumnWidth = 0; let cumWordHeight = 0,cumColumnWidth = 0;
let rtPI = rt*Math.PI/180; let rtPI = rt*Math.PI/180;
let lastLine = split_all_size[splitLen-1]; let lastLine = split_all_size[splitLen-1];
let lastLineSpaceHeight = lastLine.lineHeight; let lastLineSpaceHeight = lastLine.lineHeight;
textH_all = textH_all - lastLineSpaceHeight + lastLine.desc; textH_all = textH_all - lastLineSpaceHeight + lastLine.desc;
let rw = (textH_all)/Math.sin(rtPI) + textW_all_inner*Math.cos(rtPI); let rw = (textH_all)/Math.sin(rtPI) + textW_all_inner*Math.cos(rtPI);
@ -1181,7 +1202,7 @@ function getCellTextInfo(cell , ctx, option){
let size = split_all_size[i]; let size = split_all_size[i];
cumColumnWidth = 0; cumColumnWidth = 0;
for(let c=splitLists.length-1;c>=0;c--){ for(let c=splitLists.length-1;c>=0;c--){
let wordGroup = splitLists[c]; let wordGroup = splitLists[c];
let left, top; let left, top;
@ -1192,7 +1213,7 @@ function getCellTextInfo(cell , ctx, option){
if(horizonAlign == "0"){//center if(horizonAlign == "0"){//center
let sh = textH_all/Math.sin(rtPI); let sh = textH_all/Math.sin(rtPI);
if(verticalAlign == "0"){//mid if(verticalAlign == "0"){//mid
left = x + cellWidth/2 - (textW_all/2) + lastLineSpaceHeight*Math.cos(rtPI)/2; left = x + cellWidth/2 - (textW_all/2) + lastLineSpaceHeight*Math.cos(rtPI)/2;
top = y + cellHeight/2 - textH_all/2 - lastLineSpaceHeight*Math.cos(rtPI)/2; top = y + cellHeight/2 - textH_all/2 - lastLineSpaceHeight*Math.cos(rtPI)/2;
} }
@ -1233,17 +1254,17 @@ function getCellTextInfo(cell , ctx, option){
top = y + cellHeight - rw*Math.sin(rtPI) - lastLineSpaceHeight*Math.cos(rtPI); top = y + cellHeight - rw*Math.sin(rtPI) - lastLineSpaceHeight*Math.cos(rtPI);
} }
} }
} }
wordGroup.left = left; wordGroup.left = left;
wordGroup.top = top; wordGroup.top = top;
// console.log(left, top, cumWordHeight, size.height); // console.log(left, top, cumWordHeight, size.height);
drawLineInfo(wordGroup, cancelLine, underLine,{ drawLineInfo(wordGroup, cancelLine, underLine,{
width:wordGroup.width, width:wordGroup.width,
height:wordGroup.height, height:wordGroup.height,
left:left-wordGroup.width, left:left-wordGroup.width,
top:top, top:top,
asc:size.asc, asc:size.asc,
@ -1271,7 +1292,7 @@ function getCellTextInfo(cell , ctx, option){
let size = split_all_size[i]; let size = split_all_size[i];
cumColumnWidth = 0; cumColumnWidth = 0;
for(let c=0;c<splitLists.length;c++){ for(let c=0;c<splitLists.length;c++){
let wordGroup = splitLists[c]; let wordGroup = splitLists[c];
let left, top; let left, top;
@ -1283,7 +1304,7 @@ function getCellTextInfo(cell , ctx, option){
if(horizonAlign == "0"){//center if(horizonAlign == "0"){//center
let sh = textH_all/Math.sin(rtPI); let sh = textH_all/Math.sin(rtPI);
if(verticalAlign == "0"){//mid if(verticalAlign == "0"){//mid
left = x + cellWidth/2 - (textW_all/2) - lastLineSpaceHeight*Math.cos(rtPI)/2; left = x + cellWidth/2 - (textW_all/2) - lastLineSpaceHeight*Math.cos(rtPI)/2;
top = y + cellHeight/2 - textH_all/2 + lastLineSpaceHeight*Math.cos(rtPI)/2; top = y + cellHeight/2 - textH_all/2 + lastLineSpaceHeight*Math.cos(rtPI)/2;
} }
@ -1326,8 +1347,8 @@ function getCellTextInfo(cell , ctx, option){
} }
drawLineInfo(wordGroup, cancelLine, underLine,{ drawLineInfo(wordGroup, cancelLine, underLine,{
width:wordGroup.width, width:wordGroup.width,
height:wordGroup.height, height:wordGroup.height,
left:left, left:left,
top:top, top:top,
asc:size.asc, asc:size.asc,
@ -1345,7 +1366,7 @@ function getCellTextInfo(cell , ctx, option){
else if(horizonAlign == "2"){ else if(horizonAlign == "2"){
left = cellWidth + cumColumnWidth - size.width; left = cellWidth + cumColumnWidth - size.width;
} }
top = (cellHeight - space_height) + cumWordHeight +size.asc-textH_all; top = (cellHeight - space_height) + cumWordHeight +size.asc-textH_all;
if(verticalAlign == "0"){ if(verticalAlign == "0"){
top = cellHeight / 2 + cumWordHeight - textH_all/2 + size.asc; top = cellHeight / 2 + cumWordHeight - textH_all/2 + size.asc;
@ -1353,12 +1374,12 @@ function getCellTextInfo(cell , ctx, option){
else if(verticalAlign == "1"){ else if(verticalAlign == "1"){
top = space_height + cumWordHeight+ size.asc; top = space_height + cumWordHeight+ size.asc;
} }
drawLineInfo(wordGroup, cancelLine, underLine,{ drawLineInfo(wordGroup, cancelLine, underLine,{
width:wordGroup.width, width:wordGroup.width,
height:wordGroup.height, height:wordGroup.height,
left:left, left:left,
top:top, top:top,
asc:size.asc, asc:size.asc,
@ -1366,7 +1387,7 @@ function getCellTextInfo(cell , ctx, option){
fs:wordGroup.fs fs:wordGroup.fs
}); });
} }
wordGroup.left = left; wordGroup.left = left;
wordGroup.top = top; wordGroup.top = top;
@ -1406,7 +1427,7 @@ function getCellTextInfo(cell , ctx, option){
else if(verticalAlign == "1"){//top else if(verticalAlign == "1"){//top
textContent.textLeftAll = cellWidth/2; textContent.textLeftAll = cellWidth/2;
textContent.textTopAll = rh/2; textContent.textTopAll = rh/2;
} }
else if(verticalAlign == "2"){//bottom else if(verticalAlign == "2"){//bottom
textContent.textLeftAll = cellWidth/2; textContent.textLeftAll = cellWidth/2;
@ -1450,7 +1471,7 @@ function getCellTextInfo(cell , ctx, option){
} }
else{ else{
let measureText = getMeasureText(value, ctx); let measureText = getMeasureText(value, ctx);
let textWidth = measureText.width; let textWidth = measureText.width;
let textHeight = measureText.actualBoundingBoxDescent + measureText.actualBoundingBoxAscent; let textHeight = measureText.actualBoundingBoxDescent + measureText.actualBoundingBoxAscent;
@ -1470,7 +1491,7 @@ function getCellTextInfo(cell , ctx, option){
textContent.textHeightAll = textHeightAll+textHeight/2-measureText.actualBoundingBoxDescent-space_height; textContent.textHeightAll = textHeightAll+textHeight/2-measureText.actualBoundingBoxDescent-space_height;
} }
textContent.textWidthAll = textWidthAll; textContent.textWidthAll = textWidthAll;
// console.log(textContent.textWidthAll , textContent.textHeightAll); // console.log(textContent.textWidthAll , textContent.textHeightAll);
if(isMode=="onlyWidth"){ if(isMode=="onlyWidth"){
// console.log("plain", textContent,cell, option); // console.log("plain", textContent,cell, option);
@ -1486,9 +1507,9 @@ function getCellTextInfo(cell , ctx, option){
else if(horizonAlign == "2"){ //右对齐 else if(horizonAlign == "2"){ //右对齐
left = (cellWidth - space_width) - width + textHeight * Math.sin(rtPI)*isRotateUp; left = (cellWidth - space_width) - width + textHeight * Math.sin(rtPI)*isRotateUp;
} }
let top = (cellHeight - space_height) - height + measureText.actualBoundingBoxAscent * Math.cos(rtPI) + textWidth * Math.sin(rtPI)*isRotateUp; //默认为2,下对齐 let top = (cellHeight - space_height) - height + measureText.actualBoundingBoxAscent * Math.cos(rtPI) + textWidth * Math.sin(rtPI)*isRotateUp; //默认为2,下对齐
if(verticalAlign == "0"){ //居中对齐 if(verticalAlign == "0"){ //居中对齐
top = cellHeight / 2 - (height / 2) + measureText.actualBoundingBoxAscent* Math.cos(rtPI) + textWidth * Math.sin(rtPI)*isRotateUp; top = cellHeight / 2 - (height / 2) + measureText.actualBoundingBoxAscent* Math.cos(rtPI) + textWidth * Math.sin(rtPI)*isRotateUp;
} }
else if(verticalAlign == "1"){ //上对齐 else if(verticalAlign == "1"){ //上对齐
@ -1507,8 +1528,8 @@ function getCellTextInfo(cell , ctx, option){
} }
drawLineInfo(wordGroup, cancelLine, underLine,{ drawLineInfo(wordGroup, cancelLine, underLine,{
width:textWidth, width:textWidth,
height:textHeight, height:textHeight,
left:left, left:left,
top:top, top:top,
asc:measureText.actualBoundingBoxAscent, asc:measureText.actualBoundingBoxAscent,

Loading…
Cancel
Save