@ -6,6 +6,7 @@ import {
IDrawOption ,
IDrawOption ,
IDrawPagePayload ,
IDrawPagePayload ,
IDrawRowPayload ,
IDrawRowPayload ,
IGetImageOption ,
IGetValueOption ,
IGetValueOption ,
IPainterOption
IPainterOption
} from '../../interface/Draw'
} from '../../interface/Draw'
@ -142,6 +143,7 @@ export class Draw {
private visiblePageNoList : number [ ]
private visiblePageNoList : number [ ]
private intersectionPageNo : number
private intersectionPageNo : number
private lazyRenderIntersectionObserver : IntersectionObserver | null
private lazyRenderIntersectionObserver : IntersectionObserver | null
private printModeData : Required < IEditorData > | null
constructor (
constructor (
rootContainer : HTMLElement ,
rootContainer : HTMLElement ,
@ -217,6 +219,7 @@ export class Draw {
this . visiblePageNoList = [ ]
this . visiblePageNoList = [ ]
this . intersectionPageNo = 0
this . intersectionPageNo = 0
this . lazyRenderIntersectionObserver = null
this . lazyRenderIntersectionObserver = null
this . printModeData = null
this . render ( {
this . render ( {
isInit : true ,
isInit : true ,
@ -229,12 +232,34 @@ export class Draw {
}
}
public setMode ( payload : EditorMode ) {
public setMode ( payload : EditorMode ) {
if ( this . mode === payload ) return
// 设置打印模式
if ( payload === EditorMode . PRINT ) {
this . printModeData = {
header : this.header.getElementList ( ) ,
main : this.elementList ,
footer : this.footer.getElementList ( )
}
this . setEditorData (
this . control . filterAssistElement ( deepClone ( this . printModeData ) )
)
}
// 取消打印模式
if ( this . mode === EditorMode . PRINT && this . printModeData ) {
this . setEditorData ( this . printModeData )
this . printModeData = null
}
this . mode = payload
this . mode = payload
this . render ( {
isSetCursor : false ,
isSubmitHistory : false
} )
}
}
public isReadonly() {
public isReadonly() {
switch ( this . mode ) {
switch ( this . mode ) {
case EditorMode . READONLY :
case EditorMode . READONLY :
case EditorMode . PRINT :
return true
return true
case EditorMode . FORM :
case EditorMode . FORM :
return ! this . control . isRangeWithinControl ( )
return ! this . control . isRangeWithinControl ( )
@ -650,10 +675,18 @@ export class Draw {
return this . rowList . length
return this . rowList . length
}
}
public async getDataURL ( pixelRatio? : number ) : Promise < string [ ] > {
public async getDataURL ( payload : IGetImageOption = { } ) : Promise < string [ ] > {
const { pixelRatio , mode } = payload
// 放大像素比
if ( pixelRatio ) {
if ( pixelRatio ) {
this . setPagePixelRatio ( pixelRatio )
this . setPagePixelRatio ( pixelRatio )
}
}
// 不同模式
const currentMode = this . mode
const isSwitchMode = ! ! mode && currentMode !== mode
if ( isSwitchMode ) {
this . setMode ( mode )
}
this . render ( {
this . render ( {
isLazy : false ,
isLazy : false ,
isCompute : false ,
isCompute : false ,
@ -662,9 +695,13 @@ export class Draw {
} )
} )
await this . imageObserver . allSettled ( )
await this . imageObserver . allSettled ( )
const dataUrlList = this . pageList . map ( c = > c . toDataURL ( ) )
const dataUrlList = this . pageList . map ( c = > c . toDataURL ( ) )
// 还原
if ( pixelRatio ) {
if ( pixelRatio ) {
this . setPagePixelRatio ( null )
this . setPagePixelRatio ( null )
}
}
if ( isSwitchMode ) {
this . setMode ( currentMode )
}
return dataUrlList
return dataUrlList
}
}
@ -869,29 +906,36 @@ export class Draw {
public setValue ( payload : Partial < IEditorData > ) {
public setValue ( payload : Partial < IEditorData > ) {
const { header , main , footer } = payload
const { header , main , footer } = payload
if ( ! header && ! main && ! footer ) return
if ( ! header && ! main && ! footer ) return
if ( header ) {
const pageComponentData = [ header , main , footer ]
formatElementList ( header , {
pageComponentData . forEach ( data = > {
if ( ! data ) return
formatElementList ( data , {
editorOptions : this.options
editorOptions : this.options
} )
} )
} )
this . setEditorData ( {
header ,
main ,
footer
} )
// 渲染&计算&清空历史记录
this . historyManager . recovery ( )
this . render ( {
isSetCursor : false
} )
}
public setEditorData ( payload : Partial < IEditorData > ) {
const { header , main , footer } = payload
if ( header ) {
this . header . setElementList ( header )
this . header . setElementList ( header )
}
}
if ( main ) {
if ( main ) {
formatElementList ( main , {
editorOptions : this.options
} )
this . elementList = main
this . elementList = main
}
}
if ( footer ) {
if ( footer ) {
formatElementList ( footer , {
editorOptions : this.options
} )
this . footer . setElementList ( footer )
this . footer . setElementList ( footer )
}
}
// 渲染&计算&清空历史记录
this . historyManager . recovery ( )
this . render ( {
isSetCursor : false
} )
}
}
private _wrapContainer ( rootContainer : HTMLElement ) : HTMLDivElement {
private _wrapContainer ( rootContainer : HTMLElement ) : HTMLDivElement {
@ -1398,6 +1442,7 @@ export class Draw {
public drawRow ( ctx : CanvasRenderingContext2D , payload : IDrawRowPayload ) {
public drawRow ( ctx : CanvasRenderingContext2D , payload : IDrawRowPayload ) {
const { rowList , pageNo , elementList , positionList , startIndex , zone } =
const { rowList , pageNo , elementList , positionList , startIndex , zone } =
payload
payload
const isPrintMode = this . mode === EditorMode . PRINT
const { scale , tdPadding } = this . options
const { scale , tdPadding } = this . options
const { isCrossRowCol , tableId } = this . range . getRange ( )
const { isCrossRowCol , tableId } = this . range . getRange ( )
let index = startIndex
let index = startIndex
@ -1472,7 +1517,7 @@ export class Draw {
} else if ( element . type === ElementType . SEPARATOR ) {
} else if ( element . type === ElementType . SEPARATOR ) {
this . separatorParticle . render ( ctx , element , x , y )
this . separatorParticle . render ( ctx , element , x , y )
} else if ( element . type === ElementType . PAGE_BREAK ) {
} else if ( element . type === ElementType . PAGE_BREAK ) {
if ( this . mode !== EditorMode . CLEAN ) {
if ( this . mode !== EditorMode . CLEAN && ! isPrintMode ) {
this . pageBreakParticle . render ( ctx , element , x , y )
this . pageBreakParticle . render ( ctx , element , x , y )
}
}
} else if (
} else if (
@ -1592,21 +1637,23 @@ export class Draw {
// 绘制富文本及文字
// 绘制富文本及文字
this . _drawRichText ( ctx )
this . _drawRichText ( ctx )
// 绘制选区
// 绘制选区
if ( rangeRecord . width && rangeRecord . height ) {
if ( ! isPrintMode ) {
const { x , y , width , height } = rangeRecord
if ( rangeRecord . width && rangeRecord . height ) {
this . range . render ( ctx , x , y , width , height )
const { x , y , width , height } = rangeRecord
}
this . range . render ( ctx , x , y , width , height )
if (
}
isCrossRowCol &&
if (
tableRangeElement &&
isCrossRowCol &&
tableRangeElement . id === tableId
tableRangeElement &&
) {
tableRangeElement . id === tableId
const {
) {
coordinate : {
const {
leftTop : [ x , y ]
coordinate : {
}
leftTop : [ x , y ]
} = positionList [ curRow . startIndex ]
}
this . tableParticle . drawRange ( ctx , tableRangeElement , x , y )
} = positionList [ curRow . startIndex ]
this . tableParticle . drawRange ( ctx , tableRangeElement , x , y )
}
}
}
}
}
}
}