Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
refactor: refactor span to glyph (#1611)
Ran Luo7fb6d359789c
diff --git a/.vscode/settings.json b/.vscode/settings.jsonindex 3aa3471099..9d72325396 100644--- a/.vscode/settings.json+++ b/.vscode/settings.json@@ -7,6 +7,7 @@"commentTranslate.hover.enabled": true,"commentTranslate.source": "Google","cSpell.words": [+ "adjustability","Bandings","Catmull","clazz",@@ -51,6 +52,7 @@"Lerp","linebreak","linebreaker",+ "linebreaking","Liti","localforage","LRTBV",@@ -61,12 +63,15 @@"numfmt","Overlines","Pacifico",+ "Plass","pnmp","ponyfill","PWDEBUG","Quan","redi",+ "shrinkability","Sider",+ "strechability","SUMIF","SUMIFS","Tahoma",diff --git a/packages/docs/src/commands/commands/delete.command.ts b/packages/docs/src/commands/commands/delete.command.tsindex d9088e691a..f0dca608f8 100644--- a/packages/docs/src/commands/commands/delete.command.ts+++ b/packages/docs/src/commands/commands/delete.command.ts@@ -18,14 +18,12 @@ import type { ICommand, IDocumentBody, IMutationInfo, IParagraph, ITextRun } froimport {CommandType,ICommandService,- IUndoRedoService,IUniverInstanceService,TextX,TextXActionType,UpdateDocsAttributeType,} from '@univerjs/core';-import type { IActiveTextRange, ITextRangeWithStyle, TextRange } from '@univerjs/engine-render';-import { getParagraphBySpan, hasListSpan, isFirstSpan, isIndentBySpan } from '@univerjs/engine-render';+import { getParagraphByGlyph, hasListGlyph, type IActiveTextRange, isFirstGlyph, isIndentByGlyph, type ITextRangeWithStyle, type TextRange } from '@univerjs/engine-render';import { DocSkeletonManagerService } from '../../services/doc-skeleton-manager.service';import type { ITextActiveRange } from '../../services/text-selection-manager.service';@@ -64,9 +62,9 @@ export const DeleteLeftCommand: ICommand = {const preSpan = skeleton.findNodeByCharIndex(startOffset);// is in bullet list?- const preIsBullet = hasListSpan(preSpan);+ const preIsBullet = hasListGlyph(preSpan);// is in indented paragraph?- const preIsIndent = isIndentBySpan(preSpan, docDataModel.getBody());+ const preIsIndent = isIndentByGlyph(preSpan, docDataModel.getBody());let cursor = startOffset;@@ -74,10 +72,10 @@ export const DeleteLeftCommand: ICommand = {const span = skeleton.findNodeByCharIndex(startOffset - 1);const isUpdateParagraph =- isFirstSpan(preSpan) && span !== preSpan && (preIsBullet === true || preIsIndent === true);+ isFirstGlyph(preSpan) && span !== preSpan && (preIsBullet === true || preIsIndent === true);if (isUpdateParagraph) {- const paragraph = getParagraphBySpan(preSpan, docDataModel.getBody());+ const paragraph = getParagraphByGlyph(preSpan, docDataModel.getBody());if (paragraph == null) {return false;@@ -264,7 +262,6 @@ export const MergeTwoParagraphCommand: ICommand<IMergeTwoParagraphParams> = {const textSelectionManagerService = accessor.get(TextSelectionManagerService);const currentUniverService = accessor.get(IUniverInstanceService);const commandService = accessor.get(ICommandService);- const undoRedoService = accessor.get(IUndoRedoService);const { direction, range } = params;diff --git a/packages/docs/src/controllers/move-cursor.controller.ts b/packages/docs/src/controllers/move-cursor.controller.tsindex 1efcf75d16..540b4e3a6b 100644--- a/packages/docs/src/controllers/move-cursor.controller.ts+++ b/packages/docs/src/controllers/move-cursor.controller.ts@@ -25,8 +25,8 @@ import {} from '@univerjs/core';import type {DocumentSkeleton,+ IDocumentSkeletonGlyph,IDocumentSkeletonLine,- IDocumentSkeletonSpan,INodePosition,INodeSearch,} from '@univerjs/engine-render';@@ -294,16 +294,16 @@ export class MoveCursorController extends Disposable {private _getTopOrBottomPosition(docSkeleton: DocumentSkeleton,- span: Nullable<IDocumentSkeletonSpan>,+ glyph: Nullable<IDocumentSkeletonGlyph>,direction: boolean): Nullable<INodePosition> {- if (span == null) {+ if (glyph == null) {return;}- const offsetLeft = this._getSpanLeftOffsetInLine(span);+ const offsetLeft = this._getSpanLeftOffsetInLine(glyph);- const line = this._getNextOrPrevLine(span, direction);+ const line = this._getNextOrPrevLine(glyph, direction);if (line == null) {return;@@ -319,8 +319,8 @@ export class MoveCursorController extends Disposable {return { ...position, isBack: true };}- private _getSpanLeftOffsetInLine(span: IDocumentSkeletonSpan) {- const divide = span.parent;+ private _getSpanLeftOffsetInLine(glyph: IDocumentSkeletonGlyph) {+ const divide = glyph.parent;if (divide == null) {return Number.NEGATIVE_INFINITY;@@ -328,7 +328,7 @@ export class MoveCursorController extends Disposable {const divideLeft = divide.left;- const { left } = span;+ const { left } = glyph;const start = divideLeft + left;@@ -337,7 +337,7 @@ export class MoveCursorController extends Disposable {private _matchPositionByLeftOffset(docSkeleton: DocumentSkeleton, line: IDocumentSkeletonLine, offsetLeft: number) {const nearestNode: {- span?: IDocumentSkeletonSpan;+ glyph?: IDocumentSkeletonGlyph;distance: number;} = {distance: Number.POSITIVE_INFINITY,@@ -346,28 +346,28 @@ export class MoveCursorController extends Disposable {for (const divide of line.divides) {const divideLeft = divide.left;- for (const span of divide.spanGroup) {- const { left } = span;+ for (const glyph of divide.glyphGroup) {+ const { left } = glyph;const leftSide = divideLeft + left;const distance = Math.abs(offsetLeft - leftSide);if (distance < nearestNode.distance) {- nearestNode.span = span;+ nearestNode.glyph = glyph;nearestNode.distance = distance;}}}- if (nearestNode.span == null) {+ if (nearestNode.glyph == null) {return;}- return docSkeleton.findPositionBySpan(nearestNode.span);+ return docSkeleton.findPositionByGlyph(nearestNode.glyph);}- private _getNextOrPrevLine(span: IDocumentSkeletonSpan, direction: boolean) {- const divide = span.parent;+ private _getNextOrPrevLine(glyph: IDocumentSkeletonGlyph, direction: boolean) {+ const divide = glyph.parent;if (divide == null) {return;}diff --git a/packages/engine-render/src/basics/document-node-tools.ts b/packages/engine-render/src/basics/document-node-tools.tsindex f974a44735..20583b99df 100644--- a/packages/engine-render/src/basics/document-node-tools.ts+++ b/packages/engine-render/src/basics/document-node-tools.ts@@ -17,23 +17,23 @@import type { IDocumentBody, Nullable } from '@univerjs/core';import { checkParagraphHasIndentByStyle, DataStreamTreeTokenType } from '@univerjs/core';-import type { IDocumentSkeletonSpan } from './i-document-skeleton-cached';-import { SpanType } from './i-document-skeleton-cached';+import type { IDocumentSkeletonGlyph } from './i-document-skeleton-cached';+import { GlyphType } from './i-document-skeleton-cached';-export function hasListSpan(span: Nullable<IDocumentSkeletonSpan>) {- const divide = span?.parent;+export function hasListGlyph(glyph: Nullable<IDocumentSkeletonGlyph>) {+ const divide = glyph?.parent;if (divide == null) {return false;}- const spanGroup = divide.spanGroup;+ const glyphGroup = divide.glyphGroup;- return spanGroup[0]?.spanType === SpanType.LIST;+ return glyphGroup[0]?.glyphType === GlyphType.LIST;}-export function isIndentBySpan(span: Nullable<IDocumentSkeletonSpan>, body?: IDocumentBody) {- const paragraph = getParagraphBySpan(span, body);+export function isIndentByGlyph(glyph: Nullable<IDocumentSkeletonGlyph>, body?: IDocumentBody) {+ const paragraph = getParagraphByGlyph(glyph, body);if (paragraph == null) {return false;}@@ -46,20 +46,20 @@ export function isIndentBySpan(span: Nullable<IDocumentSkeletonSpan>, body?: IDoreturn checkParagraphHasIndentByStyle(paragraphStyle);}-export function isLastSpan(span: Nullable<IDocumentSkeletonSpan>) {- const divide = span?.parent;+export function isLastGlyph(glyph: Nullable<IDocumentSkeletonGlyph>) {+ const divide = glyph?.parent;const line = divide?.parent;- const spanGroup = divide?.spanGroup;+ const glyphGroup = divide?.glyphGroup;const divides = line?.divides;- if (spanGroup && span && divides && divide) {- const spanIndex = spanGroup.indexOf(span);+ if (glyphGroup && glyph && divides && divide) {+ const glyphIndex = glyphGroup.indexOf(glyph);const divideIndex = divides.indexOf(divide);- if (divideIndex === divides.length - 1 && spanIndex === spanGroup.length - 1) {+ if (divideIndex === divides.length - 1 && glyphIndex === glyphGroup.length - 1) {return true;}}@@ -67,24 +67,24 @@ export function isLastSpan(span: Nullable<IDocumentSkeletonSpan>) {return false;}-export function isFirstSpan(span: Nullable<IDocumentSkeletonSpan>) {- const divide = span?.parent;+export function isFirstGlyph(glyph: Nullable<IDocumentSkeletonGlyph>) {+ const divide = glyph?.parent;const line = divide?.parent;- const spanGroup = divide?.spanGroup;+ const glyphGroup = divide?.glyphGroup;const divides = line?.divides;- if (spanGroup && span && divides && divide) {- const spanIndex = spanGroup.indexOf(span);+ if (glyphGroup && glyph && divides && divide) {+ const glyphIndex = glyphGroup.indexOf(glyph);const divideIndex = divides.indexOf(divide);- if (divideIndex === 0 && spanIndex === 0) {+ if (divideIndex === 0 && glyphIndex === 0) {return true;}- if (divideIndex === 0 && spanIndex === 1 && spanGroup[0].spanType === SpanType.LIST) {+ if (divideIndex === 0 && glyphIndex === 1 && glyphGroup[0].glyphType === GlyphType.LIST) {return true;}}@@ -92,8 +92,8 @@ export function isFirstSpan(span: Nullable<IDocumentSkeletonSpan>) {return false;}-export function getParagraphBySpan(span: Nullable<IDocumentSkeletonSpan>, body?: IDocumentBody) {- const line = span?.parent?.parent;+export function getParagraphByGlyph(glyph: Nullable<IDocumentSkeletonGlyph>, body?: IDocumentBody) {+ const line = glyph?.parent?.parent;if (line == null || body == null) {return;}@@ -110,16 +110,16 @@ export function getParagraphBySpan(span: Nullable<IDocumentSkeletonSpan>, body?:}}-export function isPlaceholderOrSpace(span: Nullable<IDocumentSkeletonSpan>) {- if (span == null) {+export function isPlaceholderOrSpace(glyph: Nullable<IDocumentSkeletonGlyph>) {+ if (glyph == null) {return false;}if ([DataStreamTreeTokenType.PARAGRAPH, DataStreamTreeTokenType.TAB, DataStreamTreeTokenType.SECTION_BREAK].indexOf(- span.streamType+ glyph.streamType) !== -1 ||- span.content === DataStreamTreeTokenType.SPACE+ glyph.content === DataStreamTreeTokenType.SPACE) {return true;}@@ -127,22 +127,22 @@ export function isPlaceholderOrSpace(span: Nullable<IDocumentSkeletonSpan>) {return false;}-export function isSameLine(span1: Nullable<IDocumentSkeletonSpan>, span2: Nullable<IDocumentSkeletonSpan>) {- if (span1 == null) {+export function isSameLine(glyph1: Nullable<IDocumentSkeletonGlyph>, glyph2: Nullable<IDocumentSkeletonGlyph>) {+ if (glyph1 == null) {return false;}- if (span2 == null) {+ if (glyph2 == null) {return false;}- if (span1.parent == null) {+ if (glyph1.parent == null) {return false;}- if (span2.parent == null) {+ if (glyph2.parent == null) {return false;}- return span1.parent.parent === span2.parent.parent;+ return glyph1.parent.parent === glyph2.parent.parent;}diff --git a/packages/engine-render/src/basics/i-document-skeleton-cached.ts b/packages/engine-render/src/basics/i-document-skeleton-cached.tsindex 3a003a3036..9453bf32bc 100644--- a/packages/engine-render/src/basics/i-document-skeleton-cached.ts+++ b/packages/engine-render/src/basics/i-document-skeleton-cached.ts@@ -126,10 +126,10 @@ export interface IDocumentSkeletonLine {divides: IDocumentSkeletonDivide[]; // divides 受到对象影响,把行切分为N部分divideLen: number; // divideLen 被对象分割为多少块- lineHeight: number; // 行总体高度 lineHeight =max(span.fontBoundingBoxAscent + span.fontBoundingBoxDescent, span2.....) + space- contentHeight: number; // contentHeight 行内容高度,contentHeight,=max(span.fontBoundingBoxAscent + span.fontBoundingBoxDescent, span2.....)+ lineHeight: number; // 行总体高度 lineHeight =max(glyph.fontBoundingBoxAscent + glyph.fontBoundingBoxDescent, glyph2.....) + space+ contentHeight: number; // contentHeight 行内容高度,contentHeight,=max(glyph.fontBoundingBoxAscent + glyph.fontBoundingBoxDescent, glyph2.....)top: number; // top paragraph(spaceAbove, spaceBelow, lineSpacing*PreLineHeight)- asc: number; // =max(span.textMetrics.asc) alphabet对齐,需要校准+ asc: number; // =max(glyph.textMetrics.asc) alphabet对齐,需要校准paddingTop: number; // paddingTop 内容到顶部的距离paddingBottom: number; // paddingBottom 内容到底部的距离marginTop: number; // marginTop 针对段落的spaceAbove@@ -150,7 +150,7 @@ export interface IDocumentSkeletonLine {export interface IDocumentSkeletonDivide {// divide 分割,为了适配插入对象、图片、表格等,图文混排- spanGroup: IDocumentSkeletonSpan[]; // spanGroup+ glyphGroup: IDocumentSkeletonGlyph[]; // glyphGroupwidth: number; // width 被分割后的总宽度left: number; // left 被对象分割后的偏移位置 | d1 | | d2 |paddingLeft: number; // paddingLeft 根据horizonAlign和width计算对齐偏移@@ -160,17 +160,26 @@ export interface IDocumentSkeletonDivide {parent?: IDocumentSkeletonLine;}-export interface IDocumentSkeletonSpan {+export interface IAdjustability {+ // The left and right strechability+ stretchability: [number, number];+ // The left and right shrinkability+ shrinkability: [number, number];+}++export interface IDocumentSkeletonGlyph {// word or letter or image or custom- eId?: string; // elementId, For custom cases- spanType: SpanType; // SpanType+ glyphId?: string; // elementId, For custom cases+ glyphType: GlyphType; // GlyphTypestreamType: DataStreamTreeTokenType;width: number; // cum width- bBox: IDocumentSkeletonBoundingBox; // bBox: size of Span- paddingLeft: number; // paddingLeft, adjust text align in span+ bBox: IDocumentSkeletonBoundingBox; // bBox: size of glyph+ paddingLeft: number; // paddingLeft, adjust text align in glyphleft: number; // leftcount: number; // count, content length,default 1content: string; // content+ adjustability: IAdjustability; // The adjustability of the glyph.+ isJustifiable: boolean; // Whether this glyph is justifiable for CJK scripts.ts?: ITextStyle; // text stylefontStyle?: IDocumentSkeletonFontStyle; // fontStyle : ITextStyle convert to canvas fontparent?: IDocumentSkeletonDivide;@@ -195,8 +204,8 @@ export interface IDocumentSkeletonBullet extends IIndentStart {export interface IDocumentSkeletonDrawing {objectId: string;- aLeft: number; // 相对于page的左方- aTop: number; // 相对于page的上方+ aLeft: number; // 相对于 page 的左方+ aTop: number; // 相对于 page 的上方width: number;height: number;angle: number; // 旋转@@ -224,7 +233,7 @@ export interface IDocumentSkeletonBoundingBox {}export enum SkeletonType {- SPAN,+ GLYPH,DIVIDE,LINE,COLUMN,@@ -248,7 +257,7 @@ export enum LineType {BLOCK,}-export enum SpanType {+export enum GlyphType {LETTER,WORD,LIST,diff --git a/packages/engine-render/src/basics/interfaces.ts b/packages/engine-render/src/basics/interfaces.tsindex 0e3a74945d..7d6d186608 100644--- a/packages/engine-render/src/basics/interfaces.ts+++ b/packages/engine-render/src/basics/interfaces.ts@@ -37,8 +37,8 @@ import type {IDocumentSkeletonDrawingAnchor,IDocumentSkeletonFontStyle,IDocumentSkeletonFooter,+ IDocumentSkeletonGlyph,IDocumentSkeletonHeader,- IDocumentSkeletonSpan,} from './i-document-skeleton-cached';import type { Vector2 } from './vector2';@@ -157,13 +157,13 @@ export interface IFontCreateConfig {// }export interface INodeInfo {- node: IDocumentSkeletonSpan;+ node: IDocumentSkeletonGlyph;ratioX: number;ratioY: number;}export interface INodeSearch {- span: number;+ glyph: number;divide: number;line: number;column: number;diff --git a/packages/engine-render/src/basics/tools.ts b/packages/engine-render/src/basics/tools.tsindex a79a46bc69..9d81a6d280 100644--- a/packages/engine-render/src/basics/tools.ts+++ b/packages/engine-render/src/basics/tools.ts@@ -33,18 +33,10 @@ import type { IBoundRectNoAngle } from './vector2';const DEG180 = 180;-const OBJECT_ARRAY = '[object Array]';-const OBJECT_NUMBER = '[object Number]';-const OBJECT_STRING = '[object String]';-const OBJECT_BOOLEAN = '[object Boolean]';const PI_OVER_DEG180 = Math.PI / DEG180;const DEG180_OVER_PI = DEG180 / Math.PI;-const HASH = '#';-const EMPTY_STRING = '';-const ZERO = '0';const RGB_PAREN = 'rgb(';const RGBA_PAREN = 'rgba(';-const RGB_REGEX = /rgb\((\d{1,3}),(\d{1,3}),(\d{1,3})\)/;// TODO :move to core @jerryexport const getColor = (RgbArray: number[], opacity?: number): string => {@@ -349,6 +341,11 @@ export function hasCJK(text: string) {return CJK_ALL_REG.test(text);}+const CJK_PUNCTUATION_REG = cjk.punctuations().toRegExp();+export function hasCJKPunctuation(text: string) {+ return CJK_PUNCTUATION_REG.test(text);+}+export function hasAllLatin(text: string) {const pattern = /[\u0000-\u024F]/gi;if (!pattern.exec(text)) {@@ -417,6 +414,29 @@ export function hasSpace(text: string) {return pattern.test(text);}+// See <https://www.w3.org/TR/clreq/#punctuation_width_adjustment>+export function isCjkLeftAlignedPunctuation(text: string) {+ const LEFT_ALIGNED_PUNCTUATION = ['”', '’', ',', '。', '.', '、', ':', ';', '?', '!', '》', ')', '』', '」', '】', '〗', '〕', '〉', ']', '}'];++ return LEFT_ALIGNED_PUNCTUATION.indexOf(text) > -1;+}++// See <https://www.w3.org/TR/clreq/#punctuation_width_adjustment>+export function isCjkRightAlignedPunctuation(text: string) {+ const RIGHT_ALIGNED_PUNCTUATION = ['“', '‘', '《', '(', '『', '「', '【', '〖', '〔', '〈', '[', '{'];++ return RIGHT_ALIGNED_PUNCTUATION.indexOf(text) > -1;+}++// See <https://www.w3.org/TR/clreq/#punctuation_width_adjustment>+export function isCjkCenterAlignedPunctuation(text: string) {+ // U+30FB: Katakana Middle Dot+ // U+00B7: Middle Dot+ const CENTER_ALIGNED_PUNCTUATION = ['\u{30FB}', '\u{00B7}'];++ return CENTER_ALIGNED_PUNCTUATION.indexOf(text) > -1;+}+const one_thousand = 1000;// 返回屏幕 DPIdiff --git a/packages/engine-render/src/components/docs/doc-component.ts b/packages/engine-render/src/components/docs/doc-component.tsindex 5ddb3ab58d..06c162c5f3 100644--- a/packages/engine-render/src/components/docs/doc-component.ts+++ b/packages/engine-render/src/components/docs/doc-component.ts@@ -17,7 +17,7 @@import type { Nullable } from '@univerjs/core';import { RENDER_CLASS_TYPE } from '../../basics/const';-import type { IDocumentSkeletonLine, IDocumentSkeletonSpan } from '../../basics/i-document-skeleton-cached';+import type { IDocumentSkeletonGlyph, IDocumentSkeletonLine } from '../../basics/i-document-skeleton-cached';import { PageLayoutType } from '../../basics/i-document-skeleton-cached';import type { INodeInfo } from '../../basics/interfaces';import type { IBoundRectNoAngle, IViewportBound } from '../../basics/vector2';@@ -27,7 +27,7 @@ import type { DOCS_EXTENSION_TYPE } from './doc-extension';import type { DocumentSkeleton } from './layout/doc-skeleton';export class DocComponent extends RenderComponent<- IDocumentSkeletonSpan | IDocumentSkeletonLine,+ IDocumentSkeletonGlyph | IDocumentSkeletonLine,DOCS_EXTENSION_TYPE,IBoundRectNoAngle[]> {@@ -96,7 +96,7 @@ export class DocComponent extends RenderComponent<findNodeByCoord(offsetX: number, offsetY: number): Nullable<INodeInfo> {}- findCoordByNode(span: IDocumentSkeletonSpan) {}+ findCoordByNode(glyph: IDocumentSkeletonGlyph) {}protected _getBounding(bounds?: IViewportBound) {}diff --git a/packages/engine-render/src/components/docs/doc-extension.ts b/packages/engine-render/src/components/docs/doc-extension.tsindex fb3119623d..ad60f820e5 100644--- a/packages/engine-render/src/components/docs/doc-extension.ts+++ b/packages/engine-render/src/components/docs/doc-extension.ts@@ -14,7 +14,7 @@* limitations under the License.*/-import type { IDocumentSkeletonLine, IDocumentSkeletonSpan } from '../../basics/i-document-skeleton-cached';+import type { IDocumentSkeletonGlyph, IDocumentSkeletonLine } from '../../basics/i-document-skeleton-cached';import type { IBoundRectNoAngle } from '../../basics/vector2';import { ComponentExtension } from '../extension';@@ -24,7 +24,7 @@ export enum DOCS_EXTENSION_TYPE {}export class docExtension extends ComponentExtension<- IDocumentSkeletonSpan | IDocumentSkeletonLine,+ IDocumentSkeletonGlyph | IDocumentSkeletonLine,DOCS_EXTENSION_TYPE,IBoundRectNoAngle> {diff --git a/packages/engine-render/src/components/docs/document.ts b/packages/engine-render/src/components/docs/document.tsindex e73e9d3b90..e3c5aa61d6 100644--- a/packages/engine-render/src/components/docs/document.ts+++ b/packages/engine-render/src/components/docs/document.ts@@ -385,17 +385,17 @@ export class Documents extends DocComponent {for (let i = 0; i < divideLength; i++) {const divide = divides[i];- const { spanGroup } = divide;+ const { glyphGroup } = divide;this._drawLiquid.translateSave();this._drawLiquid.translateDivide(divide);- for (const span of spanGroup) {- if (!span.content || span.content.length === 0) {+ for (const glyph of glyphGroup) {+ if (!glyph.content || glyph.content.length === 0) {continue;}- const { width: spanWidth, left: spanLeft, paddingLeft } = span;+ const { width: spanWidth, left: spanLeft, paddingLeft } = glyph;const { x: translateX, y: translateY } = this._drawLiquid;@@ -434,7 +434,7 @@ export class Documents extends DocComponent {for (const extension of extensions) {if (extension.type === DOCS_EXTENSION_TYPE.SPAN) {extension.extensionOffset = extensionOffset;- extension.draw(ctx, parentScale, span);+ extension.draw(ctx, parentScale, glyph);}}}diff --git a/packages/engine-render/src/components/docs/extensions/background.ts b/packages/engine-render/src/components/docs/extensions/background.tsindex d2b59eb703..51da3b74e0 100644--- a/packages/engine-render/src/components/docs/extensions/background.ts+++ b/packages/engine-render/src/components/docs/extensions/background.ts@@ -17,7 +17,7 @@import type { IScale } from '@univerjs/core';import { getColorStyle } from '@univerjs/core';-import type { IDocumentSkeletonSpan } from '../../../basics/i-document-skeleton-cached';+import type { IDocumentSkeletonGlyph } from '../../../basics/i-document-skeleton-cached';import { Vector2 } from '../../../basics/vector2';import type { UniverRenderingContext } from '../../../context';import { DocumentsSpanAndLineExtensionRegistry } from '../../extension';@@ -34,7 +34,7 @@ export class Background extends docExtension {private _preBackgroundColor = '';- override draw(ctx: UniverRenderingContext, parentScale: IScale, span: IDocumentSkeletonSpan) {+ override draw(ctx: UniverRenderingContext, parentScale: IScale, span: IDocumentSkeletonGlyph) {const line = span.parent?.parent;if (!line) {return;diff --git a/packages/engine-render/src/components/docs/extensions/border.ts b/packages/engine-render/src/components/docs/extensions/border.tsindex 71d8916b0c..75465e510e 100644--- a/packages/engine-render/src/components/docs/extensions/border.ts+++ b/packages/engine-render/src/components/docs/extensions/border.ts@@ -19,7 +19,7 @@ import { getColorStyle } from '@univerjs/core';import { BORDER_TYPE, COLOR_BLACK_RGB, FIX_ONE_PIXEL_BLUR_OFFSET } from '../../../basics/const';import { drawLineByBorderType, getLineWidth, setLineType } from '../../../basics/draw';-import type { IDocumentSkeletonSpan } from '../../../basics/i-document-skeleton-cached';+import type { IDocumentSkeletonGlyph } from '../../../basics/i-document-skeleton-cached';import { Vector2 } from '../../../basics/vector2';import type { UniverRenderingContext } from '../../../context';import { DocumentsSpanAndLineExtensionRegistry } from '../../extension';@@ -36,15 +36,15 @@ export class Border extends docExtension {private _preBorderColor = '';- override draw(ctx: UniverRenderingContext, parentScale: IScale, span: IDocumentSkeletonSpan) {- const line = span.parent?.parent;+ override draw(ctx: UniverRenderingContext, parentScale: IScale, glyph: IDocumentSkeletonGlyph) {+ const line = glyph.parent?.parent;if (!line) {return;}const { asc: maxLineAsc = 0, lineHeight = 0 } = line;- const { ts: textStyle, left, width: spanWidth } = span;+ const { ts: textStyle, left, width: spanWidth } = glyph;if (!textStyle) {return;}diff --git a/packages/engine-render/src/components/docs/extensions/font-and-base-line.ts b/packages/engine-render/src/components/docs/extensions/font-and-base-line.tsindex 2701397fdb..96a6c93645 100644--- a/packages/engine-render/src/components/docs/extensions/font-and-base-line.ts+++ b/packages/engine-render/src/components/docs/extensions/font-and-base-line.ts@@ -19,7 +19,7 @@ import { BaselineOffset, getColorStyle } from '@univerjs/core';import { hasCJK } from '../../../basics';import { COLOR_BLACK_RGB } from '../../../basics/const';-import type { IDocumentSkeletonSpan } from '../../../basics/i-document-skeleton-cached';+import type { IDocumentSkeletonGlyph } from '../../../basics/i-document-skeleton-cached';import { Vector2 } from '../../../basics/vector2';import type { UniverRenderingContext } from '../../../context';import { DocumentsSpanAndLineExtensionRegistry } from '../../extension';@@ -38,8 +38,8 @@ export class FontAndBaseLine extends docExtension {private _preFontColor = '';- override draw(ctx: UniverRenderingContext, parentScale: IScale, span: IDocumentSkeletonSpan) {- const line = span.parent?.parent;+ override draw(ctx: UniverRenderingContext, parentScale: IScale, glyph: IDocumentSkeletonGlyph) {+ const line = glyph.parent?.parent;if (!line) {return;}@@ -48,7 +48,7 @@ export class FontAndBaseLine extends docExtension {// const maxLineAsc = asc + lineMarginTop + linePaddingTop;- const { ts: textStyle, content, fontStyle, bBox } = span;+ const { ts: textStyle, content, fontStyle, bBox } = glyph;const { spanPointWithFont = Vector2.create(0, 0) } = this.extensionOffset;@@ -57,7 +57,7 @@ export class FontAndBaseLine extends docExtension {}if (!textStyle) {- this._fillText(ctx, span, spanPointWithFont);+ this._fillText(ctx, glyph, spanPointWithFont);return;}@@ -89,12 +89,12 @@ export class FontAndBaseLine extends docExtension {}// console.log(content, spanPointWithFont.x, spanPointWithFont.y, startX, startY);- this._fillText(ctx, span, spanPointWithFont);+ this._fillText(ctx, glyph, spanPointWithFont);}- private _fillText(ctx: UniverRenderingContext, span: IDocumentSkeletonSpan, spanPointWithFont: Vector2) {+ private _fillText(ctx: UniverRenderingContext, glyph: IDocumentSkeletonGlyph, spanPointWithFont: Vector2) {const { renderConfig, spanStartPoint, centerPoint } = this.extensionOffset;- const { content, width, bBox } = span;+ const { content, width, bBox } = glyph;const { aba, abd } = bBox;if (content == null || spanStartPoint == null || centerPoint == null) {diff --git a/packages/engine-render/src/components/docs/extensions/line.ts b/packages/engine-render/src/components/docs/extensions/line.tsindex 0707c06292..6e9761c539 100644--- a/packages/engine-render/src/components/docs/extensions/line.ts+++ b/packages/engine-render/src/components/docs/extensions/line.ts@@ -19,7 +19,7 @@ import { BooleanNumber, getColorStyle, TextDecoration } from '@univerjs/core';import { COLOR_BLACK_RGB, DEFAULT_OFFSET_SPACING, FIX_ONE_PIXEL_BLUR_OFFSET } from '../../../basics/const';import { calculateRectRotate } from '../../../basics/draw';-import type { IDocumentSkeletonSpan } from '../../../basics/i-document-skeleton-cached';+import type { IDocumentSkeletonGlyph } from '../../../basics/i-document-skeleton-cached';import { degToRad, getScale } from '../../../basics/tools';import { Vector2 } from '../../../basics/vector2';import type { UniverRenderingContext } from '../../../context';@@ -37,7 +37,7 @@ export class Line extends docExtension {private _preBackgroundColor = '';- override draw(ctx: UniverRenderingContext, parentScale: IScale, span: IDocumentSkeletonSpan) {+ override draw(ctx: UniverRenderingContext, parentScale: IScale, span: IDocumentSkeletonGlyph) {const line = span.parent?.parent;if (!line) {return;@@ -84,7 +84,7 @@ export class Line extends docExtension {private _drawLine(ctx: UniverRenderingContext,- span: IDocumentSkeletonSpan,+ span: IDocumentSkeletonGlyph,line: ITextDecoration,startY: number,scale: numberdiff --git a/packages/engine-render/src/components/docs/layout/block/paragraph/language-ruler.ts b/packages/engine-render/src/components/docs/layout/block/paragraph/language-ruler.tsindex cb732ccdd6..02005fc942 100644--- a/packages/engine-render/src/components/docs/layout/block/paragraph/language-ruler.ts+++ b/packages/engine-render/src/components/docs/layout/block/paragraph/language-ruler.ts@@ -18,7 +18,7 @@ import type { IParagraphStyle } from '@univerjs/core';import type { ISectionBreakConfig } from '../../../../../basics/interfaces';import { EMOJI_REG, hasArabic, hasSpace, hasTibetan, startWithEmoji } from '../../../../../basics/tools';-import { createSkeletonLetterSpan, createSkeletonWordSpan } from '../../model/span';+import { createSkeletonLetterGlyph, createSkeletonWordGlyph } from '../../model/glyph';import { getFontCreateConfig } from '../../tools';import type { DataStreamTreeNode } from '../../../view-model/data-stream-tree-node';import type { DocumentViewModel } from '../../../view-model/document-view-model';@@ -33,7 +33,7 @@ export function otherHandler(sectionBreakConfig: ISectionBreakConfig,paragraphStyle: IParagraphStyle) {- const spanGroup = [];+ const glyphGroup = [];let step = 0;for (let i = 0; i < charArray.length; i++) {@@ -44,15 +44,15 @@ export function otherHandler(}const config = getFontCreateConfig(index + i, bodyModel, paragraphNode, sectionBreakConfig, paragraphStyle);- const span = createSkeletonLetterSpan(newChar, config);+ const glyph = createSkeletonLetterGlyph(newChar, config);- spanGroup.push(span);+ glyphGroup.push(glyph);step++;}return {step,- spanGroup,+ glyphGroup,};}@@ -66,13 +66,13 @@ export function ArabicHandler() {// 组合阿拉伯语的词组const config = getFontCreateConfig(index, bodyModel, paragraphNode, sectionBreakConfig, paragraphStyle);- const span = [];+ const glyph = [];let step = 0;for (let i = 0; i < charArray.length; i++) {const newChar = charArray[i];if (hasArabic(newChar)) {- span.unshift(newChar);+ glyph.unshift(newChar);step++;} else {break;@@ -81,7 +81,7 @@ export function ArabicHandler(return {step,- spanGroup: [createSkeletonLetterSpan(span.join(''), config)],+ glyphGroup: [createSkeletonLetterGlyph(glyph.join(''), config)],};}@@ -98,7 +98,7 @@ export function emojiHandler(return {step: match![0].length,- spanGroup: [createSkeletonLetterSpan(match![0], config)],+ glyphGroup: [createSkeletonLetterGlyph(match![0], config)],};}@@ -112,12 +112,12 @@ export function TibetanHandler() {// 组合藏语词组const config = getFontCreateConfig(index, bodyModel, paragraphNode, sectionBreakConfig, paragraphStyle);- const span = [];+ const glyph = [];let step = 0;for (let i = 0; i < charArray.length; i++) {const newChar = charArray[i];if (hasTibetan(newChar)) {- span.push(newChar);+ glyph.push(newChar);step++;} else {break;@@ -126,6 +126,6 @@ export function TibetanHandler(return {step,- spanGroup: [createSkeletonWordSpan(span.join(''), config)],+ glyphGroup: [createSkeletonWordGlyph(glyph.join(''), config)],};}diff --git a/packages/engine-render/src/components/docs/layout/block/paragraph/layout-ruler.ts b/packages/engine-render/src/components/docs/layout/block/paragraph/layout-ruler.tsindex d6a9632b82..b8a91f9047 100644--- a/packages/engine-render/src/components/docs/layout/block/paragraph/layout-ruler.ts+++ b/packages/engine-render/src/components/docs/layout/block/paragraph/layout-ruler.ts@@ -23,11 +23,11 @@ import type {IDocumentSkeletonBullet,IDocumentSkeletonColumn,IDocumentSkeletonDrawing,+ IDocumentSkeletonGlyph,IDocumentSkeletonLine,IDocumentSkeletonPage,- IDocumentSkeletonSpan,} from '../../../../../basics/i-document-skeleton-cached';-import { LineType, SpanType } from '../../../../../basics/i-document-skeleton-cached';+import { GlyphType, LineType } from '../../../../../basics/i-document-skeleton-cached';import type { IParagraphConfig, ISectionBreakConfig } from '../../../../../basics/interfaces';import {calculateLineTopByDrawings,@@ -38,7 +38,7 @@ import {import { createSkeletonPage } from '../../model/page';import { setColumnFullState } from '../../model/section';-import { addSpanToDivide, createSkeletonBulletSpan, hasMixedTextLayout } from '../../model/span';+import { addGlyphToDivide, createSkeletonBulletGlyph, hasMixedTextLayout } from '../../model/glyph';import {getCharSpaceApply,getCharSpaceConfig,@@ -55,7 +55,7 @@ import {} from '../../tools';export function layoutParagraph(- spanGroup: IDocumentSkeletonSpan[],+ glyphGroup: IDocumentSkeletonGlyph[],pages: IDocumentSkeletonPage[],sectionBreakConfig: ISectionBreakConfig,paragraphConfig: IParagraphConfig,@@ -74,20 +74,20 @@ export function layoutParagraph(__bulletIndentHandler(paragraphStyle, bulletSkeleton, charSpaceApply);- const bulletSpan = createSkeletonBulletSpan(spanGroup[0], bulletSkeleton, charSpaceApply);- _lineOperator([bulletSpan, ...spanGroup], pages, sectionBreakConfig, paragraphConfig, paragraphStart);+ const bulletSpan = createSkeletonBulletGlyph(glyphGroup[0], bulletSkeleton, charSpaceApply);+ _lineOperator([bulletSpan, ...glyphGroup], pages, sectionBreakConfig, paragraphConfig, paragraphStart);} else {- _lineOperator(spanGroup, pages, sectionBreakConfig, paragraphConfig, paragraphStart);+ _lineOperator(glyphGroup, pages, sectionBreakConfig, paragraphConfig, paragraphStart);}} else {- _divideOperator(spanGroup, pages, sectionBreakConfig, paragraphConfig, paragraphStart);+ _divideOperator(glyphGroup, pages, sectionBreakConfig, paragraphConfig, paragraphStart);}return [...pages];}function _divideOperator(- spanGroup: IDocumentSkeletonSpan[],+ glyphGroup: IDocumentSkeletonGlyph[],pages: IDocumentSkeletonPage[],sectionBreakConfig: ISectionBreakConfig,paragraphConfig: IParagraphConfig,@@ -99,31 +99,31 @@ function _divideOperator(const divideInfo = getLastNotFullDivideInfo(lastPage); // 取得最新一行里内容未满的第一个 divide.if (divideInfo) {- const width = __getSpanGroupWidth(spanGroup);+ const width = __getSpanGroupWidth(glyphGroup);const { divide } = divideInfo;- const lastSpan = divide?.spanGroup?.[divide.spanGroup.length - 1];- const preWidth = lastSpan?.width || 0;- const preLeft = lastSpan?.left || 0;+ const lastGlyph = divide?.glyphGroup?.[divide.glyphGroup.length - 1];+ const preWidth = lastGlyph?.width || 0;+ const preLeft = lastGlyph?.left || 0;- // Last span is western char and the current span is Chinese word or vice verse.- const isMixedCJKWesternTextLayout = hasMixedTextLayout(lastSpan, spanGroup[0]);+ // Last glyph is western char and the current glyph is Chinese word or vice verse.+ const isMixedCJKWesternTextLayout = hasMixedTextLayout(lastGlyph, glyphGroup[0]);let wordSpaceWidth = 0;let preOffsetLeft = preWidth + preLeft;- // Only add word space between Chinese text and Western text when processing span for the first time,+ // Only add word space between Chinese text and Western text when processing glyph for the first time,// otherwise it will be added multiple times during recursion.if (isMixedCJKWesternTextLayout && isOutMost) {- const lastSpanIsCJKWord = hasCJKText(lastSpan.content!);+ const lastSpanIsCJKWord = hasCJKText(lastGlyph.content!);const WORD_INNER_SPACE = '\u0020';wordSpaceWidth = FontCache.getTextSize(WORD_INNER_SPACE, // word space.- lastSpanIsCJKWord ? spanGroup[0].fontStyle! : lastSpan.fontStyle!+ lastSpanIsCJKWord ? glyphGroup[0].fontStyle! : lastGlyph.fontStyle!).width;preOffsetLeft += wordSpaceWidth;- lastSpan.width += wordSpaceWidth;+ lastGlyph.width += wordSpaceWidth;}if (preOffsetLeft + width > divide.width) {@@ -139,16 +139,16 @@ function _divideOperator(// There is a boundary case, that is, the width of the English character exceeds the width of the divide, and this character needs to be appended to the previous line.if (divideInfo.isLast &&- spanGroup.length === 1 &&- (spanGroup[0].content === DataStreamTreeTokenType.SPACE ||- spanGroup[0].content === DataStreamTreeTokenType.PARAGRAPH)+ glyphGroup.length === 1 &&+ (glyphGroup[0].content === DataStreamTreeTokenType.SPACE ||+ glyphGroup[0].content === DataStreamTreeTokenType.PARAGRAPH)) {- addSpanToDivide(divide, spanGroup, preOffsetLeft);- } else if (divide?.spanGroup.length === 0) {- const sliceSpanGroup: IDocumentSkeletonSpan[] = [];+ addGlyphToDivide(divide, glyphGroup, preOffsetLeft);+ } else if (divide?.glyphGroup.length === 0) {+ const sliceSpanGroup: IDocumentSkeletonGlyph[] = [];- while (spanGroup.length) {- sliceSpanGroup.push(spanGroup.shift()!);+ while (glyphGroup.length) {+ sliceSpanGroup.push(glyphGroup.shift()!);const sliceSpanGroupWidth = __getSpanGroupWidth(sliceSpanGroup);if (sliceSpanGroupWidth > divide.width) {@@ -156,11 +156,11 @@ function _divideOperator(}}- addSpanToDivide(divide, sliceSpanGroup, preOffsetLeft);+ addGlyphToDivide(divide, sliceSpanGroup, preOffsetLeft);- if (spanGroup.length) {+ if (glyphGroup.length) {_lineOperator(- spanGroup,+ glyphGroup,pages,sectionBreakConfig,paragraphConfig,@@ -170,7 +170,7 @@ function _divideOperator(}} else {_lineOperator(- spanGroup,+ glyphGroup,pages,sectionBreakConfig,paragraphConfig,@@ -181,7 +181,7 @@ function _divideOperator(} else {// w 不超过 divide 宽度,加入到 divide 中去const currentLine = divide.parent;- const maxBox = __maxFontBoundingBoxBySpanGroup(spanGroup);+ const maxBox = __maxFontBoundingBoxBySpanGroup(glyphGroup);if (currentLine && maxBox && !__isNullLine(currentLine)) {const { paragraphLineGapDefault, linePitch, lineSpacing, spacingRule, snapToGrid, gridType } =@@ -208,7 +208,7 @@ function _divideOperator(let newSpanGroup = [];let startIndex = 1;- if (spanGroupCachedLen > 2 && spanGroupCached[0].spanType === SpanType.LIST) {+ if (spanGroupCachedLen > 2 && spanGroupCached[0].glyphType === GlyphType.LIST) {newSpanGroup = [spanGroupCached[0], spanGroupCached[1]];startIndex = 2;} else {@@ -238,21 +238,21 @@ function _divideOperator();}- _divideOperator(spanGroup, pages, sectionBreakConfig, paragraphConfig, paragraphStart, false);+ _divideOperator(glyphGroup, pages, sectionBreakConfig, paragraphConfig, paragraphStart, false);return;}}- addSpanToDivide(divide, spanGroup, preOffsetLeft);+ addGlyphToDivide(divide, glyphGroup, preOffsetLeft);}} else {- _lineOperator(spanGroup, pages, sectionBreakConfig, paragraphConfig, paragraphStart, defaultSpanLineHeight);+ _lineOperator(glyphGroup, pages, sectionBreakConfig, paragraphConfig, paragraphStart, defaultSpanLineHeight);}}function _lineOperator(- spanGroup: IDocumentSkeletonSpan[],+ glyphGroup: IDocumentSkeletonGlyph[],pages: IDocumentSkeletonPage[],sectionBreakConfig: ISectionBreakConfig,paragraphConfig: IParagraphConfig,@@ -263,7 +263,7 @@ function _lineOperator(let columnInfo = getLastNotFullColumnInfo(lastPage);if (!columnInfo || !columnInfo.column) {// 如果列不存在,则做一个兜底策略,新增一页。- _pageOperator(spanGroup, pages, sectionBreakConfig, paragraphConfig);+ _pageOperator(glyphGroup, pages, sectionBreakConfig, paragraphConfig);lastPage = getLastPage(pages);columnInfo = getLastNotFullColumnInfo(lastPage);}@@ -281,8 +281,8 @@ function _lineOperator(const line = getLastLineByColumn(column);- const ascent = Math.max(...spanGroup.map((span) => span.bBox.ba));- const descent = Math.max(...spanGroup.map((span) => span.bBox.bd));+ const ascent = Math.max(...glyphGroup.map((glyph) => glyph.bBox.ba));+ const descent = Math.max(...glyphGroup.map((glyph) => glyph.bBox.bd));const spanLineHeight = defaultSpanLineHeight || ascent + descent;const {@@ -376,9 +376,9 @@ function _lineOperator(if (lineHeight + newLineTop > section.height && column.lines.length > 0 && lastPage.sections.length > 0) {// 行高超过Col高度,且列中已存在一行以上,且section大于一个;- // console.log('_lineOperator', { spanGroup, pages, lineHeight, newLineTop, sectionHeight: section.height, lastPage });+ // console.log('_lineOperator', { glyphGroup, pages, lineHeight, newLineTop, sectionHeight: section.height, lastPage });setColumnFullState(column, true);- _columnOperator(spanGroup, pages, sectionBreakConfig, paragraphConfig, paragraphStart, defaultSpanLineHeight);+ _columnOperator(glyphGroup, pages, sectionBreakConfig, paragraphConfig, paragraphStart, defaultSpanLineHeight);return;}@@ -387,7 +387,7 @@ function _lineOperator(const { charSpace, defaultTabStop } = getCharSpaceConfig(sectionBreakConfig, paragraphConfig);const charSpaceApply = getCharSpaceApply(charSpace, defaultTabStop, gridType, snapToGrid);const { paddingLeft, paddingRight, changeBulletWidth } = __getIndentPadding(- spanGroup[0],+ glyphGroup[0],indentFirstLine,hanging,indentStart,@@ -396,7 +396,7 @@ function _lineOperator();if (changeBulletWidth.state) {// 为了保持__getIndentPadding的纯函数特性,把修改首行列表宽度的逻辑外置到这里- spanGroup[0].width = changeBulletWidth.hangingNumber;+ glyphGroup[0].width = changeBulletWidth.hangingNumber;}const newLine = createSkeletonLine(paragraphIndex,@@ -423,11 +423,11 @@ function _lineOperator(column.lines.push(newLine);newLine.parent = column;createAndUpdateBlockAnchor(paragraphIndex, newLine, lineTop, drawingAnchor);- _divideOperator(spanGroup, pages, sectionBreakConfig, paragraphConfig, paragraphStart, true, defaultSpanLineHeight);+ _divideOperator(glyphGroup, pages, sectionBreakConfig, paragraphConfig, paragraphStart, true, defaultSpanLineHeight);}function _columnOperator(- spanGroup: IDocumentSkeletonSpan[],+ glyphGroup: IDocumentSkeletonGlyph[],pages: IDocumentSkeletonPage[],sectionBreakConfig: ISectionBreakConfig,paragraphConfig: IParagraphConfig,@@ -438,14 +438,14 @@ function _columnOperator(const columnIsFull = isColumnFull(lastPage);if (columnIsFull === true) {- _pageOperator(spanGroup, pages, sectionBreakConfig, paragraphConfig, paragraphStart, defaultSpanLineHeight);+ _pageOperator(glyphGroup, pages, sectionBreakConfig, paragraphConfig, paragraphStart, defaultSpanLineHeight);} else {- _lineOperator(spanGroup, pages, sectionBreakConfig, paragraphConfig, paragraphStart, defaultSpanLineHeight);+ _lineOperator(glyphGroup, pages, sectionBreakConfig, paragraphConfig, paragraphStart, defaultSpanLineHeight);}}function _pageOperator(- spanGroup: IDocumentSkeletonSpan[],+ glyphGroup: IDocumentSkeletonGlyph[],pages: IDocumentSkeletonPage[],sectionBreakConfig: ISectionBreakConfig,paragraphConfig: IParagraphConfig,@@ -456,21 +456,21 @@ function _pageOperator(const { skeHeaders, skeFooters } = paragraphConfig;pages.push(createSkeletonPage(sectionBreakConfig, { skeHeaders, skeFooters }, curSkeletonPage?.pageNumber));- _columnOperator(spanGroup, pages, sectionBreakConfig, paragraphConfig, paragraphStart, defaultSpanLineHeight);+ _columnOperator(glyphGroup, pages, sectionBreakConfig, paragraphConfig, paragraphStart, defaultSpanLineHeight);}/*** 17.3.1.12 ind (Paragraph Indentation)*/function __getIndentPadding(- span: IDocumentSkeletonSpan,+ glyph: IDocumentSkeletonGlyph,indentFirstLine: INumberUnit | number = 0,hanging: INumberUnit | number = 0,indentStart: INumberUnit | number = 0,indentEnd: INumberUnit | number = 0,charSpaceApply: number) {- const { spanType = SpanType.LETTER, bBox } = span;+ const { glyphType = GlyphType.LETTER, bBox } = glyph;const indentFirstLineNumber = getNumberUnitValue(indentFirstLine, charSpaceApply);const hangingNumber = getNumberUnitValue(hanging, charSpaceApply);const indentStartNumber = getNumberUnitValue(indentStart, charSpaceApply);@@ -483,14 +483,14 @@ function __getIndentPadding(hangingNumber: 0,};- if (spanType === SpanType.LIST) {+ if (glyphType === GlyphType.LIST) {// 首行的处理const { width: fontWidth } = bBox;if (indentFirstLineNumber > 0) {paddingLeft += indentFirstLineNumber;} else if (hangingNumber > 0 && hangingNumber > fontWidth) {- // span.w = hangingNumber;+ // glyph.w = hangingNumber;changeBulletWidth.state = true;changeBulletWidth.hangingNumber = hangingNumber;}@@ -692,25 +692,25 @@ function __checkPageBreak(column: IDocumentSkeletonColumn) {return true;}-function __getSpanGroupWidth(spanGroup: IDocumentSkeletonSpan[]) {- const spanGroupLen = spanGroup.length;+function __getSpanGroupWidth(glyphGroup: IDocumentSkeletonGlyph[]) {+ const spanGroupLen = glyphGroup.length;let width = 0;for (let i = 0; i < spanGroupLen; i++) {- const span = spanGroup[i];- width += span.width;+ const glyph = glyphGroup[i];+ width += glyph.width;}return width;}-function __maxFontBoundingBoxBySpanGroup(spanGroup: IDocumentSkeletonSpan[]) {- const spanGroupLen = spanGroup.length;+function __maxFontBoundingBoxBySpanGroup(glyphGroup: IDocumentSkeletonGlyph[]) {+ const spanGroupLen = glyphGroup.length;let height = Number.NEGATIVE_INFINITY;let maxBox;for (let i = 0; i < spanGroupLen; i++) {- const span = spanGroup[i];- const { ba: boundingBoxAscent, bd: boundingBoxDescent } = span.bBox;+ const glyph = glyphGroup[i];+ const { ba: boundingBoxAscent, bd: boundingBoxDescent } = glyph.bBox;if (height < boundingBoxAscent + boundingBoxDescent) {maxBox = { boundingBoxAscent, boundingBoxDescent };@@ -725,14 +725,14 @@ function __maxFontBoundingBoxBySpanGroup(spanGroup: IDocumentSkeletonSpan[]) {function __getSpanGroupByLine(line: IDocumentSkeletonLine) {const divides = line.divides;const dividesLen = divides.length;- const spanGroup = [];+ const glyphGroup = [];for (let i = 0; i < dividesLen; i++) {const divide = divides[i];- spanGroup.push(...divide.spanGroup);+ glyphGroup.push(...divide.glyphGroup);}- return spanGroup;+ return glyphGroup;}function __bulletIndentHandler(@@ -758,5 +758,5 @@ function __bulletIndentHandler(}function __isNullLine(line: IDocumentSkeletonLine) {- return !line.divides[0].spanGroup[0];+ return !line.divides[0].glyphGroup[0];}diff --git a/packages/engine-render/src/components/docs/layout/block/paragraph/layout.ts b/packages/engine-render/src/components/docs/layout/block/paragraph/layout.tsindex ae83a50ea9..a07107c25e 100644--- a/packages/engine-render/src/components/docs/layout/block/paragraph/layout.ts+++ b/packages/engine-render/src/components/docs/layout/block/paragraph/layout.ts@@ -14,37 +14,22 @@* limitations under the License.*/-import type { IBullet, ICustomBlock, IDrawing, IDrawings, Nullable } from '@univerjs/core';-import {- DataStreamTreeTokenType,- HorizontalAlign,- PositionedObjectLayoutType,-} from '@univerjs/core';-+import { HorizontalAlign } from '@univerjs/core';import type {- IDocumentSkeletonBullet,- IDocumentSkeletonDrawing,IDocumentSkeletonLine,IDocumentSkeletonPage,ISkeletonResourceReference,} from '../../../../../basics/i-document-skeleton-cached';-import { BreakType } from '../../../../../basics/i-document-skeleton-cached';-import type { IParagraphConfig, ISectionBreakConfig } from '../../../../../basics/interfaces';--import { createSkeletonPage } from '../../model/page';-import { setColumnFullState } from '../../model/section';+import type { ISectionBreakConfig } from '../../../../../basics/interfaces';import {clearFontCreateConfigCache,- getLastNotFullColumnInfo,getSpanGroupWidth,lineIterator,} from '../../tools';import type { DataStreamTreeNode } from '../../../view-model/data-stream-tree-node';import type { DocumentViewModel } from '../../../view-model/document-view-model';-import { dealWithBullet } from './bullet';-import { dealWidthInlineDrawing } from './inline-drawing';-import { layoutParagraph } from './layout-ruler';import { shaping } from './shaping';+import { lineBreaking } from './linebreaking';export function dealWidthParagraph(bodyModel: DocumentViewModel,@@ -53,99 +38,13 @@ export function dealWidthParagraph(sectionBreakConfig: ISectionBreakConfig,skeletonResourceReference: ISkeletonResourceReference): IDocumentSkeletonPage[] {- const {- pageSize: _pageSize = {- width: Number.POSITIVE_INFINITY,- height: Number.POSITIVE_INFINITY,- },-- marginRight: _marginRight = 0,- marginLeft: _marginLeft = 0,-- lists,- drawings = {},- localeService,- } = sectionBreakConfig;-- const { endIndex, startIndex, content = '', blocks = [] } = paragraphNode;-- const paragraph = bodyModel.getParagraph(endIndex) || { startIndex: 0 };-- const { paragraphStyle = {}, bullet } = paragraph;-- // const paragraphAffectSkeDrawings = _changeDrawingToSkeletonFormat(drawingIds, drawings);-- // curPage.skeDrawings = paragraphAffectSkeDrawings;-- const { skeHeaders, skeFooters, skeListLevel, drawingAnchor } = skeletonResourceReference;-- // const pageWidth = pageSize.w || Infinity;- // const pageHeight = pageSize.h || Infinity;-- // const headerAndFooterAffectSkeDrawings = new Map([- // ...(skeHeaders?.get(curPage.headerId)?.get(pageWidth)?.skeDrawings || []),- // ...(skeFooters?.get(curPage.footerId)?.get(pageWidth)?.skeDrawings || []),- // ]);-- // curPage.skeDrawings = affectSkeDrawings; // 加入本段落的对象-- // const pages = [curPage];- // let lastPage = curPage;-- // if (pageSize.h === Infinity) {- // // 无需分页的情况,适合表格单元格或者类似notion的block布局- // }-- // if (curPage.sections.length > 0) {- // // 处理接上一页的情况- // let columnHeight = _getColumnHeight(curPage);- // curPage.skeDrawings;-- // return [];- // }-- const paragraphAffectSkeDrawings: Map<string, IDocumentSkeletonDrawing> = new Map();-- const paragraphConfig: IParagraphConfig = {- paragraphIndex: endIndex,- paragraphStyle,- paragraphAffectSkeDrawings,- skeHeaders,- skeFooters,- drawingAnchor,- };-- const listLevelAncestors = _getListLevelAncestors(bullet, skeListLevel); // 取得列表所有 level 的缓存- const bulletSkeleton = dealWithBullet(bullet, lists, listLevelAncestors, localeService); // 生成 bullet-- _updateListLevelAncestors(bullet, bulletSkeleton, skeListLevel); // 更新最新的 level 缓存列表-- paragraphConfig.bulletSkeleton = bulletSkeleton;-- const { horizontalAlign = HorizontalAlign.UNSPECIFIED } = paragraphStyle;-- let allPages = [curPage];-- const customBlockCache = new Map<number, Nullable<ICustomBlock>>();-- for (let i = 0, len = blocks.length; i < len; i++) {- const charIndex = blocks[i];- const customBlock = bodyModel.getCustomBlock(charIndex);- if (customBlock == null) {- continue;- }-- customBlockCache.set(charIndex, customBlock);- const blockId = customBlock.blockId;- const drawingOrigin = drawings[blockId];- if (drawingOrigin.layoutType !== PositionedObjectLayoutType.INLINE) {- paragraphAffectSkeDrawings.set(blockId, _getDrawingSkeletonFormat(drawingOrigin));- }- }-clearFontCreateConfigCache();// Step 1: Text Shaping.+ const { endIndex, content = '' } = paragraphNode;+ const paragraph = bodyModel.getParagraph(endIndex) || { startIndex: 0 };+ const { paragraphStyle = {} } = paragraph;+const shapedTextList = shaping(content,bodyModel,@@ -155,84 +54,18 @@ export function dealWidthParagraph();// Step 2: Line Breaking.- let paragraphStart = true;- let charIndex = startIndex;- for (const { text, glyphs } of shapedTextList) {- charIndex += text.length;- const pushPending = () => {- if (glyphs.length === 0) {- return;- }-- allPages = layoutParagraph(- glyphs,- allPages,- sectionBreakConfig,- paragraphConfig,- paragraphStart- );-- paragraphStart = false;- };-- if (text.endsWith(DataStreamTreeTokenType.CUSTOM_BLOCK)) {- let customBlock = customBlockCache.get(charIndex);- if (customBlock == null) {- customBlock = bodyModel.getCustomBlock(charIndex);- }- if (customBlock != null) {- const blockId = customBlock.blockId;- const drawingOrigin = drawings[blockId];- if (drawingOrigin.layoutType === PositionedObjectLayoutType.INLINE) {- allPages = dealWidthInlineDrawing(- drawingOrigin,- sectionBreakConfig,- allPages,- paragraphConfig,- localeService- );- }- }- pushPending();- continue;- } else if (text.endsWith(DataStreamTreeTokenType.PAGE_BREAK)) {- pushPending();- allPages.push(- createSkeletonPage(- sectionBreakConfig,- skeletonResourceReference,- _getNextPageNumber(allPages[allPages.length - 1]),- BreakType.PAGE- )- );- paragraphAffectSkeDrawings.clear();- continue;- } else if (text.endsWith(DataStreamTreeTokenType.COLUMN_BREAK)) {- pushPending();- // 换列标识,还在同一个节内- const lastPage = allPages[allPages.length - 1];- const columnInfo = getLastNotFullColumnInfo(lastPage);-- if (columnInfo && !columnInfo.isLast) {- setColumnFullState(columnInfo.column, true);- } else {- allPages.push(- createSkeletonPage(- sectionBreakConfig,- skeletonResourceReference,- _getNextPageNumber(lastPage),- BreakType.COLUMN- )- );- }- continue;- }-- pushPending();- }+ const allPages = lineBreaking(+ shapedTextList,+ curPage,+ bodyModel,+ paragraphNode,+ sectionBreakConfig,+ skeletonResourceReference+ );// Step 3: Line Adjustment.// Handle horizontal align: left\center\right\justified.+ const { horizontalAlign = HorizontalAlign.UNSPECIFIED } = paragraphStyle;lineIterator(allPages, (line) => {horizontalAlignHandler(line, horizontalAlign);});@@ -240,82 +73,6 @@ export function dealWidthParagraph(return allPages;}-function _getListLevelAncestors(- bullet?: IBullet,- listLevel?: Map<string, IDocumentSkeletonBullet[]>-): Array<Nullable<IDocumentSkeletonBullet>> | undefined {- if (!bullet || !listLevel) {- return;- }-- const { listId, nestingLevel } = bullet;-- const sameList = listLevel?.get(listId);-- let level = nestingLevel;-- if (level < 0) {- level = 0;- }-- const listLevelAncestors: Array<Nullable<IDocumentSkeletonBullet>> = [];-- for (let i = level; i >= 0; i--) {- const bs = sameList?.[i];- listLevelAncestors[i] = bs || null;- }-- return listLevelAncestors;-}--function _updateListLevelAncestors(- bullet?: IBullet,- bulletSkeleton?: IDocumentSkeletonBullet,- listLevel?: Map<string, IDocumentSkeletonBullet[]>-) {- if (!bullet || !bulletSkeleton) {- return;- }-- const { listId, nestingLevel } = bullet;-- const cacheItem: IDocumentSkeletonBullet[] = [...(listLevel?.get(listId) || [])];-- // [[nestingLevel, bulletSkeleton]];-- cacheItem[nestingLevel] = bulletSkeleton;-- cacheItem.splice(nestingLevel + 1); // 文档自上而下渲染,如果一个level被更新,则它以下的level数据的startIndex就要重置-- listLevel?.set(listId, cacheItem);-}--function _changeDrawingToSkeletonFormat(- drawingIds: string[],- drawings: IDrawings-): Map<string, IDocumentSkeletonDrawing> {- const skeDrawings: Map<string, IDocumentSkeletonDrawing> = new Map();- drawingIds.forEach((objectId) => {- const drawingOrigin = drawings[objectId];- drawingOrigin && skeDrawings.set(objectId, _getDrawingSkeletonFormat(drawingOrigin));- });- return skeDrawings;-}--function _getDrawingSkeletonFormat(drawingOrigin: IDrawing) {- const objectId = drawingOrigin.objectId;- return {- objectId,- aLeft: 0,- aTop: 0,- width: 0,- height: 0,- angle: 0,- initialState: false,- drawingOrigin,- };-}-function _checkAndPush(pages: IDocumentSkeletonPage[], currentPages: IDocumentSkeletonPage[]) {const curLast = pages.slice(-1)[0];const newFirst = currentPages[0];@@ -340,10 +97,6 @@ function _checkAndPush(pages: IDocumentSkeletonPage[], currentPages: IDocumentSk// ]);// }-function _getNextPageNumber(lastPage: IDocumentSkeletonPage) {- return lastPage.pageNumber + 1;-}-/*** todo: @author DR-univer* When aligning text horizontally within a document,diff --git a/packages/engine-render/src/components/docs/layout/block/paragraph/linebreaking.ts b/packages/engine-render/src/components/docs/layout/block/paragraph/linebreaking.tsnew file mode 100644index 0000000000..69d9e4fa05--- /dev/null+++ b/packages/engine-render/src/components/docs/layout/block/paragraph/linebreaking.ts@@ -0,0 +1,248 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import type { IBullet, ICustomBlock, IDrawing, IDrawings, Nullable } from '@univerjs/core';+import { DataStreamTreeTokenType, PositionedObjectLayoutType } from '@univerjs/core';+import { BreakType } from '../../../../../basics/i-document-skeleton-cached';+import type { IDocumentSkeletonBullet, IDocumentSkeletonDrawing, IDocumentSkeletonPage, ISkeletonResourceReference } from '../../../../../basics/i-document-skeleton-cached';+import { createSkeletonPage } from '../../model/page';+import { setColumnFullState } from '../../model/section';+import { getLastNotFullColumnInfo } from '../../tools';+import type { DataStreamTreeNode } from '../../../view-model/data-stream-tree-node';+import type { DocumentViewModel } from '../../../view-model/document-view-model';+import type { IParagraphConfig, ISectionBreakConfig } from '../../../../../basics/interfaces';+import { layoutParagraph } from './layout-ruler';+import type { IShapedText } from './shaping';+import { dealWidthInlineDrawing } from './inline-drawing';+import { dealWithBullet } from './bullet';++function _getListLevelAncestors(+ bullet?: IBullet,+ listLevel?: Map<string, IDocumentSkeletonBullet[]>+): Array<Nullable<IDocumentSkeletonBullet>> | undefined {+ if (!bullet || !listLevel) {+ return;+ }++ const { listId, nestingLevel } = bullet;++ const sameList = listLevel?.get(listId);++ let level = nestingLevel;++ if (level < 0) {+ level = 0;+ }++ const listLevelAncestors: Array<Nullable<IDocumentSkeletonBullet>> = [];++ for (let i = level; i >= 0; i--) {+ const bs = sameList?.[i];+ listLevelAncestors[i] = bs || null;+ }++ return listLevelAncestors;+}++function _updateListLevelAncestors(+ bullet?: IBullet,+ bulletSkeleton?: IDocumentSkeletonBullet,+ listLevel?: Map<string, IDocumentSkeletonBullet[]>+) {+ if (!bullet || !bulletSkeleton) {+ return;+ }++ const { listId, nestingLevel } = bullet;++ const cacheItem: IDocumentSkeletonBullet[] = [...(listLevel?.get(listId) || [])];++ // [[nestingLevel, bulletSkeleton]];++ cacheItem[nestingLevel] = bulletSkeleton;++ cacheItem.splice(nestingLevel + 1); // 文档自上而下渲染,如果一个level被更新,则它以下的level数据的startIndex就要重置++ listLevel?.set(listId, cacheItem);+}++function _changeDrawingToSkeletonFormat(+ drawingIds: string[],+ drawings: IDrawings+): Map<string, IDocumentSkeletonDrawing> {+ const skeDrawings: Map<string, IDocumentSkeletonDrawing> = new Map();+ drawingIds.forEach((objectId) => {+ const drawingOrigin = drawings[objectId];+ drawingOrigin && skeDrawings.set(objectId, _getDrawingSkeletonFormat(drawingOrigin));+ });+ return skeDrawings;+}++function _getDrawingSkeletonFormat(drawingOrigin: IDrawing) {+ const objectId = drawingOrigin.objectId;+ return {+ objectId,+ aLeft: 0,+ aTop: 0,+ width: 0,+ height: 0,+ angle: 0,+ initialState: false,+ drawingOrigin,+ };+}++function _getNextPageNumber(lastPage: IDocumentSkeletonPage) {+ return lastPage.pageNumber + 1;+}++export function lineBreaking(+ shapedTextList: IShapedText[],+ curPage: IDocumentSkeletonPage,+ bodyModel: DocumentViewModel,+ paragraphNode: DataStreamTreeNode,+ sectionBreakConfig: ISectionBreakConfig,+ skeletonResourceReference: ISkeletonResourceReference+): IDocumentSkeletonPage[] {+ const {+ lists,+ drawings = {},+ localeService,+ } = sectionBreakConfig;++ const { endIndex, startIndex, blocks = [] } = paragraphNode;++ const paragraph = bodyModel.getParagraph(endIndex) || { startIndex: 0 };++ const { paragraphStyle = {}, bullet } = paragraph;++ const { skeHeaders, skeFooters, skeListLevel, drawingAnchor } = skeletonResourceReference;++ const paragraphAffectSkeDrawings: Map<string, IDocumentSkeletonDrawing> = new Map();++ const paragraphConfig: IParagraphConfig = {+ paragraphIndex: endIndex,+ paragraphStyle,+ paragraphAffectSkeDrawings,+ skeHeaders,+ skeFooters,+ drawingAnchor,+ };++ const listLevelAncestors = _getListLevelAncestors(bullet, skeListLevel); // 取得列表所有 level 的缓存+ const bulletSkeleton = dealWithBullet(bullet, lists, listLevelAncestors, localeService); // 生成 bullet++ _updateListLevelAncestors(bullet, bulletSkeleton, skeListLevel); // 更新最新的 level 缓存列表++ paragraphConfig.bulletSkeleton = bulletSkeleton;++ const customBlockCache = new Map<number, Nullable<ICustomBlock>>();++ for (let i = 0, len = blocks.length; i < len; i++) {+ const charIndex = blocks[i];+ const customBlock = bodyModel.getCustomBlock(charIndex);+ if (customBlock == null) {+ continue;+ }++ customBlockCache.set(charIndex, customBlock);+ const blockId = customBlock.blockId;+ const drawingOrigin = drawings[blockId];+ if (drawingOrigin.layoutType !== PositionedObjectLayoutType.INLINE) {+ paragraphAffectSkeDrawings.set(blockId, _getDrawingSkeletonFormat(drawingOrigin));+ }+ }++ let allPages = [curPage];+ let paragraphStart = true;+ let charIndex = startIndex;++ for (const { text, glyphs } of shapedTextList) {+ charIndex += text.length;+ const pushPending = () => {+ if (glyphs.length === 0) {+ return;+ }++ allPages = layoutParagraph(+ glyphs,+ allPages,+ sectionBreakConfig,+ paragraphConfig,+ paragraphStart+ );++ paragraphStart = false;+ };++ if (text.endsWith(DataStreamTreeTokenType.CUSTOM_BLOCK)) {+ let customBlock = customBlockCache.get(charIndex);+ if (customBlock == null) {+ customBlock = bodyModel.getCustomBlock(charIndex);+ }+ if (customBlock != null) {+ const blockId = customBlock.blockId;+ const drawingOrigin = drawings[blockId];+ if (drawingOrigin.layoutType === PositionedObjectLayoutType.INLINE) {+ allPages = dealWidthInlineDrawing(+ drawingOrigin,+ sectionBreakConfig,+ allPages,+ paragraphConfig,+ localeService+ );+ }+ }+ pushPending();+ continue;+ } else if (text.endsWith(DataStreamTreeTokenType.PAGE_BREAK)) {+ pushPending();+ allPages.push(+ createSkeletonPage(+ sectionBreakConfig,+ skeletonResourceReference,+ _getNextPageNumber(allPages[allPages.length - 1]),+ BreakType.PAGE+ )+ );+ paragraphAffectSkeDrawings.clear();+ continue;+ } else if (text.endsWith(DataStreamTreeTokenType.COLUMN_BREAK)) {+ pushPending();+ // 换列标识,还在同一个节内+ const lastPage = allPages[allPages.length - 1];+ const columnInfo = getLastNotFullColumnInfo(lastPage);++ if (columnInfo && !columnInfo.isLast) {+ setColumnFullState(columnInfo.column, true);+ } else {+ allPages.push(+ createSkeletonPage(+ sectionBreakConfig,+ skeletonResourceReference,+ _getNextPageNumber(lastPage),+ BreakType.COLUMN+ )+ );+ }+ continue;+ }++ pushPending();+ }++ return allPages;+}diff --git a/packages/engine-render/src/components/docs/layout/block/paragraph/shaping.ts b/packages/engine-render/src/components/docs/layout/block/paragraph/shaping.tsindex d2537d1b48..633b9cc245 100644--- a/packages/engine-render/src/components/docs/layout/block/paragraph/shaping.ts+++ b/packages/engine-render/src/components/docs/layout/block/paragraph/shaping.ts@@ -16,10 +16,10 @@import type { IParagraphStyle } from '@univerjs/core';import { BooleanNumber, DataStreamTreeTokenType, GridType } from '@univerjs/core';-import type { IDocumentSkeletonSpan } from '../../../../../basics/i-document-skeleton-cached';+import type { IDocumentSkeletonGlyph } from '../../../../../basics/i-document-skeleton-cached';import { LineBreaker } from '../../linebreak';import { tabLineBreakExtension } from '../../linebreak/extensions/tab-linebreak-extension';-import { createSkeletonLetterSpan, createSkeletonTabSpan } from '../../model/span';+import { createSkeletonLetterGlyph, createSkeletonTabGlyph } from '../../model/glyph';import { getCharSpaceApply, getFontCreateConfig } from '../../tools';import type { DataStreamTreeNode } from '../../../view-model/data-stream-tree-node';import type { DocumentViewModel } from '../../../view-model/document-view-model';@@ -29,7 +29,7 @@ import { ArabicHandler, emojiHandler, otherHandler, TibetanHandler } from './lanexport interface IShapedText {text: string;- glyphs: IDocumentSkeletonSpan[];+ glyphs: IDocumentSkeletonGlyph[];}export function shaping(@@ -59,27 +59,27 @@ export function shaping(const word = content.slice(last, bk.position);let src = word;let i = last;- const shapedGlyphs: IDocumentSkeletonSpan[] = [];+ const shapedGlyphs: IDocumentSkeletonGlyph[] = [];while (src.length > 0) {const char = src[0];if (/\s/.test(char) || hasCJK(char)) {const config = getFontCreateConfig(i, bodyModel, paragraphNode, sectionBreakConfig, paragraphStyle);- let newSpan: IDocumentSkeletonSpan;+ let newSpan: IDocumentSkeletonGlyph;if (char === DataStreamTreeTokenType.TAB) {const charSpaceApply = getCharSpaceApply(charSpace, defaultTabStop, gridType, snapToGrid);- newSpan = createSkeletonTabSpan(config, charSpaceApply);+ newSpan = createSkeletonTabGlyph(config, charSpaceApply);} else {- newSpan = createSkeletonLetterSpan(char, config);+ newSpan = createSkeletonLetterGlyph(char, config);}shapedGlyphs.push(newSpan);i++;src = src.substring(1);} else if (startWithEmoji(src)) {- const { step, spanGroup } = emojiHandler(+ const { step, glyphGroup } = emojiHandler(i,src,bodyModel,@@ -87,12 +87,12 @@ export function shaping(sectionBreakConfig,paragraphStyle);- shapedGlyphs.push(...spanGroup);+ shapedGlyphs.push(...glyphGroup);i += step;src = src.substring(step);} else if (hasArabic(char)) {- const { step, spanGroup } = ArabicHandler(+ const { step, glyphGroup } = ArabicHandler(i,src,bodyModel,@@ -100,12 +100,12 @@ export function shaping(sectionBreakConfig,paragraphStyle);- shapedGlyphs.push(...spanGroup);+ shapedGlyphs.push(...glyphGroup);i += step;src = src.substring(step);} else if (hasTibetan(char)) {- const { step, spanGroup } = TibetanHandler(+ const { step, glyphGroup } = TibetanHandler(i,src,bodyModel,@@ -113,13 +113,13 @@ export function shaping(sectionBreakConfig,paragraphStyle);- shapedGlyphs.push(...spanGroup);+ shapedGlyphs.push(...glyphGroup);i += step;src = src.substring(step);} else {// TODO: 处理一个单词超过 page width 情况- const { step, spanGroup } = otherHandler(+ const { step, glyphGroup } = otherHandler(i,src,bodyModel,@@ -127,7 +127,7 @@ export function shaping(sectionBreakConfig,paragraphStyle);- shapedGlyphs.push(...spanGroup);+ shapedGlyphs.push(...glyphGroup);i += step;src = src.substring(step);diff --git a/packages/engine-render/src/components/docs/layout/doc-skeleton.ts b/packages/engine-render/src/components/docs/layout/doc-skeleton.tsindex ac8f637f94..d0198c07a4 100644--- a/packages/engine-render/src/components/docs/layout/doc-skeleton.ts+++ b/packages/engine-render/src/components/docs/layout/doc-skeleton.ts@@ -28,11 +28,11 @@ import {import type {IDocumentSkeletonCached,+ IDocumentSkeletonGlyph,IDocumentSkeletonPage,- IDocumentSkeletonSpan,ISkeletonResourceReference,} from '../../../basics/i-document-skeleton-cached';-import { LineType, PageLayoutType, SpanType } from '../../../basics/i-document-skeleton-cached';+import { GlyphType, LineType, PageLayoutType } from '../../../basics/i-document-skeleton-cached';import type { IDocsConfig, INodeInfo, INodePosition, INodeSearch, ISectionBreakConfig } from '../../../basics/interfaces';import type { IViewportBound, Vector2 } from '../../../basics/vector2';import { Skeleton } from '../../skeleton';@@ -118,8 +118,8 @@ export class DocumentSkeleton extends Skeleton {for (const line of column.lines) {let lineWidth = 0;for (const divide of line.divides) {- for (const span of divide.spanGroup) {- lineWidth += span.width;+ for (const glyph of divide.glyphGroup) {+ lineWidth += glyph.width;}}maxWidth = Math.max(maxWidth, lineWidth);@@ -134,8 +134,8 @@ export class DocumentSkeleton extends Skeleton {return this.getViewModel().getDataModel().documentStyle.pageSize;}- findPositionBySpan(span: IDocumentSkeletonSpan): Nullable<INodeSearch> {- const divide = span.parent;+ findPositionByGlyph(glyph: IDocumentSkeletonGlyph): Nullable<INodeSearch> {+ const divide = glyph.parent;const line = divide?.parent;@@ -151,7 +151,7 @@ export class DocumentSkeleton extends Skeleton {return;}- const spanIndex = divide.spanGroup.indexOf(span);+ const glyphIndex = divide.glyphGroup.indexOf(glyph);const divideIndex = line.divides.indexOf(divide);@@ -164,7 +164,7 @@ export class DocumentSkeleton extends Skeleton {const pageIndex = skeletonData.pages.indexOf(page);return {- span: spanIndex,+ glyph: glyphIndex,divide: divideIndex,line: lineIndex,column: columnIndex,@@ -188,10 +188,10 @@ export class DocumentSkeleton extends Skeleton {const pages = skeletonData.pages;- const { span, divide, line, column, section, page } = nodes;+ const { glyph, divide, line, column, section, page } = nodes;return {- span: divide.spanGroup.indexOf(span),+ glyph: divide.glyphGroup.indexOf(glyph),divide: line.divides.indexOf(divide),line: column.lines.indexOf(line),column: section.columns.indexOf(column),@@ -201,13 +201,13 @@ export class DocumentSkeleton extends Skeleton {};}- findNodeByCharIndex(charIndex: number): Nullable<IDocumentSkeletonSpan> {+ findNodeByCharIndex(charIndex: number): Nullable<IDocumentSkeletonGlyph> {const nodes = this._findNodeIterator(charIndex);- return nodes?.span;+ return nodes?.glyph;}- findSpanByPosition(position: Nullable<INodePosition>) {+ findGlyphByPosition(position: Nullable<INodePosition>) {if (position == null) {return;}@@ -220,22 +220,22 @@ export class DocumentSkeleton extends Skeleton {const { divide, line, column, section, page, isBack } = position;- let { span } = position;+ let { glyph } = position;if (isBack === true) {- span -= 1;+ glyph -= 1;}- span = span < 0 ? 0 : span;+ glyph = glyph < 0 ? 0 : glyph;- const spanGroup =- skeletonData.pages[page].sections[section].columns[column].lines[line].divides[divide].spanGroup;+ const glyphGroup =+ skeletonData.pages[page].sections[section].columns[column].lines[line].divides[divide].glyphGroup;- if (spanGroup[span].spanType === SpanType.LIST) {- return spanGroup[span + 1];+ if (glyphGroup[glyph].glyphType === GlyphType.LIST) {+ return glyphGroup[glyph + 1];}- return spanGroup[span];+ return glyphGroup[glyph];}findNodeByCoord(@@ -326,7 +326,7 @@ export class DocumentSkeleton extends Skeleton {const divideLength = divides.length;for (let i = 0; i < divideLength; i++) {const divide = divides[i];- const { spanGroup, width: divideWidth } = divide;+ const { glyphGroup, width: divideWidth } = divide;this._findLiquid.translateSave();this._findLiquid.translateDivide(divide);@@ -338,23 +338,23 @@ export class DocumentSkeleton extends Skeleton {// continue;// }- for (const span of spanGroup) {- if (!span.content || span.content.length === 0) {+ for (const glyph of glyphGroup) {+ if (!glyph.content || glyph.content.length === 0) {continue;}- const { width: spanWidth, left: spanLeft } = span;+ const { width: glyphWidth, left: glyphLeft } = glyph;- const startX_fin = startX + spanLeft;+ const startX_fin = startX + glyphLeft;- const endX_fin = startX + spanLeft + spanWidth;+ const endX_fin = startX + glyphLeft + glyphWidth;const distanceX = Math.abs(x - endX_fin);if (y >= startY_fin && y <= endY_fin) {if (x >= startX_fin && x <= endX_fin) {return {- node: span,+ node: glyph,ratioX: x / (startX_fin + endX_fin),ratioY: y / (startY_fin + endY_fin),};@@ -365,7 +365,7 @@ export class DocumentSkeleton extends Skeleton {nearestNodeDistanceList = [];}nearestNodeList.push({- node: span,+ node: glyph,ratioX: x / (startX_fin + endX_fin),ratioY: y / (startY_fin + endY_fin),});@@ -384,7 +384,7 @@ export class DocumentSkeleton extends Skeleton {if (distanceY === nearestNodeDistanceY) {nearestNodeList.push({- node: span,+ node: glyph,ratioX: x / (startX_fin + endX_fin),ratioY: y / (startY_fin + endY_fin),});@@ -763,17 +763,17 @@ export class DocumentSkeleton extends Skeleton {for (let i = 0; i < divideLength; i++) {const divide = divides[i];- const { spanGroup, st, ed } = divide;+ const { glyphGroup, st, ed } = divide;if (charIndex < st || charIndex > ed) {continue;}- // Some span.content's length maybe great than 1, so the charIndex is not equal to spanIndex.+ // Some glyph.content's length maybe great than 1, so the charIndex is not equal to glyphIndex.let delta = charIndex - st;- for (const span of spanGroup) {- delta -= span.count;+ for (const glyph of glyphGroup) {+ delta -= glyph.count;if (delta < 0) {return {@@ -782,7 +782,7 @@ export class DocumentSkeleton extends Skeleton {column,line,divide,- span,+ glyph,};}}diff --git a/packages/engine-render/src/components/docs/layout/model/__test__/glyph.spec.ts b/packages/engine-render/src/components/docs/layout/model/__test__/glyph.spec.tsnew file mode 100644index 0000000000..4aa423917f--- /dev/null+++ b/packages/engine-render/src/components/docs/layout/model/__test__/glyph.spec.ts@@ -0,0 +1,54 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { describe, expect, it } from 'vitest';+import { baseAdjustability } from '../glyph';++describe('Glyph utils test cases', () => {+ describe('test baseAdjustability', () => {+ it('should return correct adjustability for space', () => {+ const result = baseAdjustability(' ', 12);+ expect(result).toEqual({+ stretchability: [0, 6],+ shrinkability: [0, 4],+ });+ });++ it('should return correct adjustability for CJK left aligned punctuation', () => {+ const result = baseAdjustability(',', 10);+ expect(result).toEqual({+ stretchability: [0, 0],+ shrinkability: [0, 5],+ });+ });++ it('should return correct adjustability for CJK right aligned punctuation', () => {+ const result = baseAdjustability('“', 10);+ expect(result).toEqual({+ stretchability: [0, 0],+ shrinkability: [5, 0],+ });+ });++ it('should return correct adjustability for CJK center aligned punctuation', () => {+ const result = baseAdjustability('\u{30FB}', 12);+ expect(result).toEqual({+ stretchability: [0, 0],+ shrinkability: [3, 3],+ });+ });+ });+});diff --git a/packages/engine-render/src/components/docs/layout/model/span.ts b/packages/engine-render/src/components/docs/layout/model/glyph.tssimilarity index 55%rename from packages/engine-render/src/components/docs/layout/model/span.tsrename to packages/engine-render/src/components/docs/layout/model/glyph.tsindex 1ecb4346ca..bec6244ab2 100644--- a/packages/engine-render/src/components/docs/layout/model/span.ts+++ b/packages/engine-render/src/components/docs/layout/model/glyph.ts@@ -19,41 +19,89 @@ import { BooleanNumber, BulletAlignment, DataStreamTreeTokenType as DT, GridTypeimport { FontCache } from '../../../../basics/font-cache';import type {+ IAdjustability,IDocumentSkeletonBullet,IDocumentSkeletonDivide,- IDocumentSkeletonSpan,+ IDocumentSkeletonGlyph,} from '../../../../basics/i-document-skeleton-cached';-import { SpanType } from '../../../../basics/i-document-skeleton-cached';+import { GlyphType } from '../../../../basics/i-document-skeleton-cached';import type { IFontCreateConfig } from '../../../../basics/interfaces';-import { hasCJK, hasCJKText } from '../../../../basics/tools';+import { hasCJK, hasCJKText, isCjkCenterAlignedPunctuation, isCjkLeftAlignedPunctuation, isCjkRightAlignedPunctuation } from '../../../../basics/tools';import { validationGrid } from '../tools';-export function createSkeletonWordSpan(+export function isSpace(char: string) {+ const SPACE_CHARS = [' ', '\u{00A0}', ' '];++ return SPACE_CHARS.includes(char);+}+// Whether the glyph is justifiable.+export function isJustifiable(+ content: string+) {+ // punctuation style is not relevant here.+ return isSpace(content)+ || hasCJKText(content)+ || isCjkLeftAlignedPunctuation(content)+ || isCjkRightAlignedPunctuation(content)+ || isCjkCenterAlignedPunctuation(content);+}++export function baseAdjustability(content: string, width: number): IAdjustability {+ if (isSpace(content)) {+ return {+ // The number for spaces is from Knuth-Plass' paper+ stretchability: [0, width / 2.0],+ shrinkability: [0, width / 3.0],+ };+ } else if (isCjkLeftAlignedPunctuation(content)) {+ return {+ stretchability: [0, 0],+ shrinkability: [0, width / 2.0],+ };+ } else if (isCjkRightAlignedPunctuation(content)) {+ return {+ stretchability: [0, 0],+ shrinkability: [width / 2.0, 0],+ };+ } else if (isCjkCenterAlignedPunctuation(content)) {+ return {+ stretchability: [0, 0],+ shrinkability: [width / 4.0, width / 4.0],+ };+ } else {+ return {+ stretchability: [0, 0],+ shrinkability: [0, 0],+ };+ }+}++export function createSkeletonWordGlyph(content: string,config: IFontCreateConfig,- spanWidth?: number-): IDocumentSkeletonSpan {- return _createSkeletonWordOrLetter(SpanType.WORD, content, config, spanWidth);+ glyphWidth?: number+): IDocumentSkeletonGlyph {+ return _createSkeletonWordOrLetter(GlyphType.WORD, content, config, glyphWidth);}-export function createSkeletonLetterSpan(+export function createSkeletonLetterGlyph(content: string,config: IFontCreateConfig,- spanWidth?: number-): IDocumentSkeletonSpan {- return _createSkeletonWordOrLetter(SpanType.LETTER, content, config, spanWidth);+ glyphWidth?: number+): IDocumentSkeletonGlyph {+ return _createSkeletonWordOrLetter(GlyphType.LETTER, content, config, glyphWidth);}-export function createSkeletonTabSpan(config: IFontCreateConfig, spanWidth?: number): IDocumentSkeletonSpan {- return _createSkeletonWordOrLetter(SpanType.TAB, DT.TAB, config, spanWidth);+export function createSkeletonTabGlyph(config: IFontCreateConfig, glyphWidth?: number): IDocumentSkeletonGlyph {+ return _createSkeletonWordOrLetter(GlyphType.TAB, DT.TAB, config, glyphWidth);}export function _createSkeletonWordOrLetter(- spanType: SpanType,+ glyphType: GlyphType,content: string,config: IFontCreateConfig,- spanWidth?: number-): IDocumentSkeletonSpan {+ glyphWidth?: number+): IDocumentSkeletonGlyph {const { fontStyle, textStyle, charSpace = 1, gridType = GridType.LINES, snapToGrid = BooleanNumber.FALSE } = config;const skipWidthList: string[] = [DT.SECTION_BREAK,@@ -92,7 +140,9 @@ export function _createSkeletonWordOrLetter(},paddingLeft: 0,left: 0,- spanType: SpanType.PLACEHOLDER,+ isJustifiable: false,+ adjustability: baseAdjustability(content, 0),+ glyphType: GlyphType.PLACEHOLDER,streamType: content as DT,count: 1,};@@ -104,7 +154,7 @@ export function _createSkeletonWordOrLetter(const bBox = FontCache.getTextSize(content, fontStyle);const { width: contentWidth = 0 } = bBox;- let width = spanWidth ?? contentWidth;+ let width = glyphWidth ?? contentWidth;let paddingLeft = 0;if (validationGrid(gridType, snapToGrid)) {@@ -124,17 +174,19 @@ export function _createSkeletonWordOrLetter(bBox,paddingLeft,left: 0,- spanType,+ glyphType,streamType,+ isJustifiable: isJustifiable(content),+ adjustability: baseAdjustability(content, width),count: content.length,};}-export function createSkeletonBulletSpan(- span: IDocumentSkeletonSpan,+export function createSkeletonBulletGlyph(+ glyph: IDocumentSkeletonGlyph,bulletSkeleton: IDocumentSkeletonBullet,charSpaceApply: number-): IDocumentSkeletonSpan {+): IDocumentSkeletonGlyph {const {bBox: boundingBox,symbol: content,@@ -162,7 +214,7 @@ export function createSkeletonBulletSpan(}}- const bBox = _getMaxBoundingBox(span, bulletSkeleton);+ const bBox = _getMaxBoundingBox(glyph, bulletSkeleton);return {content,@@ -172,79 +224,82 @@ export function createSkeletonBulletSpan(paddingLeft: 0,bBox,left,- spanType: SpanType.LIST,+ isJustifiable: isJustifiable(content),+ adjustability: baseAdjustability(content, width),+ glyphType: GlyphType.LIST,streamType: DT.LETTER,// Deliberately set to 0 so that there is no need to count when calculating the cursor.count: 0,};}-// Set the left value of the current span based on the width of pre span and the left value of the previous span.-export function setSpanGroupLeft(spanGroup: IDocumentSkeletonSpan[], left: number = 0) {- const spanGroupLen = spanGroup.length;- let preSpan;+// Set the left value of the current glyph based on the width of pre glyph and the left value of the previous glyph.+export function setGlyphGroupLeft(glyphGroup: IDocumentSkeletonGlyph[], left: number = 0) {+ const spanGroupLen = glyphGroup.length;+ let preGlyph;for (let i = 0; i < spanGroupLen; i++) {- const span = spanGroup[i];- span.left = preSpan ? preSpan.left + preSpan.width : left;+ const glyph = glyphGroup[i];+ glyph.left = preGlyph ? preGlyph.left + preGlyph.width : left;- preSpan = span;+ preGlyph = glyph;}}-export function setSpanLeft(span: IDocumentSkeletonSpan, left: number = 0) {- span.left = left;+export function setGlyphLeft(glyph: IDocumentSkeletonGlyph, left: number = 0) {+ glyph.left = left;}-export function addSpanToDivide(+export function addGlyphToDivide(divide: IDocumentSkeletonDivide,- spanGroup: IDocumentSkeletonSpan[],+ glyphGroup: IDocumentSkeletonGlyph[],offsetLeft: number = 0) {// const line = divide.parent;// if (line != null) {- // const isFirstLine = line.divides[0].spanGroup[0] == null;- // const firstSpan = spanGroup[0];+ // const isFirstLine = line.divides[0].glyphGroup[0] == null;+ // const firstSpan = glyphGroup[0];// const firstSpanContent = firstSpan.content || ' ';// if (isFirstLine && firstSpanContent === ' ') {// const width = firstSpan.width;// firstSpan.width = 0;- // for (const span of spanGroup) {- // if (span === firstSpan) {+ // for (const glyph of glyphGroup) {+ // if (glyph === firstSpan) {// continue;// }- // span.left -= width;+ // glyph.left -= width;// }// }// }- setSpanGroupLeft(spanGroup, offsetLeft);+ setGlyphGroupLeft(glyphGroup, offsetLeft);- // Set span parent pointer.- for (const span of spanGroup) {- span.parent = divide;+ // Set glyph parent pointer.+ for (const glyph of glyphGroup) {+ glyph.parent = divide;}- divide.spanGroup.push(...spanGroup);+ divide.glyphGroup.push(...glyphGroup);}-function _getMaxBoundingBox(span: IDocumentSkeletonSpan, bulletSkeleton: IDocumentSkeletonBullet) {- const { ba: spanAscent, bd: spanDescent } = span.bBox;+function _getMaxBoundingBox(glyph: IDocumentSkeletonGlyph, bulletSkeleton: IDocumentSkeletonBullet) {+ const { ba: spanAscent, bd: spanDescent } = glyph.bBox;const { ba: bulletAscent, bd: bulletDescent } = bulletSkeleton.bBox;if (spanAscent + spanDescent > bulletAscent + bulletDescent) {- return span.bBox;+ return glyph.bBox;}+return bulletSkeleton.bBox;}-export function hasMixedTextLayout(preSpan: Nullable<IDocumentSkeletonSpan>, span: IDocumentSkeletonSpan) {- if (preSpan == null) {+export function hasMixedTextLayout(preGlyph: Nullable<IDocumentSkeletonGlyph>, glyph: IDocumentSkeletonGlyph) {+ if (preGlyph == null) {return false;}- const { content: preContent } = preSpan;- const { content: curContent } = span;+ const { content: preContent } = preGlyph;+ const { content: curContent } = glyph;if (preContent == null || curContent == null) {return false;diff --git a/packages/engine-render/src/components/docs/layout/model/line.ts b/packages/engine-render/src/components/docs/layout/model/line.tsindex 48c26aa530..6904d0cc17 100644--- a/packages/engine-render/src/components/docs/layout/model/line.ts+++ b/packages/engine-render/src/components/docs/layout/model/line.ts@@ -449,7 +449,7 @@ function _calculateDivideByDrawings(columnWidth: number, drawingSplit: IDrawingsfunction __getDivideSKe(left: number, width: number): IDocumentSkeletonDivide {return {// divide 分割,为了适配插入对象、图片、表格等,图文混排- spanGroup: [], // spanGroup+ glyphGroup: [], // glyphGroupwidth, // width 被分割后的总宽度left, // left 被对象分割后的偏移位置 | d1 | | d2 |paddingLeft: 0, // paddingLeft 根据horizonAlign和width计算对齐偏移@@ -464,10 +464,10 @@ function _getLineSke(lineType: LineType, paragraphIndex: number): IDocumentSkeleparagraphIndex,type: lineType,divides: [], // /divides 受到对象影响,把行切分为 N 部分- lineHeight: 0, // lineHeight =max(span.fontBoundingBoxAscent + span.fontBoundingBoxDescent, span2.....) + space- contentHeight: 0, // contentHeight =max(span.fontBoundingBoxAscent + span.fontBoundingBoxDescent, span2.....)+ lineHeight: 0, // lineHeight =max(glyph.fontBoundingBoxAscent + glyph.fontBoundingBoxDescent, span2.....) + space+ contentHeight: 0, // contentHeight =max(glyph.fontBoundingBoxAscent + glyph.fontBoundingBoxDescent, span2.....)top: 0, // top paragraph(spaceAbove, spaceBelow, lineSpacing*PreLineHeight)- asc: 0, // =max(span.textMetrics.asc) alphaBeta对齐,需要校准+ asc: 0, // =max(glyph.textMetrics.asc) alphaBeta对齐,需要校准paddingTop: 0, // paddingTop 内容到顶部的距离paddingBottom: 0, // paddingBottom 内容到底部的距离marginTop: 0, // marginTop 针对段落的spaceAbovediff --git a/packages/engine-render/src/components/docs/layout/tools.ts b/packages/engine-render/src/components/docs/layout/tools.tsindex 9eb385361a..75e1032a81 100644--- a/packages/engine-render/src/components/docs/layout/tools.ts+++ b/packages/engine-render/src/components/docs/layout/tools.ts@@ -38,11 +38,11 @@ import { DEFAULT_DOCUMENT_FONTSIZE } from '../../../basics/const';import type {IDocumentSkeletonColumn,IDocumentSkeletonDivide,+ IDocumentSkeletonGlyph,IDocumentSkeletonLine,IDocumentSkeletonPage,- IDocumentSkeletonSpan,} from '../../../basics/i-document-skeleton-cached';-import { SpanType } from '../../../basics/i-document-skeleton-cached';+import { GlyphType } from '../../../basics/i-document-skeleton-cached';import type { IParagraphConfig, ISectionBreakConfig } from '../../../basics/interfaces';import { getFontStyleString, isFunction } from '../../../basics/tools';import type { DataStreamTreeNode } from '../view-model/data-stream-tree-node';@@ -140,18 +140,18 @@ export function getLastRemainingDivide(curLine: IDocumentSkeletonLine) {for (let i = 0; i < curLine.divides.length; i++) {const curDivide = curLine.divides[i];const nextDivide = curLine.divides[i + 1];- if (curDivide.spanGroup.length === 0) {+ if (curDivide.glyphGroup.length === 0) {return curDivide;}- if (!nextDivide || nextDivide.spanGroup.length === 0) {+ if (!nextDivide || nextDivide.glyphGroup.length === 0) {return curDivide;}}}export function getLastSpan(page: IDocumentSkeletonPage) {- const spanGroup = getLastNotFullDivideInfo(page)?.divide.spanGroup;- return spanGroup?.[spanGroup.length - 1];+ const glyphGroup = getLastNotFullDivideInfo(page)?.divide.glyphGroup;+ return glyphGroup?.[glyphGroup.length - 1];}export function isColumnFull(page: IDocumentSkeletonPage) {@@ -203,14 +203,14 @@ function isLineBlank(line?: IDocumentSkeletonLine) {}for (let i = 0; i < line.divides.length; i++) {- const spanCount = line.divides[i].spanGroup.length;+ const spanCount = line.divides[i].glyphGroup.length;if (spanCount > 1) {return false;}if (spanCount === 1) {- const lastSpan = line.divides[i].spanGroup[0];- const { spanType } = lastSpan;- if (spanType !== SpanType.TAB && spanType !== SpanType.LIST) {+ const lastSpan = line.divides[i].glyphGroup[0];+ const { glyphType } = lastSpan;+ if (glyphType !== GlyphType.TAB && glyphType !== GlyphType.LIST) {return false;}}@@ -328,24 +328,24 @@ export function updateBlockIndex(pages: IDocumentSkeletonPage[], start: number =for (let i = 0; i < divideLength; i++) {const divide = divides[i];- const { spanGroup } = divide;+ const { glyphGroup } = divide;const divStartIndex = preDivideStartIndex;let divEndIndex = divStartIndex;- for (const span of spanGroup) {- const increaseValue = span.spanType === SpanType.LIST ? 0 : span.count;+ for (const glyph of glyphGroup) {+ const increaseValue = glyph.glyphType === GlyphType.LIST ? 0 : glyph.count;divEndIndex += increaseValue;- const bBox = span.bBox;+ const bBox = glyph.bBox;const { ba } = bBox;maxLineAsc = Math.max(maxLineAsc, ba);if (i === divideLength - 1) {// When the width is set to Infinity, the last divide should also be Infinity, and an actual width needs to be calculated.- actualWidth += span.width;+ actualWidth += glyph.width;}}@@ -358,7 +358,7 @@ export function updateBlockIndex(pages: IDocumentSkeletonPage[], start: number =actualWidth += divide.left;}- if (spanGroup.length === 0) {+ if (glyphGroup.length === 0) {continue;}@@ -408,7 +408,7 @@ export function updateBlockIndex(pages: IDocumentSkeletonPage[], start: number =}}-export function spanIterator(pages: IDocumentSkeletonPage[], iteratorFunction: (span: IDocumentSkeletonSpan) => void) {+export function spanIterator(pages: IDocumentSkeletonPage[], iteratorFunction: (glyph: IDocumentSkeletonGlyph) => void) {for (const page of pages) {const { sections } = page;@@ -423,11 +423,11 @@ export function spanIterator(pages: IDocumentSkeletonPage[], iteratorFunction: (const divideLength = divides.length;for (let i = 0; i < divideLength; i++) {const divide = divides[i];- const { spanGroup } = divide;+ const { glyphGroup } = divide;- for (const span of spanGroup) {+ for (const glyph of glyphGroup) {if (iteratorFunction && isFunction(iteratorFunction)) {- iteratorFunction(span);+ iteratorFunction(glyph);}}}@@ -651,16 +651,12 @@ export function getPositionVertical(}}-// export function getPositionHorizonBySpan(positionH: ObjectPositionH, span: IDocumentSkeletonSpan) {-// const { relativeFrom, align, posOffset, percent } = positionH;-// }-export function getSpanGroupWidth(divide: IDocumentSkeletonDivide) {- const spanGroup = divide.spanGroup;+ const glyphGroup = divide.glyphGroup;let width = 0;- for (const span of spanGroup) {- width += span.width;+ for (const glyph of glyphGroup) {+ width += glyph.width;}return width;diff --git a/packages/engine-render/src/components/docs/liquid.ts b/packages/engine-render/src/components/docs/liquid.tsindex 90a172accc..9130cf7b58 100644--- a/packages/engine-render/src/components/docs/liquid.ts+++ b/packages/engine-render/src/components/docs/liquid.ts@@ -17,10 +17,10 @@import type {IDocumentSkeletonColumn,IDocumentSkeletonDivide,+ IDocumentSkeletonGlyph,IDocumentSkeletonLine,IDocumentSkeletonPage,IDocumentSkeletonSection,- IDocumentSkeletonSpan,} from '../../basics/i-document-skeleton-cached';import { PageLayoutType } from '../../basics/i-document-skeleton-cached';@@ -100,9 +100,9 @@ export class Liquid {translatePagePadding(page: IDocumentSkeletonPage) {const {marginTop: pagePaddingTop = 0,- marginBottom: pagePaddingBottom = 0,+ marginBottom: _pagePaddingBottom = 0,marginLeft: pagePaddingLeft = 0,- marginRight: pagePaddingRight = 0,+ marginRight: _pagePaddingRight = 0,} = page;this.translate(pagePaddingLeft, pagePaddingTop);@@ -111,9 +111,9 @@ export class Liquid {restorePagePadding(page: IDocumentSkeletonPage) {const {marginTop: pagePaddingTop = 0,- marginBottom: pagePaddingBottom = 0,+ marginBottom: _pagePaddingBottom = 0,marginLeft: pagePaddingLeft = 0,- marginRight: pagePaddingRight = 0,+ marginRight: _pagePaddingRight = 0,} = page;this.translate(-pagePaddingLeft, -pagePaddingTop);@@ -124,8 +124,8 @@ export class Liquid {type = PageLayoutType.VERTICAL,left = 0,top = 0,- right = 0,- bottom = 0+ _right = 0,+ _bottom = 0) {const {// sections,@@ -182,10 +182,10 @@ export class Liquid {translateLine(line: IDocumentSkeletonLine, isDraw = false) {const {top: lineTop,- marginBottom: lineMarginBottom = 0,+ marginBottom: _lineMarginBottom = 0,marginTop: lineMarginTop = 0,paddingTop: linePaddingTop = 0,- paddingBottom: linePaddingBottom = 0,+ paddingBottom: _linePaddingBottom = 0,} = line;const lineOffset = lineTop + (isDraw === true ? lineMarginTop : 0) + linePaddingTop;this.translate(0, lineOffset);@@ -206,8 +206,8 @@ export class Liquid {};}- translateSpan(span: IDocumentSkeletonSpan) {- const { left: spanLeft } = span;+ translateSpan(glyph: IDocumentSkeletonGlyph) {+ const { left: spanLeft } = glyph;this.translate(spanLeft, 0);return {diff --git a/packages/engine-render/src/components/docs/text-selection/convert-cursor.ts b/packages/engine-render/src/components/docs/text-selection/convert-cursor.tsindex 4196ff786c..ef1ee8be6f 100644--- a/packages/engine-render/src/components/docs/text-selection/convert-cursor.ts+++ b/packages/engine-render/src/components/docs/text-selection/convert-cursor.ts@@ -19,12 +19,12 @@ import type { IPosition, ITextRange, Nullable } from '@univerjs/core';import type {IDocumentSkeletonColumn,IDocumentSkeletonDivide,+ IDocumentSkeletonGlyph,IDocumentSkeletonLine,IDocumentSkeletonPage,IDocumentSkeletonSection,- IDocumentSkeletonSpan,} from '../../../basics/i-document-skeleton-cached';-import { SpanType } from '../../../basics/i-document-skeleton-cached';+import { GlyphType } from '../../../basics/i-document-skeleton-cached';import type { INodePosition } from '../../../basics/interfaces';import type { IPoint } from '../../../basics/vector2';import type { DocumentSkeleton } from '../layout/doc-skeleton';@@ -43,7 +43,7 @@ export enum NodePositionType {column,line,divide,- span,+ glyph,}export interface ICurrentNodePositionState {@@ -52,7 +52,7 @@ export interface ICurrentNodePositionState {column: NodePositionStateType;line: NodePositionStateType;divide: NodePositionStateType;- span: NodePositionStateType;+ glyph: NodePositionStateType;}export const NodePositionMap = {@@ -61,7 +61,7 @@ export const NodePositionMap = {column: 2,line: 3,divide: 4,- span: 5,+ glyph: 5,};export function compareNodePositionLogic(pos1: INodePosition, pos2: INodePosition) {@@ -105,11 +105,11 @@ export function compareNodePositionLogic(pos1: INodePosition, pos2: INodePositioreturn true;}- if (pos1.span > pos2.span) {+ if (pos1.glyph > pos2.glyph) {return false;}- if (pos1.span < pos2.span) {+ if (pos1.glyph < pos2.glyph) {return true;}@@ -152,7 +152,7 @@ export function getOneTextSelectionRange(rangeList: ITextRange[]): Nullable<ITex}function getOffsetInDivide(- spanGroup: IDocumentSkeletonSpan[],+ glyphGroup: IDocumentSkeletonGlyph[],startSpanIndex: number,endSpanIndex: number,st: number@@ -160,8 +160,8 @@ function getOffsetInDivide(let startOffset = st;let endOffset = st;- for (let i = 0; i < spanGroup.length; i++) {- const span = spanGroup[i];+ for (let i = 0; i < glyphGroup.length; i++) {+ const span = glyphGroup[i];const contentLength = span.count;if (i < startSpanIndex) {@@ -188,7 +188,7 @@ export class NodePositionConvertToCursor {column: NodePositionStateType.NORMAL,line: NodePositionStateType.NORMAL,divide: NodePositionStateType.NORMAL,- span: NodePositionStateType.NORMAL,+ glyph: NodePositionStateType.NORMAL,};private _currentEndState: ICurrentNodePositionState = {@@ -197,7 +197,7 @@ export class NodePositionConvertToCursor {column: NodePositionStateType.NORMAL,line: NodePositionStateType.NORMAL,divide: NodePositionStateType.NORMAL,- span: NodePositionStateType.NORMAL,+ glyph: NodePositionStateType.NORMAL,};constructor(@@ -224,15 +224,15 @@ export class NodePositionConvertToCursor {this._selectionIterator(start, end, (start_sp, end_sp, isFirst, isLast, divide, line) => {const { lineHeight, marginTop, contentHeight } = line;- const { spanGroup, st } = divide;+ const { glyphGroup, st } = divide;const { x: startX, y: startY } = this._liquid;let borderBoxPosition: IPosition;let contentBoxPosition: IPosition;- const firstSpan = spanGroup[start_sp];- const lastSpan = spanGroup[end_sp];+ const firstSpan = glyphGroup[start_sp];+ const lastSpan = glyphGroup[end_sp];const firstSpanLeft = firstSpan?.left || 0;const firstSpanWidth = firstSpan?.width || 0;@@ -240,17 +240,17 @@ export class NodePositionConvertToCursor {const lastSpanLeft = lastSpan?.left || 0;const lastSpanWidth = lastSpan?.width || 0;- const isCurrentList = firstSpan?.spanType === SpanType.LIST;+ const isCurrentList = firstSpan?.glyphType === GlyphType.LIST;- const { startOffset, endOffset } = getOffsetInDivide(spanGroup, start_sp, end_sp, st);+ const { startOffset, endOffset } = getOffsetInDivide(glyphGroup, start_sp, end_sp, st);- const isStartBack = start.span === start_sp && isFirst ? start.isBack : true;+ const isStartBack = start.glyph === start_sp && isFirst ? start.isBack : true;- const isEndBack = end.span === end_sp && isLast ? end.isBack : false;+ const isEndBack = end.glyph === end_sp && isLast ? end.isBack : false;const collapsed = start === end;- if (start_sp === 0 && end_sp === spanGroup.length - 1) {+ if (start_sp === 0 && end_sp === glyphGroup.length - 1) {borderBoxPosition = {startX: startX + firstSpanLeft + (isCurrentList ? firstSpanWidth : 0),startY,@@ -306,7 +306,7 @@ export class NodePositionConvertToCursor {column: NodePositionStateType.NORMAL,line: NodePositionStateType.NORMAL,divide: NodePositionStateType.NORMAL,- span: NodePositionStateType.NORMAL,+ glyph: NodePositionStateType.NORMAL,};this._currentEndState = {@@ -315,7 +315,7 @@ export class NodePositionConvertToCursor {column: NodePositionStateType.NORMAL,line: NodePositionStateType.NORMAL,divide: NodePositionStateType.NORMAL,- span: NodePositionStateType.NORMAL,+ glyph: NodePositionStateType.NORMAL,};}@@ -544,13 +544,13 @@ export class NodePositionConvertToCursor {this._liquid.translateSave();this._liquid.translateDivide(divide);- const spanGroup = divide.spanGroup;+ const glyphGroup = divide.glyphGroup;const { start_next: start_sp, end_next: end_sp } = this._getSelectionRuler(NodePositionMap.divide,startPosition,endPosition,- spanGroup.length - 1,+ glyphGroup.length - 1,d);diff --git a/packages/engine-render/src/components/docs/text-selection/text-selection-render-manager.ts b/packages/engine-render/src/components/docs/text-selection/text-selection-render-manager.tsindex 018cd9a41d..4858eb4c70 100644--- a/packages/engine-render/src/components/docs/text-selection/text-selection-render-manager.ts+++ b/packages/engine-render/src/components/docs/text-selection/text-selection-render-manager.ts@@ -21,7 +21,7 @@ import type { Observable } from 'rxjs';import { BehaviorSubject, fromEvent, Subject } from 'rxjs';import { CURSOR_TYPE } from '../../../basics/const';-import type { IDocumentSkeletonSpan } from '../../../basics/i-document-skeleton-cached';+import type { IDocumentSkeletonGlyph } from '../../../basics/i-document-skeleton-cached';import { PageLayoutType } from '../../../basics/i-document-skeleton-cached';import type { IMouseEvent, IPointerEvent } from '../../../basics/i-events';import type { INodeInfo, INodePosition } from '../../../basics/interfaces';@@ -61,7 +61,7 @@ export function getCanvasOffsetByEngine(engine: Nullable<Engine>) {};}-function getParagraphInfoBySpan(node: IDocumentSkeletonSpan) {+function getParagraphInfoBySpan(node: IDocumentSkeletonGlyph) {const line = node.parent?.parent;const column = line?.parent;@@ -77,15 +77,15 @@ function getParagraphInfoBySpan(node: IDocumentSkeletonSpan) {for (const line of lines) {for (const divide of line.divides) {- for (const span of divide.spanGroup) {+ for (const glyph of divide.glyphGroup) {if (!hasFound) {- nodeIndex += span.count;+ nodeIndex += glyph.count;}- if (span === node) {+ if (glyph === node) {hasFound = true;}- content += span.count > 0 ? span.content : '';+ content += glyph.count > 0 ? glyph.content : '';}}}@@ -679,9 +679,9 @@ export class TextSelectionRenderManager extends RxDisposable implements ITextSelreturn;}- const { node: span, ratioX } = node;+ const { node: glyph, ratioX } = node;- const position = this._docSkeleton?.findPositionBySpan(span);+ const position = this._docSkeleton?.findPositionByGlyph(glyph);if (position == null) {return;