feat: add defaultColor option #405

pr675
Hufe921 2 years ago
parent 5272c85bbe
commit a324ecc417

@ -16,6 +16,7 @@ new Editor(container, IEditorData | IElement[], {
interface IEditorOption {
mode?: EditorMode // Editor mode: Edit, Clean (Visual aids are not displayed, For example: page break), ReadOnly, Form (Only editable within the control), Print (Visual aids are not displayed, Unwritten content control). default: Edit
defaultType?: string // Default element type. default: TEXT
defaultColor?: string // Default color. default: #000000
defaultFont?: string // Default font. default: Microsoft YaHei
defaultSize?: number // Default font size. default: 16
minSize?: number // Min font size。default: 5

@ -16,6 +16,7 @@ new Editor(container, IEditorData | IElement[], {
interface IEditorOption {
mode?: EditorMode // 编辑器模式:编辑、清洁(不显示视觉辅助元素。如:分页符)、只读、表单(仅控件内可编辑)、打印(不显示辅助元素、未书写控件及前后括号)。默认:编辑
defaultType?: string // 默认元素类型。默认TEXT
defaultColor?: string // 默认字体颜色。默认:#000000
defaultFont?: string // 默认字体。默认Microsoft YaHei
defaultSize?: number // 默认字号。默认16
minSize?: number // 最小字号。默认5

@ -1,5 +1,6 @@
import { ElementType, IElement } from '../../..'
import { ElementType, IEditorOption, IElement } from '../../..'
import { PUNCTUATION_LIST } from '../../../dataset/constant/Common'
import { DeepRequired } from '../../../interface/Common'
import { IRowElement } from '../../../interface/Row'
import { Draw } from '../Draw'
@ -10,6 +11,8 @@ export interface IMeasureWordResult {
export class TextParticle {
private draw: Draw
private options: DeepRequired<IEditorOption>
private ctx: CanvasRenderingContext2D
private curX: number
private curY: number
@ -20,6 +23,7 @@ export class TextParticle {
constructor(draw: Draw) {
this.draw = draw
this.options = draw.getOptions()
this.ctx = draw.getCtx()
this.curX = -1
this.curY = -1
@ -129,9 +133,7 @@ export class TextParticle {
if (!this.text || !~this.curX || !~this.curX) return
this.ctx.save()
this.ctx.font = this.curStyle
if (this.curColor) {
this.ctx.fillStyle = this.curColor
}
this.ctx.fillStyle = this.curColor || this.options.defaultColor
this.ctx.fillText(this.text, this.curX, this.curY)
this.ctx.restore()
}

@ -149,6 +149,7 @@ export default class Editor {
const editorOptions: DeepRequired<IEditorOption> = {
mode: EditorMode.EDIT,
defaultType: 'TEXT',
defaultColor: '#000000',
defaultFont: 'Microsoft YaHei',
defaultSize: 16,
minSize: 5,

@ -30,6 +30,7 @@ export interface IEditorData {
export interface IEditorOption {
mode?: EditorMode
defaultType?: string
defaultColor?: string
defaultFont?: string
defaultSize?: number
minSize?: number

Loading…
Cancel
Save