fix:continuity page render error in lazy mode

pr675
Hufe921 3 years ago
parent dc54622258
commit ff06e50138

@ -198,13 +198,13 @@ export class Draw {
return Math.floor(this.options.height * this.options.scale) return Math.floor(this.options.height * this.options.scale)
} }
public getCanvasWidth(): number { public getCanvasWidth(pageNo = -1): number {
const page = this.getPage() const page = this.getPage(pageNo)
return page.width return page.width
} }
public getCanvasHeight(): number { public getCanvasHeight(pageNo = -1): number {
const page = this.getPage() const page = this.getPage(pageNo)
return page.height return page.height
} }
@ -289,8 +289,8 @@ export class Draw {
this.pageNo = payload this.pageNo = payload
} }
public getPage(): HTMLCanvasElement { public getPage(pageNo = -1): HTMLCanvasElement {
return this.pageList[this.pageNo] return this.pageList[~pageNo ? pageNo : this.pageNo]
} }
public getPageList(): HTMLCanvasElement[] { public getPageList(): HTMLCanvasElement[] {
@ -482,6 +482,8 @@ export class Draw {
const canvas = this.pageList[0] const canvas = this.pageList[0]
canvas.style.height = `${height}px` canvas.style.height = `${height}px`
canvas.height = height * dpr canvas.height = height * dpr
// canvas尺寸发生变化上下文被重置
this.ctxList[0].scale(dpr, dpr)
} }
this.render({ this.render({
isSubmitHistory: false, isSubmitHistory: false,
@ -896,6 +898,7 @@ export class Draw {
pageDom.style.height = `${reduceHeight}px` pageDom.style.height = `${reduceHeight}px`
pageDom.height = reduceHeight * dpr pageDom.height = reduceHeight * dpr
} }
this.ctxList[0].scale(dpr, dpr)
} else { } else {
for (let i = 0; i < this.rowList.length; i++) { for (let i = 0; i < this.rowList.length; i++) {
const row = this.rowList[i] const row = this.rowList[i]
@ -1095,7 +1098,7 @@ export class Draw {
// 绘制背景 // 绘制背景
this.background.render(ctx) this.background.render(ctx)
// 绘制页边距 // 绘制页边距
this.margin.render(ctx) this.margin.render(ctx, pageNo)
// 渲染元素 // 渲染元素
const index = rowList[0].startIndex const index = rowList[0].startIndex
this._drawRow(ctx, { this._drawRow(ctx, {
@ -1143,6 +1146,7 @@ export class Draw {
} }
public render(payload?: IDrawOption) { public render(payload?: IDrawOption) {
const { pageMode } = this.options
const { const {
isSubmitHistory = true, isSubmitHistory = true,
isSetCursor = true, isSetCursor = true,
@ -1185,7 +1189,8 @@ export class Draw {
.forEach(page => page.remove()) .forEach(page => page.remove())
} }
// 绘制元素 // 绘制元素
if (isLazy) { // 连续页因为有高度的变化会导致canvas渲染空白需立即渲染否则会出现闪动
if (isLazy && pageMode === PageMode.PAGING) {
this._lazyRender() this._lazyRender()
} else { } else {
this._immediateRender() this._immediateRender()

@ -12,11 +12,11 @@ export class Margin {
this.options = draw.getOptions() this.options = draw.getOptions()
} }
public render(ctx: CanvasRenderingContext2D) { public render(ctx: CanvasRenderingContext2D, pageNo: number) {
const { marginIndicatorColor, pageMode } = this.options const { marginIndicatorColor, pageMode } = this.options
const width = this.draw.getWidth() const width = this.draw.getWidth()
const height = pageMode === PageMode.CONTINUITY const height = pageMode === PageMode.CONTINUITY
? this.draw.getCanvasHeight() ? this.draw.getCanvasHeight(pageNo)
: this.draw.getHeight() : this.draw.getHeight()
const margins = this.draw.getMargins() const margins = this.draw.getMargins()
const marginIndicatorSize = this.draw.getMarginIndicatorSize() const marginIndicatorSize = this.draw.getMarginIndicatorSize()

@ -16,7 +16,7 @@ export class PageNumber {
const { pageNumberSize, pageNumberFont, scale, pageMode } = this.options const { pageNumberSize, pageNumberFont, scale, pageMode } = this.options
const width = this.draw.getWidth() const width = this.draw.getWidth()
const height = pageMode === PageMode.CONTINUITY const height = pageMode === PageMode.CONTINUITY
? this.draw.getCanvasHeight() ? this.draw.getCanvasHeight(pageNo)
: this.draw.getHeight() : this.draw.getHeight()
const pageNumberBottom = this.draw.getPageNumberBottom() const pageNumberBottom = this.draw.getPageNumberBottom()
ctx.save() ctx.save()

Loading…
Cancel
Save