Skip to content

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.

fix(docs): support special emoticons (#3512)

Ran Luo61ee1cdcef8c
diff --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.ts
index 7dd88805d4..74a1979259 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
@@ -16,10 +16,10 @@
import type { IParagraph } from '@univerjs/core';
-import type { ISectionBreakConfig } from '../../../../../basics/interfaces';
import { EMOJI_REG, hasArabic, hasSpace, hasTibetan, startWithEmoji } from '../../../../../basics/tools';
import { createSkeletonLetterGlyph, createSkeletonWordGlyph } from '../../model/glyph';
import { getFontCreateConfig } from '../../tools';
+import type { ISectionBreakConfig } from '../../../../../basics/interfaces';
import type { DataStreamTreeNode } from '../../../view-model/data-stream-tree-node';
import type { DocumentViewModel } from '../../../view-model/document-view-model';
@@ -35,19 +35,27 @@ export function otherHandler(
) {
const glyphGroup = [];
let step = 0;
+ let src = charArray;
- for (let i = 0; i < charArray.length; i++) {
- const newChar = charArray[i];
+ while (src.length) {
+ const char = src.match(/^[\s\S]/gu)?.[0];
- if (hasSpace(newChar) || startWithEmoji(charArray.substring(i))) {
+ if (char == null) {
break;
}
- const config = getFontCreateConfig(index + i, viewModel, paragraphNode, sectionBreakConfig, paragraph);
- const glyph = createSkeletonLetterGlyph(newChar, config);
+ if (hasSpace(char) || startWithEmoji(charArray.substring(step))) {
+ break;
+ }
+
+ const config = getFontCreateConfig(index + step, viewModel, paragraphNode, sectionBreakConfig, paragraph);
+ const glyph = createSkeletonLetterGlyph(char, config);
glyphGroup.push(glyph);
- step++;
+
+ src = src.substring(char.length);
+
+ step += char.length;
}
return {
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.ts
index 200f10a22a..213fb87006 100644
--- a/packages/engine-render/src/components/docs/layout/block/paragraph/linebreaking.ts
+++ b/packages/engine-render/src/components/docs/layout/block/paragraph/linebreaking.ts
@@ -14,20 +14,20 @@
* limitations under the License.
*/
-import type { IBullet, IDocDrawingBase, IDrawings, Nullable } from '@univerjs/core';
import { DataStreamTreeTokenType, PositionedObjectLayoutType, Tools } from '@univerjs/core';
+import type { IBullet, IDocDrawingBase, IDrawings, Nullable } from '@univerjs/core';
import { BreakType } from '../../../../../basics/i-document-skeleton-cached';
-import type { IDocumentSkeletonBullet, IDocumentSkeletonDrawing, IDocumentSkeletonPage, IDocumentSkeletonTable } from '../../../../../basics/i-document-skeleton-cached';
import { createSkeletonPage } from '../../model/page';
import { setColumnFullState } from '../../model/section';
-import type { ILayoutContext } from '../../tools';
import { getLastNotFullColumnInfo } from '../../tools';
-import type { DataStreamTreeNode } from '../../../view-model/data-stream-tree-node';
+import { dealWithBullet } from './bullet';
+import { layoutParagraph } from './layout-ruler';
+import type { IDocumentSkeletonBullet, IDocumentSkeletonDrawing, IDocumentSkeletonPage, IDocumentSkeletonTable } from '../../../../../basics/i-document-skeleton-cached';
import type { IParagraphConfig, ISectionBreakConfig } from '../../../../../basics/interfaces';
+import type { DataStreamTreeNode } from '../../../view-model/data-stream-tree-node';
import type { DocumentViewModel } from '../../../view-model/document-view-model';
+import type { ILayoutContext } from '../../tools';
import type { IShapedText } from './shaping';
-import { layoutParagraph } from './layout-ruler';
-import { dealWithBullet } from './bullet';
function _getListLevelAncestors(
bullet?: IBullet,
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.ts
index cf94d1a22c..9656503f17 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
@@ -14,29 +14,29 @@
* limitations under the License.
*/
-import type { IParagraphStyle, Nullable } from '@univerjs/core';
import { BooleanNumber, DataStreamTreeTokenType, GridType, PositionedObjectLayoutType } from '@univerjs/core';
-import type { IDocumentSkeletonGlyph } from '../../../../../basics/i-document-skeleton-cached';
+import type { IParagraphStyle, Nullable } from '@univerjs/core';
+import { hasArabic, hasCJK, hasCJKPunctuation, hasCJKText, hasTibetan, startWithEmoji } from '../../../../../basics/tools';
+import { Lang } from '../../hyphenation/lang';
import { LineBreaker } from '../../line-breaker';
+import { BreakPointType } from '../../line-breaker/break';
+import { LineBreakerHyphenEnhancer } from '../../line-breaker/enhancers/hyphen-enhancer';
+import { LineBreakerLinkEnhancer } from '../../line-breaker/enhancers/link-enhancer';
+import { customBlockLineBreakExtension } from '../../line-breaker/extensions/custom-block-linebreak-extension';
import { tabLineBreakExtension } from '../../line-breaker/extensions/tab-linebreak-extension';
import { createSkeletonCustomBlockGlyph, createSkeletonLetterGlyph, createSkeletonTabGlyph, glyphShrinkLeft, glyphShrinkRight } from '../../model/glyph';
-import type { ILayoutContext } from '../../tools';
+import { getBoundingBox } from '../../model/line';
+import { fontLibrary } from '../../shaping-engine/font-library';
+import { textShape } from '../../shaping-engine/text-shaping';
+import { prepareParagraphBody } from '../../shaping-engine/utils';
import { getCharSpaceApply, getFontCreateConfig } from '../../tools';
+import { ArabicHandler, emojiHandler, otherHandler, TibetanHandler } from './language-ruler';
+import type { IDocumentSkeletonGlyph } from '../../../../../basics/i-document-skeleton-cached';
+import type { ISectionBreakConfig } from '../../../../../basics/interfaces';
import type { DataStreamTreeNode } from '../../../view-model/data-stream-tree-node';
import type { DocumentViewModel } from '../../../view-model/document-view-model';
-import type { ISectionBreakConfig } from '../../../../../basics/interfaces';
-import { hasArabic, hasCJK, hasCJKPunctuation, hasCJKText, hasTibetan, startWithEmoji } from '../../../../../basics/tools';
import type { IOpenTypeGlyphInfo } from '../../shaping-engine/text-shaping';
-import { textShape } from '../../shaping-engine/text-shaping';
-import { fontLibrary } from '../../shaping-engine/font-library';
-import { prepareParagraphBody } from '../../shaping-engine/utils';
-import { LineBreakerHyphenEnhancer } from '../../line-breaker/enhancers/hyphen-enhancer';
-import { Lang } from '../../hyphenation/lang';
-import { BreakPointType } from '../../line-breaker/break';
-import { getBoundingBox } from '../../model/line';
-import { customBlockLineBreakExtension } from '../../line-breaker/extensions/custom-block-linebreak-extension';
-import { LineBreakerLinkEnhancer } from '../../line-breaker/enhancers/link-enhancer';
-import { ArabicHandler, emojiHandler, otherHandler, TibetanHandler } from './language-ruler';
+import type { ILayoutContext } from '../../tools';
// Now we apply consecutive punctuation adjustment, specified in Chinese Layout
// Requirements, section 3.1.6.1 Punctuation Adjustment Space, and Japanese Layout
@@ -292,7 +292,6 @@ export function shaping(
src = src.substring(step);
} else {
- // TODO: 处理一个单词超过 page width 情况
const { step, glyphGroup } = otherHandler(
i,
src,