feat:add page margin

This commit is contained in:
Hufe921
2022-09-17 19:11:35 +08:00
parent bad379c7aa
commit f540261500
9 changed files with 105 additions and 10 deletions
+14 -1
View File
@@ -3,6 +3,7 @@ import { EditorMode, PageMode } from '../../dataset/enum/Editor'
import { RowFlex } from '../../dataset/enum/Row'
import { IDrawImagePayload, IPainterOptions } from '../../interface/Draw'
import { IEditorResult } from '../../interface/Editor'
import { IMargin } from '../../interface/Margin'
import { IWatermark } from '../../interface/Watermark'
import { CommandAdapt } from './CommandAdapt'
@@ -68,6 +69,8 @@ export class Command {
private static pageScaleMinus: CommandAdapt['pageScaleMinus']
private static pageScaleAdd: CommandAdapt['pageScaleAdd']
private static paperSize: CommandAdapt['paperSize']
private static getPaperMargin: CommandAdapt['getPaperMargin']
private static setPaperMargin: CommandAdapt['setPaperMargin']
private static insertElementList: CommandAdapt['insertElementList']
private static removeControl: CommandAdapt['removeControl']
@@ -132,6 +135,8 @@ export class Command {
Command.pageScaleMinus = adapt.pageScaleMinus.bind(adapt)
Command.pageScaleAdd = adapt.pageScaleAdd.bind(adapt)
Command.paperSize = adapt.paperSize.bind(adapt)
Command.getPaperMargin = adapt.getPaperMargin.bind(adapt)
Command.setPaperMargin = adapt.setPaperMargin.bind(adapt)
Command.insertElementList = adapt.insertElementList.bind(adapt)
Command.removeControl = adapt.removeControl.bind(adapt)
}
@@ -360,7 +365,7 @@ export class Command {
return Command.getWordCount()
}
// 页面模式、页面缩放、纸张大小
// 页面模式、页面缩放、纸张大小、页边距
public executePageMode(payload: PageMode) {
return Command.pageMode(payload)
}
@@ -381,6 +386,14 @@ export class Command {
return Command.paperSize(width, height)
}
public getPaperMargin() {
return Command.getPaperMargin()
}
public executeSetPaperMargin(payload: IMargin) {
return Command.setPaperMargin(payload)
}
// 通用
public executeInsertElementList(payload: IElement[]) {
return Command.insertElementList(payload)
+9
View File
@@ -9,6 +9,7 @@ import { RowFlex } from '../../dataset/enum/Row'
import { IDrawImagePayload, IPainterOptions } from '../../interface/Draw'
import { IEditorOption, IEditorResult } from '../../interface/Editor'
import { IElement, IElementStyle } from '../../interface/Element'
import { IMargin } from '../../interface/Margin'
import { IColgroup } from '../../interface/table/Colgroup'
import { ITd } from '../../interface/table/Td'
import { ITr } from '../../interface/table/Tr'
@@ -1407,6 +1408,14 @@ export class CommandAdapt {
this.draw.setPaperSize(width, height)
}
public getPaperMargin(): number[] {
return this.draw.getOriginalMargins()
}
public setPaperMargin(payload: IMargin) {
return this.draw.setPaperMargin(payload)
}
public insertElementList(payload: IElement[]) {
if (!payload.length) return
const isReadonly = this.draw.isReadonly()
+15 -2
View File
@@ -45,6 +45,7 @@ import { formatElementList } from '../../utils/element'
import { WorkerManager } from '../worker/WorkerManager'
import { Previewer } from './particle/previewer/Previewer'
import { DateParticle } from './particle/date/DateParticle'
import { IMargin } from '../../interface/Margin'
export class Draw {
@@ -202,8 +203,12 @@ export class Draw {
return width - margins[1] - margins[3]
}
public getMargins(): number[] {
return this.options.margins.map(m => m * this.options.scale)
public getMargins(): IMargin {
return <IMargin>this.options.margins.map(m => m * this.options.scale)
}
public getOriginalMargins(): number[] {
return this.options.margins
}
public getPageGap(): number {
@@ -489,6 +494,14 @@ export class Draw {
})
}
public setPaperMargin(payload: IMargin) {
this.options.margins = payload
this.render({
isSubmitHistory: false,
isSetCursor: false
})
}
public getValue(): IEditorResult {
// 配置
const { width, height, margins, watermark } = this.options
+3 -2
View File
@@ -3,6 +3,7 @@ import { EditorMode, PageMode } from '../dataset/enum/Editor'
import { ICheckboxOption } from './Checkbox'
import { IControlOption } from './Control'
import { IHeader } from './Header'
import { IMargin } from './Margin'
import { IWatermark } from './Watermark'
export interface IEditorOption {
@@ -32,7 +33,7 @@ export interface IEditorOption {
resizerSize?: number;
marginIndicatorSize?: number;
marginIndicatorColor?: string,
margins?: [top: number, right: number, bottom: number, left: number],
margins?: IMargin,
pageMode?: PageMode;
tdPadding?: number;
defaultTdHeight?: number;
@@ -48,7 +49,7 @@ export interface IEditorResult {
version: string;
width: number;
height: number;
margins: [top: number, right: number, bottom: number, left: number];
margins: IMargin;
watermark?: IWatermark;
data: IElement[];
}
+1
View File
@@ -0,0 +1 @@
export type IMargin = [top: number, right: number, bottom: number, left: number]