feat: add fontSize settings API
This commit is contained in:
@@ -22,6 +22,7 @@ export class Command {
|
||||
private static applyPainterStyle: CommandAdapt['applyPainterStyle']
|
||||
private static format: CommandAdapt['format']
|
||||
private static font: CommandAdapt['font']
|
||||
private static sizeSet: CommandAdapt['sizeSet']
|
||||
private static sizeAdd: CommandAdapt['sizeAdd']
|
||||
private static sizeMinus: CommandAdapt['sizeMinus']
|
||||
private static bold: CommandAdapt['bold']
|
||||
@@ -95,6 +96,7 @@ export class Command {
|
||||
Command.applyPainterStyle = adapt.applyPainterStyle.bind(adapt)
|
||||
Command.format = adapt.format.bind(adapt)
|
||||
Command.font = adapt.font.bind(adapt)
|
||||
Command.sizeSet = adapt.sizeSet.bind(adapt)
|
||||
Command.sizeAdd = adapt.sizeAdd.bind(adapt)
|
||||
Command.sizeMinus = adapt.sizeMinus.bind(adapt)
|
||||
Command.bold = adapt.bold.bind(adapt)
|
||||
@@ -205,11 +207,15 @@ export class Command {
|
||||
return Command.format()
|
||||
}
|
||||
|
||||
// 字体、字体变大、字体变小、加粗、斜体、下划线、删除线、字体颜色、背景色
|
||||
// 字体、字体大小、字体变大、字体变小、加粗、斜体、下划线、删除线、字体颜色、背景色
|
||||
public executeFont(payload: string) {
|
||||
return Command.font(payload)
|
||||
}
|
||||
|
||||
public executeSize(size: number) {
|
||||
return Command.sizeSet(size)
|
||||
}
|
||||
|
||||
public executeSizeAdd() {
|
||||
return Command.sizeAdd()
|
||||
}
|
||||
|
||||
@@ -185,6 +185,20 @@ export class CommandAdapt {
|
||||
this.draw.render({ isSetCursor: false })
|
||||
}
|
||||
|
||||
public sizeSet(size: number) {
|
||||
const isReadonly = this.draw.isReadonly()
|
||||
if (isReadonly) return
|
||||
const selection = this.range.getSelection()
|
||||
if (!selection) return
|
||||
const lessThanMaxSizeIndex = selection.findIndex(s => !s.size || s.size + 2 <= 72)
|
||||
if (!~lessThanMaxSizeIndex) return
|
||||
selection.forEach(el => {
|
||||
if (size > 72) return
|
||||
el.size = size
|
||||
})
|
||||
this.draw.render({ isSetCursor: false })
|
||||
}
|
||||
|
||||
public sizeAdd() {
|
||||
const isReadonly = this.draw.isReadonly()
|
||||
if (isReadonly) return
|
||||
|
||||
@@ -135,6 +135,7 @@ export class RangeManager {
|
||||
const type = curElement.type || ElementType.TEXT
|
||||
// 富文本
|
||||
const font = curElement.font || this.options.defaultFont
|
||||
const size = curElement.size || this.options.defaultSize
|
||||
const bold = !~curElementList.findIndex(el => !el.bold)
|
||||
const italic = !~curElementList.findIndex(el => !el.italic)
|
||||
const underline = !~curElementList.findIndex(el => !el.underline)
|
||||
@@ -154,6 +155,7 @@ export class RangeManager {
|
||||
redo,
|
||||
painter,
|
||||
font,
|
||||
size,
|
||||
bold,
|
||||
italic,
|
||||
underline,
|
||||
@@ -169,6 +171,7 @@ export class RangeManager {
|
||||
public recoveryRangeStyle() {
|
||||
if (!this.listener.rangeStyleChange) return
|
||||
const font = this.options.defaultFont
|
||||
const size = this.options.defaultSize
|
||||
const rowMargin = this.options.defaultRowMargin
|
||||
const painter = !!this.draw.getPainterStyle()
|
||||
const undo = this.historyManager.isCanUndo()
|
||||
@@ -179,6 +182,7 @@ export class RangeManager {
|
||||
redo,
|
||||
painter,
|
||||
font,
|
||||
size,
|
||||
bold: false,
|
||||
italic: false,
|
||||
underline: false,
|
||||
|
||||
@@ -9,6 +9,7 @@ export interface IRangeStyle {
|
||||
redo: boolean;
|
||||
painter: boolean;
|
||||
font: string;
|
||||
size: number;
|
||||
bold: boolean;
|
||||
italic: boolean;
|
||||
underline: boolean;
|
||||
|
||||
Reference in New Issue
Block a user