feat: add fontSize settings API

This commit is contained in:
zhoujingfu
2023-03-21 10:00:01 +08:00
parent 4306d44ed6
commit d951532998
4 changed files with 26 additions and 1 deletions
+7 -1
View File
@@ -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()
}
+14
View File
@@ -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
+4
View File
@@ -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,
+1
View File
@@ -9,6 +9,7 @@ export interface IRangeStyle {
redo: boolean;
painter: boolean;
font: string;
size: number;
bold: boolean;
italic: boolean;
underline: boolean;