From 0bbd7ec7183ce2fdffd498263c48bc1786032e92 Mon Sep 17 00:00:00 2001 From: liuyang Date: Tue, 15 Sep 2020 19:12:53 +0800 Subject: [PATCH] refactor(inline develop): inline string --- src/global/draw.js | 42 ++-- src/global/getRowlen.js | 420 ++++++++++++++++++++++++++++++---------- src/global/getdata.js | 15 ++ src/index.html | 2 +- 4 files changed, 356 insertions(+), 123 deletions(-) diff --git a/src/global/draw.js b/src/global/draw.js index 4ea78d3..1598568 100644 --- a/src/global/draw.js +++ b/src/global/draw.js @@ -9,7 +9,7 @@ import { dynamicArrayCompute } from './dynamicArray'; import browser from './browser'; import { isRealNull, isRealNum } from './validate'; import { getCellTextSplitArr,getMeasureText,getCellTextInfo } from './getRowlen'; -import { getcellvalue } from './getdata'; +import { getcellvalue,getRealCellValue } from './getdata'; import { getBorderInfoCompute } from './border'; import { getSheetIndex } from '../methods/get'; import { getObjType, chatatABC, luckysheetfontformat } from '../utils/util'; @@ -674,10 +674,7 @@ function luckysheetDrawMain(scrollWidth, scrollHeight, drawWidth, drawHeight, of // continue; } else{ - value = getcellvalue(r, c, null, "m"); - if(value == null){ - value = getcellvalue(r, c); - } + value = getRealCellValue(r,c); } if(value == null || value.toString().length == 0){ @@ -718,11 +715,13 @@ function luckysheetDrawMain(scrollWidth, scrollHeight, drawWidth, drawHeight, of let value = null; let margeMaindata = cell["mc"]; - value = getcellvalue(margeMaindata.r, margeMaindata.c, null, "m"); + // value = getcellvalue(margeMaindata.r, margeMaindata.c, null, "m"); - if(value == null){ - value = getcellvalue(margeMaindata.r, margeMaindata.c); - } + // if(value == null){ + // value = getcellvalue(margeMaindata.r, margeMaindata.c); + // } + + value = getRealCellValue(margeMaindata.r,margeMaindata.c); r = margeMaindata.r; c = margeMaindata.c; @@ -2052,19 +2051,26 @@ function cellTextRender(textInfo, ctx, option){ // ctx.fillStyle = "rgb(0,0,0)"; for(let i=0;i0){ - let strArr = []; - let sharedStrings = cell.ct.s; - for(let i=0;i0){ + let sharedStrings = cell.ct.s, similarIndex = 0; + for(let i=0;icellHeight && text_all_split[splitIndex]!=null){ - // console.log("cut",anchor, i , str); anchor = i-1; + + for(let s=0;scellHeight && text_all_split[splitIndex]!=null){ + // console.log("cut",anchor, i , str); + anchor = i-1; + + for(let s=0;scellWidth && text_all_split[splitIndex]!=null){ - - 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 - }); + else{//plain + if((width+space_width)>cellWidth && text_all_split[splitIndex]!=null){ + + anchor = i-1; + + for(let s=0;scellHeight && 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]= []; + } + 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{ - if(text_all_split[splitIndex]==null){ - text_all_split[splitIndex]= []; + else{//plain + if((width+space_width)>cellWidth && text_all_split[splitIndex]!=null){ + + 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; + } + 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 + }); + + break; + } + else{ + if(text_all_split[splitIndex]==null){ + text_all_split[splitIndex]= []; + } + i++; } - i++; } + + preWidth = width; + preHeight = height; + preStr = str; + preTextHeight = textHeight; + preTextWidth = textWidth; + } - - preWidth = width; - preHeight = height; - preStr = str; - preTextHeight = textHeight; - preTextWidth = textWidth; - } let split_all_size = [], oneLinemaxWordCount=0; @@ -1117,6 +1323,12 @@ function getCellTextInfo(cell , ctx, option){ 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(wordGroup.inline==true && wordGroup.style!=null){ + cancelLine = wordGroup.style.cl; + underLine = wordGroup.style.un; + } + if(cancelLine!="0"){ wordGroup.cancelLine = {}; wordGroup.cancelLine.startX = left; diff --git a/src/global/getdata.js b/src/global/getdata.js index 5fa8401..dca78e8 100644 --- a/src/global/getdata.js +++ b/src/global/getdata.js @@ -261,4 +261,19 @@ export function getOrigincell(r, c, i) { return data[r][c]; +} + +export function getRealCellValue(r, c){ + let value = getcellvalue(r, c, null, "m"); + if(value == null){ + value = getcellvalue(r, c); + if(value==null){ + let ct = getcellvalue(r, c, null, "ct"); + if(ct!=null && ct.t=="inlineStr" && ct.s!=null && ct.s.length>0){ + value = ct.s; + } + } + } + + return value; } \ No newline at end of file diff --git a/src/index.html b/src/index.html index e109f38..98f47b3 100644 --- a/src/index.html +++ b/src/index.html @@ -37,7 +37,7 @@ // "ct":{ // "fa":"General", // "t":"inlineStr", - // "sharedStrings":[ + // "s":[ // { // "ff":"等线", //font family // "fc":"#fff000",//font color