fix: limit word break element type #212

pr675
Hufe921 3 years ago
parent d471165430
commit d7424f8b87

@ -1112,15 +1112,20 @@ export class Draw {
// 累计行宽 + 当前元素宽度 + 排版宽度(英文单词整体宽度 + 后面标点符号宽度) // 累计行宽 + 当前元素宽度 + 排版宽度(英文单词整体宽度 + 后面标点符号宽度)
let curRowWidth = curRow.width + metrics.width let curRowWidth = curRow.width + metrics.width
if (this.options.wordBreak === WordBreak.BREAK_WORD) { if (this.options.wordBreak === WordBreak.BREAK_WORD) {
// 英文单词 if (
const word = `${preElement?.value || ''}${element.value}` (!preElement?.type || preElement?.type === ElementType.TEXT) &&
if (WORD_LIKE_REG.test(word)) { (!element.type || element.type === ElementType.TEXT)
const { width, endElement } = this.textParticle.measureWord(ctx, elementList, i) ) {
curRowWidth += width // 英文单词
nextElement = endElement const word = `${preElement?.value || ''}${element.value}`
if (WORD_LIKE_REG.test(word)) {
const { width, endElement } = this.textParticle.measureWord(ctx, elementList, i)
curRowWidth += width
nextElement = endElement
}
// 标点符号
curRowWidth += this.textParticle.measurePunctuationWidth(ctx, nextElement)
} }
// 标点符号
curRowWidth += this.textParticle.measurePunctuationWidth(ctx, nextElement)
} }
// 列表信息 // 列表信息
if (element.listId) { if (element.listId) {

Loading…
Cancel
Save