Browse Source

refactor(inline string): develop

master
liuyang 5 years ago
parent
commit
32fd31d989
  1. 153
      src/global/getRowlen.js
  2. 42
      src/index.html

153
src/global/getRowlen.js

@ -325,12 +325,16 @@ function getCellTextInfo(cell , ctx, option){
let scfontset = luckysheetfontformat(shareCell); let scfontset = luckysheetfontformat(shareCell);
let fc = shareCell.fc, cl=shareCell.cl,un = shareCell.un, v = shareCell.v; let fc = shareCell.fc, cl=shareCell.cl,un = shareCell.un, v = shareCell.v;
v = v.replace(/\r\n/g, "_x000D_").replace(/
/g, "_x000D_").replace(/\r/g, "_x000D_").replace(/\n/g, "_x000D_"); v = v.replace(/\r\n/g, "_x000D_").replace(/
/g, "_x000D_").replace(/\r/g, "_x000D_").replace(/\n/g, "_x000D_");
let splitArr = v.split("_x000D_"); let splitArr = v.split("_x000D_"), preNewValue=null;
for(let x=0;x<splitArr.length;x++){ for(let x=0;x<splitArr.length;x++){
let newValue = splitArr[x]; let newValue = splitArr[x];
if(newValue==""){ if(newValue==""){
inlineStringArr.push({ inlineStringArr.push({
fontset:scfontset,
fc:fc==null?"#000":fc,
cl:cl==null?0:cl,
un:un==null?0:un,
wrap:true wrap:true
}); });
similarIndex++; similarIndex++;
@ -351,13 +355,19 @@ function getCellTextInfo(cell , ctx, option){
} }
// if(x!=splitArr.length-1){ if(x!=splitArr.length-1 && preNewValue!=""){
// inlineStringArr.push({ inlineStringArr.push({
// wrap:true fontset:scfontset,
// }); fc:fc==null?"#000":fc,
// similarIndex++; cl:cl==null?0:cl,
// } un:un==null?0:un,
wrap:true
});
similarIndex++;
}
} }
preNewValue = newValue;
} }
@ -547,39 +557,66 @@ 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; let anchor = 0, preHeight = 0, preWidth=0, preStr, preTextHeight, preTextWidth, i=1, wrapStyle={};
if(isInline){ if(isInline){
while(i <= inlineStringArr.length){ while(i <= inlineStringArr.length){
let shareCells = inlineStringArr.slice(anchor, i); let shareCells = inlineStringArr.slice(anchor, i);
if(shareCells[shareCells.length-1].wrap===true){ if(shareCells[shareCells.length-1].wrap===true){
anchor = i-1; anchor = i;
for(let s=0;s<shareCells.length-1;s++){ if(shareCells.length>1){
let sc = shareCells[s]; for(let s=0;s<shareCells.length-1;s++){
let item = { let sc = shareCells[s];
content:sc.v, let item = {
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,
}
// if(rt!=0){//rotate
// item.textHeight = sc.textHeight;
// item.textWidth = sc.textWidth;
// }
text_all_split[splitIndex].push(item);
}
}
if(shareCells.length==1 || i==inlineStringArr.length){
let sc = shareCells[0];
let measureText = getMeasureText("M", ctx, sc.fontset);
if(text_all_split[splitIndex]==null){
text_all_split[splitIndex] = [];
}
text_all_split[splitIndex].push({
content:"",
style:sc, style:sc,
width:sc.width, width:measureText.width,
height:sc.height, height:measureText.actualBoundingBoxAscent+measureText.actualBoundingBoxDescent,
left:0, left:0,
top:0, top:0,
splitIndex:splitIndex, splitIndex:splitIndex,
asc:sc.measureText.actualBoundingBoxAscent, asc:measureText.actualBoundingBoxAscent,
desc:sc.measureText.actualBoundingBoxDescent, desc:measureText.actualBoundingBoxDescent,
inline:true, inline:true,
} wrap:true,
});
}
if(rt!=0){//rotate
item.textHeight = sc.textHeight;
item.textWidth = sc.textWidth;
}
text_all_split[splitIndex].push(item);
}
splitIndex +=1; splitIndex +=1;
i++;
continue; continue;
} }
@ -601,7 +638,7 @@ function getCellTextInfo(cell , ctx, option){
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 && tb=="2"){
// console.log("cut",anchor, i , str); // console.log("cut",anchor, i , str);
anchor = i-1; anchor = i-1;
@ -610,13 +647,11 @@ function getCellTextInfo(cell , ctx, option){
text_all_split[splitIndex].push({ text_all_split[splitIndex].push({
content:sc.v, content:sc.v,
style:sc, style:sc,
width:sc.width, width:sc.measureText.width,
height:sc.height, height:sc.measureText.actualBoundingBoxAscent+sc.measureText.actualBoundingBoxDescent,
left:0, left:0,
top:0, top:0,
splitIndex:splitIndex, splitIndex:splitIndex,
textHeight:sc.textHeight,
textWidth:sc.textWidth,
asc:sc.measureText.actualBoundingBoxAscent, asc:sc.measureText.actualBoundingBoxAscent,
desc:sc.measureText.actualBoundingBoxDescent, desc:sc.measureText.actualBoundingBoxDescent,
inline:true, inline:true,
@ -635,13 +670,11 @@ function getCellTextInfo(cell , ctx, option){
text_all_split[splitIndex].push({ text_all_split[splitIndex].push({
content:sc.v, content:sc.v,
style:sc, style:sc,
width:sc.width, width:sc.measureText.width,
height:sc.height, height:sc.measureText.actualBoundingBoxAscent+sc.measureText.actualBoundingBoxDescent,
left:0, left:0,
top:0, top:0,
splitIndex:splitIndex, splitIndex:splitIndex,
textHeight:sc.textHeight,
textWidth:sc.textWidth,
asc:sc.measureText.actualBoundingBoxAscent, asc:sc.measureText.actualBoundingBoxAscent,
desc:sc.measureText.actualBoundingBoxDescent, desc:sc.measureText.actualBoundingBoxDescent,
inline:true, inline:true,
@ -657,7 +690,7 @@ 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 && tb=="2"){
anchor = i-1; anchor = i-1;
@ -666,8 +699,8 @@ function getCellTextInfo(cell , ctx, option){
text_all_split[splitIndex].push({ text_all_split[splitIndex].push({
content:sc.v, content:sc.v,
style:sc, style:sc,
width:sc.width, width:sc.measureText.width,
height:sc.height, height:sc.measureText.actualBoundingBoxAscent+sc.measureText.actualBoundingBoxDescent,
left:0, left:0,
top:0, top:0,
splitIndex:splitIndex, splitIndex:splitIndex,
@ -689,8 +722,8 @@ function getCellTextInfo(cell , ctx, option){
text_all_split[splitIndex].push({ text_all_split[splitIndex].push({
content:sc.v, content:sc.v,
style:sc, style:sc,
width:sc.width, width:sc.measureText.width,
height:sc.height, height:sc.measureText.actualBoundingBoxAscent+sc.measureText.actualBoundingBoxDescent,
left:0, left:0,
top:0, top:0,
splitIndex:splitIndex, splitIndex:splitIndex,
@ -735,13 +768,11 @@ function getCellTextInfo(cell , ctx, option){
text_all_split[splitIndex].push({ text_all_split[splitIndex].push({
content:preStr, content:preStr,
style:fontset, style:fontset,
width:preWidth,
height:preHeight,
left:0, left:0,
top:0, top:0,
splitIndex:splitIndex, splitIndex:splitIndex,
textHeight:preTextHeight, height:preTextHeight,
textWidth:preTextWidth, width:preTextWidth,
asc:measureText.actualBoundingBoxAscent, asc:measureText.actualBoundingBoxAscent,
desc:measureText.actualBoundingBoxDescent desc:measureText.actualBoundingBoxDescent
}); });
@ -756,13 +787,11 @@ function getCellTextInfo(cell , ctx, option){
text_all_split[splitIndex].push({ text_all_split[splitIndex].push({
content:str, content:str,
style:fontset, style:fontset,
width:width,
height:height,
left:0, left:0,
top:0, top:0,
splitIndex:splitIndex, splitIndex:splitIndex,
textHeight:textHeight, height:textHeight,
textWidth:textWidth, width:textWidth,
asc:measureText.actualBoundingBoxAscent, asc:measureText.actualBoundingBoxAscent,
desc:measureText.actualBoundingBoxDescent desc:measureText.actualBoundingBoxDescent
}); });
@ -783,8 +812,8 @@ function getCellTextInfo(cell , ctx, option){
text_all_split[splitIndex].push({ text_all_split[splitIndex].push({
content:preStr, content:preStr,
style:fontset, style:fontset,
width:preWidth, width:preTextWidth,
height:preHeight, height:preTextHeight,
left:0, left:0,
top:0, top:0,
splitIndex:splitIndex, splitIndex:splitIndex,
@ -801,8 +830,8 @@ function getCellTextInfo(cell , ctx, option){
text_all_split[splitIndex].push({ text_all_split[splitIndex].push({
content:str, content:str,
style:fontset, style:fontset,
width:width, width:textWidth,
height:height, height:textHeight,
left:0, left:0,
top:0, top:0,
splitIndex:splitIndex, splitIndex:splitIndex,
@ -820,8 +849,6 @@ function getCellTextInfo(cell , ctx, option){
} }
} }
preWidth = width;
preHeight = height;
preStr = str; preStr = str;
preTextHeight = textHeight; preTextHeight = textHeight;
preTextWidth = textWidth; preTextWidth = textWidth;
@ -841,8 +868,8 @@ function getCellTextInfo(cell , ctx, option){
for(let s=0;s<splitLists.length;s++){ for(let s=0;s<splitLists.length;s++){
let sp = splitLists[s]; let sp = splitLists[s];
if(rt!=0){//rotate if(rt!=0){//rotate
sWidth += sp.textWidth; sWidth += sp.width;
sHeight = Math.max(sHeight, sp.textHeight-(supportBoundBox?sp.desc:0)); sHeight = Math.max(sHeight, sp.height-(supportBoundBox?sp.desc:0));
} }
else{//plain else{//plain
sWidth += sp.width; sWidth += sp.width;
@ -878,7 +905,7 @@ function getCellTextInfo(cell , ctx, option){
wordCount: maxWordCount wordCount: maxWordCount
}); });
} }
// console.log(textH_all,textW_all,textW_all_inner);
// let cumColumnWidth = 0; // let cumColumnWidth = 0;
let cumWordHeight = 0,cumColumnWidth = 0; let cumWordHeight = 0,cumColumnWidth = 0;
let rtPI = rt*Math.PI/180; let rtPI = rt*Math.PI/180;
@ -978,9 +1005,9 @@ function getCellTextInfo(cell , ctx, option){
wordGroup.top = top; wordGroup.top = top;
drawLineInfo(wordGroup, cancelLine, underLine,{ drawLineInfo(wordGroup, cancelLine, underLine,{
width:wordGroup.textWidth, width:wordGroup.width,
height:wordGroup.textHeight, height:wordGroup.height,
left:left-wordGroup.textWidth, left:left-wordGroup.width,
top:top, top:top,
asc:size.asc, asc:size.asc,
desc:size.desc desc:size.desc
@ -1059,8 +1086,8 @@ function getCellTextInfo(cell , ctx, option){
} }
drawLineInfo(wordGroup, cancelLine, underLine,{ drawLineInfo(wordGroup, cancelLine, underLine,{
width:wordGroup.textWidth, width:wordGroup.width,
height:wordGroup.textHeight, height:wordGroup.height,
left:left, left:left,
top:top, top:top,
asc:size.asc, asc:size.asc,
@ -1324,6 +1351,10 @@ function getCellTextInfo(cell , ctx, option){
function drawLineInfo(wordGroup, cancelLine,underLine,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; let left = option.left, top = option.top, width=option.width, height = option.height, asc = option.asc,desc = option.desc;
if(wordGroup.wrap===true){
return;
}
if(wordGroup.inline==true && wordGroup.style!=null){ if(wordGroup.inline==true && wordGroup.style!=null){
cancelLine = wordGroup.style.cl; cancelLine = wordGroup.style.cl;
underLine = wordGroup.style.un; underLine = wordGroup.style.un;

42
src/index.html

@ -77,8 +77,46 @@
allowEdit:true, allowEdit:true,
forceCalculation:false, forceCalculation:false,
plugins: ['chart'], plugins: ['chart'],
data: data: [sheetCell,sheetFormula,sheetConditionFormat,sheetSparkline,sheetTable,sheetComment,sheetPivotTableData,sheetPivotTable,sheetChart]
[sheetCell,sheetFormula,sheetConditionFormat,sheetSparkline,sheetTable,sheetComment,sheetPivotTableData,sheetPivotTable,sheetChart] // [{"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":[
// {"r":0,"c":0,
// "v":{
// "ct":{
// "fa":"General",
// "t":"inlineStr",
// "s":[
// {
// "ff":"等线", //font family
// "fc":"#fff000",//font color
// "fs":12,//font size
// "cl":0,//strike
// "un":0,//underline
// "bl":0,//blod
// "it":1,//italic
// v:"我在马路\r\n边捡到\r\n\r\n一分钱"
// },
// {
// "ff":"等线", //font family
// "fc":"#ff0000",//font color
// "fs":14,//font size
// "cl":"1",//strike
// "un":"1",//underline
// "bl":"1",//blod
// "it":"0",//italic
// v:"交给警\r\n察叔叔\r\n"
// },
// ]
// },
// "fs":11,
// "ff":"等线",
// "vt":0,
// "tb":2,
// "v":"",
// "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"}}
// ],"calcChain":[]}]
}) })
}) })

Loading…
Cancel
Save