Browse Source

fix(fix text whole text wrap bug): fix

master
wbfsa 5 years ago
parent
commit
ef3d324e80
  1. 36
      src/controllers/selection.js
  2. 295
      src/global/getRowlen.js
  3. 7
      src/global/validate.js
  4. 4
      src/index.html

36
src/controllers/selection.js

@ -8,7 +8,7 @@ import formula from '../global/formula';
import { getBorderInfoCompute } from '../global/border'; import { getBorderInfoCompute } from '../global/border';
import { getdatabyselection, getcellvalue, datagridgrowth } from '../global/getdata'; import { getdatabyselection, getcellvalue, datagridgrowth } from '../global/getdata';
import { rowlenByRange } from '../global/getRowlen'; 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 { jfrefreshgrid, jfrefreshgrid_pastcut } from '../global/refresh';
import { genarate, update } from '../global/format'; import { genarate, update } from '../global/format';
import { getSheetIndex } from '../methods/get'; import { getSheetIndex } from '../methods/get';
@ -801,14 +801,36 @@ const selection = {
for (let r = 0; r < rlen; r++) { for (let r = 0; r < rlen; r++) {
let x = [].concat(d[r + curR]); let x = [].concat(d[r + curR]);
for (let c = 0; c < clen; c++) { for (let c = 0; c < clen; c++) {
let cell = {};
let mask = genarate(dataChe[r][c]); let value = dataChe[r][c];
cell.v = mask[2]; if(isRealNum(value)){
cell.ct = mask[1]; value = parseFloat(value);
cell.m = mask[0]; }
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; d[r + curR] = x;
} }

295
src/global/getRowlen.js

@ -2,7 +2,7 @@ import { luckysheetfontformat } from '../utils/util';
import menuButton from '../controllers/menuButton'; import menuButton from '../controllers/menuButton';
import { getcellvalue,checkstatusByCell } from './getdata'; import { getcellvalue,checkstatusByCell } from './getdata';
import { colLocationByIndex } from './location'; import { colLocationByIndex } from './location';
import { hasChinaword, isRealNull } from './validate'; import { hasChinaword, isRealNull,checkWordByteLength } from './validate';
import { isInlineStringCell } from '../controllers/inlineString'; import { isInlineStringCell } from '../controllers/inlineString';
import Store from '../store'; import Store from '../store';
@ -649,7 +649,7 @@ function getCellTextInfo(cell , ctx, option){
textContent.rotate = rt; textContent.rotate = rt;
rt = Math.abs(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){ if(isInline){
while(i <= inlineStringArr.length){ while(i <= inlineStringArr.length){
let shareCells = inlineStringArr.slice(anchor, i); let shareCells = inlineStringArr.slice(anchor, i);
@ -722,6 +722,7 @@ function getCellTextInfo(cell , ctx, option){
} }
textWidth += sc.measureText.width; textWidth += sc.measureText.width;
textHeight += sc.measureText.actualBoundingBoxAscent+sc.measureText.actualBoundingBoxDescent; 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 let width = textWidth * Math.cos(rt*Math.PI/180) + textHeight * Math.sin(rt*Math.PI/180);//consider text box wdith and line height
@ -730,30 +731,70 @@ function getCellTextInfo(cell , ctx, option){
// textW_all += textW; // textW_all += textW;
let lastWord = shareCells[shareCells.length-1];
if(lastWord.v==" " || checkWordByteLength(lastWord.v)==2){
spaceOrTwoByteIndex = i;
}
if(rt!=0){//rotate if(rt!=0){//rotate
// console.log("all",anchor, i , str); // 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); // console.log("cut",anchor, i , str);
anchor = i-1;
for(let s=0;s<shareCells.length-1;s++){ if(spaceOrTwoByteIndex!=null && spaceOrTwoByteIndex<i){
let sc = shareCells[s];
text_all_split[splitIndex].push({ for(let s=0;s<spaceOrTwoByteIndex-anchor;s++){
content:sc.v, let sc = shareCells[s];
style:sc, text_all_split[splitIndex].push({
width:sc.measureText.width, content:sc.v,
height:sc.measureText.actualBoundingBoxAscent+sc.measureText.actualBoundingBoxDescent, style:sc,
left:0, width:sc.measureText.width,
top:0, height:sc.measureText.actualBoundingBoxAscent+sc.measureText.actualBoundingBoxDescent,
splitIndex:splitIndex, left:0,
asc:sc.measureText.actualBoundingBoxAscent, top:0,
desc:sc.measureText.actualBoundingBoxDescent, splitIndex:splitIndex,
inline:true, asc:sc.measureText.actualBoundingBoxAscent,
fs:sc.fs desc:sc.measureText.actualBoundingBoxDescent,
}); inline:true,
fs:sc.fs
});
}
anchor = spaceOrTwoByteIndex;
i = spaceOrTwoByteIndex + 1;
splitIndex +=1;
spaceOrTwoByteIndex = null;
}
else{
anchor = i-1;
for(let s=0;s<shareCells.length-1;s++){
let sc = shareCells[s];
text_all_split[splitIndex].push({
content:sc.v,
style:sc,
width:sc.measureText.width,
height:sc.measureText.actualBoundingBoxAscent+sc.measureText.actualBoundingBoxDescent,
left:0,
top:0,
splitIndex:splitIndex,
asc:sc.measureText.actualBoundingBoxAscent,
desc:sc.measureText.actualBoundingBoxDescent,
inline:true,
fs:sc.fs
});
}
splitIndex +=1;
} }
splitIndex +=1;
} }
else if(i== inlineStringArr.length){ else if(i== inlineStringArr.length){
// console.log("last",anchor, i , str); // console.log("last",anchor, i , str);
@ -786,28 +827,59 @@ function getCellTextInfo(cell , ctx, option){
} }
} }
else{//plain else{//plain
if((width+space_width)>cellWidth && text_all_split[splitIndex]!=null && tb=="2"){ if((width+space_width)>cellWidth && text_all_split[splitIndex]!=null && tb=="2" && i!= inlineStringArr.length){
if(spaceOrTwoByteIndex!=null && spaceOrTwoByteIndex<i){
for(let s=0;s<spaceOrTwoByteIndex-anchor;s++){
let sc = shareCells[s];
text_all_split[splitIndex].push({
content:sc.v,
style:sc,
width:sc.measureText.width,
height:sc.measureText.actualBoundingBoxAscent+sc.measureText.actualBoundingBoxDescent,
left:0,
top:0,
splitIndex:splitIndex,
asc:sc.measureText.actualBoundingBoxAscent,
desc:sc.measureText.actualBoundingBoxDescent,
inline:true,
fs:sc.fs
});
}
anchor = spaceOrTwoByteIndex;
anchor = i-1; i = spaceOrTwoByteIndex + 1;
splitIndex +=1;
spaceOrTwoByteIndex = null;
for(let s=0;s<shareCells.length-1;s++){ }
let sc = shareCells[s]; else{
text_all_split[splitIndex].push({ anchor = i-1;
content:sc.v,
style:sc, for(let s=0;s<shareCells.length-1;s++){
width:sc.measureText.width, let sc = shareCells[s];
height:sc.measureText.actualBoundingBoxAscent+sc.measureText.actualBoundingBoxDescent, text_all_split[splitIndex].push({
left:0, content:sc.v,
top:0, style:sc,
splitIndex:splitIndex, width:sc.measureText.width,
asc:sc.measureText.actualBoundingBoxAscent, height:sc.measureText.actualBoundingBoxAscent+sc.measureText.actualBoundingBoxDescent,
desc:sc.measureText.actualBoundingBoxDescent, left:0,
inline:true, top:0,
fs:sc.fs splitIndex:splitIndex,
}); asc:sc.measureText.actualBoundingBoxAscent,
desc:sc.measureText.actualBoundingBoxDescent,
inline:true,
fs:sc.fs
});
}
splitIndex +=1;
} }
splitIndex +=1;
} }
else if(i== inlineStringArr.length){ else if(i== inlineStringArr.length){
if(text_all_split[splitIndex]==null){ if(text_all_split[splitIndex]==null){
@ -854,29 +926,75 @@ function getCellTextInfo(cell , ctx, option){
let width = textWidth * Math.cos(rt*Math.PI/180) + textHeight * Math.sin(rt*Math.PI/180);//consider text box wdith and line height 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 let height = textWidth * Math.sin(rt*Math.PI/180) + textHeight * Math.cos(rt*Math.PI/180);//consider text box wdith and line height
let lastWord = str.substr(str.length-1,1);
if(lastWord==" " || checkWordByteLength(lastWord)==2){
spaceOrTwoByte = {
index:i,
str:preStr,
width:preTextWidth,
height:preTextHeight,
asc:preMeasureText.actualBoundingBoxAscent,
desc:preMeasureText.actualBoundingBoxDescent,
};
}
// textW_all += textW; // textW_all += textW;
// console.log(str,anchor,i);
if(rt!=0){//rotate if(rt!=0){//rotate
// console.log("all",anchor, i , str); // console.log("all",anchor, i , str);
if((height+space_height)>cellHeight && text_all_split[splitIndex]!=null){ if((height+space_height)>cellHeight && text_all_split[splitIndex]!=null && i!= value.length){
// console.log("cut",anchor, i , str); // console.log("cut",anchor, i , str);
anchor = i-1;
text_all_split[splitIndex].push({ if(spaceOrTwoByte!=null && spaceOrTwoByte.index<i){
content:preStr,
style:fontset, anchor = spaceOrTwoByte.index;
left:0,
top:0,
splitIndex:splitIndex,
height:preTextHeight,
width:preTextWidth,
asc:measureText.actualBoundingBoxAscent,
desc:measureText.actualBoundingBoxDescent,
fs:fontSize,
});
splitIndex +=1; i = spaceOrTwoByte.index + 1;
text_all_split[splitIndex].push({
content:spaceOrTwoByte.str,
style:fontset,
width:spaceOrTwoByte.width,
height:spaceOrTwoByte.height,
left:0,
top:0,
splitIndex:splitIndex,
asc:spaceOrTwoByte.asc,
desc:spaceOrTwoByte.desc,
fs:fontSize,
});
// console.log(1,anchor,i,splitIndex , spaceOrTwoByte.str);
splitIndex +=1;
spaceOrTwoByte = null;
}
else{
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,
});
// console.log(2,anchor,i, splitIndex, preStr);
splitIndex +=1;
}
} }
else if(i== value.length){ else if(i== value.length){
// console.log("last",anchor, i , str); // console.log("last",anchor, i , str);
@ -905,24 +1023,58 @@ function getCellTextInfo(cell , ctx, option){
} }
} }
else{//plain else{//plain
if((width+space_width)>cellWidth && text_all_split[splitIndex]!=null){ if((width+space_width)>cellWidth && text_all_split[splitIndex]!=null && i!= value.length){
// console.log(spaceOrTwoByte, i, anchor);
if(spaceOrTwoByte!=null && spaceOrTwoByte.index<i){
anchor = i-1; anchor = spaceOrTwoByte.index;
text_all_split[splitIndex].push({ i = spaceOrTwoByte.index + 1;
content:preStr,
style:fontset, text_all_split[splitIndex].push({
width:preTextWidth, content:spaceOrTwoByte.str,
height:preTextHeight, style:fontset,
left:0, width:spaceOrTwoByte.width,
top:0, height:spaceOrTwoByte.height,
splitIndex:splitIndex, left:0,
asc:measureText.actualBoundingBoxAscent, top:0,
desc:measureText.actualBoundingBoxDescent, splitIndex:splitIndex,
fs:fontSize, asc:spaceOrTwoByte.asc,
}); desc:spaceOrTwoByte.desc,
fs:fontSize,
});
splitIndex +=1;
spaceOrTwoByte = null;
}
else{
splitIndex +=1; spaceOrTwoByte = 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,
});
// console.log(2);
splitIndex +=1;
}
} }
else if(i== value.length){ else if(i== value.length){
if(text_all_split[splitIndex]==null){ if(text_all_split[splitIndex]==null){
@ -954,8 +1106,11 @@ function getCellTextInfo(cell , ctx, option){
preStr = str; preStr = str;
preTextHeight = textHeight; preTextHeight = textHeight;
preTextWidth = textWidth; preTextWidth = textWidth;
preMeasureText = measureText;
} }
// console.log(text_all_split)
} }
let split_all_size = [], oneLinemaxWordCount=0; let split_all_size = [], oneLinemaxWordCount=0;
@ -1479,6 +1634,8 @@ function drawLineInfo(wordGroup, cancelLine,underLine,option){
} }
} }
export { export {
rowlenByRange, rowlenByRange,
computeRowlenArr, computeRowlenArr,

7
src/global/validate.js

@ -188,6 +188,12 @@ function hasPartMC(cfg, r1, r2, c1, c2) {
return hasPartMC; return hasPartMC;
} }
//获取单个字符的字节数
function checkWordByteLength(value) {
return Math.ceil(value.charCodeAt().toString(2).length / 8);
}
export { export {
isRealNull, isRealNull,
isRealNum, isRealNum,
@ -195,4 +201,5 @@ export {
hasChinaword, hasChinaword,
isEditMode, isEditMode,
hasPartMC, hasPartMC,
checkWordByteLength
} }

4
src/index.html

@ -55,7 +55,7 @@
], ],
data: data:
[sheetCell,sheetFormula,sheetConditionFormat,sheetSparkline,sheetTable,sheetComment,sheetPivotTableData,sheetPivotTable,sheetChart,sheetPicture,sheetDataVerification] [sheetCell,sheetFormula,sheetConditionFormat,sheetSparkline,sheetTable,sheetComment,sheetPivotTableData,sheetPivotTable,sheetChart,sheetPicture,sheetDataVerification]
/*[{"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":[ /*[{"name":"Sheet1","config":{"columnlen":{"0":241},"rowlen":{"0":81,"17":100}},"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, {"r":0,"c":0,
"v":{ "v":{
"ct":{ "ct":{
@ -93,7 +93,7 @@
"qp":1, "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"}} {"r":17,"c":2,"v":{"v":"Luckysheet is good project, this is true","ct":{"fa":"General","t":"g"},"bg":null,"bl":0,"it":0,"ff":0,"fs":"11","fc":"rgb(51, 51, 51)","ht":1,"vt":1,tb:2,"m":"Luckysheet"}}
],"calcChain":[]}]*/ ],"calcChain":[]}]*/
/* /*

Loading…
Cancel
Save