feat: custom letter class #279
This commit is contained in:
@@ -79,7 +79,6 @@ import { Footer } from './frame/Footer'
|
||||
import { INLINE_ELEMENT_TYPE } from '../../dataset/constant/Element'
|
||||
import { ListParticle } from './particle/ListParticle'
|
||||
import { Placeholder } from './frame/Placeholder'
|
||||
import { WORD_LIKE_REG } from '../../dataset/constant/Regular'
|
||||
import { EventBus } from '../event/eventbus/EventBus'
|
||||
import { EventBusMap } from '../../interface/EventBus'
|
||||
import { Group } from './interactive/Group'
|
||||
@@ -140,6 +139,8 @@ export class Draw {
|
||||
private selectionObserver: SelectionObserver
|
||||
private imageObserver: ImageObserver
|
||||
|
||||
private LETTER_REG: RegExp
|
||||
private WORD_LIKE_REG: RegExp
|
||||
private rowList: IRow[]
|
||||
private pageRowList: IRow[][]
|
||||
private painterStyle: IElementStyle | null
|
||||
@@ -219,6 +220,11 @@ export class Draw {
|
||||
|
||||
this.workerManager = new WorkerManager(this)
|
||||
|
||||
const { letterClass } = options
|
||||
this.LETTER_REG = new RegExp(`[${letterClass.join('')}]`)
|
||||
this.WORD_LIKE_REG = new RegExp(
|
||||
`${letterClass.map(letter => `[^${letter}][${letter}]`).join('|')}`
|
||||
)
|
||||
this.rowList = []
|
||||
this.pageRowList = []
|
||||
this.painterStyle = null
|
||||
@@ -234,6 +240,10 @@ export class Draw {
|
||||
})
|
||||
}
|
||||
|
||||
public getLetterReg(): RegExp {
|
||||
return this.LETTER_REG
|
||||
}
|
||||
|
||||
public getMode(): EditorMode {
|
||||
return this.mode
|
||||
}
|
||||
@@ -1346,7 +1356,7 @@ export class Draw {
|
||||
) {
|
||||
// 英文单词
|
||||
const word = `${preElement?.value || ''}${element.value}`
|
||||
if (WORD_LIKE_REG.test(word)) {
|
||||
if (this.WORD_LIKE_REG.test(word)) {
|
||||
const { width, endElement } = this.textParticle.measureWord(
|
||||
ctx,
|
||||
elementList,
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { ElementType, IElement } from '../../..'
|
||||
import { PUNCTUATION_LIST } from '../../../dataset/constant/Common'
|
||||
import { LETTER_REG } from '../../../dataset/constant/Regular'
|
||||
import { IRowElement } from '../../../interface/Row'
|
||||
import { Draw } from '../Draw'
|
||||
|
||||
@@ -10,6 +9,7 @@ export interface IMeasureWordResult {
|
||||
}
|
||||
|
||||
export class TextParticle {
|
||||
private draw: Draw
|
||||
private ctx: CanvasRenderingContext2D
|
||||
private curX: number
|
||||
private curY: number
|
||||
@@ -19,6 +19,7 @@ export class TextParticle {
|
||||
public cacheMeasureText: Map<string, TextMetrics>
|
||||
|
||||
constructor(draw: Draw) {
|
||||
this.draw = draw
|
||||
this.ctx = draw.getCtx()
|
||||
this.curX = -1
|
||||
this.curY = -1
|
||||
@@ -32,6 +33,7 @@ export class TextParticle {
|
||||
elementList: IElement[],
|
||||
curIndex: number
|
||||
): IMeasureWordResult {
|
||||
const LETTER_REG = this.draw.getLetterReg()
|
||||
let width = 0
|
||||
let endElement: IElement = elementList[curIndex]
|
||||
let i = curIndex
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { ZERO } from '../../../dataset/constant/Common'
|
||||
import { LETTER_REG, NUMBER_LIKE_REG } from '../../../dataset/constant/Regular'
|
||||
import { NUMBER_LIKE_REG } from '../../../dataset/constant/Regular'
|
||||
import { CanvasEvent } from '../CanvasEvent'
|
||||
|
||||
function dblclick(host: CanvasEvent, evt: MouseEvent) {
|
||||
const draw = host.getDraw()
|
||||
const LETTER_REG = draw.getLetterReg()
|
||||
const position = draw.getPosition()
|
||||
// 切换区域
|
||||
if (draw.getIsPagingMode()) {
|
||||
|
||||
Reference in New Issue
Block a user