Browse Source

style(inline string): programing

master
wbfsa 5 years ago
parent
commit
592c1638c7
  1. 417
      src/global/getRowlen.js
  2. 44
      src/index.html

417
src/global/getRowlen.js

@ -294,6 +294,8 @@ function getCellTextInfo(cell , ctx, option){
isRotateDown = 1; isRotateDown = 1;
} }
ctx.textAlign="start";
let textContent = {}; let textContent = {};
textContent.values = []; textContent.values = [];
@ -667,84 +669,176 @@ function getCellTextInfo(cell , ctx, option){
return textContent; return textContent;
} }
if(rt!=0 && isRotateUp=="1"){
ctx.textAlign="end";
for(let i = 0; i < splitLen; i++){ for(let i = 0; i < splitLen; i++){
let splitLists = text_all_split[i]; let splitLists = text_all_split[i];
if(splitLists==null){ if(splitLists==null){
continue; continue;
} }
let size = split_all_size[i]; let size = split_all_size[i];
cumColumnWidth = 0; cumColumnWidth = 0;
for(let c=0;c<splitLists.length;c++){ for(let c=splitLists.length-1;c>=0;c--){
let wordGroup = splitLists[c]; let wordGroup = splitLists[c];
let left, top; let left, top;
if(rt!=0){//rotate if(rt!=0){//rotate
let x, y = cumWordHeight+size.asc; let x, y = cumWordHeight+size.asc;
if(isRotateUp=="1"){ if(isRotateUp=="1"){
// x = (cumWordHeight)/Math.tan(rtPI) + cumColumnWidth; // x = (cumWordHeight)/Math.tan(rtPI) + cumColumnWidth;
if(verticalAlign=="2"){ // if(verticalAlign=="2"){
x = (cumWordHeight+size.height)/Math.tan(rtPI) + cumColumnWidth; // x = (cumWordHeight)/Math.tan(rtPI) - cumColumnWidth + textW_all_inner;
} // }
else if(verticalAlign=="0"){ // else if(verticalAlign=="0"){
x = (cumWordHeight+size.height/2)/Math.tan(rtPI) + cumColumnWidth; // x = (cumWordHeight)/Math.tan(rtPI) - cumColumnWidth + textW_all_inner;
} // }
else{ // else{
x = (cumWordHeight)/Math.tan(rtPI) + cumColumnWidth; // x = (cumWordHeight)/Math.tan(rtPI) - cumColumnWidth + textW_all_inner;
} // }
if(horizonAlign == "0"){//center if(horizonAlign == "0"){//center
let sh = textH_all/Math.sin(rtPI); let sh = textH_all/Math.sin(rtPI);
x = (cumWordHeight+size.height)/Math.tan(rt*Math.PI/180) + cumColumnWidth; x = (cumWordHeight)/Math.tan(rt*Math.PI/180) - cumColumnWidth + textW_all_inner;
if(verticalAlign == "0"){//mid if(verticalAlign == "0"){//mid
left = x + cellWidth/2 - (textW_all/2); left = x + cellWidth/2 - (textW_all/2);
top = y + cellHeight/2 - textH_all/2; top = y + cellHeight/2 - textH_all/2;
} }
else if(verticalAlign == "1"){//top else if(verticalAlign == "1"){//top
left = x + cellWidth/2 - textW_all/2- lastLineSpaceHeight*Math.cos(rtPI)/2; left = x + cellWidth/2 - textW_all/2- lastLineSpaceHeight*Math.cos(rtPI)/2;
top = y - (textH_all/2 - rh/2) + lastLineSpaceHeight*Math.sin(rtPI)/2; top = y - (textH_all/2 - rh/2) + lastLineSpaceHeight*Math.sin(rtPI)/2;
} }
else if(verticalAlign == "2"){//bottom else if(verticalAlign == "2"){//bottom
left = x + cellWidth/2 - (textW_all/2); left = x + cellWidth/2 - (textW_all/2);
top = y + cellHeight - rh/2-textH_all/2; top = y + cellHeight - rh/2-textH_all/2;
} }
}
else if(horizonAlign == "1"){//left
if(verticalAlign == "0"){//mid
left = x - rh*Math.sin(rtPI)/2;
top = y + cellHeight/2 + rh*Math.cos(rtPI)/2;
}
else if(verticalAlign == "1"){//top
left = x - rh*Math.sin(rtPI);
top = y + rh*Math.cos(rtPI);
}
else if(verticalAlign == "2"){//bottom
left = x;
top = y + cellHeight;
}
}
else if(horizonAlign == "2"){//right
x = (cumWordHeight)/Math.tan(rt*Math.PI/180) + cumColumnWidth;
if(verticalAlign == "0"){//mid
// left = x + cellWidth - ( textH_all/Math.tan(rtPI) + (rh/2)*Math.sin(rtPI));
// top = y + cellHeight/2 - (textH_all - (rh/2)*Math.cos(rtPI));
left = x + cellWidth - rw/2 - (textW_all/2+(textH_all/2)/Math.tan(rtPI));
top = y + cellHeight/2 - textH_all/2;
} }
else if(verticalAlign == "1"){//top fixOneLineLeft else if(horizonAlign == "1"){//left
left = x + cellWidth - textW_all + lastLine.height*Math.cos(rtPI)/2; x = (cumWordHeight)/Math.tan(rtPI) - cumColumnWidth + textW_all_inner;
top = y - textH_all + lastLine.height*Math.sin(rtPI)/2; if(verticalAlign == "0"){//mid
left = x - rh*Math.sin(rtPI)/2 + lastLineSpaceHeight*Math.cos(rtPI)/2;
top = y + cellHeight/2 + rh*Math.cos(rtPI)/2 - lastLineSpaceHeight*Math.sin(rtPI)/2;
}
else if(verticalAlign == "1"){//top
left = x - rh*Math.sin(rtPI);
top = y + rh*Math.cos(rtPI);
}
else if(verticalAlign == "2"){//bottom
left = x + lastLineSpaceHeight*Math.cos(rtPI);
top = y + cellHeight - lastLineSpaceHeight*Math.sin(rtPI);
}
} }
else if(verticalAlign == "2"){//bottom else if(horizonAlign == "2"){//right
left = x + cellWidth - rw*Math.cos(rtPI) + lastLineSpaceHeight*Math.cos(rtPI); x = (cumWordHeight)/Math.tan(rtPI) - cumColumnWidth + textW_all_inner;
top = y + cellHeight - rw*Math.sin(rtPI) + lastLineSpaceHeight*Math.sin(rtPI); if(verticalAlign == "0"){//mid
// left = x + cellWidth - ( textH_all/Math.tan(rtPI) + (rh/2)*Math.sin(rtPI));
// top = y + cellHeight/2 - (textH_all - (rh/2)*Math.cos(rtPI));
left = x + cellWidth - rw/2 - (textW_all_inner/2+(textH_all/2)/Math.tan(rtPI));
top = y + cellHeight/2 - textH_all/2;
}
else if(verticalAlign == "1"){//top fixOneLineLeft
left = x + cellWidth - textW_all + lastLine.height*Math.cos(rtPI)/2;
top = y - textH_all + lastLine.height*Math.sin(rtPI)/2;
}
else if(verticalAlign == "2"){//bottom
left = x + cellWidth - rw*Math.cos(rtPI) + lastLineSpaceHeight*Math.cos(rtPI);
top = y + cellHeight - rw*Math.sin(rtPI) - lastLineSpaceHeight*Math.sin(rtPI);
}
} }
} }
} }
else{
wordGroup.left = left;
wordGroup.top = top;
textContent.values.push(wordGroup);
}
cumWordHeight += size.height;
}
}
else{
for(let i = 0; i < splitLen; i++){
let splitLists = text_all_split[i];
if(splitLists==null){
continue;
}
let size = split_all_size[i];
cumColumnWidth = 0;
for(let c=0;c<splitLists.length;c++){
let wordGroup = splitLists[c];
let left, top;
if(rt!=0){//rotate
let x, y = cumWordHeight+size.asc;
// if(isRotateUp=="1"){
// // x = (cumWordHeight)/Math.tan(rtPI) + cumColumnWidth;
// if(verticalAlign=="2"){
// x = (cumWordHeight+size.height)/Math.tan(rtPI) + cumColumnWidth;
// }
// else if(verticalAlign=="0"){
// x = (cumWordHeight+size.height/2)/Math.tan(rtPI) + cumColumnWidth;
// }
// else{
// x = (cumWordHeight)/Math.tan(rtPI) + cumColumnWidth;
// }
// if(horizonAlign == "0"){//center
// let sh = textH_all/Math.sin(rtPI);
// x = (cumWordHeight+size.height)/Math.tan(rt*Math.PI/180) + cumColumnWidth;
// if(verticalAlign == "0"){//mid
// left = x + cellWidth/2 - (textW_all/2);
// top = y + cellHeight/2 - textH_all/2;
// }
// else if(verticalAlign == "1"){//top
// left = x + cellWidth/2 - textW_all/2- lastLineSpaceHeight*Math.cos(rtPI)/2;
// top = y - (textH_all/2 - rh/2) + lastLineSpaceHeight*Math.sin(rtPI)/2;
// }
// else if(verticalAlign == "2"){//bottom
// left = x + cellWidth/2 - (textW_all/2);
// top = y + cellHeight - rh/2-textH_all/2;
// }
// }
// else if(horizonAlign == "1"){//left
// if(verticalAlign == "0"){//mid
// left = x - rh*Math.sin(rtPI)/2;
// top = y + cellHeight/2 + rh*Math.cos(rtPI)/2;
// }
// else if(verticalAlign == "1"){//top
// left = x - rh*Math.sin(rtPI);
// top = y + rh*Math.cos(rtPI);
// }
// else if(verticalAlign == "2"){//bottom
// left = x;
// top = y + cellHeight;
// }
// }
// else if(horizonAlign == "2"){//right
// x = (cumWordHeight)/Math.tan(rt*Math.PI/180) + cumColumnWidth;
// if(verticalAlign == "0"){//mid
// // left = x + cellWidth - ( textH_all/Math.tan(rtPI) + (rh/2)*Math.sin(rtPI));
// // top = y + cellHeight/2 - (textH_all - (rh/2)*Math.cos(rtPI));
// left = x + cellWidth - rw/2 - (textW_all/2+(textH_all/2)/Math.tan(rtPI));
// top = y + cellHeight/2 - textH_all/2;
// }
// else if(verticalAlign == "1"){//top fixOneLineLeft
// left = x + cellWidth - textW_all + lastLine.height*Math.cos(rtPI)/2;
// top = y - textH_all + lastLine.height*Math.sin(rtPI)/2;
// }
// else if(verticalAlign == "2"){//bottom
// left = x + cellWidth - rw*Math.cos(rtPI) + lastLineSpaceHeight*Math.cos(rtPI);
// top = y + cellHeight - rw*Math.sin(rtPI) - lastLineSpaceHeight*Math.sin(rtPI);
// }
// }
// }
// else{
x = (textH_all-cumWordHeight)/Math.tan(rtPI) + cumColumnWidth; x = (textH_all-cumWordHeight)/Math.tan(rtPI) + cumColumnWidth;
if(horizonAlign == "0"){//center if(horizonAlign == "0"){//center
@ -795,102 +889,103 @@ function getCellTextInfo(cell , ctx, option){
top = y + cellHeight - rw*Math.sin(rtPI); top = y + cellHeight - rw*Math.sin(rtPI);
} }
} }
} // }
// let x, y = cumWordHeight; //+ wordGroup.textHeight / Math.sin(rt*Math.PI/180)*isRotateDown;
// if(isRotateUp=="1"){
// if(horizonAlign=="2"){
// x = (cumWordHeight)/Math.tan(rt*Math.PI/180) + cumColumnWidth;
// }
// else if(horizonAlign=="0"){
// x = (cumWordHeight)/Math.tan(rt*Math.PI/180) + cumColumnWidth;
// }
// else{
// x = (cumWordHeight)/Math.tan(rt*Math.PI/180) + cumColumnWidth;
// }
// }
// else{
// if(horizonAlign=="2"){
// x = (textH_all-cumWordHeight)/Math.tan(rt*Math.PI/180) + cumColumnWidth;
// }
// else if(horizonAlign=="0"){
// x = (textH_all-cumWordHeight)/Math.tan(rt*Math.PI/180) + cumColumnWidth;
// }
// else{
// x = (textH_all-cumWordHeight)/Math.tan(rt*Math.PI/180) + cumColumnWidth;
// }
// }
// // x -= wordGroup.textHeight / Math.sin(rt*Math.PI/180)*isRotateDown;
// // x -= size.textHeight*2;
// //textH_all/Math.sin(rt*Math.PI/180) - textH_all/Math.tan(rt*Math.PI/180);
// let leftOffset = 0;
// left = x + leftOffset;
// if(horizonAlign == "0"){
// //+ space_width*textH_all_ColumnHeight.length
// left = x + cellWidth / 2 + leftOffset - textW_all/2;
// }
// else if(horizonAlign == "2"){
// left = x + cellWidth + leftOffset - textW_all;
// }
// //( textH_all/2 - rh/2 )
// let topOffset = 0;
// top = y + cellHeight - topOffset - textH_all + wordGroup.asc +wordGroup.desc +(splitLen>1?(wordGroup.textHeight/1.5):0); // let x, y = cumWordHeight; //+ wordGroup.textHeight / Math.sin(rt*Math.PI/180)*isRotateDown;
// if(verticalAlign == "0"){ // if(isRotateUp=="1"){
// top = y + cellHeight/2 - topOffset - textH_all/2 + wordGroup.asc+(splitLen>1?(wordGroup.textHeight/3):0); // if(horizonAlign=="2"){
// } // x = (cumWordHeight)/Math.tan(rt*Math.PI/180) + cumColumnWidth;
// else if(verticalAlign == "1"){ // }
// top = y - topOffset + wordGroup.asc; // else if(horizonAlign=="0"){
// } // x = (cumWordHeight)/Math.tan(rt*Math.PI/180) + cumColumnWidth;
// }
// else{
// x = (cumWordHeight)/Math.tan(rt*Math.PI/180) + cumColumnWidth;
// }
// }
// else{
// if(horizonAlign=="2"){
// x = (textH_all-cumWordHeight)/Math.tan(rt*Math.PI/180) + cumColumnWidth;
// }
// else if(horizonAlign=="0"){
// x = (textH_all-cumWordHeight)/Math.tan(rt*Math.PI/180) + cumColumnWidth;
// }
// else{
// x = (textH_all-cumWordHeight)/Math.tan(rt*Math.PI/180) + cumColumnWidth;
// }
// }
// cumColumnWidth += wordGroup.textWidth; // // x -= wordGroup.textHeight / Math.sin(rt*Math.PI/180)*isRotateDown;
// // x -= size.textHeight*2;
// if(c==0 && i==0 && isRotateUp=="1"){ // //textH_all/Math.sin(rt*Math.PI/180) - textH_all/Math.tan(rt*Math.PI/180);
// textContent.textLeftAll = left; // let leftOffset = 0;
// textContent.textTopAll = top-wordGroup.asc;
// } // left = x + leftOffset;
// else if(c==0 && i==(splitLen-1) && isRotateUp=="0"){ // if(horizonAlign == "0"){
// textContent.textLeftAll = left; // //+ space_width*textH_all_ColumnHeight.length
// textContent.textTopAll = top+wordGroup.desc; // left = x + cellWidth / 2 + leftOffset - textW_all/2;
// } // }
// else if(horizonAlign == "2"){
// console.log("plainWrap" ,left , top); // left = x + cellWidth + leftOffset - textW_all;
} // }
else{//plain
left = space_width + cumColumnWidth;
if(horizonAlign == "0"){
//+ space_width*textH_all_ColumnHeight.length
left = cellWidth / 2 + cumColumnWidth - size.width/2;
}
else if(horizonAlign == "2"){
left = cellWidth + cumColumnWidth - size.width;
}
top = (cellHeight - space_height) + cumWordHeight - textH_all + wordGroup.asc+wordGroup.height/1.5-wordGroup.desc-1; // //( textH_all/2 - rh/2 )
if(verticalAlign == "0"){ // let topOffset = 0;
top = cellHeight / 2 + cumWordHeight - textH_all/2 + wordGroup.asc+wordGroup.height/3-wordGroup.desc;
// top = y + cellHeight - topOffset - textH_all + wordGroup.asc +wordGroup.desc +(splitLen>1?(wordGroup.textHeight/1.5):0);
// if(verticalAlign == "0"){
// top = y + cellHeight/2 - topOffset - textH_all/2 + wordGroup.asc+(splitLen>1?(wordGroup.textHeight/3):0);
// }
// else if(verticalAlign == "1"){
// top = y - topOffset + wordGroup.asc;
// }
// cumColumnWidth += wordGroup.textWidth;
// if(c==0 && i==0 && isRotateUp=="1"){
// textContent.textLeftAll = left;
// textContent.textTopAll = top-wordGroup.asc;
// }
// else if(c==0 && i==(splitLen-1) && isRotateUp=="0"){
// textContent.textLeftAll = left;
// textContent.textTopAll = top+wordGroup.desc;
// }
// console.log("plainWrap" ,left , top);
} }
else if(verticalAlign == "1"){ else{//plain
top = space_height + cumWordHeight+ wordGroup.asc; left = space_width + cumColumnWidth;
if(horizonAlign == "0"){
//+ space_width*textH_all_ColumnHeight.length
left = cellWidth / 2 + cumColumnWidth - size.width/2;
}
else if(horizonAlign == "2"){
left = cellWidth + cumColumnWidth - size.width;
}
top = (cellHeight - space_height) + cumWordHeight - textH_all + wordGroup.asc+wordGroup.height/1.5-wordGroup.desc-1;
if(verticalAlign == "0"){
top = cellHeight / 2 + cumWordHeight - textH_all/2 + wordGroup.asc+wordGroup.height/3-wordGroup.desc;
}
else if(verticalAlign == "1"){
top = space_height + cumWordHeight+ wordGroup.asc;
}
cumColumnWidth += wordGroup.width;
} }
wordGroup.left = left;
wordGroup.top = top;
cumColumnWidth += wordGroup.width; textContent.values.push(wordGroup);
} }
wordGroup.left = left; cumWordHeight += size.height;
wordGroup.top = top;
textContent.values.push(wordGroup);
} }
cumWordHeight += size.height;
} }
textContent.type = "plainWrap"; textContent.type = "plainWrap";

