feat: add applyPageNumbers attribute to background option #729

This commit is contained in:
Hufe921
2024-08-02 19:52:17 +08:00
parent 87a8dbea15
commit 8d112a8518
5 changed files with 13 additions and 6 deletions
+8 -3
View File
@@ -99,14 +99,19 @@ export class Background {
}
public render(ctx: CanvasRenderingContext2D, pageNo: number) {
const { background } = this.options
if (background.image) {
const {
background: { image, color, applyPageNumbers }
} = this.options
if (
image &&
(!applyPageNumbers?.length || applyPageNumbers.includes(pageNo))
) {
const { width, height } = this.options
this._renderBackgroundImage(ctx, width, height)
} else {
const width = this.draw.getCanvasWidth(pageNo)
const height = this.draw.getCanvasHeight(pageNo)
this._renderBackgroundColor(ctx, background.color, width, height)
this._renderBackgroundColor(ctx, color, width, height)
}
}
}
+2 -1
View File
@@ -5,5 +5,6 @@ export const defaultBackground: Readonly<Required<IBackgroundOption>> = {
color: '#FFFFFF',
image: '',
size: BackgroundSize.COVER,
repeat: BackgroundRepeat.NO_REPEAT
repeat: BackgroundRepeat.NO_REPEAT,
applyPageNumbers: []
}
+1
View File
@@ -5,4 +5,5 @@ export interface IBackgroundOption {
image?: string
size?: BackgroundSize
repeat?: BackgroundRepeat
applyPageNumbers?: number[]
}