refactor: update tdPadding option format

This commit is contained in:
Hufe921
2023-09-02 16:24:32 +08:00
parent d8876b1095
commit 752ca43077
7 changed files with 32 additions and 20 deletions
+10 -8
View File
@@ -63,7 +63,7 @@ import {
import { Control } from './control/Control'
import { zipElementList } from '../../utils/element'
import { CheckboxParticle } from './particle/CheckboxParticle'
import { DeepRequired } from '../../interface/Common'
import { DeepRequired, IPadding } from '../../interface/Common'
import { ControlComponent, ImageDisplay } from '../../dataset/enum/Control'
import { formatElementList } from '../../utils/element'
import { WorkerManager } from '../worker/WorkerManager'
@@ -358,8 +358,9 @@ export class Draw {
return this.options.defaultBasicRowMarginHeight * this.options.scale
}
public getTdPadding(): number {
return this.options.tdPadding * this.options.scale
public getTdPadding(): IPadding {
const { tdPadding, scale } = this.options
return <IPadding>tdPadding.map(m => m * scale)
}
public getContainer(): HTMLDivElement {
@@ -1079,7 +1080,8 @@ export class Draw {
}
metrics.boundingBoxAscent = 0
} else if (element.type === ElementType.TABLE) {
const tdGap = tdPadding * 2
const tdPaddingWidth = tdPadding[1] + tdPadding[3]
const tdPaddingHeight = tdPadding[0] + tdPadding[2]
// 计算表格行列
this.tableParticle.computeRowColInfo(element)
// 计算表格内元素信息
@@ -1089,13 +1091,13 @@ export class Draw {
for (let d = 0; d < tr.tdList.length; d++) {
const td = tr.tdList[d]
const rowList = this.computeRowList(
(td.width! - tdGap) * scale,
(td.width! - tdPaddingWidth) * scale,
td.value
)
const rowHeight = rowList.reduce((pre, cur) => pre + cur.height, 0)
td.rowList = rowList
// 移除缩放导致的行高变化-渲染时会进行缩放调整
const curTdHeight = (rowHeight + tdGap) / scale
const curTdHeight = (rowHeight + tdPaddingHeight) / scale
// 内容高度大于当前单元格高度需增加
if (td.height! < curTdHeight) {
const extraHeight = curTdHeight - td.height!
@@ -1637,7 +1639,7 @@ export class Draw {
index++
// 绘制表格内元素
if (element.type === ElementType.TABLE) {
const tdGap = tdPadding * 2
const tdPaddingWidth = tdPadding[1] + tdPadding[3]
for (let t = 0; t < element.trList!.length; t++) {
const tr = element.trList![t]
for (let d = 0; d < tr.tdList!.length; d++) {
@@ -1648,7 +1650,7 @@ export class Draw {
rowList: td.rowList!,
pageNo,
startIndex: 0,
innerWidth: (td.width! - tdGap) * scale,
innerWidth: (td.width! - tdPaddingWidth) * scale,
zone
})
}
+7 -5
View File
@@ -142,7 +142,8 @@ export class Position {
x += metrics.width
// 计算表格内元素位置
if (element.type === ElementType.TABLE) {
const tdGap = tdPadding * 2
const tdPaddingWidth = tdPadding[1] + tdPadding[3]
const tdPaddingHeight = tdPadding[0] + tdPadding[2]
for (let t = 0; t < element.trList!.length; t++) {
const tr = element.trList![t]
for (let d = 0; d < tr.tdList!.length; d++) {
@@ -155,9 +156,9 @@ export class Position {
pageNo,
startRowIndex: 0,
startIndex: 0,
startX: (td.x! + tdPadding) * scale + tablePreX,
startY: td.y! * scale + tablePreY,
innerWidth: (td.width! - tdGap) * scale
startX: (td.x! + tdPadding[3]) * scale + tablePreX,
startY: (td.y! + tdPadding[0]) * scale + tablePreY,
innerWidth: (td.width! - tdPaddingWidth) * scale
})
// 垂直对齐方式
if (
@@ -168,7 +169,8 @@ export class Position {
(pre, cur) => pre + cur.height,
0
)
const blankHeight = (td.height! - tdGap) * scale - rowsHeight
const blankHeight =
(td.height! - tdPaddingHeight) * scale - rowsHeight
const offsetHeight =
td.verticalAlign === VerticalAlign.MIDDLE
? blankHeight / 2
+2 -2
View File
@@ -154,8 +154,8 @@ export default class Editor {
marginIndicatorColor: '#BABABA',
margins: [100, 120, 100, 120],
pageMode: PageMode.PAGING,
tdPadding: 5,
defaultTrMinHeight: 40,
tdPadding: [0, 5, 5, 5],
defaultTrMinHeight: 42,
defaultColMinWidth: 40,
defaultHyperlinkColor: '#0000FF',
paperDirection: PaperDirection.VERTICAL,
+7
View File
@@ -34,3 +34,10 @@ export type DeepRequired<T> = T extends Error
export type DeepPartial<T> = {
[P in keyof T]?: DeepPartial<T[P]>
}
export type IPadding = [
top: number,
right: number,
bottom: number,
left: number
]
+2 -1
View File
@@ -6,6 +6,7 @@ import {
WordBreak
} from '../dataset/enum/Editor'
import { ICheckboxOption } from './Checkbox'
import { IPadding } from './Common'
import { IControlOption } from './Control'
import { ICursorOption } from './Cursor'
import { IFooter } from './Footer'
@@ -53,7 +54,7 @@ export interface IEditorOption {
marginIndicatorColor?: string
margins?: IMargin
pageMode?: PageMode
tdPadding?: number
tdPadding?: IPadding
defaultTrMinHeight?: number
defaultColMinWidth?: number
defaultHyperlinkColor?: string