Skip to content
This repository has been archived by the owner on Mar 28, 2024. It is now read-only.

Commit

Permalink
fix(text wrap postion bug): wrap and rotation postion wrong
Browse files Browse the repository at this point in the history
  • Loading branch information
DR-Univer committed Oct 11, 2020
1 parent 05c49a2 commit 9538972
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 63 deletions.
18 changes: 18 additions & 0 deletions src/controllers/constant.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 47 additions & 0 deletions src/controllers/menuButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -2801,6 +2801,53 @@ const menuButton = {
openProtectionModal(sheetFile);
});

//print
$("#luckysheet-icon-print").click(function(){
let menuButtonId = $(this).attr("id") + "-menuButton";
let $menuButton = $("#" + menuButtonId);
const _locale = locale();
const locale_print = _locale.print;
if($menuButton.length == 0){
let itemdata = [
{"text": locale_print.menuItemPrint, "value": "print", "example": '<i class="iconfont icon-sousuo" aria-hidden="true"></i>'},
{"text": "", "value": "split", "example": ""},
{"text": locale_print.menuItemAreas, "value": "areas", "example": '<i class="iconfont icon-tihuan" aria-hidden="true"></i>'},
{"text": locale_print.menuItemRows, "value": "rows", "example": '<i class="iconfont icon-zhuandao1" aria-hidden="true"></i>'},
{"text": locale_print.menuItemColumns, "value": "columns", "example": '<i class="iconfont icon-dingwei" aria-hidden="true"></i>'},
];

let itemset = _this.createButtonMenu(itemdata);

let menu = replaceHtml(_this.menu, { "id": "print", "item": itemset, "subclass": "", "sub": "" });

$("body").append(menu);
$menuButton = $("#" + menuButtonId).width(180);

$menuButton.find(".luckysheet-cols-menuitem").click(function(){
$menuButton.hide();
luckysheetContainerFocus();

let $t = $(this), itemvalue = $t.attr("itemvalue");

if(itemvalue == "print"){ //Print config
alert("print");
}
else if(itemvalue == "areas" || itemvalue == "rows" || itemvalue == "columns"){ //range
alert("areas");
}
});
}

let userlen = $(this).outerWidth();
let tlen = $menuButton.outerWidth();

let menuleft = $(this).offset().left;
if(tlen > userlen && (tlen + menuleft) > $("#" + Store.container).width()){
menuleft = menuleft - tlen + userlen;
}
mouseclickposition($menuButton, menuleft, $(this).offset().top + 25, "lefttop");
});

$("body").on("mouseover mouseleave",".luckysheet-menuButton .luckysheet-cols-submenu", function(e){
let $t = $(this), attrid = $t.attr("itemvalue"),
$attr = $("#luckysheet-icon-" + attrid + "-menuButton");
Expand Down
4 changes: 3 additions & 1 deletion src/controllers/resize.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,8 @@ export function menuToolBarWidth() {
$('#luckysheet-chart-btn-screenshot').offset().left,
$('#luckysheet-icon-seachmore').offset().left,
$('#luckysheet-icon-protection').offset().left,
$('#luckysheet-icon-protection').offset().left + $('#luckysheet-icon-protection').outerWidth() + 5,
$('#luckysheet-icon-print').offset().left,
$('#luckysheet-icon-print').offset().left + $('#luckysheet-icon-protection').outerWidth() + 5,
];
toobarObject.toobarElements = [
'#luckysheet-icon-undo',
Expand Down Expand Up @@ -367,5 +368,6 @@ export function menuToolBarWidth() {
'#luckysheet-chart-btn-screenshot',
'#luckysheet-icon-seachmore',
'#luckysheet-icon-protection',
'#luckysheet-icon-print',
]
}
43 changes: 22 additions & 21 deletions src/global/getRowlen.js
Original file line number Diff line number Diff line change
Expand Up @@ -1061,43 +1061,43 @@ function getCellTextInfo(cell , ctx, option){
if(verticalAlign == "0"){//mid

left = x + cellWidth/2 - (textW_all/2) + lastLineSpaceHeight*Math.cos(rtPI)/2;
top = y + cellHeight/2 - textH_all/2 - lastLineSpaceHeight*Math.sin(rtPI)/2;
top = y + cellHeight/2 - textH_all/2 - lastLineSpaceHeight*Math.cos(rtPI)/2;
}
else if(verticalAlign == "1"){//top
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)+lastLineSpaceHeight*Math.cos(rtPI);
top = y + cellHeight - rh/2 - textH_all/2 - lastLineSpaceHeight*Math.sin(rtPI);
top = y + cellHeight - rh/2 - textH_all/2 - lastLineSpaceHeight*Math.cos(rtPI);
}
}
else if(horizonAlign == "1"){//left
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;
top = y + cellHeight/2 + rh*Math.cos(rtPI)/2 - lastLineSpaceHeight*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 + lastLineSpaceHeight*Math.cos(rtPI);
top = y + cellHeight - lastLineSpaceHeight*Math.sin(rtPI);
top = y + cellHeight - lastLineSpaceHeight*Math.cos(rtPI);
}
}
else if(horizonAlign == "2"){//right
if(verticalAlign == "0"){//mid
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;
top = y + cellHeight/2 - textH_all/2 - lastLineSpaceHeight*Math.cos(rtPI)/2;
}
else if(verticalAlign == "1"){//top fixOneLineLeft
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);
top = y + cellHeight - rw*Math.sin(rtPI) - lastLineSpaceHeight*Math.cos(rtPI);
}
}

