feat: add editor placeholder
This commit is contained in:
@@ -54,6 +54,7 @@ import { Zone } from '../zone/Zone'
|
||||
import { Footer } from './frame/Footer'
|
||||
import { INLINE_ELEMENT_TYPE } from '../../dataset/constant/Element'
|
||||
import { ListParticle } from './particle/ListParticle'
|
||||
import { Placeholder } from './frame/Placeholder'
|
||||
|
||||
export class Draw {
|
||||
|
||||
@@ -91,6 +92,7 @@ export class Draw {
|
||||
private tableTool: TableTool
|
||||
private pageNumber: PageNumber
|
||||
private waterMark: Watermark
|
||||
private placeholder: Placeholder
|
||||
private header: Header
|
||||
private footer: Footer
|
||||
private hyperlinkParticle: HyperlinkParticle
|
||||
@@ -156,6 +158,7 @@ export class Draw {
|
||||
this.tableTool = new TableTool(this)
|
||||
this.pageNumber = new PageNumber(this)
|
||||
this.waterMark = new Watermark(this)
|
||||
this.placeholder = new Placeholder(this)
|
||||
this.header = new Header(this)
|
||||
this.footer = new Footer(this)
|
||||
this.hyperlinkParticle = new HyperlinkParticle(this)
|
||||
@@ -1374,6 +1377,10 @@ export class Draw {
|
||||
if (pageMode !== PageMode.CONTINUITY && this.options.watermark.data) {
|
||||
this.waterMark.render(ctx)
|
||||
}
|
||||
// 绘制空白占位符
|
||||
if (this.elementList.length <= 1) {
|
||||
this.placeholder.render(ctx)
|
||||
}
|
||||
}
|
||||
|
||||
private _lazyRender() {
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
import { IEditorOption, IElement } from '../../..'
|
||||
import { DeepRequired } from '../../../interface/Common'
|
||||
import { IElementPosition } from '../../../interface/Element'
|
||||
import { IRow } from '../../../interface/Row'
|
||||
import { formatElementList } from '../../../utils/element'
|
||||
import { Position } from '../../position/Position'
|
||||
import { Draw } from '../Draw'
|
||||
|
||||
export class Placeholder {
|
||||
|
||||
private draw: Draw
|
||||
private position: Position
|
||||
private options: DeepRequired<IEditorOption>
|
||||
|
||||
private elementList: IElement[]
|
||||
private rowList: IRow[]
|
||||
private positionList: IElementPosition[]
|
||||
|
||||
constructor(draw: Draw) {
|
||||
this.draw = draw
|
||||
this.position = draw.getPosition()
|
||||
this.options = <DeepRequired<IEditorOption>>draw.getOptions()
|
||||
|
||||
this.elementList = []
|
||||
this.rowList = []
|
||||
this.positionList = []
|
||||
}
|
||||
|
||||
private _recovery() {
|
||||
this.elementList = []
|
||||
this.rowList = []
|
||||
this.positionList = []
|
||||
}
|
||||
|
||||
public _compute() {
|
||||
this._computeRowList()
|
||||
this._computePositionList()
|
||||
}
|
||||
|
||||
private _computeRowList() {
|
||||
const innerWidth = this.draw.getInnerWidth()
|
||||
this.rowList = this.draw.computeRowList(innerWidth, this.elementList)
|
||||
}
|
||||
|
||||
private _computePositionList() {
|
||||
const headerExtraHeight = this.draw.getHeader().getExtraHeight()
|
||||
const innerWidth = this.draw.getInnerWidth()
|
||||
const margins = this.draw.getMargins()
|
||||
const startX = margins[3]
|
||||
const startY = margins[0] + headerExtraHeight
|
||||
this.position.computePageRowPosition({
|
||||
positionList: this.positionList,
|
||||
rowList: this.rowList,
|
||||
pageNo: 0,
|
||||
startRowIndex: 0,
|
||||
startIndex: 0,
|
||||
startX,
|
||||
startY,
|
||||
innerWidth
|
||||
})
|
||||
}
|
||||
|
||||
public render(ctx: CanvasRenderingContext2D) {
|
||||
const { placeholder: { data, font, size, color, opacity } } = this.options
|
||||
if (!data) return
|
||||
this._recovery()
|
||||
// 构建元素列表并格式化
|
||||
this.elementList = [{
|
||||
value: data,
|
||||
font,
|
||||
size,
|
||||
color
|
||||
}]
|
||||
formatElementList(this.elementList, {
|
||||
editorOptions: this.options
|
||||
})
|
||||
// 计算
|
||||
this._compute()
|
||||
const innerWidth = this.draw.getInnerWidth()
|
||||
// 绘制
|
||||
ctx.save()
|
||||
ctx.globalAlpha = opacity
|
||||
this.draw.drawRow(ctx, {
|
||||
elementList: this.elementList,
|
||||
positionList: this.positionList,
|
||||
rowList: this.rowList,
|
||||
pageNo: 0,
|
||||
startIndex: 0,
|
||||
innerWidth
|
||||
})
|
||||
ctx.restore()
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user