From 2430bf70d69ce97c0cc10d5b99d50f58ff1838ed Mon Sep 17 00:00:00 2001 From: Hufe921 Date: Tue, 26 Nov 2024 20:36:06 +0800 Subject: [PATCH] feat: add executePageScale api #906 --- docs/en/guide/command-execute.md | 10 ++++++++++ docs/guide/command-execute.md | 10 ++++++++++ src/editor/core/command/Command.ts | 2 ++ src/editor/core/command/CommandAdapt.ts | 5 +++++ 4 files changed, 27 insertions(+) diff --git a/docs/en/guide/command-execute.md b/docs/en/guide/command-execute.md index 3b60463d..bd3c8e6b 100644 --- a/docs/en/guide/command-execute.md +++ b/docs/en/guide/command-execute.md @@ -692,6 +692,16 @@ Usage: instance.command.executePageMode(pageMode: PageMode) ``` +## executePageScale + +Feature: Set page scale + +Usage: + +```javascript +instance.command.executePageScale(scale: number) +``` + ## executePageScaleRecovery Feature: Restore the original zoom factor of the page diff --git a/docs/guide/command-execute.md b/docs/guide/command-execute.md index 3c252b27..a107a2dc 100644 --- a/docs/guide/command-execute.md +++ b/docs/guide/command-execute.md @@ -692,6 +692,16 @@ instance.command.executeChangeImageDisplay(element: IElement, display: ImageDisp instance.command.executePageMode(pageMode: PageMode) ``` +## executePageScale + +功能:设置缩放比例 + +用法: + +```javascript +instance.command.executePageScale(scale: number) +``` + ## executePageScaleRecovery 功能:恢复页面原始缩放比例 diff --git a/src/editor/core/command/Command.ts b/src/editor/core/command/Command.ts index 66bd267f..d67af4a8 100644 --- a/src/editor/core/command/Command.ts +++ b/src/editor/core/command/Command.ts @@ -68,6 +68,7 @@ export class Command { public executeSaveAsImageElement: CommandAdapt['saveAsImageElement'] public executeChangeImageDisplay: CommandAdapt['changeImageDisplay'] public executePageMode: CommandAdapt['pageMode'] + public executePageScale: CommandAdapt['pageScale'] public executePageScaleRecovery: CommandAdapt['pageScaleRecovery'] public executePageScaleMinus: CommandAdapt['pageScaleMinus'] public executePageScaleAdd: CommandAdapt['pageScaleAdd'] @@ -199,6 +200,7 @@ export class Command { this.executeChangeImageDisplay = adapt.changeImageDisplay.bind(adapt) // 页面模式、页面缩放、纸张大小、纸张方向、页边距 this.executePageMode = adapt.pageMode.bind(adapt) + this.executePageScale = adapt.pageScale.bind(adapt) this.executePageScaleRecovery = adapt.pageScaleRecovery.bind(adapt) this.executePageScaleMinus = adapt.pageScaleMinus.bind(adapt) this.executePageScaleAdd = adapt.pageScaleAdd.bind(adapt) diff --git a/src/editor/core/command/CommandAdapt.ts b/src/editor/core/command/CommandAdapt.ts index 19efb2ac..e2e33611 100644 --- a/src/editor/core/command/CommandAdapt.ts +++ b/src/editor/core/command/CommandAdapt.ts @@ -1672,6 +1672,11 @@ export class CommandAdapt { this.draw.setPageMode(payload) } + public pageScale(scale: number) { + if (scale === this.options.scale) return + this.draw.setPageScale(scale) + } + public pageScaleRecovery() { const { scale } = this.options if (scale !== 1) {