Expand Down Expand Up @@ -1152,43 +1152,43 @@ function getCellTextInfo(cell , ctx, option){
if(verticalAlign == "0"){//mid

left = x + cellWidth/2 - (textW_all/2) - lastLineSpaceHeight*Math.cos(rtPI)/2;
top = y + cellHeight/2 - textH_all/2 + lastLineSpaceHeight*Math.sin(rtPI)/2;
top = y + cellHeight/2 - textH_all/2 + lastLineSpaceHeight*Math.cos(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;
top = y - (textH_all/2 - rh/2)+lastLineSpaceHeight*Math.cos(rtPI)/2;
}
else if(verticalAlign == "2"){//bottom
left = x + cellWidth/2 - (textW_all/2)-lastLineSpaceHeight*Math.cos(rtPI);
top = y + cellHeight - rh/2 - textH_all/2 - lastLineSpaceHeight*Math.sin(rtPI);
top = y + cellHeight - rh/2 - textH_all/2 - lastLineSpaceHeight*Math.cos(rtPI);
}
}
else if(horizonAlign == "1"){//left
if(verticalAlign == "0"){//mid
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;
top = y - textH_all + cellHeight/2 - rh*Math.cos(rtPI)/2 - lastLineSpaceHeight*Math.cos(rtPI)/2;
}
else if(verticalAlign == "1"){//top
left = x;
top = y - textH_all;
}
else if(verticalAlign == "2"){//bottom
left = x - rh*Math.sin(rtPI) - lastLineSpaceHeight*Math.cos(rtPI);
top = y - textH_all + cellHeight - rh*Math.cos(rtPI) - lastLineSpaceHeight*Math.sin(rtPI);
top = y - textH_all + cellHeight - rh*Math.cos(rtPI) - lastLineSpaceHeight*Math.cos(rtPI);
}
}
else if(horizonAlign == "2"){//right
if(verticalAlign == "0"){//mid
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;
top = y + cellHeight/2 - textH_all/2 - lastLineSpaceHeight*Math.cos(rtPI)/2;
}
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 - textW_all - lastLineSpaceHeight*Math.cos(rtPI) + fixOneLineLeft;
top = y + cellHeight - lastLineSpaceHeight*Math.sin(rtPI);
top = y + cellHeight - lastLineSpaceHeight*Math.cos(rtPI);
}
}

