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