Browse Source

fix(underline and cancelline): add and fix

master
wbfsa 5 years ago
parent
commit
d3f23fffd7
  1. 2
      src/controllers/menuButton.js
  2. 37
      src/global/draw.js
  3. 337
      src/global/getRowlen.js
  4. 3
      src/index.html

2
src/controllers/menuButton.js

@ -3314,7 +3314,7 @@ const menuButton = {
},
checkstatusByCell:function(cell, a){
let foucsStatus =cell;
let tf = {"bl":1, "it":1 , "ff":1, "cl":1};
let tf = {"bl":1, "it":1 , "ff":1, "cl":1, "un":1};
if(a in tf){
if(foucsStatus == null){

37
src/global/draw.js

@ -2054,6 +2054,43 @@ function cellTextRender(textInfo, ctx, option){
let word = values[i];
ctx.font = word.style;
ctx.fillText(word.content, (pos_x + word.left)/Store.zoomRatio, (pos_y+word.top)/Store.zoomRatio);
if(word.cancelLine!=null){
let c = word.cancelLine;
ctx.beginPath();
ctx.moveTo(
(pos_x +c.startX)/Store.zoomRatio ,
(pos_y+c.startY)/Store.zoomRatio
);
ctx.lineTo(
(pos_x +c.endX)/Store.zoomRatio,
(pos_y+c.endY)/Store.zoomRatio
);
ctx.lineWidth = 1;
ctx.strokeStyle = ctx.fillStyle;
ctx.stroke();
ctx.closePath();
}
if(word.underLine!=null){
let underLines = word.underLine;
for(let a=0;a<underLines.length;a++){
let item = underLines[a];
ctx.beginPath();
ctx.moveTo(
(pos_x +item.startX)/Store.zoomRatio ,
(pos_y+item.startY)/Store.zoomRatio
);
ctx.lineTo(
(pos_x +item.endX)/Store.zoomRatio,
(pos_y+ item.endY)/Store.zoomRatio
);
ctx.lineWidth = 1;
ctx.strokeStyle = ctx.fillStyle;
ctx.stroke();
ctx.closePath();
}
}
}
// ctx.fillStyle = "rgba(0,0,0,0.2)";
// ctx.fillRect((pos_x + values[0].left)/Store.zoomRatio, (pos_y+values[0].top-values[0].asc)/Store.zoomRatio, textInfo.textWidthAll, textInfo.textHeightAll)

337
src/global/getRowlen.js

@ -171,12 +171,21 @@ function getCellTextSplitArr(strValue, strArr, cellWidth, canvas){
//获取有值单元格文本大小
// let measureTextCache = {}, measureTextCacheTimeOut = null;
function getMeasureText(value, ctx, fontset){
let mtc = Store.measureTextCache[value + "_" + ctx.font];
if(fontset!=null){
mtc = Store.measureTextCache[value + "_" + fontset];
}
if(mtc != null){
return mtc;
}
else{
if(fontset!=null){
let preFont = ctx.font;
ctx.font = fontset;
}
let measureText = ctx.measureText(value), cache = {};
if(measureText.actualBoundingBoxRight==null){
cache.width = measureText.width;
@ -185,6 +194,11 @@ function getMeasureText(value, ctx, fontset){
//measureText.actualBoundingBoxLeft +
cache.width = measureText.actualBoundingBoxRight;
}
if(fontset!=null){
ctx.font = preFont;
}
cache.actualBoundingBoxDescent = measureText.actualBoundingBoxDescent;
cache.actualBoundingBoxAscent = measureText.actualBoundingBoxAscent;
if(cache.actualBoundingBoxDescent==null || cache.actualBoundingBoxAscent==null || isNaN(cache.actualBoundingBoxDescent) || isNaN(cache.actualBoundingBoxAscent)){
@ -287,6 +301,10 @@ function getCellTextInfo(cell , ctx, option){
}
}
if(rt>180 || rt<0){
rt = 0;
}
rt = parseInt(rt);
if(rt>90){
rt = 90 -rt;
@ -299,20 +317,22 @@ function getCellTextInfo(cell , ctx, option){
let textContent = {};
textContent.values = [];
let fontset, cancelLine="0", underLine="0", isInline=false, value;
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;
let strArr = [];
let sharedStrings = cell.ct.s;
for(let i=0;i<cell.ct.sharedStrings.length;i++){
let s = cell.ct.sharedStrings[i];
}
isInline = true;
}
else{
let fontset = luckysheetfontformat(cell);
fontset = luckysheetfontformat(cell);
ctx.font = fontset;
let value;
cancelLine = menuButton.checkstatusByCell(cell ,"cl");//cancelLine
underLine = menuButton.checkstatusByCell(cell ,"un");//underLine
if(cell instanceof Object){
value = cell.m;
if(value == null){
@ -326,6 +346,10 @@ function getCellTextInfo(cell , ctx, option){
if(isRealNull(value)){
return null;
}
}
// let measureText = getMeasureText(value, ctx);
// //luckysheetTableContent.measureText(value);
@ -387,6 +411,8 @@ function getCellTextInfo(cell , ctx, option){
left:0,
top:0,
colIndex:colIndex,
asc:measureText.actualBoundingBoxAscent,
desc:measureText.actualBoundingBoxDescent
});
}
@ -444,6 +470,15 @@ function getCellTextInfo(cell , ctx, option){
word.left = left;
word.top = top;
drawLineInfo(word, cancelLine, underLine,{
width:columnWidth,
height:word.height,
left:left,
top:top+word.height/2,
asc:word.asc,
desc:word.desc
});
textContent.values.push(word);
}
@ -453,7 +488,14 @@ function getCellTextInfo(cell , ctx, option){
}
else{
let supportBoundBox = isSupportBoundingBox(ctx);
if(tb=="2"){//wrap
if(supportBoundBox){
ctx.textBaseline = 'alphabetic';
}
else{
ctx.textBaseline = 'bottom';
}
if(tb=="2" || isInline){//wrap
value = value.toString();
let textW_all = 0; //拆分后宽高度合计
@ -463,13 +505,6 @@ function getCellTextInfo(cell , ctx, option){
// let oneWordWidth = getMeasureText(vArr[0], ctx).width;
let splitIndex=0, text_all_cache=0, text_all_split = {}, text_all_splitLen=[];
if(supportBoundBox){
ctx.textBaseline = 'alphabetic';
}
else{
ctx.textBaseline = 'bottom';
}
textContent.rotate = rt;
rt = Math.abs(rt);
@ -646,6 +681,8 @@ function getCellTextInfo(cell , ctx, option){
textH_all = textH_all - lastLineSpaceHeight + lastLine.desc;
let rw = (textH_all)/Math.sin(rtPI) + textW_all_inner*Math.cos(rtPI);
let rh = textW_all_inner*Math.sin(rtPI), fixOneLineLeft = 0;
if(rt!=0){
if(splitLen==1){
textW_all = textW_all_inner + 2*(textH_all/Math.tan(rtPI));
fixOneLineLeft = textH_all/Math.tan(rtPI);
@ -653,16 +690,13 @@ function getCellTextInfo(cell , ctx, option){
else{
textW_all = textW_all_inner + textH_all/Math.tan(rtPI);
}
// if(rt!=0){
// textContent.textWidthAll = rw;
// textContent.textHeightAll = rh;
// }
// else{
textContent.textWidthAll = rw;
textContent.textHeightAll = rh;
}
else{
textContent.textWidthAll = textW_all;
textContent.textHeightAll = textH_all;
// }
}
if(isMode=="onlyWidth"){
// console.log("plainWrap", textContent,cell, option);
@ -685,37 +719,25 @@ function getCellTextInfo(cell , ctx, option){
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)/Math.tan(rtPI) - cumColumnWidth + textW_all_inner;
// }
// else if(verticalAlign=="0"){
// x = (cumWordHeight)/Math.tan(rtPI) - cumColumnWidth + textW_all_inner;
// }
// else{
// x = (cumWordHeight)/Math.tan(rtPI) - cumColumnWidth + textW_all_inner;
// }
x = (cumWordHeight)/Math.tan(rtPI) - cumColumnWidth + textW_all_inner;
if(horizonAlign == "0"){//center
let sh = textH_all/Math.sin(rtPI);
x = (cumWordHeight)/Math.tan(rt*Math.PI/180) - cumColumnWidth + textW_all_inner;
if(verticalAlign == "0"){//mid
left = x + cellWidth/2 - (textW_all/2);
top = y + cellHeight/2 - textH_all/2;
left = x + cellWidth/2 - (textW_all/2) + lastLineSpaceHeight*Math.cos(rtPI)/2;
top = y + cellHeight/2 - textH_all/2 - lastLineSpaceHeight*Math.sin(rtPI)/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;
left = x + cellWidth/2 - textW_all/2;
top = y - (textH_all/2 - rh/2);
}
else if(verticalAlign == "2"){//bottom
left = x + cellWidth/2 - (textW_all/2);
top = y + cellHeight - rh/2-textH_all/2;
left = x + cellWidth/2 - (textW_all/2)+lastLineSpaceHeight*Math.cos(rtPI);
top = y + cellHeight - rh/2 - textH_all/2 - lastLineSpaceHeight*Math.sin(rtPI);
}
}
else if(horizonAlign == "1"){//left
x = (cumWordHeight)/Math.tan(rtPI) - cumColumnWidth + textW_all_inner;
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;
@ -730,29 +752,34 @@ function getCellTextInfo(cell , ctx, option){
}
}
else if(horizonAlign == "2"){//right
x = (cumWordHeight)/Math.tan(rtPI) - cumColumnWidth + textW_all_inner;
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;
left = x + cellWidth - rw/2 - (textW_all_inner/2+(textH_all/2)/Math.tan(rtPI))+ lastLineSpaceHeight*Math.cos(rtPI)/2;
top = y + cellHeight/2 - textH_all/2 - lastLineSpaceHeight*Math.sin(rtPI)/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;
left = x + cellWidth - textW_all + fixOneLineLeft;
top = y - textH_all;
}
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);
}
}
}
}
wordGroup.left = left;
wordGroup.top = top;
drawLineInfo(wordGroup, cancelLine, underLine,{
width:wordGroup.textWidth,
height:wordGroup.textHeight,
left:left-wordGroup.textWidth,
top:top,
asc:size.asc,
desc:size.desc
});
textContent.values.push(wordGroup);
}
@ -777,119 +804,63 @@ function getCellTextInfo(cell , ctx, option){
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;
if(horizonAlign == "0"){//center
let sh = textH_all/Math.sin(rtPI);
x = (cumWordHeight+wordGroup.textHeight)/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;
left = x + cellWidth/2 - (textW_all/2) - lastLineSpaceHeight*Math.cos(rtPI)/2;
top = y + cellHeight/2 - textH_all/2 + lastLineSpaceHeight*Math.sin(rtPI)/2;
}
else if(verticalAlign == "1"){//top
left = x + cellWidth/2 - textW_all/2;
top = y - (textH_all/2 - rh/2)+wordGroup.textHeight/1.5;
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-wordGroup.textHeight/1.5;
left = x + cellWidth/2 - (textW_all/2)-lastLineSpaceHeight*Math.cos(rtPI);
top = y + cellHeight - rh/2 - textH_all/2 - lastLineSpaceHeight*Math.sin(rtPI);
}
}
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;
left = x - rh*Math.sin(rtPI)/2 - lastLineSpaceHeight*Math.cos(rtPI)/2;
top = y - textH_all + cellHeight/2 - rh*Math.cos(rtPI)/2 - lastLineSpaceHeight*Math.sin(rtPI)/2;
}
else if(verticalAlign == "1"){//top
left = x - lastLineSpaceHeight*Math.cos(rtPI);
top = y- textH_all + lastLineSpaceHeight*Math.sin(rtPI);
left = x;
top = y - textH_all;
}
else if(verticalAlign == "2"){//bottom
left = x;
top = y + cellHeight;
left = x - rh*Math.sin(rtPI) - lastLineSpaceHeight*Math.cos(rtPI);
top = y - textH_all + cellHeight - rh*Math.cos(rtPI) - lastLineSpaceHeight*Math.sin(rtPI);
}
}
else if(horizonAlign == "2"){//right
x = (cumWordHeight+wordGroup.textHeight)/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 - rh/2 - (textW_all/2+(textH_all/2)/Math.tan(rtPI));
top = y + cellHeight/2 - textH_all/2+wordGroup.textHeight/1.5;
left = x + cellWidth - rw/2 - textW_all/2 - lastLineSpaceHeight*Math.cos(rtPI)/2;
top = y + cellHeight/2 - textH_all/2 - lastLineSpaceHeight*Math.sin(rtPI)/2;
}
else if(verticalAlign == "1"){//top
left = x + cellWidth - textW_all+fixOneLineLeft;
top = y - textH_all+wordGroup.textHeight/1.5;
else if(verticalAlign == "1"){//top fixOneLineLeft
left = x + cellWidth - rw*Math.cos(rtPI);
top = y + rh*Math.cos(rtPI);
}
else if(verticalAlign == "2"){//bottom
left = x + cellWidth - rw*Math.cos(rtPI);
top = y + cellHeight - rw*Math.sin(rtPI);
left = x + cellWidth - textW_all - lastLineSpaceHeight*Math.cos(rtPI) + fixOneLineLeft;
top = y + cellHeight - lastLineSpaceHeight*Math.sin(rtPI);
}
}
// }
drawLineInfo(wordGroup, cancelLine, underLine,{
width:wordGroup.textWidth,
height:wordGroup.textHeight,
left:left,
top:top,
asc:size.asc,
desc:size.desc
});
// let x, y = cumWordHeight; //+ wordGroup.textHeight / Math.sin(rt*Math.PI/180)*isRotateDown;
// if(isRotateUp=="1"){
@ -963,15 +934,24 @@ function getCellTextInfo(cell , ctx, option){
left = cellWidth + cumColumnWidth - size.width;
}
top = (cellHeight - space_height) + cumWordHeight - textH_all + wordGroup.asc+wordGroup.height/1.5-wordGroup.desc-1;
top = (cellHeight - space_height) + cumWordHeight +size.asc-textH_all;
if(verticalAlign == "0"){
top = cellHeight / 2 + cumWordHeight - textH_all/2 + wordGroup.asc+wordGroup.height/3-wordGroup.desc;
top = cellHeight / 2 + cumWordHeight - textH_all/2 + size.asc;
}
else if(verticalAlign == "1"){
top = space_height + cumWordHeight+ wordGroup.asc;
top = space_height + cumWordHeight+ size.asc;
}
cumColumnWidth += wordGroup.width;
drawLineInfo(wordGroup, cancelLine, underLine,{
width:wordGroup.width,
height:wordGroup.height,
left:left,
top:top,
asc:size.asc,
desc:size.desc
});
}
@ -1011,6 +991,7 @@ function getCellTextInfo(cell , ctx, option){
else if(verticalAlign == "1"){//top
textContent.textLeftAll = cellWidth/2;
textContent.textTopAll = rh/2;
}
else if(verticalAlign == "2"){//bottom
textContent.textLeftAll = cellWidth/2;
@ -1054,13 +1035,6 @@ function getCellTextInfo(cell , ctx, option){
}
else{
if(supportBoundBox){
ctx.textBaseline = 'alphabetic';
}
else{
ctx.textBaseline = 'bottom';
}
let measureText = getMeasureText(value, ctx);
let textWidth = measureText.width;
let textHeight = measureText.actualBoundingBoxDescent + measureText.actualBoundingBoxAscent;
@ -1106,15 +1080,27 @@ function getCellTextInfo(cell , ctx, option){
}
textContent.type = "plain";
textContent.values.push({
let wordGroup = {
content:value,
style:fontset,
width:width,
height:height,
left:left,
top:top,
}
drawLineInfo(wordGroup, cancelLine, underLine,{
width:textWidth,
height:textHeight,
left:left,
top:top,
asc:measureText.actualBoundingBoxAscent,
desc:measureText.actualBoundingBoxDescent
});
textContent.values.push(wordGroup);
textContent.textLeftAll = left;
textContent.textTopAll = top;
@ -1125,11 +1111,68 @@ function getCellTextInfo(cell , ctx, option){
}
}
return textContent;
}
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;
if(cancelLine!="0"){
wordGroup.cancelLine = {};
wordGroup.cancelLine.startX = left;
wordGroup.cancelLine.startY = top-asc/2+1;
wordGroup.cancelLine.endX = left + width;
wordGroup.cancelLine.endY = top-asc/2+1;
}
if(underLine!="0"){
wordGroup.underLine = [];
if(underLine=="1" || underLine=="2"){
let item = {};
item.startX = left;
item.startY = top;
item.endX = left + width;
item.endY = top;
wordGroup.underLine.push(item);
}
return textContent;
if(underLine=="2"){
let item = {};
item.startX = left;
item.startY = top+desc;
item.endX = left + width;
item.endY = top+desc;
wordGroup.underLine.push(item);
}
if(underLine=="3" || underLine=="4"){
let item = {};
item.startX = left;
item.startY = top+desc;
item.endX = left + width;
item.endY = top+desc;
wordGroup.underLine.push(item);
}
if(underLine=="4"){
let item = {};
item.startX = left;
item.startY = top+desc+2;
item.endX = left + width;
item.endY = top+desc+2;
wordGroup.underLine.push(item);
}
}
}
export {

3
src/index.html

@ -77,7 +77,8 @@
allowEdit:true,
forceCalculation:false,
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