Expand Down Expand Up @@ -1324,10 +1324,11 @@ function getCellTextInfo(cell , ctx, option){
textContent.rotate = rt;

rt = Math.abs(rt);
let rtPI = rt*Math.PI/180;

let textWidthAll = textWidth * Math.cos(rt*Math.PI/180) + textHeight * Math.sin(rt*Math.PI/180);//consider text box wdith and line height
let textWidthAll = textWidth * Math.cos(rtPI) + textHeight * Math.sin(rtPI);//consider text box wdith and line height

let textHeightAll = textWidth * Math.sin(rt*Math.PI/180) + textHeight * Math.cos(rt*Math.PI/180);//consider text box wdith and line height
let textHeightAll = textWidth * Math.sin(rtPI) + textHeight * Math.cos(rtPI);//consider text box wdith and line height

if(rt!=0){
textContent.textHeightAll = textHeightAll;
Expand All @@ -1345,20 +1346,20 @@ function getCellTextInfo(cell , ctx, option){

let width = textWidthAll, height = textHeightAll;

let left = space_width + textHeight * Math.sin(rt*Math.PI/180)*isRotateUp; //默认为1,左对齐
let left = space_width + textHeight * Math.sin(rtPI)*isRotateUp; //默认为1,左对齐
if(horizonAlign == "0"){ //居中对齐
left = cellWidth / 2 - (width / 2) + textHeight * Math.sin(rt*Math.PI/180)*isRotateUp;
left = cellWidth / 2 - (width / 2) + textHeight * Math.sin(rtPI)*isRotateUp;
}
else if(horizonAlign == "2"){ //右对齐
left = (cellWidth - space_width) - width + textHeight * Math.sin(rt*Math.PI/180)*isRotateUp;
left = (cellWidth - space_width) - width + textHeight * Math.sin(rtPI)*isRotateUp;
}

let top = (cellHeight - space_height) - height + measureText.actualBoundingBoxAscent + textWidth * Math.sin(rt*Math.PI/180)*isRotateUp; //默认为2,下对齐
let top = (cellHeight - space_height) - height + measureText.actualBoundingBoxAscent * Math.cos(rtPI) + textWidth * Math.sin(rtPI)*isRotateUp; //默认为2,下对齐
if(verticalAlign == "0"){ //居中对齐
top = cellHeight / 2 - (height / 2) + measureText.actualBoundingBoxAscent + textWidth * Math.sin(rt*Math.PI/180)*isRotateUp;
top = cellHeight / 2 - (height / 2) + measureText.actualBoundingBoxAscent* Math.cos(rtPI) + textWidth * Math.sin(rtPI)*isRotateUp;
}
else if(verticalAlign == "1"){ //上对齐
top = space_height + measureText.actualBoundingBoxAscent + textWidth * Math.sin(rt*Math.PI/180)*isRotateUp;
top = space_height + measureText.actualBoundingBoxAscent* Math.cos(rtPI) + textWidth * Math.sin(rtPI)*isRotateUp;
}

textContent.type = "plain";
Expand Down
82 changes: 41 additions & 41 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
container: 'luckysheet',
lang: 'en',
allowEdit:true,
forceCalculation:true,
forceCalculation:false,
plugins: ['chart'],
fontList:[
{
Expand All @@ -55,46 +55,46 @@
],
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":[
// {"r":0,"c":0,
// "v":{
// "ct":{
// "fa":"General",
// "t":"inlineStr",
// "s":[
// {
// "ff":"Arial", //font family
// "fc":"#fff000",//font color
// "fs":12,//font size
// "cl":0,//strike
// "un":0,//underline
// "bl":0,//blod
// "it":0,//italic
// v:"我在马路\r\n边捡到\r\n\r\n一分钱"
// },
// {
// "ff":"Arial", //font family
// "fc":"#ff0000",//font color
// "fs":14,//font size
// "cl":"1",//strike
// "un":"1",//underline
// "bl":"1",//blod
// "it":"0",//italic
// "ss":0,//0 none 1sup 2sub
// 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":[]}]
/*[{"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":"Arial", //font family
"fc":"#fff000",//font color
"fs":12,//font size
"cl":0,//strike
"un":0,//underline
"bl":0,//blod
"it":0,//italic
v:"我在马路\r\n边捡到\r\n\r\n一分钱"
},
{
"ff":"Arial", //font family
"fc":"#ff0000",//font color
"fs":14,//font size
"cl":"1",//strike
"un":"1",//underline
"bl":"1",//blod
"it":"0",//italic
"ss":0,//0 none 1sup 2sub
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":[]}]*/

/*
[{
Expand Down
6 changes: 6 additions & 0 deletions src/locale/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export default {
moreOptions:"More Options",

cellFormat:"Cell format config",
print:"Print",
},
alternatingColors:{
applyRange: 'Apply to range',
Expand Down Expand Up @@ -1160,6 +1161,11 @@ export default {
normalBtn:"Normal",
layoutBtn:"Page Layout",
pageBtn:"Page break preview",

menuItemPrint:"Print(Ctrl+P)",
menuItemAreas:"Print areas",
menuItemRows:"Print title rows",
menuItemColumns:"Print title columns",
}
};

6 changes: 6 additions & 0 deletions src/locale/zh.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export default {
moreOptions:"更多选项",

cellFormat:"设置单元格格式",
print:"打印",
},
alternatingColors:{
applyRange: '应用范围',
Expand Down Expand Up @@ -1175,6 +1176,11 @@ export default {
normalBtn:"常规视图",
layoutBtn:"页面布局",
pageBtn:"分页预览",

menuItemPrint:"打印(Ctrl+P)",
menuItemAreas:"打印区域",
menuItemRows:"打印标题行",
menuItemColumns:"打印标题列",
}

};

0 comments on commit 9538972

Please sign in to comment.