From 266915af09be90a1a12092fdff2d266d62f3c90d Mon Sep 17 00:00:00 2001 From: Hufe921 Date: Fri, 31 Mar 2023 23:24:52 +0800 Subject: [PATCH] fix: table cell text render position error #166 --- src/editor/core/command/CommandAdapt.ts | 2 +- src/editor/core/draw/Draw.ts | 8 +++++++- src/editor/dataset/constant/Element.ts | 7 +++++++ src/mock.ts | 2 +- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/editor/core/command/CommandAdapt.ts b/src/editor/core/command/CommandAdapt.ts index d62829a..084bba1 100644 --- a/src/editor/core/command/CommandAdapt.ts +++ b/src/editor/core/command/CommandAdapt.ts @@ -465,7 +465,7 @@ export class CommandAdapt { } const element: IElement = { type: ElementType.TABLE, - value: !startIndex ? '' : ZERO, + value: '', colgroup, trList } diff --git a/src/editor/core/draw/Draw.ts b/src/editor/core/draw/Draw.ts index 559ffce..90d68c9 100644 --- a/src/editor/core/draw/Draw.ts +++ b/src/editor/core/draw/Draw.ts @@ -52,6 +52,7 @@ import { I18n } from '../i18n/I18n' import { ImageObserver } from '../observer/ImageObserver' import { Zone } from '../zone/Zone' import { Footer } from './frame/Footer' +import { INLINE_ELEMENT_TYPE } from '../../dataset/constant/Element' export class Draw { @@ -1004,7 +1005,8 @@ export class Draw { // 累计行宽 + 当前元素宽度 + 后面标点符号宽度 const curRowWidth = curRow.width + metrics.width + this.textParticle.measurePunctuationWidth(ctx, nextElement) if ( - preElement?.type === ElementType.TABLE + element.type === ElementType.TABLE + || preElement?.type === ElementType.TABLE || preElement?.type === ElementType.BLOCK || element.type === ElementType.BLOCK || preElement?.imgDisplay === ImageDisplay.INLINE @@ -1012,6 +1014,10 @@ export class Draw { || curRowWidth > innerWidth || (i !== 0 && element.value === ZERO) ) { + // 减小行元素前第一行空行行高 + if (curRow.startIndex === 0 && curRow.elementList.length === 1 && INLINE_ELEMENT_TYPE.includes(element.type!)) { + curRow.height = defaultBasicRowMarginHeight + } // 两端对齐 if (preElement?.rowFlex === RowFlex.ALIGNMENT && curRowWidth > innerWidth) { const gap = (innerWidth - curRow.width) / curRow.elementList.length diff --git a/src/editor/dataset/constant/Element.ts b/src/editor/dataset/constant/Element.ts index f3d4946..0f8c46a 100644 --- a/src/editor/dataset/constant/Element.ts +++ b/src/editor/dataset/constant/Element.ts @@ -62,4 +62,11 @@ export const TEXTLIKE_ELEMENT_TYPE: ElementType[] = [ ElementType.SUPERSCRIPT, ElementType.CONTROL, ElementType.DATE +] + +export const INLINE_ELEMENT_TYPE: ElementType[] = [ + ElementType.BLOCK, + ElementType.PAGE_BREAK, + ElementType.SEPARATOR, + ElementType.TABLE ] \ No newline at end of file diff --git a/src/mock.ts b/src/mock.ts index 16722b4..9f9b704 100644 --- a/src/mock.ts +++ b/src/mock.ts @@ -133,7 +133,7 @@ elementList.splice(575, 0, { // 模拟表格 elementList.push({ type: ElementType.TABLE, - value: `\n`, + value: '', colgroup: [{ width: 180 }, {