|
|
|
@ -1,8 +1,17 @@
|
|
|
|
import { ElementType, IElement } from '../../../..'
|
|
|
|
import { ElementType, IElement, TableBorder } from '../../../..'
|
|
|
|
import { IEditorOption } from '../../../../interface/Editor'
|
|
|
|
import { IEditorOption } from '../../../../interface/Editor'
|
|
|
|
import { RangeManager } from '../../../range/RangeManager'
|
|
|
|
import { RangeManager } from '../../../range/RangeManager'
|
|
|
|
import { Draw } from '../../Draw'
|
|
|
|
import { Draw } from '../../Draw'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
interface IDrawTableBorderOption {
|
|
|
|
|
|
|
|
ctx: CanvasRenderingContext2D;
|
|
|
|
|
|
|
|
startX: number;
|
|
|
|
|
|
|
|
startY: number;
|
|
|
|
|
|
|
|
width: number;
|
|
|
|
|
|
|
|
height: number;
|
|
|
|
|
|
|
|
isDrawFullBorder?: boolean;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export class TableParticle {
|
|
|
|
export class TableParticle {
|
|
|
|
|
|
|
|
|
|
|
|
private range: RangeManager
|
|
|
|
private range: RangeManager
|
|
|
|
@ -13,14 +22,19 @@ export class TableParticle {
|
|
|
|
this.options = draw.getOptions()
|
|
|
|
this.options = draw.getOptions()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private _drawBorder(ctx: CanvasRenderingContext2D, startX: number, startY: number, width: number, height: number) {
|
|
|
|
private _drawBorder(payload: IDrawTableBorderOption) {
|
|
|
|
|
|
|
|
const { ctx, startX, startY, width, height, isDrawFullBorder } = payload
|
|
|
|
ctx.beginPath()
|
|
|
|
ctx.beginPath()
|
|
|
|
const x = Math.round(startX)
|
|
|
|
const x = Math.round(startX)
|
|
|
|
const y = Math.round(startY)
|
|
|
|
const y = Math.round(startY)
|
|
|
|
ctx.translate(0.5, 0.5)
|
|
|
|
ctx.translate(0.5, 0.5)
|
|
|
|
ctx.moveTo(x, y + height)
|
|
|
|
if (isDrawFullBorder) {
|
|
|
|
ctx.lineTo(x, y)
|
|
|
|
ctx.rect(x, y, width, height)
|
|
|
|
ctx.lineTo(x + width, y)
|
|
|
|
} else {
|
|
|
|
|
|
|
|
ctx.moveTo(x, y + height)
|
|
|
|
|
|
|
|
ctx.lineTo(x, y)
|
|
|
|
|
|
|
|
ctx.lineTo(x + width, y)
|
|
|
|
|
|
|
|
}
|
|
|
|
ctx.stroke()
|
|
|
|
ctx.stroke()
|
|
|
|
ctx.translate(-0.5, -0.5)
|
|
|
|
ctx.translate(-0.5, -0.5)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -159,31 +173,41 @@ export class TableParticle {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public render(ctx: CanvasRenderingContext2D, element: IElement, startX: number, startY: number) {
|
|
|
|
public render(ctx: CanvasRenderingContext2D, element: IElement, startX: number, startY: number) {
|
|
|
|
const { colgroup, trList } = element
|
|
|
|
const { colgroup, trList, borderType } = element
|
|
|
|
if (!colgroup || !trList) return
|
|
|
|
if (!colgroup || !trList || borderType === TableBorder.EMPTY) return
|
|
|
|
const { scale } = this.options
|
|
|
|
const { scale } = this.options
|
|
|
|
const tableWidth = element.width! * scale
|
|
|
|
const tableWidth = element.width! * scale
|
|
|
|
const tableHeight = element.height! * scale
|
|
|
|
const tableHeight = element.height! * scale
|
|
|
|
|
|
|
|
const isExternalBorderType = borderType === TableBorder.EXTERNAL
|
|
|
|
ctx.save()
|
|
|
|
ctx.save()
|
|
|
|
// 渲染边框
|
|
|
|
// 渲染边框
|
|
|
|
this._drawBorder(ctx, startX, startY, tableWidth, tableHeight)
|
|
|
|
this._drawBorder({
|
|
|
|
// 渲染表格
|
|
|
|
ctx,
|
|
|
|
for (let t = 0; t < trList.length; t++) {
|
|
|
|
startX,
|
|
|
|
const tr = trList[t]
|
|
|
|
startY,
|
|
|
|
for (let d = 0; d < tr.tdList.length; d++) {
|
|
|
|
width: tableWidth,
|
|
|
|
const td = tr.tdList[d]
|
|
|
|
height: tableHeight,
|
|
|
|
const width = td.width! * scale
|
|
|
|
isDrawFullBorder: isExternalBorderType
|
|
|
|
const height = td.height! * scale
|
|
|
|
})
|
|
|
|
const x = Math.round(td.x! * scale + startX + width)
|
|
|
|
if (!isExternalBorderType) {
|
|
|
|
const y = Math.round(td.y! * scale + startY)
|
|
|
|
// 渲染表格
|
|
|
|
ctx.translate(0.5, 0.5)
|
|
|
|
for (let t = 0; t < trList.length; t++) {
|
|
|
|
// 绘制线条
|
|
|
|
const tr = trList[t]
|
|
|
|
ctx.beginPath()
|
|
|
|
for (let d = 0; d < tr.tdList.length; d++) {
|
|
|
|
ctx.moveTo(x, y)
|
|
|
|
const td = tr.tdList[d]
|
|
|
|
ctx.lineTo(x, y + height)
|
|
|
|
const width = td.width! * scale
|
|
|
|
ctx.lineTo(x - width, y + height)
|
|
|
|
const height = td.height! * scale
|
|
|
|
ctx.stroke()
|
|
|
|
const x = Math.round(td.x! * scale + startX + width)
|
|
|
|
ctx.translate(-0.5, -0.5)
|
|
|
|
const y = Math.round(td.y! * scale + startY)
|
|
|
|
|
|
|
|
ctx.translate(0.5, 0.5)
|
|
|
|
|
|
|
|
// 绘制线条
|
|
|
|
|
|
|
|
ctx.beginPath()
|
|
|
|
|
|
|
|
ctx.moveTo(x, y)
|
|
|
|
|
|
|
|
ctx.lineTo(x, y + height)
|
|
|
|
|
|
|
|
ctx.lineTo(x - width, y + height)
|
|
|
|
|
|
|
|
ctx.stroke()
|
|
|
|
|
|
|
|
ctx.translate(-0.5, -0.5)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ctx.restore()
|
|
|
|
ctx.restore()
|
|
|
|
|