Browse Source

refactor: inlinestr add

master
liuyang 5 years ago
parent
commit
aa3304b9bf
  1. 109
      src/global/draw.js
  2. 42
      src/index.html

109
src/global/draw.js

@ -1568,63 +1568,74 @@ let cellRender = function(r, c, start_r, start_c, end_r, end_c, value, luckyshee
//自动换行
// luckysheetTableContent.textBaseline = 'top'; //textBaseline以top计算
let strArr = [];//文本截断数组
strArr = getCellTextSplitArr(value.toString(), strArr, (cellWidth - space_width * 2), luckysheetTableContent);
let word_space_height = oneLineTextHeight/3;
for(let i = 0; i < strArr.length; i++){
let strV = strArr[i];
if(cell.ct!=null && cell.ct.t=="inlineStr" && cell.ct.sharedStrings!=null && cell.ct.sharedStrings.length>0){
let strArr = [],lineMaxHeight=[];
let sharedStrings = cell.ct.sharedStrings;
for(let i=0;i<cell.ct.sharedStrings.length;i++){
let strWidth = getMeasureText(strV, luckysheetTableContent).width;
// luckysheetTableContent.measureText(strV).width;
let strHeight = oneLineTextHeight;
//水平对齐计算
if(horizonAlign == "0"){
horizonAlignPos = (pos_x + cellWidth / 2) - (strWidth / 2);
}
else if(horizonAlign == "2"){
horizonAlignPos = (pos_x + cellWidth - space_width) - strWidth;
}
else{
horizonAlignPos = (pos_x + space_width) ;
}
}
else{
let strArr = [];
strArr = getCellTextSplitArr(value.toString(), strArr, (cellWidth - space_width * 2), luckysheetTableContent);
let word_space_height = oneLineTextHeight/3;
for(let i = 0; i < strArr.length; i++){
let strV = strArr[i];
let strWidth = getMeasureText(strV, luckysheetTableContent).width;
// luckysheetTableContent.measureText(strV).width;
let strHeight = oneLineTextHeight;
//水平对齐计算
if(horizonAlign == "0"){
horizonAlignPos = (pos_x + cellWidth / 2) - (strWidth / 2);
}
else if(horizonAlign == "2"){
horizonAlignPos = (pos_x + cellWidth - space_width) - strWidth;
}
else{
horizonAlignPos = (pos_x + space_width) ;
}
//垂直对齐计算
let clLine = 0;
if(verticalAlign == "0"){
verticalAlignPos = (pos_y + cellHeight / 2) - (strHeight+word_space_height) * (strArr.length-1)/2;
}
else if(verticalAlign == "1"){
verticalAlignPos = (pos_y + space_height) ;
clLine = strHeight / 2;
}
else{
verticalAlignPos = (pos_y + cellHeight - space_height) - (strHeight+word_space_height) * (strArr.length-1);
clLine = -strHeight / 2;
}
//垂直对齐计算
let clLine = 0;
if(verticalAlign == "0"){
verticalAlignPos = (pos_y + cellHeight / 2) - (strHeight+word_space_height) * (strArr.length-1)/2;
}
else if(verticalAlign == "1"){
verticalAlignPos = (pos_y + space_height) ;
clLine = strHeight / 2;
}
else{
verticalAlignPos = (pos_y + cellHeight - space_height) - (strHeight+word_space_height) * (strArr.length-1);
clLine = -strHeight / 2;
}
verticalAlignPos = (verticalAlignPos + i * (strHeight+word_space_height));
verticalAlignPos = verticalAlignPos/Store.zoomRatio;
horizonAlignPos = horizonAlignPos/Store.zoomRatio;
verticalAlignPos = (verticalAlignPos + i * (strHeight+word_space_height));
verticalAlignPos = verticalAlignPos/Store.zoomRatio;
horizonAlignPos = horizonAlignPos/Store.zoomRatio;
luckysheetTableContent.fillText(strV, horizonAlignPos, verticalAlignPos);
luckysheetTableContent.fillText(strV, horizonAlignPos, verticalAlignPos);
if(cl == "1" && !isRealNull(strV)){
luckysheetTableContent.beginPath();
luckysheetTableContent.strokeStyle = "#000";
clLine = clLine/Store.zoomRatio;
luckysheetTableContent.moveTo(
horizonAlignPos,
verticalAlignPos +clLine
);
luckysheetTableContent.lineTo(
horizonAlignPos + strWidth/Store.zoomRatio,
verticalAlignPos + clLine
);
luckysheetTableContent.stroke();
luckysheetTableContent.closePath();
if(cl == "1" && !isRealNull(strV)){
luckysheetTableContent.beginPath();
luckysheetTableContent.strokeStyle = "#000";
clLine = clLine/Store.zoomRatio;
luckysheetTableContent.moveTo(
horizonAlignPos,
verticalAlignPos +clLine
);
luckysheetTableContent.lineTo(
horizonAlignPos + strWidth/Store.zoomRatio,
verticalAlignPos + clLine
);
luckysheetTableContent.stroke();
luckysheetTableContent.closePath();
}
}
}
}
else if(cell.tr != null && cell.tr != '0'){
//旋转

42
src/index.html

@ -37,7 +37,47 @@
allowEdit:true,
forceCalculation:false,
plugins: ['chart'],
data: [sheetCell,sheetFormula,sheetConditionFormat,sheetTable,sheetSparkline,sheetComment,sheetPivotTableData,sheetPivotTable,sheetChart]
data: [{"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:"我在"
},
{
"t":1,//换行符
},
{
"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,
}
}
],"calcChain":[]}]
})
})

Loading…
Cancel
Save