From ef3d324e80bc648080b1e5a53108b30dccf74520 Mon Sep 17 00:00:00 2001 From: wbfsa Date: Tue, 20 Oct 2020 01:48:19 +0800 Subject: [PATCH] fix(fix text whole text wrap bug): fix --- src/controllers/selection.js | 38 ++++- src/global/getRowlen.js | 313 ++++++++++++++++++++++++++--------- src/global/validate.js | 7 + src/index.html | 4 +- 4 files changed, 274 insertions(+), 88 deletions(-) diff --git a/src/controllers/selection.js b/src/controllers/selection.js index c66fecfd0..191d9fea6 100644 --- a/src/controllers/selection.js +++ b/src/controllers/selection.js @@ -8,7 +8,7 @@ import formula from '../global/formula'; import { getBorderInfoCompute } from '../global/border'; import { getdatabyselection, getcellvalue, datagridgrowth } from '../global/getdata'; import { rowlenByRange } from '../global/getRowlen'; -import { isEditMode, hasPartMC } from '../global/validate'; +import { isEditMode, hasPartMC, isRealNum } from '../global/validate'; import { jfrefreshgrid, jfrefreshgrid_pastcut } from '../global/refresh'; import { genarate, update } from '../global/format'; import { getSheetIndex } from '../methods/get'; @@ -801,14 +801,36 @@ const selection = { for (let r = 0; r < rlen; r++) { let x = [].concat(d[r + curR]); for (let c = 0; c < clen; c++) { - let cell = {}; - - let mask = genarate(dataChe[r][c]); - cell.v = mask[2]; - cell.ct = mask[1]; - cell.m = mask[0]; + + let value = dataChe[r][c]; + if(isRealNum(value)){ + value = parseFloat(value); + } + let originCell = x[c + curC]; + if(originCell instanceof Object){ + originCell.v = value; + if(originCell.ct!=null && originCell.ct.fa!=null){ + originCell.m = update(originCell["ct"]["fa"], value); + } + else{ + originCell.m = value; + } + + if(originCell.f!=null && originCell.f.length>0){ + originCell.f = ""; + formula.delFunctionGroup(r + curR,c + curC,Store.currentSheetIndex); + } + } + else{ + let cell = {}; + let mask = genarate(value); + cell.v = mask[2]; + cell.ct = mask[1]; + cell.m = mask[0]; - x[c + curC] = cell; + x[c + curC] = cell; + } + } d[r + curR] = x; } diff --git a/src/global/getRowlen.js b/src/global/getRowlen.js index b7e1e76f1..63e6fd73a 100644 --- a/src/global/getRowlen.js +++ b/src/global/getRowlen.js @@ -2,7 +2,7 @@ import { luckysheetfontformat } from '../utils/util'; import menuButton from '../controllers/menuButton'; import { getcellvalue,checkstatusByCell } from './getdata'; import { colLocationByIndex } from './location'; -import { hasChinaword, isRealNull } from './validate'; +import { hasChinaword, isRealNull,checkWordByteLength } from './validate'; import { isInlineStringCell } from '../controllers/inlineString'; import Store from '../store'; @@ -649,7 +649,7 @@ function getCellTextInfo(cell , ctx, option){ textContent.rotate = rt; rt = Math.abs(rt); - let anchor = 0, preHeight = 0, preWidth=0, preStr, preTextHeight, preTextWidth, i=1, wrapStyle={}; + let anchor = 0, preHeight = 0, preWidth=0, preStr, preTextHeight, preTextWidth, preMeasureText, i=1, wrapStyle={}, spaceOrTwoByte=null, spaceOrTwoByteIndex=null; if(isInline){ while(i <= inlineStringArr.length){ let shareCells = inlineStringArr.slice(anchor, i); @@ -722,6 +722,7 @@ function getCellTextInfo(cell , ctx, option){ } textWidth += sc.measureText.width; textHeight += 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 @@ -729,31 +730,71 @@ function getCellTextInfo(cell , ctx, option){ 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; + + + let lastWord = shareCells[shareCells.length-1]; + if(lastWord.v==" " || checkWordByteLength(lastWord.v)==2){ + spaceOrTwoByteIndex = i; + } + if(rt!=0){//rotate // console.log("all",anchor, i , str); - if((height+space_height)>cellHeight && text_all_split[splitIndex]!=null && tb=="2"){ + // console.log(height,space_height, cellHeight); + if((height+space_height)>cellHeight && text_all_split[splitIndex]!=null && tb=="2" && i!= inlineStringArr.length){ // console.log("cut",anchor, i , str); - anchor = i-1; - - for(let s=0;scellWidth && text_all_split[splitIndex]!=null && tb=="2"){ - - anchor = i-1; + if((width+space_width)>cellWidth && text_all_split[splitIndex]!=null && tb=="2" && i!= inlineStringArr.length){ + - for(let s=0;scellHeight && text_all_split[splitIndex]!=null){ + if((height+space_height)>cellHeight && text_all_split[splitIndex]!=null && i!= value.length){ // console.log("cut",anchor, i , str); - anchor = i-1; - - text_all_split[splitIndex].push({ - content:preStr, - style:fontset, - left:0, - top:0, - splitIndex:splitIndex, - height:preTextHeight, - width:preTextWidth, - asc:measureText.actualBoundingBoxAscent, - desc:measureText.actualBoundingBoxDescent, - fs:fontSize, - }); - - splitIndex +=1; + + if(spaceOrTwoByte!=null && spaceOrTwoByte.indexcellWidth && text_all_split[splitIndex]!=null){ - - anchor = i-1; - - text_all_split[splitIndex].push({ - content:preStr, - style:fontset, - width:preTextWidth, - height:preTextHeight, - left:0, - top:0, - splitIndex:splitIndex, - asc:measureText.actualBoundingBoxAscent, - desc:measureText.actualBoundingBoxDescent, - fs:fontSize, - }); - - splitIndex +=1; + if((width+space_width)>cellWidth && text_all_split[splitIndex]!=null && i!= value.length){ + // console.log(spaceOrTwoByte, i, anchor); + if(spaceOrTwoByte!=null && spaceOrTwoByte.index