44
src/index.html

@ -30,14 +30,54 @@
import sheetSparkline from './demoData/sheetSparkline.js' import sheetSparkline from './demoData/sheetSparkline.js'
import sheetChart from './demoData/sheetChart.js' import sheetChart from './demoData/sheetChart.js'
$(function () { $(function () {
// [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",
// "sharedStrings":[
// {
// "ff":"等线", //font family
// "fc":"#fff000",//font color
// "fs":12,//font size
// "cl":1,//strike
// "un":0,//underline
// "bl":0,//blod
// "it":1,//italic
// v:"我在\r\n"
// },
// {
// "ff":"等线", //font family
// "fc":"#ff0000",//font color
// "fs":14,//font size
// "cl":"1",//strike
// "un":"0",//underline
// "bl":"1",//blod
// "it":"0",//italic
// v:"马路边"
// },
// ]
// },
// "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":[]}]
luckysheet.create({ luckysheet.create({
container: 'luckysheet', container: 'luckysheet',
lang: 'en', lang: 'en',
allowEdit:true, allowEdit:true,
forceCalculation:false, forceCalculation:false,
plugins: ['chart'], plugins: ['chart'],
data: [sheetCell,sheetFormula,sheetConditionFormat,sheetSparkline,sheetTable,sheetComment,sheetPivotTableData,sheetPivotTable,sheetChart] data: [sheetCell,sheetFormula,sheetConditionFormat,sheetSparkline,sheetTable,sheetComment,sheetPivotTableData,sheetPivotTable,sheetChart]
}) })
}) })

Loading…
Cancel
Save