feat:add watermark
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { IElement } from "../.."
|
||||
import { RowFlex } from "../../dataset/enum/Row"
|
||||
import { IDrawImagePayload } from "../../interface/Draw"
|
||||
import { IWatermark } from "../../interface/Watermark"
|
||||
import { CommandAdapt } from "./CommandAdapt"
|
||||
|
||||
export class Command {
|
||||
@@ -41,6 +42,8 @@ export class Command {
|
||||
private static image: Function
|
||||
private static hyperlink: Function
|
||||
private static separator: Function
|
||||
private static addWatermark: Function
|
||||
private static deleteWatermark: Function
|
||||
private static search: Function
|
||||
private static print: Function
|
||||
private static pageScaleRecovery: Function
|
||||
@@ -84,6 +87,8 @@ export class Command {
|
||||
Command.image = adapt.image.bind(adapt)
|
||||
Command.hyperlink = adapt.hyperlink.bind(adapt)
|
||||
Command.separator = adapt.separator.bind(adapt)
|
||||
Command.addWatermark = adapt.addWatermark.bind(adapt)
|
||||
Command.deleteWatermark = adapt.deleteWatermark.bind(adapt)
|
||||
Command.search = adapt.search.bind(adapt)
|
||||
Command.print = adapt.print.bind(adapt)
|
||||
Command.pageScaleRecovery = adapt.pageScaleRecovery.bind(adapt)
|
||||
@@ -239,6 +244,14 @@ export class Command {
|
||||
return Command.separator(payload)
|
||||
}
|
||||
|
||||
public executeAddWatermark(payload: IWatermark) {
|
||||
return Command.addWatermark(payload)
|
||||
}
|
||||
|
||||
public executeDeleteWatermark() {
|
||||
return Command.deleteWatermark()
|
||||
}
|
||||
|
||||
public executeSearch(payload: string | null) {
|
||||
return Command.search(payload)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { ZERO } from "../../dataset/constant/Common"
|
||||
import { EDITOR_ELEMENT_STYLE_ATTR, TEXTLIKE_ELEMENT_TYPE } from "../../dataset/constant/Element"
|
||||
import { defaultWatermarkOption } from "../../dataset/constant/Watermark"
|
||||
import { EditorContext } from "../../dataset/enum/Editor"
|
||||
import { ElementType } from "../../dataset/enum/Element"
|
||||
import { ElementStyleKey } from "../../dataset/enum/ElementStyle"
|
||||
@@ -11,6 +12,7 @@ import { ISearchResult, ISearchResultRestArgs } from "../../interface/Search"
|
||||
import { IColgroup } from "../../interface/table/Colgroup"
|
||||
import { ITd } from "../../interface/table/Td"
|
||||
import { ITr } from "../../interface/table/Tr"
|
||||
import { IWatermark } from "../../interface/Watermark"
|
||||
import { getUUID } from "../../utils"
|
||||
import { formatElementList } from "../../utils/element"
|
||||
import { printImageBase64 } from "../../utils/print"
|
||||
@@ -920,6 +922,31 @@ export class CommandAdapt {
|
||||
this.draw.render({ curIndex })
|
||||
}
|
||||
|
||||
public addWatermark(payload: IWatermark) {
|
||||
const options = this.draw.getOptions()
|
||||
const { color, size, opacity, font } = defaultWatermarkOption
|
||||
options.watermark.data = payload.data
|
||||
options.watermark.color = payload.color || color
|
||||
options.watermark.size = payload.size || size
|
||||
options.watermark.opacity = payload.opacity || opacity
|
||||
options.watermark.font = payload.font || font
|
||||
this.draw.render({
|
||||
isSetCursor: false,
|
||||
isSubmitHistory: false
|
||||
})
|
||||
}
|
||||
|
||||
public deleteWatermark() {
|
||||
const options = this.draw.getOptions()
|
||||
if (options.watermark && options.watermark.data) {
|
||||
options.watermark = { ...defaultWatermarkOption }
|
||||
this.draw.render({
|
||||
isSetCursor: false,
|
||||
isSubmitHistory: false
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
public image(payload: IDrawImagePayload) {
|
||||
const { startIndex, endIndex } = this.range.getRange()
|
||||
if (!~startIndex && !~endIndex) return
|
||||
|
||||
@@ -462,7 +462,7 @@ export class CanvasEvent {
|
||||
|
||||
public save(): IEditorResult {
|
||||
// 配置
|
||||
const { width, height, margins } = this.draw.getOptions()
|
||||
const { width, height, margins, watermark } = this.draw.getOptions()
|
||||
// 数据
|
||||
const elementList = this.draw.getOriginalElementList()
|
||||
const data = zipElementList(elementList)
|
||||
@@ -471,6 +471,7 @@ export class CanvasEvent {
|
||||
width,
|
||||
height,
|
||||
margins,
|
||||
watermark: watermark.data ? watermark : undefined,
|
||||
data
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user