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

BREAKING CHANGE: bug

bug
  • Loading branch information
wpxp123456 committed Jul 23, 2020
1 parent 139bc6e commit 1082ab0
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 69 deletions.
15 changes: 2 additions & 13 deletions src/controllers/menuButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +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 { setcellvalue } from '../global/setdata';
import { countfunc } from '../global/count';
import { getSheetIndex, getRangetxt, getluckysheetfile } from '../methods/get';
Expand Down Expand Up @@ -2928,19 +2929,7 @@ const menuButton = {

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);
}
}
strArr = getCellTextSplitArr(strValue, strArr, cellWidth, canvas);

let computeRowlen = oneLineTextHeight * strArr.length;
//比较计算高度和当前高度取最大高度
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -1391,7 +1391,7 @@ const selection = {
}

//复制范围 是否有 条件格式
let ruleArr_cf = [];
let ruleArr_cf = [], cdformat = [];
if(copyRange["copyRange"].length == 1){
let c_file = Store.luckysheetfile[getSheetIndex(copySheetIndex)];
let a_file = Store.luckysheetfile[getSheetIndex(Store.currentSheetIndex)];
Expand All @@ -1402,7 +1402,7 @@ const selection = {
c_c2 = copyRange["copyRange"][0].column[1];

ruleArr_cf = $.extend(true, [], c_file["luckysheet_conditionformat_save"]);
let cdformat = $.extend(true, [], a_file["luckysheet_conditionformat_save"]);
cdformat = $.extend(true, [], a_file["luckysheet_conditionformat_save"]);

if(ruleArr_cf != null && ruleArr_cf.length > 0){
for(let i = 0; i < ruleArr_cf.length; i++){
Expand Down
5 changes: 3 additions & 2 deletions src/controllers/sparkline.js
Original file line number Diff line number Diff line change
Expand Up @@ -1913,11 +1913,12 @@ const luckysheetSparkline = {

},
_getContext: function (lineColor, fillColor, lineWidth) {
let context;
if(this.ctx != null){
let context = this.ctx;
context = this.ctx;
}
else{
let context = $("#" + this._canvasID ).get(0).getContext('2d');
context = $("#" + this._canvasID ).get(0).getContext('2d');
}

if (lineColor !== undefined) {
Expand Down
65 changes: 26 additions & 39 deletions src/global/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { luckysheet_searcharray } from '../controllers/sheetSearch';
import { dynamicArrayCompute } from './dynamicArray';
import browser from './browser';
import { isRealNull } from './validate';
import { getCellTextSplitArr } from './getRowlen';
import { getcellvalue } from './getdata';
import { getBorderInfoCompute } from './border';
import { getObjType, chatatABC, luckysheetfontformat } from '../utils/util';
Expand Down Expand Up @@ -781,23 +782,17 @@ function luckysheetDrawMain(scrollWidth, scrollHeight, drawWidth, drawHeight, of

if(Store.flowdata[r][c].tb == "2"){
let strValue = value.toString();
let tbWidth = luckysheetTableContent.measureText(strValue).width;
let cellWidth = end_c - start_c - 8;
let strArr = [];

for(let strI = 1; strI <= strValue.length; strI++){
let strV = strValue.substring(strArr.join("").length, strI);
let strtextMetrics = luckysheetTableContent.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);
}
}

textH = strArr.length * oneLineTextHeight;
if(tbWidth > cellWidth){
let strArr = [];//文本截断数组
strArr = getCellTextSplitArr(strValue, strArr, cellWidth, luckysheetTableContent);
textH = strArr.length * oneLineTextHeight;
}
else{
textH = oneLineTextHeight;
}
}
else if(Store.flowdata[r][c].tr != null && Store.flowdata[r][c].tr != "0"){
let tr = Store.flowdata[r][c].tr;
Expand Down Expand Up @@ -831,6 +826,11 @@ function luckysheetDrawMain(scrollWidth, scrollHeight, drawWidth, drawHeight, of
textH = oneLineTextHeight;
}

//水平对齐
let horizonAlign = menuButton.checkstatus(Store.flowdata, r, c , "ht");
//垂直对齐
let verticalAlign = menuButton.checkstatus(Store.flowdata, r, c , "vt");

//水平对齐方式是 居中或居右对齐 且单元格宽度小于文字宽度 (用离屏canvas渲染)
let canvasName, cellsize;
if(browser.BrowserType() != "Safari" && (canvasType == "offline" || ((horizonAlign == "0" || horizonAlign == "2") && (end_c - start_c) < textW) || ((verticalAlign == "0" || verticalAlign == "2") && (end_r - start_r) < textH))){
Expand All @@ -855,21 +855,19 @@ function luckysheetDrawMain(scrollWidth, scrollHeight, drawWidth, drawHeight, of
];
}

//水平对齐
let horizonAlign = menuButton.checkstatus(Store.flowdata, r, c , "ht");
let horizonAlignPos = (start_c + 4 + offsetLeft) * Store.devicePixelRatio; //horizonAlign默认为1,左对齐
if(horizonAlign == "0"){ //居中对齐
//horizonAlign默认为1,左对齐
let horizonAlignPos = (start_c + 4 + offsetLeft) * Store.devicePixelRatio;
if(horizonAlign == "0"){
//居中对齐
horizonAlignPos = (start_c + (end_c - start_c) / 2 + offsetLeft) * Store.devicePixelRatio - (textMetrics) / 2;
}
else if(horizonAlign == "2"){ //右对齐
else if(horizonAlign == "2"){
//右对齐
horizonAlignPos = (end_c + offsetLeft - 8) * Store.devicePixelRatio - (textMetrics);
}

//垂直对齐
let verticalAlign = menuButton.checkstatus(Store.flowdata, r, c , "vt");
let verticalFixed = browser.luckysheetrefreshfixed();

//verticalAlign默认为2,下对齐
let verticalFixed = browser.luckysheetrefreshfixed();
let verticalAlignPos = (end_r + offsetTop - 2 + verticalFixed) * Store.devicePixelRatio - oneLineTextHeight;
let verticalAlignPos_text = (end_r + offsetTop - 2 + verticalFixed) * Store.devicePixelRatio;
canvasName.textBaseline = "bottom";
Expand Down Expand Up @@ -1109,21 +1107,10 @@ function luckysheetDrawMain(scrollWidth, scrollHeight, drawWidth, drawHeight, of

let strValue = value.toString();
let cellWidth = end_c - start_c - 8;
let strArr = [];

for(let strI = 1; strI <= strValue.length; strI++){
let strV = strValue.substring(strArr.join("").length, strI);
let strtextMetrics = canvasName.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);
}
}


let strArr = [];//文本截断数组
strArr = getCellTextSplitArr(strValue, strArr, cellWidth, canvasName);

for(let iFill = 0; iFill < strArr.length; iFill++){
//水平对齐计算
let strWidth = canvasName.measureText(strArr[iFill]).width;
Expand Down
20 changes: 7 additions & 13 deletions src/global/formula.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import luckysheetFreezen from '../controllers/freezen';
import { seletedHighlistByindex, luckysheet_count_show } from '../controllers/select';
import { isRealNum, isRealNull, valueIsError, isEditMode } from './validate';
import { isdatetime, isdatatype } from './datecontroll';
import { getCellTextSplitArr } from '../global/getRowlen';
import { getcellvalue } from './getdata';
import { setcellvalue } from './setdata';
import { genarate, valueShowEs } from './format';
Expand Down Expand Up @@ -1307,21 +1308,14 @@ const luckysheetformula = {

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

for(let strI = 1; strI <= strValue.length; strI++){
let strV = strValue.substring(strArr.join("").length,strI);
let strtextMetrics = offlinecanvas.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);
}
}
strArr = getCellTextSplitArr(strValue, strArr, cellWidth, offlinecanvas);

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

if(currentRowLen != defaultrowlen){
Expand Down
24 changes: 24 additions & 0 deletions src/global/getRowlen.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,31 @@ function computeRowlenArr(rowHeight, cfg) {
return rowlenArr;
}

//获取换行单元格截断数组
function getCellTextSplitArr(strValue, strArr, cellWidth, canvas){
for(let strI = 1; strI <= strValue.length; strI++){
let strV = strValue.substring(0, strI);
let strtextMetrics = canvas.measureText(strV).width;

if(strtextMetrics > cellWidth){
if(strI - 1 <= 0){
return strArr;
}
else{
strArr.push(strValue.substring(0, strI - 1));
return getCellTextSplitArr(strValue.substring(strI - 1), strArr, cellWidth, canvas);
}
}
else if(strI == strValue.length){
strArr.push(strV);
}
}

return strArr;
}

export {
rowlenByRange,
computeRowlenArr,
getCellTextSplitArr,
}

0 comments on commit 1082ab0

Please sign in to comment.