Browse Source

fix(fix text whole text wrap bug): fix

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

38
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;
}

313
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;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
});
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;
i = spaceOrTwoByteIndex + 1;
splitIndex +=1;
spaceOrTwoByteIndex = null;
}
splitIndex +=1;
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;
}
}
else if(i== inlineStringArr.length){
// console.log("last",anchor, i , str);
@ -786,28 +827,59 @@ function getCellTextInfo(cell , ctx, option){
}
}
else{//plain
if((width+space_width)>cellWidth && 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;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
});
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;
i = spaceOrTwoByteIndex + 1;
splitIndex +=1;
spaceOrTwoByteIndex = null;
}
else{
anchor = i-1;
splitIndex +=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;
}
}
else if(i== inlineStringArr.length){
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 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;
// console.log(str,anchor,i);
if(rt!=0){//rotate
// 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);
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.index<i){
anchor = spaceOrTwoByte.index;
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){
// console.log("last",anchor, i , str);
@ -905,24 +1023,58 @@ function getCellTextInfo(cell , ctx, option){
}
}
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: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<i){
anchor = spaceOrTwoByte.index;
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,
});
splitIndex +=1;
spaceOrTwoByte = null;
}
else{
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){
if(text_all_split[splitIndex]==null){
@ -954,8 +1106,11 @@ function getCellTextInfo(cell , ctx, option){
preStr = str;
preTextHeight = textHeight;
preTextWidth = textWidth;
preMeasureText = measureText;
}
// console.log(text_all_split)
}
let split_all_size = [], oneLinemaxWordCount=0;
@ -1479,6 +1634,8 @@ function drawLineInfo(wordGroup, cancelLine,underLine,option){
}
}
export {
rowlenByRange,
computeRowlenArr,

7
src/global/validate.js

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

4
src/index.html

@ -55,7 +55,7 @@
],
data:
[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,
"v":{
"ct":{
@ -93,7 +93,7 @@
"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":[]}]*/
/*

Loading…
Cancel
Save