diff --git a/src/controllers/menuButton.js b/src/controllers/menuButton.js index 7b9e04631..e06ab2027 100644 --- a/src/controllers/menuButton.js +++ b/src/controllers/menuButton.js @@ -2948,10 +2948,10 @@ const menuButton = { } if(attr == "tb" || attr == "tr" || attr == "fs"){ - jfrefreshgrid(d, Store.luckysheet_select_save, cfg, null, true); + jfrefreshgrid(d, Store.luckysheet_select_save, cfg, null, true, false); } else{ - jfrefreshgrid(d, Store.luckysheet_select_save); + jfrefreshgrid(d, Store.luckysheet_select_save, undefined, undefined,undefined,false); } }, updateFormat_mc: function(d, foucsStatus){ diff --git a/src/global/draw.js b/src/global/draw.js index d717dd6bc..c9507dcc9 100644 --- a/src/global/draw.js +++ b/src/global/draw.js @@ -1517,7 +1517,17 @@ let cellRender = function(r, c, start_r, start_c, end_r, end_c, value, luckyshee let value = textInfo.values[0] let horizonAlignPos = pos_x + value.left; - let verticalAlignPos = pos_y + value.top; + let verticalAlignPos = pos_y + value.top- textInfo.textHeightAll; + + if(verticalAlign == "0"){ //居中对齐 + verticalAlignPos = pos_y + cellHeight/2 - textInfo.textHeightAll/2; + } + else if(verticalAlign == "1"){ //上对齐 + verticalAlignPos = pos_y; + } + else if(verticalAlign == "2"){ //下对齐 + verticalAlignPos =verticalAlignPos - textInfo.desc; + } verticalAlignPos = verticalAlignPos/Store.zoomRatio; horizonAlignPos = horizonAlignPos/Store.zoomRatio; @@ -1530,12 +1540,12 @@ let cellRender = function(r, c, start_r, start_c, end_r, end_c, value, luckyshee 32, pos_x/Store.zoomRatio , verticalAlignPos, - textContent.textHeightAll/Store.zoomRatio, - textContent.textHeightAll/Store.zoomRatio + textInfo.textHeightAll/Store.zoomRatio, + textInfo.textHeightAll/Store.zoomRatio ); if(horizonAlign != "0" && horizonAlign != "2"){ //左对齐时 文本渲染空出一个图标的距离 - horizonAlignPos = horizonAlignPos + textContent.textHeightAll/Store.zoomRatio; + horizonAlignPos = horizonAlignPos + textInfo.textHeightAll/Store.zoomRatio; } } @@ -1805,10 +1815,15 @@ function getCellOverflowMap(canvas, col_st, col_ed, row_st, row_end){ // value = getcellvalue(r, c); // } - let textMetrics = getCellTextInfo(cell, canvas,{ + let textMetricsObj = getCellTextInfo(cell, canvas,{ r:r, c:c, - }).textWidthAll; + }); + let textMetrics = 0; + if(textMetricsObj!=null){ + textMetrics = textMetricsObj.textWidthAll; + } + //canvas.measureText(value).width; let start_c = c - 1 < 0 ? 0 : Store.visibledatacolumn[c - 1]; @@ -2008,12 +2023,24 @@ function cellOverflow_colIn(map, r, c, col_st, col_ed){ } function cellTextRender(textInfo, ctx, option){ + if(textInfo==null){ + return + } let values = textInfo.values; let pos_x = option.pos_x, pos_y = option.pos_y; if(values==null){ return; } - console.log(textInfo, pos_x, pos_y, values[0].width, values[0].left, ctx); + // console.log(textInfo, pos_x, pos_y, values[0].width, values[0].left, ctx); + + // for(let i=0;icellHeight && text_all_split[splitIndex]!=null){ - console.log("cut",anchor, i , str); + // console.log("cut",anchor, i , str); anchor = i-1; text_all_split[splitIndex].push({ @@ -492,7 +507,7 @@ function getCellTextInfo(cell , ctx, option){ splitIndex +=1; } else if(i== value.length){ - console.log("last",anchor, i , str); + // console.log("last",anchor, i , str); if(text_all_split[splitIndex]==null){ text_all_split[splitIndex]= []; } @@ -571,15 +586,15 @@ function getCellTextInfo(cell , ctx, option){ } - let split_all_size = []; - // console.log(splitIndex, text_all_split); + 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; } - let sWidth = 0, sHeight=0; + let sWidth = 0, sHeight=0, maxDesc=0,maxAsc=0, lineHeight=0, maxWordCount=0; for(let s=0;s1?(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); + // 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; @@ -706,9 +869,9 @@ function getCellTextInfo(cell , ctx, option){ left = cellWidth + cumColumnWidth - size.width; } - top = (cellHeight - space_height) + cumWordHeight - textH_all - wordGroup.desc + wordGroup.height*2/1.5-1; + 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.height/2 + wordGroup.height/3+1; + top = cellHeight / 2 + cumWordHeight - textH_all/2 + wordGroup.asc+wordGroup.height/3-wordGroup.desc; } else if(verticalAlign == "1"){ top = space_height + cumWordHeight+ wordGroup.asc; @@ -733,22 +896,59 @@ function getCellTextInfo(cell , ctx, option){ textContent.type = "plainWrap"; if(rt!=0){ - // textContent.textWidthAll = rw; - // textContent.textHeightAll = rh; - - let leftCenter = (textW_all + textH_all/Math.tan(rt*Math.PI/180))/2; - let topCenter = textH_all/2; - - // let leftCenter = 0; - // let topCenter = 0; - - if(isRotateUp=="1"){ - textContent.textLeftAll += leftCenter; - textContent.textTopAll += topCenter; + // 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; + } } - else { - textContent.textLeftAll += leftCenter; - textContent.textTopAll -= topCenter; + 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(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; + } } } @@ -786,8 +986,9 @@ function getCellTextInfo(cell , ctx, option){ } textContent.textWidthAll = textWidthAll; - console.log(textContent.textWidthAll , textContent.textHeightAll); + // console.log(textContent.textWidthAll , textContent.textHeightAll); if(isMode=="onlyWidth"){ + // console.log("plain", textContent,cell, option); return textContent; } @@ -822,7 +1023,10 @@ function getCellTextInfo(cell , ctx, option){ textContent.textLeftAll = left; textContent.textTopAll = top; - console.log("plain",left,top); + textContent.asc = measureText.actualBoundingBoxAscent; + textContent.desc = measureText.actualBoundingBoxDescent; + + // console.log("plain",left,top); } } diff --git a/src/index.html b/src/index.html index bd30e7782..a724e839a 100644 --- a/src/index.html +++ b/src/index.html @@ -37,45 +37,7 @@ allowEdit:true, forceCalculation:false, plugins: ['chart'], - data: [{"name":"Sheet1","config":{"columnlen":{"0":241},"rowlen":{"0":81}},"index":"1","status":"1","order":"0","luckysheet_select_save":[{"row":[0,0],"column":[4,4],"sheetIndex":1}],"zoomRatio":1,"showGridLines":"1","defaultColWidth":72,"defaultRowHeight":18,"celldata":[ - {"r":0,"c":0, - "v":{ - "ct":{ - "fa":"General", - "t":"inlineStr", - "sharedStrings":[ - { - "ff":"等线", //font family - "fc":"#fff000",//font color - "fs":12,//font size - "cl":1,//strike - "un":0,//underline - "bl":0,//blod - "it":1,//italic - v:"我在\r\n" - }, - { - "ff":"等线", //font family - "fc":"#ff0000",//font color - "fs":14,//font size - "cl":"1",//strike - "un":"0",//underline - "bl":"1",//blod - "it":"0",//italic - v:"马路边" - }, - ] - }, - "fs":11, - "ff":"等线", - "vt":0, - "tb":2, - "v":"", - "qp":1, - } - }, - {"r":17,"c":2,"v":{"v":"Luckysheet","ct":{"fa":"General","t":"g"},"bg":null,"bl":0,"it":0,"ff":0,"fs":"11","fc":"rgb(51, 51, 51)","ht":1,"vt":1,"m":"Luckysheet"}} - ],"calcChain":[]}] + data: [sheetCell,sheetFormula,sheetConditionFormat,sheetSparkline,sheetTable,sheetComment,sheetPivotTableData,sheetPivotTable,sheetChart] }) })