From 2e40d1f14da1098742f78aa7f6dfe005488c9f32 Mon Sep 17 00:00:00 2001 From: wbfsa Date: Tue, 8 Sep 2020 00:45:44 +0800 Subject: [PATCH 1/7] refactor(iniline): inline --- src/global/getRowlen.js | 138 +++++++++++++++++++++++----------------- 1 file changed, 80 insertions(+), 58 deletions(-) diff --git a/src/global/getRowlen.js b/src/global/getRowlen.js index 88b1919..e2753f5 100644 --- a/src/global/getRowlen.js +++ b/src/global/getRowlen.js @@ -416,91 +416,113 @@ function getCellTextInfo(cell , ctx, option){ textContent.rotate = rt; rt = Math.abs(rt); - let anchor = 0; + let anchor = 0, preHeight = 0, preWidth=0, preStr; for(let i = 1; i <= value.length; i++){ - let str = value.substr(anchor, i); + let str = value.substring(anchor, i); let measureText = getMeasureText(str, ctx); - let textW = measureText.width; - let textH = measureText.actualBoundingBoxAscent+measureText.actualBoundingBoxDescent; + let textWidth = measureText.width; + let textHeight = measureText.actualBoundingBoxAscent+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 + + 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; + if(text_all_split[splitIndex]==null){ + text_all_split[splitIndex]= []; + } if(rt!=0){ - text_all_cache += textH; - if(text_all_cache>cellHeight && text_all_split[splitIndex]!=null){ - text_all_splitLen.push(text_all_cache-textH); - text_all_cache = textH; - splitIndex +=1; - - anchor = i; + if(height>cellHeight){ + anchor = i-1; + + text_all_split[splitIndex].push({ + content:preStr, + style:fontset, + width:preWidth, + height:preHeight, + left:0, + top:0, + splitIndex:splitIndex, + }); - if(i== value.length){ - textH_all_ColumnHeight.push(textH_all_cache); - } - - if(textH_all_Column[colIndex]==null){ - text_all_split[colIndex]= []; - } + splitIndex +=1; + } + else if(i== value.length){ text_all_split[splitIndex].push({ - content:vArr[i], + content:str, style:fontset, - width:textW, - height:textH, + width:width, + height:height, left:0, top:0, - colIndex:colIndex, + colIndex:splitIndex, }); } } else{ + if(width>cellWidth){ - } - + anchor = i-1; + + text_all_split[splitIndex].push({ + content:preStr, + style:fontset, + width:preWidth, + height:preHeight, + left:0, + top:0, + splitIndex:splitIndex, + }); - if(i== vArr.length-1){ - textH_all_ColumnHeight.push(textH_all_cache); + splitIndex +=1; + } + else if(i== value.length){ + + text_all_split[splitIndex].push({ + content:str, + style:fontset, + width:width, + height:height, + left:0, + top:0, + colIndex:splitIndex, + }); + } } - if(textH_all_Column[colIndex]==null){ - text_all_split[colIndex]= []; - } + preWidth = width; + preHeight = height; + preStr = str; - text_all_split[splitIndex].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;c Date: Tue, 8 Sep 2020 15:17:52 +0800 Subject: [PATCH 2/7] fix(bugs): fix issue #27 #29 --- src/controllers/formulaBar.js | 4 ++++ src/controllers/handler.js | 2 +- src/controllers/keyboard.js | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/controllers/formulaBar.js b/src/controllers/formulaBar.js index b2c5aa2..2919942 100644 --- a/src/controllers/formulaBar.js +++ b/src/controllers/formulaBar.js @@ -33,6 +33,10 @@ export function formulaBarInitial(){ let row_index = last["row_focus"], col_index = last["column_focus"]; + let $input = $("#luckysheet-rich-text-editor"),value = $input.text(); + if(value) { + formula.updatecell(row_index, col_index); + } luckysheetupdateCell(row_index, col_index, Store.flowdata, null, true); formula.rangeResizeTo = $("#luckysheet-functionbox-cell"); } diff --git a/src/controllers/handler.js b/src/controllers/handler.js index a4c7fc4..0ff6f83 100644 --- a/src/controllers/handler.js +++ b/src/controllers/handler.js @@ -4580,7 +4580,7 @@ export default function luckysheetHandler() { } } - let fs = Math.floor(parseInt($td.css("font-size")) * 72 / dpi_y) + 1; + let fs = Math.floor(parseInt($td.css("font-size")) * 72 / 96) + 1; cell.fs = fs; let fc = $td.css("color"); diff --git a/src/controllers/keyboard.js b/src/controllers/keyboard.js index 8a334ed..4db7733 100644 --- a/src/controllers/keyboard.js +++ b/src/controllers/keyboard.js @@ -834,7 +834,7 @@ export function keyboardInitial(){ else if (kcode == keycode.RIGHT && parseInt($inputbox.css("top")) > 0) { formulaMoveEvent("right", ctrlKey, shiftKey); } - else if (!((kcode >= 112 && kcode <= 123) || kcode <= 46 || kcode == 144 || kcode == 108 || event.ctrlKey || event.altKey || (event.shiftKey && (kcode == 37 || kcode == 38 || kcode == 39 || kcode == 40))) || kcode == 8 || kcode == 32 || kcode == 46 || (event.ctrlKey && kcode == 86)) { + else if (!((kcode >= 112 && kcode <= 123) || kcode <= 46 || kcode == 144 || kcode == 108 || event.ctrlKey || event.altKey || (event.shiftKey && (kcode == 37 || kcode == 38 || kcode == 39 || kcode == 40 || kcode == keycode.WIN || kcode == keycode.WIN_R || kcode == keycode.MENU))) || kcode == 8 || kcode == 32 || kcode == 46 || (event.ctrlKey && kcode == 86)) { formula.functionInputHanddler($("#luckysheet-functionbox-cell"), $("#luckysheet-rich-text-editor"), kcode); setCenterInputPosition(Store.luckysheetCellUpdate[0], Store.luckysheetCellUpdate[1], Store.flowdata); } From 40550d6e59c44e0f47e23f8b5fac4c5e79a5c122 Mon Sep 17 00:00:00 2001 From: liuyang Date: Tue, 8 Sep 2020 15:34:04 +0800 Subject: [PATCH 3/7] fix(render): render --- src/global/draw.js | 4 ++-- src/global/getRowlen.js | 43 ++++++++++++++++++++++++----------------- 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/src/global/draw.js b/src/global/draw.js index dba093a..3dc866e 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 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; @@ -1600,7 +1600,7 @@ let cellRender = function(r, c, start_r, start_c, end_r, end_c, value, luckyshee } //非空白单元格渲染 -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; diff --git a/src/global/getRowlen.js b/src/global/getRowlen.js index e2753f5..8e54887 100644 --- a/src/global/getRowlen.js +++ b/src/global/getRowlen.js @@ -433,7 +433,7 @@ function getCellTextInfo(cell , ctx, option){ text_all_split[splitIndex]= []; } - if(rt!=0){ + if(rt!=0){//rotate if(height>cellHeight){ anchor = i-1; @@ -462,7 +462,7 @@ function getCellTextInfo(cell , ctx, option){ }); } } - else{ + else{//plain if(width>cellWidth){ anchor = i-1; @@ -499,22 +499,27 @@ function getCellTextInfo(cell , ctx, option){ } - // let textH_all_ColumWidth = []; - // for(let i = 0; i < text_all_split.length; i++){ - // let splitLen = text_all_split[i]; - // let col = splitLen[i], colMaxW=0; - - // if(rt!=0){ - - // } - // for(let c=0;c Date: Tue, 8 Sep 2020 17:41:51 +0800 Subject: [PATCH 4/7] refactor(rander): reander --- src/global/getRowlen.js | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/global/getRowlen.js b/src/global/getRowlen.js index 8e54887..f0566e4 100644 --- a/src/global/getRowlen.js +++ b/src/global/getRowlen.js @@ -416,7 +416,7 @@ function getCellTextInfo(cell , ctx, option){ textContent.rotate = rt; rt = Math.abs(rt); - let anchor = 0, preHeight = 0, preWidth=0, preStr; + let anchor = 0, preHeight = 0, preWidth=0, preStr, preTextHeight; for(let i = 1; i <= value.length; i++){ let str = value.substring(anchor, i); let measureText = getMeasureText(str, ctx); @@ -445,6 +445,7 @@ function getCellTextInfo(cell , ctx, option){ left:0, top:0, splitIndex:splitIndex, + textHeight:preTextHeight }); splitIndex +=1; @@ -458,7 +459,8 @@ function getCellTextInfo(cell , ctx, option){ height:height, left:0, top:0, - colIndex:splitIndex, + splitIndex:splitIndex, + textHeight:textHeight }); } } @@ -488,7 +490,7 @@ function getCellTextInfo(cell , ctx, option){ height:height, left:0, top:0, - colIndex:splitIndex, + splitIndex:splitIndex, }); } } @@ -496,18 +498,20 @@ function getCellTextInfo(cell , ctx, option){ preWidth = width; preHeight = height; preStr = str; + preTextHeight = textHeight; } let split_all_size = []; for(let i = 0; i <= splitIndex; i++){ let splitLists = text_all_split[i]; - let sWidth = 0, sHeight=0; + let sWidth = 0, sHeight=0, textHeight=0; for(let s=0;s Date: Wed, 9 Sep 2020 10:07:55 +0800 Subject: [PATCH 5/7] fix(bug): bug bug --- src/global/extend.js | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/src/global/extend.js b/src/global/extend.js index 8b27377..2591c65 100644 --- a/src/global/extend.js +++ b/src/global/extend.js @@ -105,8 +105,6 @@ function luckysheetextendtable(type, index, value, direction, order) { d[calc_r][calc_c].f = functionStr; } - // calc.func[2] = functionStr; - if(direction == "lefttop"){ if(calc_r >= index){ calc.r += value; @@ -127,8 +125,6 @@ function luckysheetextendtable(type, index, value, direction, order) { d[calc_r][calc_c].f = functionStr; } - // calc.func[2] = functionStr; - if(direction == "lefttop"){ if(calc_c >= index){ calc.c += value; @@ -900,8 +896,6 @@ function luckysheetdeletetable(type, st, ed, order) { d[calc_r][calc_c].f = functionStr; } - // calc.func[2] = functionStr; - if(calc_r > ed){ calc.r = calc_r - slen; } @@ -917,8 +911,6 @@ function luckysheetdeletetable(type, st, ed, order) { d[calc_r][calc_c].f = functionStr; } - // calc.func[2] = functionStr; - if(calc_c > ed){ calc.c = calc_c - slen; } @@ -1545,20 +1537,20 @@ function luckysheetDeleteCell(type, str, edr, stc, edc, order) { let calc = $.extend(true, {}, calcChain[i]); let calc_r = calc.r, calc_c = calc.c, calc_i = calc.index, calc_funcStr = getcellFormula(calc_r, calc_c, calc_i); - if((calc_r < str || calc_r > edr) && (calc_c < stc || calc_c > edc)){ + if(calc_r < str || calc_r > edr || calc_c < stc || calc_c > edc){ let functionStr; if(type == 'moveLeft'){ functionStr = "=" + formula.functionStrChange(calc_funcStr, "del", "col", null, stc, clen); - if(calc_c > edc){ + if(calc_c > edc && calc_r >= str && calc_r <= edr){ calc.c = calc_c - clen; } } else if(type == 'moveUp'){ functionStr = "=" + formula.functionStrChange(calc_funcStr, "del", "row", null, str, rlen); - if(calc_r > edr){ + if(calc_r > edr && calc_c >= stc && calc_c <= edc){ calc.r = calc_r - rlen; } } @@ -1567,8 +1559,6 @@ function luckysheetDeleteCell(type, str, edr, stc, edc, order) { d[calc_r][calc_c].f = functionStr; } - // calc.func[2] = functionStr; - newCalcChain.push(calc); } } From 6c84420ad4461281ba87378af41cde0e5a7fee93 Mon Sep 17 00:00:00 2001 From: wpxp123456 <2677556700@qq.com> Date: Wed, 9 Sep 2020 10:19:14 +0800 Subject: [PATCH 6/7] fix(formula bug): formula bug formula bug --- src/function/functionImplementation.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/function/functionImplementation.js b/src/function/functionImplementation.js index 3df4cdd..3f2280b 100644 --- a/src/function/functionImplementation.js +++ b/src/function/functionImplementation.js @@ -483,7 +483,7 @@ const functionImplementation = { try { //身份证号 - var UUserCard = func_methods.getFirstValue(arguments[0]); + var UUserCard = func_methods.getFirstValue(arguments[0]).toString(); if(valueIsError(UUserCard)){ return UUserCard; } @@ -523,7 +523,7 @@ const functionImplementation = { try { //身份证号 - var UUserCard = func_methods.getFirstValue(arguments[0]); + var UUserCard = func_methods.getFirstValue(arguments[0]).toString(); if(valueIsError(UUserCard)){ return UUserCard; } @@ -595,7 +595,7 @@ const functionImplementation = { try { //身份证号 - var UUserCard = func_methods.getFirstValue(arguments[0]); + var UUserCard = func_methods.getFirstValue(arguments[0]).toString(); if(valueIsError(UUserCard)){ return UUserCard; } @@ -637,7 +637,7 @@ const functionImplementation = { try { //身份证号 - var UUserCard = func_methods.getFirstValue(arguments[0]); + var UUserCard = func_methods.getFirstValue(arguments[0]).toString(); if(valueIsError(UUserCard)){ return UUserCard; } From 6da076dc56071020245d67547ce6dd13eb41dc8d Mon Sep 17 00:00:00 2001 From: liuyang Date: Wed, 9 Sep 2020 18:17:41 +0800 Subject: [PATCH 7/7] refactor(inline string develop): develop --- src/global/getRowlen.js | 142 ++++++++++++++++++++++++++++++---------- 1 file changed, 106 insertions(+), 36 deletions(-) diff --git a/src/global/getRowlen.js b/src/global/getRowlen.js index f0566e4..66197e1 100644 --- a/src/global/getRowlen.js +++ b/src/global/getRowlen.js @@ -416,7 +416,7 @@ function getCellTextInfo(cell , ctx, option){ textContent.rotate = rt; rt = Math.abs(rt); - let anchor = 0, preHeight = 0, preWidth=0, preStr, preTextHeight; + let anchor = 0, preHeight = 0, preWidth=0, preStr, preTextHeight, preTextWidth; for(let i = 1; i <= value.length; i++){ let str = value.substring(anchor, i); let measureText = getMeasureText(str, ctx); @@ -434,7 +434,7 @@ function getCellTextInfo(cell , ctx, option){ } if(rt!=0){//rotate - if(height>cellHeight){ + if((height+space_height)>cellHeight){ anchor = i-1; text_all_split[splitIndex].push({ @@ -445,7 +445,10 @@ function getCellTextInfo(cell , ctx, option){ left:0, top:0, splitIndex:splitIndex, - textHeight:preTextHeight + textHeight:preTextHeight, + textWidth:preTextWidth, + asc:measureText.actualBoundingBoxAscent, + desc:measureText.actualBoundingBoxDescent }); splitIndex +=1; @@ -460,12 +463,15 @@ function getCellTextInfo(cell , ctx, option){ left:0, top:0, splitIndex:splitIndex, - textHeight:textHeight + textHeight:textHeight, + textWidth:textWidth, + asc:measureText.actualBoundingBoxAscent, + desc:measureText.actualBoundingBoxDescent }); } } else{//plain - if(width>cellWidth){ + if((width+space_width)>cellWidth){ anchor = i-1; @@ -477,6 +483,8 @@ function getCellTextInfo(cell , ctx, option){ left:0, top:0, splitIndex:splitIndex, + asc:measureText.actualBoundingBoxAscent, + desc:measureText.actualBoundingBoxDescent }); splitIndex +=1; @@ -491,6 +499,8 @@ function getCellTextInfo(cell , ctx, option){ left:0, top:0, splitIndex:splitIndex, + asc:measureText.actualBoundingBoxAscent, + desc:measureText.actualBoundingBoxDescent }); } } @@ -499,15 +509,21 @@ function getCellTextInfo(cell , ctx, option){ preHeight = height; preStr = str; preTextHeight = textHeight; + preTextWidth = textWidth; } let split_all_size = []; - for(let i = 0; i <= splitIndex; i++){ + console.log(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, textHeight=0; for(let s=0;s