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

Commit

Permalink
fix(bug): bug
Browse files Browse the repository at this point in the history
bug
  • Loading branch information
wpxp123456 committed Aug 3, 2020
1 parent f057d7d commit 6236e5e
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 272 deletions.
217 changes: 22 additions & 195 deletions src/controllers/menuButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { sortSelection } from '../global/sort';
import luckysheetformula from '../global/formula';
import { rowLocationByIndex, colLocationByIndex } from '../global/location';
import { isdatatypemulti } from '../global/datecontroll';
import { getCellTextSplitArr } from '../global/getRowlen';
import { rowlenByRange, getCellTextSplitArr } from '../global/getRowlen';
import { setcellvalue } from '../global/setdata';
import { countfunc } from '../global/count';
import { getSheetIndex, getRangetxt, getluckysheetfile } from '../methods/get';
Expand Down Expand Up @@ -848,6 +848,25 @@ const menuButton = {
}
mouseclickposition($menuButton, menuleft, $(this).offset().top + 25, "lefttop");
})
.find("input.luckysheet-toolbar-textinput").keyup(function(e){
if(e.keyCode != 13){//Enter
return;
}

let $this = $(this);

let itemvalue = parseInt($this.val());
let $menuButton = $("#luckysheet-icon-font-size-menuButton");
_this.focus($menuButton, itemvalue);

let d = editor.deepCopyFlowData(Store.flowdata);
_this.updateFormat(d, "fs", itemvalue);

luckysheet_fs_setTimeout = setTimeout(function(){
$menuButton.hide();
$this.blur();
}, 200);
});

//边框设置
$("#luckysheet-icon-border-all").click(function(){
Expand Down Expand Up @@ -2924,202 +2943,10 @@ const menuButton = {
}
}

if(attr == "tb" && foucsStatus == "2"){
//自动换行
for (let r = row_st; r <= row_ed; r++) {
if (Store.config["rowhidden"] != null && Store.config["rowhidden"][r] != null) {
continue;
}

let currentRowLen = Store.defaultrowlen;
if(cfg["rowlen"][r] != null){
currentRowLen = cfg["rowlen"][r];
}

for (let c = col_st; c <= col_ed; c++) {
let cell = d[r][c];

if(cell != null && !isRealNull(cell.v)){
let fontset = luckysheetfontformat(cell);
let oneLineTextHeight = _this.getTextSize("田", fontset)[1];
canvas.font = fontset;

let strValue = cell.m.toString();
let tbWidth = canvas.measureText(strValue).width;
let cellWidth = colLocationByIndex(c)[1] - colLocationByIndex(c)[0] - 8;

if(tbWidth > cellWidth){
let strArr = [];//文本截断数组
strArr = getCellTextSplitArr(strValue, strArr, cellWidth, canvas);

let computeRowlen = oneLineTextHeight * strArr.length;
//比较计算高度和当前高度取最大高度
if(computeRowlen > currentRowLen){
currentRowLen = computeRowlen;
}
}
}
}

if(currentRowLen != Store.defaultrowlen){
cfg["rowlen"][r] = currentRowLen;
}
}
}
else if(attr == "tr"){
//文本旋转
for (let r = row_st; r <= row_ed; r++) {
if (Store.config["rowhidden"] != null && Store.config["rowhidden"][r] != null) {
continue;
}

let currentRowLen = Store.defaultrowlen;
if(cfg["rowlen"][r] != null){
currentRowLen = cfg["rowlen"][r];
}

for (let c = col_st; c <= col_ed; c++) {
let cell = d[r][c];

if(cell != null && !isRealNull(cell.v)){
let fontset = luckysheetfontformat(cell);
let oneLineTextHeight = _this.getTextSize("田", fontset)[1];
canvas.font = fontset;

let value = cell.m.toString();
let textMetrics = canvas.measureText(value).width;

let computeRowlen; //计算高度
if(foucsStatus == "0"){
//无旋转
computeRowlen = oneLineTextHeight;
}
else if(foucsStatus == "1" || foucsStatus == "2"){
//向下倾斜(45 旋转)----向上倾斜(-45 旋转)
computeRowlen = 0.707 * (textMetrics + oneLineTextHeight) + 4;
}
else if(foucsStatus == "3"){
//竖排文字
computeRowlen = value.length * oneLineTextHeight + 4;
}
else if(foucsStatus == "4" || foucsStatus == "5"){
//向下90(90 旋转)----向上90(-90 旋转)
computeRowlen = textMetrics + 4;
}
computeRowlen = Math.round(computeRowlen);
//比较计算高度和当前高度取最大高度
if(computeRowlen > currentRowLen){
currentRowLen = computeRowlen;
}
}
}

if(currentRowLen != Store.defaultrowlen){
cfg["rowlen"][r] = currentRowLen;
}
}
}
else if(attr == "fs"){
//字体大小
for (let r = row_st; r <= row_ed; r++) {
if (Store.config["rowhidden"] != null && Store.config["rowhidden"][r] != null) {
continue;
}

let currentRowLen = Store.defaultrowlen;
if(cfg["rowlen"][r] != null){
currentRowLen = cfg["rowlen"][r];
}

for (let c = col_st; c <= col_ed; c++) {
let cell = d[r][c];

if(cell == null){
continue;
}

let fontset = luckysheetfontformat(cell);
let oneLineTextHeight = _this.getTextSize("田", fontset)[1];
canvas.font = fontset;

//计算高度
let computeRowlen;
if(isRealNull(cell.v)){
computeRowlen = oneLineTextHeight;
}
else{
if(cell.tb == "2"){
//单元格有自动换行标示
let strValue = cell.m.toString();
let tbWidth = canvas.measureText(strValue).width;
let cellWidth = colLocationByIndex(c)[1] - colLocationByIndex(c)[0] - 8;

if(tbWidth > cellWidth){
let strArr = [];//文本截断数组

for(let strI = 1; strI <= strValue.length; strI++){
let strV = strValue.substring(strArr.join("").length, strI);
let strtextMetrics = canvas.measureText(strV).width;

if(strtextMetrics > cellWidth){
strArr.push(strValue.substring(strArr.join("").length, strI-1));
strI = strI - 2;
}
else if(strtextMetrics <= cellWidth && strI == strValue.length){
strArr.push(strV);
}
}

computeRowlen = oneLineTextHeight * strArr.length;
}
else{
computeRowlen = oneLineTextHeight;
}
}
else if(cell.tr != null){
//单元格有旋转标示
let tr = cell.tr;
let value = cell.m.toString();
let textMetrics = canvas.measureText(value).width;

if(tr == "0"){
//无旋转
computeRowlen = oneLineTextHeight;
}
else if(tr == "1" || tr == "2"){
//向下倾斜(45 旋转)----向上倾斜(-45 旋转)
computeRowlen = 0.707 * (textMetrics + oneLineTextHeight) + 4;
}
else if(tr == "3"){
//竖排文字
computeRowlen = value.length * oneLineTextHeight + 4;
}
else if(tr == "4" || tr == "5"){
//向下90(90 旋转)----向上90(-90 旋转)
computeRowlen = textMetrics + 4;
}

computeRowlen = Math.round(computeRowlen);
}
else{
computeRowlen = oneLineTextHeight;
}
}

//比较计算高度和当前高度取最大高度
if(computeRowlen > currentRowLen){
currentRowLen = computeRowlen;
}
}

if(currentRowLen != Store.defaultrowlen){
cfg["rowlen"][r] = currentRowLen;
}
}
}
cfg = rowlenByRange(d, row_st, row_ed, cfg);
}

