From 4eecdf652cc20bf940a0174def7b6e7df4b0ac29 Mon Sep 17 00:00:00 2001 From: liuyang Date: Mon, 7 Sep 2020 19:01:01 +0800 Subject: [PATCH] refactor(inline string programing): develop --- src/global/draw.js | 6 ++-- src/global/getRowlen.js | 65 ++++++++++++++++++++++++++++++++++++----- 2 files changed, 60 insertions(+), 11 deletions(-) diff --git a/src/global/draw.js b/src/global/draw.js index 379f9ee..dba093a 100644 --- a/src/global/draw.js +++ b/src/global/draw.js @@ -1178,7 +1178,7 @@ let nullCellRender = function(r, c, start_r, start_c, end_r, end_c,luckysheetTab } -let cellRender1 = function(r, c, start_r, start_c, end_r, end_c, value, luckysheetTableContent,af_compute, cf_compute,offsetLeft,offsetTop,dynamicArray_compute,cellOverflowMap, dataset_col_st, dataset_col_ed,scrollHeight,scrollWidth,bodrder05,isMerge){ +let cellRender = function(r, c, start_r, start_c, end_r, end_c, value, luckysheetTableContent,af_compute, cf_compute,offsetLeft,offsetTop,dynamicArray_compute,cellOverflowMap, dataset_col_st, dataset_col_ed,scrollHeight,scrollWidth,bodrder05,isMerge){ let cell = Store.flowdata[r][c]; let cellWidth = end_c - start_c - 2; @@ -1203,7 +1203,7 @@ let cellRender1 = function(r, c, start_r, start_c, end_r, end_c, value, luckyshe if(checksCF != null && checksCF["cellColor"] != null){ //若单元格有条件格式 背景颜色 fillStyle = checksCF["cellColor"]; } - luckysheetTableContent.textBaseline = 'top'; + // luckysheetTableContent.textBaseline = 'top'; if(fillStyle==null){ luckysheetTableContent.fillStyle = "#FFFFFF"; } @@ -1600,7 +1600,7 @@ let cellRender1 = function(r, c, start_r, start_c, end_r, end_c, value, luckyshe } //非空白单元格渲染 -let cellRender = function(r, c, start_r, start_c, end_r, end_c, value, luckysheetTableContent,af_compute, cf_compute,offsetLeft,offsetTop,dynamicArray_compute,cellOverflowMap, dataset_col_st, dataset_col_ed,scrollHeight,scrollWidth,bodrder05,isMerge){ +let cellRender1 = function(r, c, start_r, start_c, end_r, end_c, value, luckysheetTableContent,af_compute, cf_compute,offsetLeft,offsetTop,dynamicArray_compute,cellOverflowMap, dataset_col_st, dataset_col_ed,scrollHeight,scrollWidth,bodrder05,isMerge){ let cell = Store.flowdata[r][c]; let cellWidth = end_c - start_c - 2; diff --git a/src/global/getRowlen.js b/src/global/getRowlen.js index ccb8b2c..88b1919 100644 --- a/src/global/getRowlen.js +++ b/src/global/getRowlen.js @@ -156,7 +156,7 @@ function getCellTextSplitArr(strValue, strArr, cellWidth, canvas){ //获取有值单元格文本大小 // let measureTextCache = {}, measureTextCacheTimeOut = null; -function getMeasureText(value, ctx){ +function getMeasureText(value, ctx, fontset){ let mtc = Store.measureTextCache[value + "_" + ctx.font]; if(mtc != null){ @@ -164,11 +164,12 @@ function getMeasureText(value, ctx){ } else{ let measureText = ctx.measureText(value), cache = {}; - if(measureText.actualBoundingBoxLeft==null){ + if(measureText.actualBoundingBoxRight==null){ cache.width = measureText.width; } else{ - cache.width = measureText.actualBoundingBoxLeft + measureText.actualBoundingBoxRight; + //measureText.actualBoundingBoxLeft + + cache.width = measureText.actualBoundingBoxRight; } cache.actualBoundingBoxDescent = measureText.actualBoundingBoxDescent; cache.actualBoundingBoxAscent = measureText.actualBoundingBoxAscent; @@ -192,6 +193,14 @@ function getMeasureText(value, ctx){ } } +function isSupportBoundingBox(ctx){ + let measureText = ctx.measureText("田"); + if(measureText.actualBoundingBoxAscent==null){ + return false; + } + return true; +} + //获取单元格文本内容的渲染信息 // let measureTextCache = {}, measureTextCacheTimeOut = null; @@ -254,6 +263,7 @@ function getCellTextInfo(cell , ctx, option){ } else{ + let fontset = luckysheetfontformat(cell); ctx.font = fontset; @@ -266,12 +276,16 @@ function getCellTextInfo(cell , ctx, option){ return null; } - let measureText = getMeasureText(value, ctx); - //luckysheetTableContent.measureText(value); - let textWidth = measureText.width; - let textHeight = measureText.actualBoundingBoxDescent + measureText.actualBoundingBoxAscent; + // let measureText = getMeasureText(value, ctx); + // //luckysheetTableContent.measureText(value); + // let textWidth = measureText.width; + // let textHeight = measureText.actualBoundingBoxDescent + measureText.actualBoundingBoxAscent; if(tr=="3"){//vertical text + ctx.textBaseline = 'top'; + let measureText = getMeasureText(value, ctx); + let textHeight = measureText.actualBoundingBoxDescent + measureText.actualBoundingBoxAscent; + value = value.toString(); let vArr = []; @@ -382,6 +396,7 @@ function getCellTextInfo(cell , ctx, option){ textContent.textHeightAll = textH_all; } else{ + let supportBoundBox = isSupportBoundingBox(ctx); if(tb=="2"){//wrap value = value.toString(); @@ -391,6 +406,12 @@ function getCellTextInfo(cell , ctx, option){ // let oneWordWidth = getMeasureText(vArr[0], ctx).width; let splitIndex=0, text_all_cache=0, text_all_split = {}, text_all_splitLen=[]; + if(supportBoundBox){ + ctx.textBaseline = 'alphabetic'; + } + else{ + ctx.textBaseline = 'bottom'; + } textContent.rotate = rt; rt = Math.abs(rt); @@ -411,6 +432,26 @@ function getCellTextInfo(cell , ctx, option){ text_all_splitLen.push(text_all_cache-textH); text_all_cache = textH; splitIndex +=1; + + anchor = i; + + if(i== value.length){ + textH_all_ColumnHeight.push(textH_all_cache); + } + + if(textH_all_Column[colIndex]==null){ + text_all_split[colIndex]= []; + } + + text_all_split[splitIndex].push({ + content:vArr[i], + style:fontset, + width:textW, + height:textH, + left:0, + top:0, + colIndex:colIndex, + }); } } else{ @@ -494,7 +535,15 @@ function getCellTextInfo(cell , ctx, option){ textContent.textHeightAll = textH_all; } else{ - + ctx.textBaseline = 'top'; + let measureText = getMeasureText(value, ctx); + let textWidth = measureText.width; + let textHeight = measureText.actualBoundingBoxDescent + measureText.actualBoundingBoxAscent; + + // let centerFix = 0; + // if(supportBoundBox){ + // centerFix = measureText.actualBoundingBoxDescent/2; + // } textContent.rotate = rt; rt = Math.abs(rt);