From 1eefa570b23a3330971c595dde8cef0e6ec2f530 Mon Sep 17 00:00:00 2001 From: Hufe921 Date: Wed, 15 Mar 2023 20:04:43 +0800 Subject: [PATCH] feat:adjust margins when paper direction change --- src/editor/core/command/CommandAdapt.ts | 5 ++--- src/editor/core/draw/Draw.ts | 10 +++++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/editor/core/command/CommandAdapt.ts b/src/editor/core/command/CommandAdapt.ts index 35367c7..57168e0 100644 --- a/src/editor/core/command/CommandAdapt.ts +++ b/src/editor/core/command/CommandAdapt.ts @@ -405,8 +405,7 @@ export class CommandAdapt { const { startIndex, endIndex } = this.range.getRange() if (!~startIndex && !~endIndex) return const elementList = this.draw.getElementList() - const { width, margins } = this.options - const innerWidth = width - margins[1] - margins[3] + const innerWidth = this.draw.getInnerWidth() // colgroup const colgroup: IColgroup[] = [] const colWidth = innerWidth / col @@ -1460,7 +1459,7 @@ export class CommandAdapt { } public getPaperMargin(): number[] { - return this.draw.getOriginalMargins() + return this.options.margins } public setPaperMargin(payload: IMargin) { diff --git a/src/editor/core/draw/Draw.ts b/src/editor/core/draw/Draw.ts index 744ca91..dae5ec9 100644 --- a/src/editor/core/draw/Draw.ts +++ b/src/editor/core/draw/Draw.ts @@ -225,16 +225,20 @@ export class Draw { } public getOriginalInnerWidth(): number { - const { width, margins } = this.options + const width = this.getOriginalWidth() + const margins = this.getOriginalMargins() return width - margins[1] - margins[3] } public getMargins(): IMargin { - return this.options.margins.map(m => m * this.options.scale) + return this.getOriginalMargins().map(m => m * this.options.scale) } public getOriginalMargins(): number[] { - return this.options.margins + const { margins, paperDirection } = this.options + return paperDirection === PaperDirection.VERTICAL + ? margins + : [margins[1], margins[2], margins[3], margins[0]] } public getPageGap(): number {