if((attr == "tb" && foucsStatus == "2") || attr == "tr" || attr == "fs"){
if(attr == "tb" || attr == "tr" || attr == "fs"){
jfrefreshgrid(d, Store.luckysheet_select_save, cfg, null, true);
}
else{
Expand Down
3 changes: 0 additions & 3 deletions src/global/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -955,9 +955,6 @@ let nullCellRender = function(r, c, start_r, start_c, end_r, end_c,luckysheetTab
let fontset = luckysheetdefaultFont();
luckysheetTableContent.font = fontset;

// let textMetrics = luckysheetTableContent.measureText(value).width;
// let oneLineTextHeight = menuButton.getTextSize("田", fontset)[1];

//水平对齐 (默认为1,左对齐)
let horizonAlignPos = (start_c + 4 + offsetLeft) * Store.devicePixelRatio;

Expand Down
14 changes: 9 additions & 5 deletions src/global/formula.js
Original file line number Diff line number Diff line change
Expand Up @@ -1312,6 +1312,8 @@ const luckysheetformula = {
let defaultrowlen = 19;

let offlinecanvas = $("#luckysheetTableContentF").get(0).getContext("2d");
offlinecanvas.textBaseline = 'top'; //textBaseline以top计算

let fontset = luckysheetfontformat(d[r][c]);
offlinecanvas.font = fontset;

Expand All @@ -1321,15 +1323,17 @@ const luckysheetformula = {
}

let strValue = getcellvalue(r, c, d).toString();
let tbWidth = offlinecanvas.measureText(strValue).width;
let cellWidth = colLocationByIndex(c)[1] - colLocationByIndex(c)[0] - 8;
let measureText = offlinecanvas.measureText(strValue);

let textMetrics = measureText.width;
let cellWidth = colLocationByIndex(c)[1] - colLocationByIndex(c)[0] - 4;
let oneLineTextHeight = measureText.actualBoundingBoxDescent - measureText.actualBoundingBoxAscent;

if(tbWidth > cellWidth){
if(textMetrics > cellWidth){
let strArr = [];//文本截断数组
strArr = getCellTextSplitArr(strValue, strArr, cellWidth, offlinecanvas);

let oneLineTextHeight = menuButton.getTextSize("田", fontset)[1];
let computeRowlen = oneLineTextHeight * strArr.length;
let computeRowlen = oneLineTextHeight * strArr.length + 4;
//比较计算高度和当前高度取最大高度
if(computeRowlen > currentRowLen){
currentRowLen = computeRowlen;
Expand Down
Loading

0 comments on commit 6236e5e

Please sign in to comment.