Browse Source

API setauto rowheight cs

master
Smillence 5 years ago
parent
commit
717ccaf6df
  1. 36
      src/global/getRowlen.js
  2. 23
      src/global/location.js

36
src/global/getRowlen.js

@ -1,9 +1,9 @@
import { luckysheetfontformat } from '../utils/util'; import {luckysheetfontformat} from '../utils/util';
import menuButton from '../controllers/menuButton'; import menuButton from '../controllers/menuButton';
import { getcellvalue,checkstatusByCell } from './getdata'; import {checkstatusByCell} from './getdata';
import { colLocationByIndex } from './location'; import {colLocationByIndex,colSpanLocationByIndex} from './location';
import { hasChinaword, isRealNull,checkWordByteLength } from './validate'; import {checkWordByteLength, hasChinaword, isRealNull} from './validate';
import { isInlineStringCell } from '../controllers/inlineString'; import {isInlineStringCell} from '../controllers/inlineString';
import Store from '../store'; import Store from '../store';
/** /**
@ -90,12 +90,19 @@ function computeRowlenByContent(d, r) {
for(let c = 0; c < d[r].length; c++){ for(let c = 0; c < d[r].length; c++){
let cell = d[r][c]; let cell = d[r][c];
if(cell == null || cell.mc != null){ if (cell == null) {
continue; continue;
} }
if (cell.mc != null) {
if (1 !== cell.mc.rs) {
continue;
}
}
if(cell != null && (cell.v != null || isInlineStringCell(cell)) ){ if(cell != null && (cell.v != null || isInlineStringCell(cell)) ){
let cellWidth = colLocationByIndex(c)[1] - colLocationByIndex(c)[0] - 2; let cellWidth = computeCellWidth(cell, c);
let textInfo = getCellTextInfo(cell, canvas,{ let textInfo = getCellTextInfo(cell, canvas,{
r:r, r:r,
@ -105,12 +112,12 @@ function computeRowlenByContent(d, r) {
let computeRowlen = 0; let computeRowlen = 0;
if(textInfo!=null){ if (textInfo != null) {
computeRowlen = textInfo.textHeightAll+2; computeRowlen = textInfo.textHeightAll + 2;
} }
//比较计算高度和当前高度取最大高度 //比较计算高度和当前高度取最大高度
if(computeRowlen > currentRowLen){ if (computeRowlen > currentRowLen) {
currentRowLen = computeRowlen; currentRowLen = computeRowlen;
} }
} }
@ -119,6 +126,15 @@ function computeRowlenByContent(d, r) {
return currentRowLen; return currentRowLen;
} }
function computeCellWidth(cell, col_index) {
let colLocationArr = colLocationByIndex(col_index);
if (cell.mc && cell.mc.c !== cell.mc.cs) {
colLocationArr = colSpanLocationByIndex(col_index, cell.mc.cs);
}
return colLocationArr[1] - colLocationArr[0] - 2;
}
//计算表格行高数组 //计算表格行高数组
function computeRowlenArr(rowHeight, cfg) { function computeRowlenArr(rowHeight, cfg) {

23
src/global/location.js

@ -24,12 +24,12 @@ function rowLocation(y) {
else if (row_index == -1 && y <= 0) { else if (row_index == -1 && y <= 0) {
row_index = 0; row_index = 0;
} }
return rowLocationByIndex(row_index); return rowLocationByIndex(row_index);
} }
function colLocationByIndex(col_index){ function colLocationByIndex(col_index){
let col = 0, col_pre = 0; let col = 0, col_pre = 0;
col = Store.visibledatacolumn[col_index]; col = Store.visibledatacolumn[col_index];
if (col_index == 0) { if (col_index == 0) {
@ -42,6 +42,20 @@ function colLocationByIndex(col_index){
return [col_pre, col, col_index]; return [col_pre, col, col_index];
} }
function colSpanLocationByIndex(col_index, span){
let col = 0, col_pre = 0;
col = Store.visibledatacolumn[col_index + span - 1];
if (col_index == 0) {
col_pre = 0;
}
else {
col_pre = Store.visibledatacolumn[col_index - 1];
}
return [col_pre, col, col_index];
}
function colLocation(x) { function colLocation(x) {
let col_index = luckysheet_searcharray(Store.visibledatacolumn, x); let col_index = luckysheet_searcharray(Store.visibledatacolumn, x);
@ -57,7 +71,7 @@ function colLocation(x) {
function mouseposition(x, y) { function mouseposition(x, y) {
let container_offset = $("#" + Store.container).offset(); let container_offset = $("#" + Store.container).offset();
let newX = x - container_offset.left - Store.rowHeaderWidth, let newX = x - container_offset.left - Store.rowHeaderWidth,
newY = y - container_offset.top - Store.infobarHeight - Store.toolbarHeight - Store.calculatebarHeight - Store.columnHeaderHeight; newY = y - container_offset.top - Store.infobarHeight - Store.toolbarHeight - Store.calculatebarHeight - Store.columnHeaderHeight;
@ -68,6 +82,7 @@ export {
rowLocationByIndex, rowLocationByIndex,
rowLocation, rowLocation,
colLocationByIndex, colLocationByIndex,
colSpanLocationByIndex,
colLocation, colLocation,
mouseposition, mouseposition,
} }

Loading…
Cancel
Save