diff --git a/src/controllers/menuButton.js b/src/controllers/menuButton.js index e06ab20..56ef056 100644 --- a/src/controllers/menuButton.js +++ b/src/controllers/menuButton.js @@ -3314,7 +3314,7 @@ const menuButton = { }, checkstatusByCell:function(cell, a){ let foucsStatus =cell; - let tf = {"bl":1, "it":1 , "ff":1, "cl":1}; + let tf = {"bl":1, "it":1 , "ff":1, "cl":1, "un":1}; if(a in tf){ if(foucsStatus == null){ diff --git a/src/global/draw.js b/src/global/draw.js index c9507dc..4ea78d3 100644 --- a/src/global/draw.js +++ b/src/global/draw.js @@ -2054,6 +2054,43 @@ function cellTextRender(textInfo, ctx, option){ let word = values[i]; ctx.font = word.style; ctx.fillText(word.content, (pos_x + word.left)/Store.zoomRatio, (pos_y+word.top)/Store.zoomRatio); + + if(word.cancelLine!=null){ + let c = word.cancelLine; + ctx.beginPath(); + ctx.moveTo( + (pos_x +c.startX)/Store.zoomRatio , + (pos_y+c.startY)/Store.zoomRatio + ); + ctx.lineTo( + (pos_x +c.endX)/Store.zoomRatio, + (pos_y+c.endY)/Store.zoomRatio + ); + ctx.lineWidth = 1; + ctx.strokeStyle = ctx.fillStyle; + ctx.stroke(); + ctx.closePath(); + } + + if(word.underLine!=null){ + let underLines = word.underLine; + for(let a=0;a180 || rt<0){ + rt = 0; + } + rt = parseInt(rt); if(rt>90){ rt = 90 -rt; @@ -299,20 +317,22 @@ function getCellTextInfo(cell , ctx, option){ let textContent = {}; textContent.values = []; + let fontset, cancelLine="0", underLine="0", isInline=false, value; if(cell.ct!=null && cell.ct.t=="inlineStr" && cell.ct.sharedStrings!=null && cell.ct.sharedStrings.length>0){ - let strArr = [],lineMaxHeight=[]; - let sharedStrings = cell.ct.sharedStrings; + let strArr = []; + let sharedStrings = cell.ct.s; for(let i=0;i 1){ - vArr = value.split(""); - } - else{ - vArr.push(value); - } + // let measureText = getMeasureText(value, ctx); + // //luckysheetTableContent.measureText(value); + // let textWidth = measureText.width; + // let textHeight = measureText.actualBoundingBoxDescent + measureText.actualBoundingBoxAscent; - let textW_all = 0; //拆分后宽高度合计 - let textH_all = 0; + if(tr=="3"){//vertical text + ctx.textBaseline = 'top'; + let measureText = getMeasureText(value, ctx); + let textHeight = measureText.actualBoundingBoxDescent + measureText.actualBoundingBoxAscent; - let oneWordWidth = getMeasureText(vArr[0], ctx).width; - let colIndex=0, textH_all_cache=0, textH_all_Column = {}, textH_all_ColumnHeight=[]; + value = value.toString(); + + let vArr = []; + if(value.length > 1){ + vArr = value.split(""); + } + else{ + vArr.push(value); + } - for(let i = 0; i < vArr.length; i++){ - let textW = oneWordWidth + space_width; - let textH = textHeight + space_height; - - // textW_all += textW; - textH_all_cache += textH; + let textW_all = 0; //拆分后宽高度合计 + let textH_all = 0; + let oneWordWidth = getMeasureText(vArr[0], ctx).width; + let colIndex=0, textH_all_cache=0, textH_all_Column = {}, textH_all_ColumnHeight=[]; - if(tb=="2"){ - if(textH_all_cache>cellHeight && textH_all_Column[colIndex]!=null){ - // textW_all += textW; - // textH_all = Math.max(textH_all,textH_all_cache); - textH_all_ColumnHeight.push(textH_all_cache-textH); - textH_all_cache = textH; - colIndex +=1; - } - } + for(let i = 0; i < vArr.length; i++){ + let textW = oneWordWidth + space_width; + let textH = textHeight + space_height; + + // textW_all += textW; + textH_all_cache += textH; - if(i== vArr.length-1){ - textH_all_ColumnHeight.push(textH_all_cache); - } - if(textH_all_Column[colIndex]==null){ - textH_all_Column[colIndex]= []; + if(tb=="2"){ + if(textH_all_cache>cellHeight && textH_all_Column[colIndex]!=null){ + // textW_all += textW; + // textH_all = Math.max(textH_all,textH_all_cache); + textH_all_ColumnHeight.push(textH_all_cache-textH); + textH_all_cache = textH; + colIndex +=1; } - - textH_all_Column[colIndex].push({ - content:vArr[i], - style:fontset, - width:textW, - height:textH, - left:0, - top:0, - colIndex:colIndex, - }); - } - let textH_all_ColumWidth = []; - for(let i = 0; i < textH_all_ColumnHeight.length; i++){ - let columnHeight = textH_all_ColumnHeight[i]; - let col = textH_all_Column[i], colMaxW=0; - for(let c=0;ccellHeight && text_all_split[splitIndex]!=null){ - // console.log("cut",anchor, i , str); - anchor = i-1; - - text_all_split[splitIndex].push({ - content:preStr, - style:fontset, - width:preWidth, - height:preHeight, - left:0, - top:0, - splitIndex:splitIndex, - textHeight:preTextHeight, - textWidth:preTextWidth, - asc:measureText.actualBoundingBoxAscent, - desc:measureText.actualBoundingBoxDescent - }); + textContent.rotate = rt; + rt = Math.abs(rt); - 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, - width:width, - height:height, - left:0, - top:0, - splitIndex:splitIndex, - textHeight:textHeight, - textWidth:textWidth, - asc:measureText.actualBoundingBoxAscent, - desc:measureText.actualBoundingBoxDescent - }); - 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){ + let anchor = 0, preHeight = 0, preWidth=0, preStr, preTextHeight, preTextWidth, i=0; + 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; - anchor = i-1; - - text_all_split[splitIndex].push({ - content:preStr, - style:fontset, - width:preWidth, - height:preHeight, - left:0, - top:0, - splitIndex:splitIndex, - asc:measureText.actualBoundingBoxAscent, - desc: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 - 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:width, - height:height, - left:0, - top:0, - splitIndex:splitIndex, - asc:measureText.actualBoundingBoxAscent, - desc:measureText.actualBoundingBoxDescent - }); + 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; - break; + if(rt!=0){//rotate + // console.log("all",anchor, i , str); + if((height+space_height)>cellHeight && text_all_split[splitIndex]!=null){ + // console.log("cut",anchor, i , str); + anchor = i-1; + + text_all_split[splitIndex].push({ + content:preStr, + style:fontset, + width:preWidth, + height:preHeight, + left:0, + top:0, + splitIndex:splitIndex, + textHeight:preTextHeight, + textWidth:preTextWidth, + asc:measureText.actualBoundingBoxAscent, + desc:measureText.actualBoundingBoxDescent + }); + + splitIndex +=1; + } + else if(i== value.length){ + // console.log("last",anchor, i , str); + if(text_all_split[splitIndex]==null){ + text_all_split[splitIndex]= []; } - else{ - if(text_all_split[splitIndex]==null){ - text_all_split[splitIndex]= []; - } - i++; + text_all_split[splitIndex].push({ + content:str, + style:fontset, + width:width, + height:height, + left:0, + top:0, + splitIndex:splitIndex, + textHeight:textHeight, + textWidth:textWidth, + asc:measureText.actualBoundingBoxAscent, + desc:measureText.actualBoundingBoxDescent + }); + break; + } + else{ + if(text_all_split[splitIndex]==null){ + text_all_split[splitIndex]= []; } + i++; } - - preWidth = width; - preHeight = height; - preStr = str; - preTextHeight = textHeight; - preTextWidth = textWidth; - } + else{//plain + if((width+space_width)>cellWidth && text_all_split[splitIndex]!=null){ - let split_all_size = [], oneLinemaxWordCount=0; - // console.log("split",splitIndex, text_all_split); - let splitLen = Object.keys(text_all_split).length; - for(let i = 0; i < splitLen; i++){ - let splitLists = text_all_split[i]; - if(splitLists==null){ - continue; + anchor = i-1; + + text_all_split[splitIndex].push({ + content:preStr, + style:fontset, + width:preWidth, + height:preHeight, + left:0, + top:0, + splitIndex:splitIndex, + asc:measureText.actualBoundingBoxAscent, + desc:measureText.actualBoundingBoxDescent + }); + + splitIndex +=1; } - let sWidth = 0, sHeight=0, maxDesc=0,maxAsc=0, lineHeight=0, maxWordCount=0; - for(let s=0;s=0;c--){ - let wordGroup = splitLists[c]; - let left, top; - if(rt!=0){//rotate - let x, y = cumWordHeight+size.asc; - if(isRotateUp=="1"){ - // x = (cumWordHeight)/Math.tan(rtPI) + cumColumnWidth; - // if(verticalAlign=="2"){ - // x = (cumWordHeight)/Math.tan(rtPI) - cumColumnWidth + textW_all_inner; - // } - // else if(verticalAlign=="0"){ - // x = (cumWordHeight)/Math.tan(rtPI) - cumColumnWidth + textW_all_inner; - // } - // else{ - // x = (cumWordHeight)/Math.tan(rtPI) - cumColumnWidth + textW_all_inner; - // } - - if(horizonAlign == "0"){//center - let sh = textH_all/Math.sin(rtPI); - x = (cumWordHeight)/Math.tan(rt*Math.PI/180) - cumColumnWidth + textW_all_inner; - if(verticalAlign == "0"){//mid - - left = x + cellWidth/2 - (textW_all/2); - top = y + cellHeight/2 - textH_all/2; - } - else if(verticalAlign == "1"){//top - left = x + cellWidth/2 - textW_all/2- lastLineSpaceHeight*Math.cos(rtPI)/2; - top = y - (textH_all/2 - rh/2) + lastLineSpaceHeight*Math.sin(rtPI)/2; - } - else if(verticalAlign == "2"){//bottom - left = x + cellWidth/2 - (textW_all/2); - top = y + cellHeight - rh/2-textH_all/2; - } - } - else if(horizonAlign == "1"){//left - x = (cumWordHeight)/Math.tan(rtPI) - cumColumnWidth + textW_all_inner; - if(verticalAlign == "0"){//mid - left = x - rh*Math.sin(rtPI)/2 + lastLineSpaceHeight*Math.cos(rtPI)/2; - top = y + cellHeight/2 + rh*Math.cos(rtPI)/2 - lastLineSpaceHeight*Math.sin(rtPI)/2; - } - else if(verticalAlign == "1"){//top - left = x - rh*Math.sin(rtPI); - top = y + rh*Math.cos(rtPI); - } - else if(verticalAlign == "2"){//bottom - left = x + lastLineSpaceHeight*Math.cos(rtPI); - top = y + cellHeight - lastLineSpaceHeight*Math.sin(rtPI); - } - } - else if(horizonAlign == "2"){//right - x = (cumWordHeight)/Math.tan(rtPI) - cumColumnWidth + textW_all_inner; - if(verticalAlign == "0"){//mid - // left = x + cellWidth - ( textH_all/Math.tan(rtPI) + (rh/2)*Math.sin(rtPI)); - // top = y + cellHeight/2 - (textH_all - (rh/2)*Math.cos(rtPI)); - left = x + cellWidth - rw/2 - (textW_all_inner/2+(textH_all/2)/Math.tan(rtPI)); - top = y + cellHeight/2 - textH_all/2; - } - else if(verticalAlign == "1"){//top fixOneLineLeft - left = x + cellWidth - textW_all + lastLine.height*Math.cos(rtPI)/2; - top = y - textH_all + lastLine.height*Math.sin(rtPI)/2; - } - else if(verticalAlign == "2"){//bottom - left = x + cellWidth - rw*Math.cos(rtPI) + lastLineSpaceHeight*Math.cos(rtPI); - top = y + cellHeight - rw*Math.sin(rtPI) - lastLineSpaceHeight*Math.sin(rtPI); - } - } + cumColumnWidth = 0; + + for(let c=splitLists.length-1;c>=0;c--){ + let wordGroup = splitLists[c]; + let left, top; + if(rt!=0){//rotate + let x, y = cumWordHeight+size.asc; + + x = (cumWordHeight)/Math.tan(rtPI) - cumColumnWidth + textW_all_inner; + if(horizonAlign == "0"){//center + let sh = textH_all/Math.sin(rtPI); + if(verticalAlign == "0"){//mid + + left = x + cellWidth/2 - (textW_all/2) + lastLineSpaceHeight*Math.cos(rtPI)/2; + top = y + cellHeight/2 - textH_all/2 - lastLineSpaceHeight*Math.sin(rtPI)/2; + } + else if(verticalAlign == "1"){//top + left = x + cellWidth/2 - textW_all/2; + top = y - (textH_all/2 - rh/2); + } + else if(verticalAlign == "2"){//bottom + left = x + cellWidth/2 - (textW_all/2)+lastLineSpaceHeight*Math.cos(rtPI); + top = y + cellHeight - rh/2 - textH_all/2 - lastLineSpaceHeight*Math.sin(rtPI); + } + } + else if(horizonAlign == "1"){//left + if(verticalAlign == "0"){//mid + left = x - rh*Math.sin(rtPI)/2 + lastLineSpaceHeight*Math.cos(rtPI)/2; + top = y + cellHeight/2 + rh*Math.cos(rtPI)/2 - lastLineSpaceHeight*Math.sin(rtPI)/2; + } + else if(verticalAlign == "1"){//top + left = x - rh*Math.sin(rtPI); + top = y + rh*Math.cos(rtPI); + } + else if(verticalAlign == "2"){//bottom + left = x + lastLineSpaceHeight*Math.cos(rtPI); + top = y + cellHeight - lastLineSpaceHeight*Math.sin(rtPI); + } + } + else if(horizonAlign == "2"){//right + if(verticalAlign == "0"){//mid + left = x + cellWidth - rw/2 - (textW_all_inner/2+(textH_all/2)/Math.tan(rtPI))+ lastLineSpaceHeight*Math.cos(rtPI)/2; + top = y + cellHeight/2 - textH_all/2 - lastLineSpaceHeight*Math.sin(rtPI)/2; + } + else if(verticalAlign == "1"){//top fixOneLineLeft + left = x + cellWidth - textW_all + fixOneLineLeft; + top = y - textH_all; + } + else if(verticalAlign == "2"){//bottom + left = x + cellWidth - rw*Math.cos(rtPI) + lastLineSpaceHeight*Math.cos(rtPI); + top = y + cellHeight - rw*Math.sin(rtPI) - lastLineSpaceHeight*Math.sin(rtPI); } - } - wordGroup.left = left; - wordGroup.top = top; - - textContent.values.push(wordGroup); } - - - cumWordHeight += size.height; - - + + wordGroup.left = left; + wordGroup.top = top; + + drawLineInfo(wordGroup, cancelLine, underLine,{ + width:wordGroup.textWidth, + height:wordGroup.textHeight, + left:left-wordGroup.textWidth, + top:top, + asc:size.asc, + desc:size.desc + }); + + textContent.values.push(wordGroup); } + + + cumWordHeight += size.height; + + } - else{ - for(let i = 0; i < splitLen; i++){ - let splitLists = text_all_split[i]; - if(splitLists==null){ - continue; - } - let size = split_all_size[i]; - - cumColumnWidth = 0; - - for(let c=0;c1?(wordGroup.textHeight/1.5):0); - // if(verticalAlign == "0"){ - // top = y + cellHeight/2 - topOffset - textH_all/2 + wordGroup.asc+(splitLen>1?(wordGroup.textHeight/3):0); - // } - // else if(verticalAlign == "1"){ - // top = y - topOffset + wordGroup.asc; - // } - - // cumColumnWidth += wordGroup.textWidth; - - // if(c==0 && i==0 && isRotateUp=="1"){ - // textContent.textLeftAll = left; - // textContent.textTopAll = top-wordGroup.asc; - // } - // else if(c==0 && i==(splitLen-1) && isRotateUp=="0"){ - // textContent.textLeftAll = left; - // textContent.textTopAll = top+wordGroup.desc; - // } - - // console.log("plainWrap" ,left , top); } - else{//plain - left = space_width + cumColumnWidth; - if(horizonAlign == "0"){ - //+ space_width*textH_all_ColumnHeight.length - left = cellWidth / 2 + cumColumnWidth - size.width/2; + else if(horizonAlign == "1"){//left + if(verticalAlign == "0"){//mid + left = x - rh*Math.sin(rtPI)/2 - lastLineSpaceHeight*Math.cos(rtPI)/2; + top = y - textH_all + cellHeight/2 - rh*Math.cos(rtPI)/2 - lastLineSpaceHeight*Math.sin(rtPI)/2; } - else if(horizonAlign == "2"){ - left = cellWidth + cumColumnWidth - size.width; + else if(verticalAlign == "1"){//top + left = x; + top = y - textH_all; } - - top = (cellHeight - space_height) + cumWordHeight - textH_all + wordGroup.asc+wordGroup.height/1.5-wordGroup.desc-1; - if(verticalAlign == "0"){ - top = cellHeight / 2 + cumWordHeight - textH_all/2 + wordGroup.asc+wordGroup.height/3-wordGroup.desc; + else if(verticalAlign == "2"){//bottom + left = x - rh*Math.sin(rtPI) - lastLineSpaceHeight*Math.cos(rtPI); + top = y - textH_all + cellHeight - rh*Math.cos(rtPI) - lastLineSpaceHeight*Math.sin(rtPI); } - else if(verticalAlign == "1"){ - top = space_height + cumWordHeight+ wordGroup.asc; + } + else if(horizonAlign == "2"){//right + if(verticalAlign == "0"){//mid + left = x + cellWidth - rw/2 - textW_all/2 - lastLineSpaceHeight*Math.cos(rtPI)/2; + top = y + cellHeight/2 - textH_all/2 - lastLineSpaceHeight*Math.sin(rtPI)/2; + } + else if(verticalAlign == "1"){//top fixOneLineLeft + left = x + cellWidth - rw*Math.cos(rtPI); + top = y + rh*Math.cos(rtPI); + } + else if(verticalAlign == "2"){//bottom + left = x + cellWidth - textW_all - lastLineSpaceHeight*Math.cos(rtPI) + fixOneLineLeft; + top = y + cellHeight - lastLineSpaceHeight*Math.sin(rtPI); } - - cumColumnWidth += wordGroup.width; } - + + drawLineInfo(wordGroup, cancelLine, underLine,{ + width:wordGroup.textWidth, + height:wordGroup.textHeight, + left:left, + top:top, + asc:size.asc, + desc:size.desc + }); + + + // let x, y = cumWordHeight; //+ wordGroup.textHeight / Math.sin(rt*Math.PI/180)*isRotateDown; + // if(isRotateUp=="1"){ + // if(horizonAlign=="2"){ + // x = (cumWordHeight)/Math.tan(rt*Math.PI/180) + cumColumnWidth; + // } + // else if(horizonAlign=="0"){ + // x = (cumWordHeight)/Math.tan(rt*Math.PI/180) + cumColumnWidth; + // } + // else{ + // x = (cumWordHeight)/Math.tan(rt*Math.PI/180) + cumColumnWidth; + // } + // } + // else{ + // if(horizonAlign=="2"){ + // x = (textH_all-cumWordHeight)/Math.tan(rt*Math.PI/180) + cumColumnWidth; + // } + // else if(horizonAlign=="0"){ + // x = (textH_all-cumWordHeight)/Math.tan(rt*Math.PI/180) + cumColumnWidth; + // } + // else{ + // x = (textH_all-cumWordHeight)/Math.tan(rt*Math.PI/180) + cumColumnWidth; + // } + // } + + // // x -= wordGroup.textHeight / Math.sin(rt*Math.PI/180)*isRotateDown; + // // x -= size.textHeight*2; + // //textH_all/Math.sin(rt*Math.PI/180) - textH_all/Math.tan(rt*Math.PI/180); + // let leftOffset = 0; + + // left = x + leftOffset; + // if(horizonAlign == "0"){ + // //+ space_width*textH_all_ColumnHeight.length + // left = x + cellWidth / 2 + leftOffset - textW_all/2; + // } + // else if(horizonAlign == "2"){ + // left = x + cellWidth + leftOffset - textW_all; + // } + + // //( textH_all/2 - rh/2 ) + // let topOffset = 0; - wordGroup.left = left; - wordGroup.top = top; + // top = y + cellHeight - topOffset - textH_all + wordGroup.asc +wordGroup.desc +(splitLen>1?(wordGroup.textHeight/1.5):0); + // if(verticalAlign == "0"){ + // top = y + cellHeight/2 - topOffset - textH_all/2 + wordGroup.asc+(splitLen>1?(wordGroup.textHeight/3):0); + // } + // else if(verticalAlign == "1"){ + // top = y - topOffset + wordGroup.asc; + // } - textContent.values.push(wordGroup); + // cumColumnWidth += wordGroup.textWidth; + + // if(c==0 && i==0 && isRotateUp=="1"){ + // textContent.textLeftAll = left; + // textContent.textTopAll = top-wordGroup.asc; + // } + // else if(c==0 && i==(splitLen-1) && isRotateUp=="0"){ + // textContent.textLeftAll = left; + // textContent.textTopAll = top+wordGroup.desc; + // } + + // console.log("plainWrap" ,left , top); } + else{//plain + left = space_width + cumColumnWidth; + if(horizonAlign == "0"){ + //+ space_width*textH_all_ColumnHeight.length + left = cellWidth / 2 + cumColumnWidth - size.width/2; + } + else if(horizonAlign == "2"){ + left = cellWidth + cumColumnWidth - size.width; + } + top = (cellHeight - space_height) + cumWordHeight +size.asc-textH_all; + if(verticalAlign == "0"){ + top = cellHeight / 2 + cumWordHeight - textH_all/2 + size.asc; + } + else if(verticalAlign == "1"){ + top = space_height + cumWordHeight+ size.asc; + } - cumWordHeight += size.height; - - + cumColumnWidth += wordGroup.width; + + drawLineInfo(wordGroup, cancelLine, underLine,{ + width:wordGroup.width, + height:wordGroup.height, + left:left, + top:top, + asc:size.asc, + desc:size.desc + }); + } + + + wordGroup.left = left; + wordGroup.top = top; + + textContent.values.push(wordGroup); } + + + cumWordHeight += size.height; + + } + } - textContent.type = "plainWrap"; - - if(rt!=0){ - // let leftCenter = (textW_all + textH_all/Math.tan(rt*Math.PI/180))/2; - // let topCenter = textH_all/2; - - // if(isRotateUp=="1"){ - // textContent.textLeftAll += leftCenter; - // textContent.textTopAll += topCenter; - // } - // else { - // textContent.textLeftAll += leftCenter; - // textContent.textTopAll -= topCenter; - // } - - if(horizonAlign == "0"){//center - if(verticalAlign == "0"){//mid - textContent.textLeftAll = cellWidth/2; - textContent.textTopAll = cellHeight/2; - } - else if(verticalAlign == "1"){//top - textContent.textLeftAll = cellWidth/2; - textContent.textTopAll = rh/2; - } - else if(verticalAlign == "2"){//bottom - textContent.textLeftAll = cellWidth/2; - textContent.textTopAll = cellHeight - rh/2; - } + textContent.type = "plainWrap"; + + if(rt!=0){ + // let leftCenter = (textW_all + textH_all/Math.tan(rt*Math.PI/180))/2; + // let topCenter = textH_all/2; + + // if(isRotateUp=="1"){ + // textContent.textLeftAll += leftCenter; + // textContent.textTopAll += topCenter; + // } + // else { + // textContent.textLeftAll += leftCenter; + // textContent.textTopAll -= topCenter; + // } + + if(horizonAlign == "0"){//center + if(verticalAlign == "0"){//mid + textContent.textLeftAll = cellWidth/2; + textContent.textTopAll = cellHeight/2; } - else if(horizonAlign == "1"){//left - if(verticalAlign == "0"){//mid - textContent.textLeftAll = 0; - textContent.textTopAll = cellHeight/2; - } - else if(verticalAlign == "1"){//top - textContent.textLeftAll = 0; - textContent.textTopAll = 0; - } - else if(verticalAlign == "2"){//bottom - textContent.textLeftAll = 0; - textContent.textTopAll = cellHeight; - } + else if(verticalAlign == "1"){//top + textContent.textLeftAll = cellWidth/2; + textContent.textTopAll = rh/2; + } - else if(horizonAlign == "2"){//right - if(verticalAlign == "0"){//mid - textContent.textLeftAll = cellWidth - rw/2; - textContent.textTopAll = cellHeight/2; - } - else if(verticalAlign == "1"){//top - textContent.textLeftAll = cellWidth; - textContent.textTopAll = 0; - } - else if(verticalAlign == "2"){//bottom - textContent.textLeftAll = cellWidth; - textContent.textTopAll = cellHeight; - } + else if(verticalAlign == "2"){//bottom + textContent.textLeftAll = cellWidth/2; + textContent.textTopAll = cellHeight - rh/2; } - } - // else{ - // textContent.textWidthAll = textW_all; - // textContent.textHeightAll = textH_all; - // } - - } - else{ - if(supportBoundBox){ - ctx.textBaseline = 'alphabetic'; + else if(horizonAlign == "1"){//left + if(verticalAlign == "0"){//mid + textContent.textLeftAll = 0; + textContent.textTopAll = cellHeight/2; + } + else if(verticalAlign == "1"){//top + textContent.textLeftAll = 0; + textContent.textTopAll = 0; + } + else if(verticalAlign == "2"){//bottom + textContent.textLeftAll = 0; + textContent.textTopAll = cellHeight; + } } - else{ - ctx.textBaseline = 'bottom'; + else if(horizonAlign == "2"){//right + if(verticalAlign == "0"){//mid + textContent.textLeftAll = cellWidth - rw/2; + textContent.textTopAll = cellHeight/2; + } + else if(verticalAlign == "1"){//top + textContent.textLeftAll = cellWidth; + textContent.textTopAll = 0; + } + else if(verticalAlign == "2"){//bottom + textContent.textLeftAll = cellWidth; + textContent.textTopAll = cellHeight; + } } - let measureText = getMeasureText(value, ctx); - let textWidth = measureText.width; - let textHeight = measureText.actualBoundingBoxDescent + measureText.actualBoundingBoxAscent; + } + // else{ + // textContent.textWidthAll = textW_all; + // textContent.textHeightAll = textH_all; + // } - textContent.rotate = rt; + } + else{ + let measureText = getMeasureText(value, ctx); + let textWidth = measureText.width; + let textHeight = measureText.actualBoundingBoxDescent + measureText.actualBoundingBoxAscent; - rt = Math.abs(rt); + textContent.rotate = rt; - let textWidthAll = textWidth * Math.cos(rt*Math.PI/180) + textHeight * Math.sin(rt*Math.PI/180);//consider text box wdith and line height + rt = Math.abs(rt); - let textHeightAll = textWidth * Math.sin(rt*Math.PI/180) + textHeight * Math.cos(rt*Math.PI/180);//consider text box wdith and line height + let textWidthAll = textWidth * Math.cos(rt*Math.PI/180) + textHeight * Math.sin(rt*Math.PI/180);//consider text box wdith and line height - if(rt!=0){ - textContent.textHeightAll = textHeightAll; - } - else{ - textContent.textHeightAll = textHeightAll+textHeight/1.5-measureText.actualBoundingBoxDescent-space_height; - } - textContent.textWidthAll = textWidthAll; - - // console.log(textContent.textWidthAll , textContent.textHeightAll); - if(isMode=="onlyWidth"){ - // console.log("plain", textContent,cell, option); - return textContent; - } + let textHeightAll = textWidth * Math.sin(rt*Math.PI/180) + textHeight * Math.cos(rt*Math.PI/180);//consider text box wdith and line height - let width = textWidthAll, height = textHeightAll; - - let left = space_width + textHeight * Math.sin(rt*Math.PI/180)*isRotateUp; //默认为1,左对齐 - if(horizonAlign == "0"){ //居中对齐 - left = cellWidth / 2 - (width / 2) + textHeight * Math.sin(rt*Math.PI/180)*isRotateUp; - } - else if(horizonAlign == "2"){ //右对齐 - left = (cellWidth - space_width) - width + textHeight * Math.sin(rt*Math.PI/180)*isRotateUp; - } - - let top = (cellHeight - space_height) - height + measureText.actualBoundingBoxAscent + textWidth * Math.sin(rt*Math.PI/180)*isRotateUp; //默认为2,下对齐 - if(verticalAlign == "0"){ //居中对齐 - top = cellHeight / 2 - (height / 2) + measureText.actualBoundingBoxAscent + textWidth * Math.sin(rt*Math.PI/180)*isRotateUp; - } - else if(verticalAlign == "1"){ //上对齐 - top = space_height + measureText.actualBoundingBoxAscent + textWidth * Math.sin(rt*Math.PI/180)*isRotateUp; - } + if(rt!=0){ + textContent.textHeightAll = textHeightAll; + } + else{ + textContent.textHeightAll = textHeightAll+textHeight/1.5-measureText.actualBoundingBoxDescent-space_height; + } + textContent.textWidthAll = textWidthAll; + + // console.log(textContent.textWidthAll , textContent.textHeightAll); + if(isMode=="onlyWidth"){ + // console.log("plain", textContent,cell, option); + return textContent; + } - textContent.type = "plain"; - textContent.values.push({ - content:value, - style:fontset, - width:width, - height:height, - left:left, - top:top, - }); + let width = textWidthAll, height = textHeightAll; - textContent.textLeftAll = left; - textContent.textTopAll = top; + let left = space_width + textHeight * Math.sin(rt*Math.PI/180)*isRotateUp; //默认为1,左对齐 + if(horizonAlign == "0"){ //居中对齐 + left = cellWidth / 2 - (width / 2) + textHeight * Math.sin(rt*Math.PI/180)*isRotateUp; + } + else if(horizonAlign == "2"){ //右对齐 + left = (cellWidth - space_width) - width + textHeight * Math.sin(rt*Math.PI/180)*isRotateUp; + } + + let top = (cellHeight - space_height) - height + measureText.actualBoundingBoxAscent + textWidth * Math.sin(rt*Math.PI/180)*isRotateUp; //默认为2,下对齐 + if(verticalAlign == "0"){ //居中对齐 + top = cellHeight / 2 - (height / 2) + measureText.actualBoundingBoxAscent + textWidth * Math.sin(rt*Math.PI/180)*isRotateUp; + } + else if(verticalAlign == "1"){ //上对齐 + top = space_height + measureText.actualBoundingBoxAscent + textWidth * Math.sin(rt*Math.PI/180)*isRotateUp; + } - textContent.asc = measureText.actualBoundingBoxAscent; - textContent.desc = measureText.actualBoundingBoxDescent; + textContent.type = "plain"; - // console.log("plain",left,top); + let wordGroup = { + content:value, + style:fontset, + width:width, + height:height, + left:left, + top:top, } - } + drawLineInfo(wordGroup, cancelLine, underLine,{ + width:textWidth, + height:textHeight, + left:left, + top:top, + asc:measureText.actualBoundingBoxAscent, + desc:measureText.actualBoundingBoxDescent + }); + textContent.values.push(wordGroup); + textContent.textLeftAll = left; + textContent.textTopAll = top; + + textContent.asc = measureText.actualBoundingBoxAscent; + textContent.desc = measureText.actualBoundingBoxDescent; + + // console.log("plain",left,top); + } } return textContent; } + +function drawLineInfo(wordGroup, cancelLine,underLine,option){ + let left = option.left, top = option.top, width=option.width, height = option.height, asc = option.asc,desc = option.desc; + if(cancelLine!="0"){ + wordGroup.cancelLine = {}; + wordGroup.cancelLine.startX = left; + wordGroup.cancelLine.startY = top-asc/2+1; + + wordGroup.cancelLine.endX = left + width; + wordGroup.cancelLine.endY = top-asc/2+1; + + } + + if(underLine!="0"){ + wordGroup.underLine = []; + if(underLine=="1" || underLine=="2"){ + let item = {}; + item.startX = left; + item.startY = top; + + item.endX = left + width; + item.endY = top; + + wordGroup.underLine.push(item); + } + + if(underLine=="2"){ + let item = {}; + item.startX = left; + item.startY = top+desc; + + item.endX = left + width; + item.endY = top+desc; + + wordGroup.underLine.push(item); + } + + if(underLine=="3" || underLine=="4"){ + let item = {}; + item.startX = left; + item.startY = top+desc; + + item.endX = left + width; + item.endY = top+desc; + + wordGroup.underLine.push(item); + } + + if(underLine=="4"){ + let item = {}; + item.startX = left; + item.startY = top+desc+2; + + item.endX = left + width; + item.endY = top+desc+2; + + wordGroup.underLine.push(item); + } + } +} + export { rowlenByRange, computeRowlenArr, diff --git a/src/index.html b/src/index.html index 5534a29..e109f38 100644 --- a/src/index.html +++ b/src/index.html @@ -77,7 +77,8 @@ allowEdit:true, forceCalculation:false, plugins: ['chart'], - data: [sheetCell,sheetFormula,sheetConditionFormat,sheetSparkline,sheetTable,sheetComment,sheetPivotTableData,sheetPivotTable,sheetChart] + data: + [sheetCell,sheetFormula,sheetConditionFormat,sheetSparkline,sheetTable,sheetComment,sheetPivotTableData,sheetPivotTable,sheetChart] }) })