|
|
|
|
@ -86,6 +86,7 @@ export class Draw {
|
|
|
|
|
private pageList: HTMLCanvasElement[]
|
|
|
|
|
private ctxList: CanvasRenderingContext2D[]
|
|
|
|
|
private pageNo: number
|
|
|
|
|
private pagePixelRatio: number | null
|
|
|
|
|
private mode: EditorMode
|
|
|
|
|
private options: DeepRequired<IEditorOption>
|
|
|
|
|
private position: Position
|
|
|
|
|
@ -151,6 +152,7 @@ export class Draw {
|
|
|
|
|
this.pageList = []
|
|
|
|
|
this.ctxList = []
|
|
|
|
|
this.pageNo = 0
|
|
|
|
|
this.pagePixelRatio = null
|
|
|
|
|
this.mode = options.mode
|
|
|
|
|
this.options = options
|
|
|
|
|
this.headerElementList = data.header || []
|
|
|
|
|
@ -627,7 +629,10 @@ export class Draw {
|
|
|
|
|
return this.rowList.length
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async getDataURL(): Promise<string[]> {
|
|
|
|
|
public async getDataURL(pixelRatio?: number): Promise<string[]> {
|
|
|
|
|
if (pixelRatio) {
|
|
|
|
|
this.setPagePixelRatio(pixelRatio)
|
|
|
|
|
}
|
|
|
|
|
this.render({
|
|
|
|
|
isLazy: false,
|
|
|
|
|
isCompute: false,
|
|
|
|
|
@ -635,7 +640,11 @@ export class Draw {
|
|
|
|
|
isSubmitHistory: false
|
|
|
|
|
})
|
|
|
|
|
await this.imageObserver.allSettled()
|
|
|
|
|
return this.pageList.map(c => c.toDataURL())
|
|
|
|
|
const dataUrlList = this.pageList.map(c => c.toDataURL())
|
|
|
|
|
if (pixelRatio) {
|
|
|
|
|
this.setPagePixelRatio(null)
|
|
|
|
|
}
|
|
|
|
|
return dataUrlList
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public getPainterStyle(): IElementStyle | null {
|
|
|
|
|
@ -678,7 +687,7 @@ export class Draw {
|
|
|
|
|
// 纸张大小重置
|
|
|
|
|
if (payload === PageMode.PAGING) {
|
|
|
|
|
const { height } = this.options
|
|
|
|
|
const dpr = window.devicePixelRatio
|
|
|
|
|
const dpr = this.getPagePixelRatio()
|
|
|
|
|
const canvas = this.pageList[0]
|
|
|
|
|
canvas.style.height = `${height}px`
|
|
|
|
|
canvas.height = height * dpr
|
|
|
|
|
@ -704,7 +713,7 @@ export class Draw {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public setPageScale(payload: number) {
|
|
|
|
|
const dpr = window.devicePixelRatio
|
|
|
|
|
const dpr = this.getPagePixelRatio()
|
|
|
|
|
this.options.scale = payload
|
|
|
|
|
const width = this.getWidth()
|
|
|
|
|
const height = this.getHeight()
|
|
|
|
|
@ -726,8 +735,23 @@ export class Draw {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public getPagePixelRatio(): number {
|
|
|
|
|
return this.pagePixelRatio || window.devicePixelRatio
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public setPagePixelRatio(payload: number | null) {
|
|
|
|
|
if (
|
|
|
|
|
(!this.pagePixelRatio && payload === window.devicePixelRatio) ||
|
|
|
|
|
payload === this.pagePixelRatio
|
|
|
|
|
) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
this.pagePixelRatio = payload
|
|
|
|
|
this.setPageDevicePixel()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public setPageDevicePixel() {
|
|
|
|
|
const dpr = window.devicePixelRatio
|
|
|
|
|
const dpr = this.getPagePixelRatio()
|
|
|
|
|
const width = this.getWidth()
|
|
|
|
|
const height = this.getHeight()
|
|
|
|
|
this.pageList.forEach((p, i) => {
|
|
|
|
|
@ -744,7 +768,7 @@ export class Draw {
|
|
|
|
|
public setPaperSize(width: number, height: number) {
|
|
|
|
|
this.options.width = width
|
|
|
|
|
this.options.height = height
|
|
|
|
|
const dpr = window.devicePixelRatio
|
|
|
|
|
const dpr = this.getPagePixelRatio()
|
|
|
|
|
const realWidth = this.getWidth()
|
|
|
|
|
const realHeight = this.getHeight()
|
|
|
|
|
this.container.style.width = `${realWidth}px`
|
|
|
|
|
@ -762,7 +786,7 @@ export class Draw {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public setPaperDirection(payload: PaperDirection) {
|
|
|
|
|
const dpr = window.devicePixelRatio
|
|
|
|
|
const dpr = this.getPagePixelRatio()
|
|
|
|
|
this.options.paperDirection = payload
|
|
|
|
|
const width = this.getWidth()
|
|
|
|
|
const height = this.getHeight()
|
|
|
|
|
@ -878,7 +902,7 @@ export class Draw {
|
|
|
|
|
canvas.setAttribute('data-index', String(pageNo))
|
|
|
|
|
this.pageContainer.append(canvas)
|
|
|
|
|
// 调整分辨率
|
|
|
|
|
const dpr = window.devicePixelRatio
|
|
|
|
|
const dpr = this.getPagePixelRatio()
|
|
|
|
|
canvas.width = width * dpr
|
|
|
|
|
canvas.height = height * dpr
|
|
|
|
|
canvas.style.cursor = 'text'
|
|
|
|
|
@ -891,7 +915,7 @@ export class Draw {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private _initPageContext(ctx: CanvasRenderingContext2D) {
|
|
|
|
|
const dpr = window.devicePixelRatio
|
|
|
|
|
const dpr = this.getPagePixelRatio()
|
|
|
|
|
ctx.scale(dpr, dpr)
|
|
|
|
|
// 重置以下属性是因部分浏览器(chrome)会应用css样式
|
|
|
|
|
ctx.letterSpacing = '0px'
|
|
|
|
|
@ -1309,7 +1333,7 @@ export class Draw {
|
|
|
|
|
pageRowList[0] = this.rowList
|
|
|
|
|
// 重置高度
|
|
|
|
|
pageHeight += this.rowList.reduce((pre, cur) => pre + cur.height, 0)
|
|
|
|
|
const dpr = window.devicePixelRatio
|
|
|
|
|
const dpr = this.getPagePixelRatio()
|
|
|
|
|
const pageDom = this.pageList[0]
|
|
|
|
|
const pageDomHeight = Number(pageDom.style.height.replace('px', ''))
|
|
|
|
|
if (pageHeight > pageDomHeight) {
|
|
|
|
|
|