From 2152c00238aed30ae15770bcb8efe2617ce7469d Mon Sep 17 00:00:00 2001 From: Hufe921 Date: Sun, 17 Apr 2022 14:49:52 +0800 Subject: [PATCH] feat:add letter spacing --- src/editor/core/draw/Draw.ts | 3 +++ src/editor/interface/Element.ts | 1 + src/editor/utils/element.ts | 3 +++ 3 files changed, 7 insertions(+) diff --git a/src/editor/core/draw/Draw.ts b/src/editor/core/draw/Draw.ts index 4cf93b6..df83163 100644 --- a/src/editor/core/draw/Draw.ts +++ b/src/editor/core/draw/Draw.ts @@ -587,6 +587,9 @@ export class Draw { ctx.font = this._getFont(element) const fontMetrics = this.textParticle.measureText(ctx, element) metrics.width = fontMetrics.width * scale + if (element.letterSpacing) { + metrics.width += element.letterSpacing * scale + } metrics.boundingBoxAscent = (element.value === ZERO ? defaultSize : fontMetrics.actualBoundingBoxAscent) * scale metrics.boundingBoxDescent = fontMetrics.actualBoundingBoxDescent * scale if (element.type === ElementType.SUPERSCRIPT) { diff --git a/src/editor/interface/Element.ts b/src/editor/interface/Element.ts index c914eb1..81125df 100644 --- a/src/editor/interface/Element.ts +++ b/src/editor/interface/Element.ts @@ -25,6 +25,7 @@ export interface IElementStyle { strikeout?: boolean; rowFlex?: RowFlex; rowMargin?: number; + letterSpacing?: number; } export interface ITableAttr { diff --git a/src/editor/utils/element.ts b/src/editor/utils/element.ts index dcaa900..e41f576 100644 --- a/src/editor/utils/element.ts +++ b/src/editor/utils/element.ts @@ -1,5 +1,6 @@ import { deepClone, getUUID } from '.' import { ElementType, IEditorOption, IElement } from '..' +import { defaultCheckboxOption } from '../dataset/constant/Checkbox' import { ZERO } from '../dataset/constant/Common' import { defaultControlOption } from '../dataset/constant/Control' import { EDITOR_ELEMENT_ZIP_ATTR } from '../dataset/constant/Element' @@ -123,10 +124,12 @@ export function formatElementList(elementList: IElement[], options: IFormatEleme const valueStrList = valueSet.value.split('') for (let e = 0; e < valueStrList.length; e++) { const value = valueStrList[e] + const isLastLetter = e === valueStrList.length - 1 elementList.splice(i, 0, { controlId, value, type: el.type, + letterSpacing: isLastLetter ? defaultCheckboxOption.gap : 0, control: el.control, controlComponent: ControlComponent.VALUE })