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.

feat(doc): refactor of text shaping and support kerning (#1785)

Ran Luoe7f103622f6c
diff --git a/.vscode/settings.json b/.vscode/settings.json
index 9131ba7442..1ca5f45911 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -23,12 +23,14 @@
"customd",
"Datas",
"DATEFMTLISG",
+ "demi",
"dppx",
"Dushusir",
"endindex",
"esbuild",
"evented",
"execa",
+ "EXTRALIGHT",
"FONTFACE",
"fract",
"gainsboro",
@@ -53,6 +55,8 @@
"kcode",
"keyof",
"Lerp",
+ "letterform",
+ "liga",
"linebreak",
"linebreaker",
"linebreaking",
@@ -64,6 +68,8 @@
"mengshukeji",
"Neue",
"numfmt",
+ "opencollective",
+ "opentype",
"Overlines",
"Pacifico",
"Plass",
diff --git a/examples/src/data/docs/default-document.data-simple.ts b/examples/src/data/docs/default-document.data-simple.ts
index a3cb23de78..4f7e0202be 100644
--- a/examples/src/data/docs/default-document.data-simple.ts
+++ b/examples/src/data/docs/default-document.data-simple.ts
@@ -20,7 +20,7 @@ import { BooleanNumber } from '@univerjs/core';
export const DEFAULT_DOCUMENT_DATA_SIMPLE: IDocumentData = {
id: 'default-document-id',
body: {
- dataStream: '荷塘月色\r作者:朱自清\r\n',
+ dataStream: '荷塘𠮷\r作者:朱自清 👨‍👩‍👧‍👦 Today Office\r\n',
textRuns: [
{
st: 0,
@@ -36,10 +36,10 @@ export const DEFAULT_DOCUMENT_DATA_SIMPLE: IDocumentData = {
},
{
st: 5,
- ed: 11,
+ ed: 36,
ts: {
fs: 18,
- ff: 'Microsoft YaHei',
+ ff: 'Times New Roman',
cl: {
rgb: 'rgb(30, 30, 30)',
},
@@ -57,7 +57,7 @@ export const DEFAULT_DOCUMENT_DATA_SIMPLE: IDocumentData = {
},
},
{
- startIndex: 11,
+ startIndex: 36,
paragraphStyle: {
spaceAbove: 10,
lineSpacing: 2,
@@ -67,7 +67,7 @@ export const DEFAULT_DOCUMENT_DATA_SIMPLE: IDocumentData = {
],
sectionBreaks: [
{
- startIndex: 12,
+ startIndex: 37,
// columnProperties: [
// {
// width: 250,
diff --git a/examples/src/docs/main.ts b/examples/src/docs/main.ts
index 786c657e2e..6556c32a0d 100644
--- a/examples/src/docs/main.ts
+++ b/examples/src/docs/main.ts
@@ -23,8 +23,11 @@ import { UniverRenderEnginePlugin } from '@univerjs/engine-render';
import { UniverUIPlugin } from '@univerjs/ui';
import { UniverFormulaEnginePlugin } from '@univerjs/engine-formula';
-import { DEFAULT_DOCUMENT_DATA_CN } from '../data';
+
+import { DEFAULT_DOCUMENT_DATA_SIMPLE } from '../data';
+
import { DebuggerPlugin } from '../plugins/debugger';
+
import { locales } from './locales';
// package info
@@ -61,7 +64,7 @@ univer.registerPlugin(UniverDocsUIPlugin, {
},
});
-univer.createUniverDoc(DEFAULT_DOCUMENT_DATA_CN);
+univer.createUniverDoc(DEFAULT_DOCUMENT_DATA_SIMPLE);
// use for console test
declare global {
diff --git a/packages/engine-render/package.json b/packages/engine-render/package.json
index 0d28c827fe..593cce3204 100644
--- a/packages/engine-render/package.json
+++ b/packages/engine-render/package.json
@@ -69,9 +69,10 @@
},
"dependencies": {
"cjk-regex": "^3.1.0",
- "linebreak": "^1.1.0"
+ "opentype.js": "^1.3.4"
},
"devDependencies": {
+ "@types/opentype.js": "^1.3.8",
"@univerjs/core": "workspace:*",
"@univerjs/shared": "workspace:*",
"@wendellhu/redi": "^0.13.0",
diff --git a/packages/engine-render/src/basics/const.ts b/packages/engine-render/src/basics/const.ts
index 350d2ba654..3275797144 100644
--- a/packages/engine-render/src/basics/const.ts
+++ b/packages/engine-render/src/basics/const.ts
@@ -77,8 +77,6 @@ export const DEFAULT_SKELETON_FOOTER = {
marginBottom: 20,
};
-export const DEFAULT_MEASURE_TEXT = '0';
-
export const DEFAULT_OFFSET_SPACING = 1;
export const DEFAULT_DOCUMENT_FONTSIZE = 14;
diff --git a/packages/engine-render/src/basics/index.ts b/packages/engine-render/src/basics/index.ts
index abc5ef76b7..ebc50be8a1 100644
--- a/packages/engine-render/src/basics/index.ts
+++ b/packages/engine-render/src/basics/index.ts
@@ -18,7 +18,7 @@ export * from './cell-data';
export * from './const';
export * from './document-node-tools';
export * from './draw';
-export * from './font-cache';
+export * from '../components/docs/layout/shaping-engine/font-cache';
export * from './i-document-skeleton-cached';
export * from './i-events';
export * from './interfaces';
diff --git a/packages/engine-render/src/basics/interfaces.ts b/packages/engine-render/src/basics/interfaces.ts
index 7d6d186608..9214adcfdf 100644
--- a/packages/engine-render/src/basics/interfaces.ts
+++ b/packages/engine-render/src/basics/interfaces.ts
@@ -88,14 +88,6 @@ export interface IFontLocale {
defaultFontSize: number;
}
-export interface IMeasureTextCache {
- fontBoundingBoxAscent: number;
- fontBoundingBoxDescent: number;
- actualBoundingBoxAscent: number;
- actualBoundingBoxDescent: number;
- width: number;
-}
-
export interface IDocsConfig extends IReferenceSource, IDocumentLayout {
localeService: LocaleService;
documentTextStyle?: ITextStyle;
diff --git a/packages/engine-render/src/basics/tools.ts b/packages/engine-render/src/basics/tools.ts
index dc8e76ea35..381782fc2f 100644
--- a/packages/engine-render/src/basics/tools.ts
+++ b/packages/engine-render/src/basics/tools.ts
@@ -27,8 +27,8 @@ import type {
import { BaselineOffset, FontStyleType, Tools } from '@univerjs/core';
import * as cjk from 'cjk-regex';
+import { FontCache } from '../components/docs/layout/shaping-engine/font-cache';
import { DEFAULT_FONTFACE_PLANE } from './const';
-import { FontCache } from './font-cache';
import type { IBoundRectNoAngle } from './vector2';
const DEG180 = 180;
diff --git a/packages/engine-render/src/components/docs/layout/block/paragraph/bullet.ts b/packages/engine-render/src/components/docs/layout/block/paragraph/bullet.ts
index 694cc36ae2..b507847363 100644
--- a/packages/engine-render/src/components/docs/layout/block/paragraph/bullet.ts
+++ b/packages/engine-render/src/components/docs/layout/block/paragraph/bullet.ts
@@ -16,7 +16,7 @@
import type { IBullet, ILists, INestingLevel, ITextStyle, LocaleService, Nullable } from '@univerjs/core';
-import { FontCache } from '../../../../../basics/font-cache';
+import { FontCache } from '../../shaping-engine/font-cache';
import type { IDocumentSkeletonBullet } from '../../../../../basics/i-document-skeleton-cached';
import { getFontStyleString } from '../../../../../basics/tools';
import { getBulletOrderedSymbol } from './bullet-ruler';
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 69d9e4fa05..8cfb41f8d4 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
@@ -24,8 +24,8 @@ 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 { layoutParagraph } from './layout-ruler';
import { dealWidthInlineDrawing } from './inline-drawing';
import { dealWithBullet } from './bullet';
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 64c909bd47..bbbe6ef6e4 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
@@ -25,6 +25,10 @@ import type { DataStreamTreeNode } from '../../../view-model/data-stream-tree-no
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 { ArabicHandler, emojiHandler, otherHandler, TibetanHandler } from './language-ruler';
// Now we apply consecutive punctuation adjustment, specified in Chinese Layout
@@ -92,7 +96,8 @@ export function shaping(
bodyModel: DocumentViewModel,
paragraphNode: DataStreamTreeNode,
sectionBreakConfig: ISectionBreakConfig,
- paragraphStyle: IParagraphStyle
+ paragraphStyle: IParagraphStyle,
+ useOpenType = false // Temporarily disable using opentype for shaping.
): IShapedText[] {
const {
gridType = GridType.LINES,
@@ -102,8 +107,20 @@ export function shaping(
const { snapToGrid = BooleanNumber.TRUE } = paragraphStyle;
const shapedTextList: IShapedText[] = [];
const breaker = new LineBreaker(content);
+ const { endIndex } = paragraphNode;
let last = 0;
let bk;
+ let lastGlyphIndex = 0;
+
+ const paragraphBody = prepareParagraphBody(bodyModel.getBody()!, endIndex);
+
+ // const now = +new Date();
+ let glyphInfos: IOpenTypeGlyphInfo[] = [];
+
+ if (useOpenType) {
+ glyphInfos = textShape(paragraphBody);
+ }
+ // console.log('Text Shaping Time:', +new Date() - now);
// Add custom extension for linebreak.
tabLineBreakExtension(breaker);
@@ -112,84 +129,118 @@ export function shaping(
while ((bk = breaker.nextBreak())) {
// get the string between the last break and this one
const word = content.slice(last, bk.position);
- let src = word;
- let i = last;
const shapedGlyphs: IDocumentSkeletonGlyph[] = [];
- while (src.length > 0) {
- const char = src.match(/^[\s\S]/gu)?.[0];
+ if (fontLibrary.isReady && useOpenType) {
+ const glyphInfosInWord = [];
+
+ let i = 0;
+ for (i = lastGlyphIndex; i < glyphInfos.length; i++) {
+ const glyphInfo = glyphInfos[i];
+ const { end } = glyphInfo;
- if (char == null) {
- break;
+ if (end > bk.position) {
+ break;
+ }
+
+ glyphInfosInWord.push(glyphInfo);
}
+ lastGlyphIndex = i;
- if (/\s/.test(char) || hasCJK(char)) {
- const config = getFontCreateConfig(i, bodyModel, paragraphNode, sectionBreakConfig, paragraphStyle);
- let newSpan: IDocumentSkeletonGlyph;
+ for (const glyphInfo of glyphInfosInWord) {
+ const { start, char } = glyphInfo;
+ const config = getFontCreateConfig(start, bodyModel, paragraphNode, sectionBreakConfig, paragraphStyle);
if (char === DataStreamTreeTokenType.TAB) {
const charSpaceApply = getCharSpaceApply(charSpace, defaultTabStop, gridType, snapToGrid);
- newSpan = createSkeletonTabGlyph(config, charSpaceApply);
+ const newSpan = createSkeletonTabGlyph(config, charSpaceApply);
+ shapedGlyphs.push(newSpan);
+ } else if (startWithEmoji(char)) {
+ const newSpan = createSkeletonLetterGlyph(char, config);
+ shapedGlyphs.push(newSpan);
} else {
- newSpan = createSkeletonLetterGlyph(char, config);
+ const newSpan = createSkeletonLetterGlyph(char, config, undefined, glyphInfo);
+ shapedGlyphs.push(newSpan);
+ }
+ }
+ } else {
+ let src = word;
+ let i = last;
+ while (src.length > 0) {
+ const char = src.match(/^[\s\S]/gu)?.[0];
+
+ if (char == null) {
+ break;
}
- shapedGlyphs.push(newSpan);
- i += char.length;
- src = src.substring(char.length);
- } else if (startWithEmoji(src)) {
- const { step, glyphGroup } = emojiHandler(
- i,
- src,
- bodyModel,
- paragraphNode,
- sectionBreakConfig,
- paragraphStyle
- );
- shapedGlyphs.push(...glyphGroup);
- i += step;
-
- src = src.substring(step);
- } else if (hasArabic(char)) {
- const { step, glyphGroup } = ArabicHandler(
- i,
- src,
- bodyModel,
- paragraphNode,
- sectionBreakConfig,
- paragraphStyle
- );
- shapedGlyphs.push(...glyphGroup);
- i += step;
-
- src = src.substring(step);
- } else if (hasTibetan(char)) {
- const { step, glyphGroup } = TibetanHandler(
- i,
- src,
- bodyModel,
- paragraphNode,
- sectionBreakConfig,
- paragraphStyle
- );
- shapedGlyphs.push(...glyphGroup);
- i += step;
-
- src = src.substring(step);
- } else {
- // TODO: 处理一个单词超过 page width 情况
- const { step, glyphGroup } = otherHandler(
- i,
- src,
- bodyModel,
- paragraphNode,
- sectionBreakConfig,
- paragraphStyle
- );
- shapedGlyphs.push(...glyphGroup);
- i += step;
-
- src = src.substring(step);
+ if (/\s/.test(char) || hasCJK(char)) {
+ const config = getFontCreateConfig(i, bodyModel, paragraphNode, sectionBreakConfig, paragraphStyle);
+ let newSpan: IDocumentSkeletonGlyph;
+
+ if (char === DataStreamTreeTokenType.TAB) {
+ const charSpaceApply = getCharSpaceApply(charSpace, defaultTabStop, gridType, snapToGrid);
+ newSpan = createSkeletonTabGlyph(config, charSpaceApply);
+ } else {
+ newSpan = createSkeletonLetterGlyph(char, config);
+ }
+
+ shapedGlyphs.push(newSpan);
+ i += char.length;
+ src = src.substring(char.length);
+ } else if (startWithEmoji(src)) {
+ const { step, glyphGroup } = emojiHandler(
+ i,
+ src,
+ bodyModel,
+ paragraphNode,
+ sectionBreakConfig,
+ paragraphStyle
+ );
+ shapedGlyphs.push(...glyphGroup);
+ i += step;
+
+ src = src.substring(step);
+ } else if (hasArabic(char)) {
+ const { step, glyphGroup } = ArabicHandler(
+ i,
+ src,
+ bodyModel,
+ paragraphNode,
+ sectionBreakConfig,
+ paragraphStyle
+ );
+ shapedGlyphs.push(...glyphGroup);
+ i += step;
+
+ src = src.substring(step);
+ } else if (hasTibetan(char)) {
+ const { step, glyphGroup } = TibetanHandler(
+ i,
+ src,
+ bodyModel,
+ paragraphNode,
+ sectionBreakConfig,
+ paragraphStyle
+ );
+ shapedGlyphs.push(...glyphGroup);
+ i += step;
+
+ src = src.substring(step);
+ } else {
+ // TODO: 处理一个单词超过 page width 情况
+ const { step, glyphGroup } = otherHandler(
+ i,
+ src,
+ bodyModel,
+ paragraphNode,
+ sectionBreakConfig,
+ paragraphStyle
+ );
+ shapedGlyphs.push(...glyphGroup);
+ i += step;
+
+ src = src.substring(step);
+ }
}
}
@@ -206,5 +257,6 @@ export function shaping(
// Add some spacing between Han characters and western characters.
addCJKLatinSpacing(shapedTextList);
+ // console.log(shapedTextList);
return shapedTextList;
}
diff --git a/packages/engine-render/src/components/docs/layout/doc-skeleton.ts b/packages/engine-render/src/components/docs/layout/doc-skeleton.ts
index 477978d110..b4f551d792 100644
--- a/packages/engine-render/src/components/docs/layout/doc-skeleton.ts
+++ b/packages/engine-render/src/components/docs/layout/doc-skeleton.ts
@@ -85,7 +85,9 @@ export class DocumentSkeleton extends Skeleton {
return;
}
+ // const start = +new Date();
this._skeletonData = this._createSkeleton(bounds);
+ // console.log('skeleton calculate cost', +new Date() - start);
}
getSkeletonData() {
diff --git a/packages/engine-render/src/components/docs/layout/linebreak/__tests__/linebreak.spec.ts b/packages/engine-render/src/components/docs/layout/linebreak/__tests__/linebreak.spec.ts
index 51805583c7..0309058241 100644
--- a/packages/engine-render/src/components/docs/layout/linebreak/__tests__/linebreak.spec.ts
+++ b/packages/engine-render/src/components/docs/layout/linebreak/__tests__/linebreak.spec.ts
@@ -15,6 +15,7 @@
*/
import fs from 'node:fs';
+import { resolve } from 'node:path';
import { describe, expect, it } from 'vitest';
import { tabLineBreakExtension } from '../extensions/tab-linebreak-extension';
@@ -29,7 +30,7 @@ describe('unicode line break tests', () => {
7604, 7610, 7611, 7681,
];
- const data = fs.readFileSync(new URL('LineBreakTest.txt', import.meta.url), 'utf8');
+ const data = fs.readFileSync(resolve(__dirname, 'LineBreakTest.txt'), 'utf8');
const lines = data.split('\n');
return lines.forEach((line, i) => {
diff --git a/packages/engine-render/src/components/docs/layout/model/__test__/glyph.spec.ts b/packages/engine-render/src/components/docs/layout/model/__tests__/glyph.spec.ts
similarity index 100%
rename from packages/engine-render/src/components/docs/layout/model/__test__/glyph.spec.ts
rename to packages/engine-render/src/components/docs/layout/model/__tests__/glyph.spec.ts
diff --git a/packages/engine-render/src/components/docs/layout/model/glyph.ts b/packages/engine-render/src/components/docs/layout/model/glyph.ts
index f40b443211..bc837ff656 100644
--- a/packages/engine-render/src/components/docs/layout/model/glyph.ts
+++ b/packages/engine-render/src/components/docs/layout/model/glyph.ts
@@ -16,7 +16,7 @@
import { BooleanNumber, BulletAlignment, DataStreamTreeTokenType as DT, GridType } from '@univerjs/core';
-import { FontCache } from '../../../../basics/font-cache';
+import { FontCache } from '../shaping-engine/font-cache';
import type {
IAdjustability,
IDocumentSkeletonBullet,
@@ -25,8 +25,9 @@ import type {
} from '../../../../basics/i-document-skeleton-cached';
import { GlyphType } from '../../../../basics/i-document-skeleton-cached';
import type { IFontCreateConfig } from '../../../../basics/interfaces';
-import { hasCJK, hasCJKText, isCjkCenterAlignedPunctuation, isCjkLeftAlignedPunctuation, isCjkRightAlignedPunctuation } from '../../../../basics/tools';
+import { hasCJK, hasCJKText, isCjkCenterAlignedPunctuation, isCjkLeftAlignedPunctuation, isCjkRightAlignedPunctuation, ptToPixel } from '../../../../basics/tools';
import { validationGrid } from '../tools';
+import type { IOpenTypeGlyphInfo } from '../shaping-engine/text-shaping';
export function isSpace(char: string) {
const SPACE_CHARS = [' ', '\u{00A0}', ' '];
@@ -86,9 +87,10 @@ export function createSkeletonWordGlyph(
export function createSkeletonLetterGlyph(
content: string,
config: IFontCreateConfig,
- glyphWidth?: number
+ glyphWidth?: number,
+ glyphInfo?: IOpenTypeGlyphInfo
): IDocumentSkeletonGlyph {
- return _createSkeletonWordOrLetter(GlyphType.LETTER, content, config, glyphWidth);
+ return _createSkeletonWordOrLetter(GlyphType.LETTER, content, config, glyphWidth, glyphInfo);
}
export function createSkeletonTabGlyph(config: IFontCreateConfig, glyphWidth?: number): IDocumentSkeletonGlyph {
@@ -99,7 +101,8 @@ export function _createSkeletonWordOrLetter(
glyphType: GlyphType,
content: string,
config: IFontCreateConfig,
- glyphWidth?: number
+ glyphWidth?: number,
+ glyphInfo?: IOpenTypeGlyphInfo
): IDocumentSkeletonGlyph {
const { fontStyle, textStyle, charSpace = 1, gridType = GridType.LINES, snapToGrid = BooleanNumber.FALSE } = config;
const skipWidthList: string[] = [
@@ -151,10 +154,17 @@ export function _createSkeletonWordOrLetter(
streamType = DT.PARAGRAPH;
}
- const bBox = FontCache.getTextSize(content, fontStyle);
+ let bBox = null;
+ let xOffset = 0;
+
+ if (glyphInfo && glyphInfo.boundingBox && glyphInfo.font) {
+ bBox = FontCache.getBBoxFromGlyphInfo(glyphInfo, fontStyle.fontSize);
+ } else {
+ bBox = FontCache.getTextSize(content, fontStyle);
+ }
+
const { width: contentWidth = 0 } = bBox;
let width = glyphWidth ?? contentWidth;
- let xOffset = 0;
if (validationGrid(gridType, snapToGrid)) {
// 当文字也需要对齐到网格式,进行处理
@@ -165,6 +175,15 @@ export function _createSkeletonWordOrLetter(
}
}
+ // Handle kerning.
+ if (glyphInfo && glyphInfo.kerning !== 0 && glyphInfo.font) {
+ const radio = ptToPixel(fontStyle.fontSize) / glyphInfo.font.unitsPerEm;
+ const delta = glyphInfo.kerning * radio;
+
+ width += delta;
+ xOffset += delta;
+ }
+
return {
content,
ts: textStyle,
diff --git a/packages/engine-render/src/components/docs/layout/shaping-engine/__tests__/text-shaping.spec.ts b/packages/engine-render/src/components/docs/layout/shaping-engine/__tests__/text-shaping.spec.ts
new file mode 100644
index 0000000000..548c1f317a
--- /dev/null
+++ b/packages/engine-render/src/components/docs/layout/shaping-engine/__tests__/text-shaping.spec.ts
@@ -0,0 +1,146 @@
+/**
+ * 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 { IDocumentBody } from '@univerjs/core';
+import { BooleanNumber } from '@univerjs/core';
+import { describe, expect, it } from 'vitest';
+import { prepareParagraphBody, prepareTextChunks } from '../utils';
+
+function getDocumentBody(): IDocumentBody {
+ return ({
+ dataStream: '荷塘𠮷\r作者:朱自清 👨‍👩‍👧‍👦 Today Office\r\n',
+ textRuns: [
+ {
+ st: 0,
+ ed: 4,
+ ts: {
+ fs: 24,
+ ff: 'Microsoft YaHei',
+ cl: {
+ rgb: 'rgb(0, 0, 0)',
+ },
+ bl: BooleanNumber.TRUE,
+ },
+ },
+ {
+ st: 5,
+ ed: 36,
+ ts: {
+ fs: 18,
+ ff: 'Times New Roman',
+ cl: {
+ rgb: 'rgb(30, 30, 30)',
+ },
+ bl: BooleanNumber.FALSE,
+ },
+ },
+ ],
+ paragraphs: [
+ {
+ startIndex: 4,
+ paragraphStyle: {
+ spaceAbove: 10,
+ lineSpacing: 2,
+ spaceBelow: 0,
+ },
+ },
+ {
+ startIndex: 36,
+ paragraphStyle: {
+ spaceAbove: 10,
+ lineSpacing: 2,
+ spaceBelow: 0,
+ },
+ },
+ ],
+ sectionBreaks: [
+ {
+ startIndex: 37,
+ },
+ ],
+ });
+}
+
+describe('Text shaping test cases', () => {
+ describe('Test prepareParagraphBody', () => {
+ it('Should return correct paragraph body', () => {
+ const body: IDocumentBody = getDocumentBody();
+ const paragraphIndex = 36;
+ const expectedParagraphBody: IDocumentBody = {
+ dataStream: '作者:朱自清 👨‍👩‍👧‍👦 Today Office\r',
+ textRuns: [
+ {
+ st: 0,
+ ed: 31,
+ ts: {
+ fs: 18,
+ ff: 'Times New Roman',
+ cl: {
+ rgb: 'rgb(30, 30, 30)',
+ },
+ bl: BooleanNumber.FALSE,
+ },
+ },
+ ],
+ };
+
+ expect(prepareParagraphBody(body, paragraphIndex)).toEqual(expectedParagraphBody);
+ });
+ });
+
+ describe('Test prepareTextChunks', () => {
+ it('Should return correct text chunks', () => {
+ const body: IDocumentBody = {
+ dataStream: '作者:朱自清 👨‍👩‍👧‍👦 Today Office\r',
+ textRuns: [
+ {
+ st: 4,
+ ed: 31,
+ ts: {
+ fs: 18,
+ ff: 'Times New Roman',
+ cl: {
+ rgb: 'rgb(30, 30, 30)',
+ },
+ bl: BooleanNumber.FALSE,
+ },
+ },
+ ],
+ };
+ const expectedTextChunks = [
+ {
+ content: '作者:朱',
+ },
+ {
+ content: '自清 👨‍👩‍👧‍👦 Today Office',
+ style: {
+ fs: 18,
+ ff: 'Times New Roman',
+ cl: {
+ rgb: 'rgb(30, 30, 30)',
+ },
+ bl: BooleanNumber.FALSE,
+ },
+ },
+ {
+ content: '\r',
+ },
+ ];
+
+ expect(prepareTextChunks(body)).toEqual(expectedTextChunks);
+ });
+ });
+});
diff --git a/packages/engine-render/src/basics/font-cache.ts b/packages/engine-render/src/components/docs/layout/shaping-engine/font-cache.ts
similarity index 91%
rename from packages/engine-render/src/basics/font-cache.ts
rename to packages/engine-render/src/components/docs/layout/shaping-engine/font-cache.ts
index 4c678b0050..6275f79d16 100644
--- a/packages/engine-render/src/basics/font-cache.ts
+++ b/packages/engine-render/src/components/docs/layout/shaping-engine/font-cache.ts
@@ -15,10 +15,19 @@
*/
import type { Nullable } from '@univerjs/core';
+import type { IDocumentSkeletonBoundingBox, IDocumentSkeletonFontStyle } from '../../../../basics/i-document-skeleton-cached';
+import { ptToPixel } from '../../../../basics/tools';
+import type { IOpenTypeGlyphInfo } from './text-shaping';
-import { DEFAULT_MEASURE_TEXT } from './const';
-import type { IDocumentSkeletonBoundingBox, IDocumentSkeletonFontStyle } from './i-document-skeleton-cached';
-import type { IMeasureTextCache } from './interfaces';
+export const DEFAULT_MEASURE_TEXT = '0';
+
+export interface IMeasureTextCache {
+ fontBoundingBoxAscent: number;
+ fontBoundingBoxDescent: number;
+ actualBoundingBoxAscent: number;
+ actualBoundingBoxDescent: number;
+ width: number;
+}
const getDefaultBaselineOffset = (fontSize: number) => ({
sbr: 0.6,
@@ -55,7 +64,6 @@ export class FontCache {
private static _fontDataMap: Map<string, IFontData> = new Map();
- // 文字缓存全局变量
private static _globalFontMeasureCache: Map<string, Map<string, IMeasureTextCache>> = new Map();
static get globalFontMeasureCache() {
@@ -193,6 +201,23 @@ export class FontCache {
return bBox;
}
+ static getBBoxFromGlyphInfo(glyphInfo: IOpenTypeGlyphInfo, fontSize: number) {
+ const glyph = glyphInfo.glyph!;
+ const font = glyphInfo.font!;
+ const { y1, y2 } = glyphInfo.boundingBox!;
+ const scale = ptToPixel(fontSize) / font.unitsPerEm;
+
+ const { ascender, descender } = font;
+
+ return this._calculateBoundingBoxByMeasureText({
+ width: (glyph.advanceWidth ?? 0) * scale,
+ fontBoundingBoxAscent: ascender * scale,
+ fontBoundingBoxDescent: Math.abs(descender * scale),
+ actualBoundingBoxAscent: y2 * scale,
+ actualBoundingBoxDescent: Math.abs(y1 * scale),
+ }, fontSize);
+ }
+
// 获取有值单元格文本大小
// let measureTextCache = {}, measureTextCacheTimeOut = null;
static getMeasureText(content: string, fontString: string): IMeasureTextCache {
diff --git a/packages/engine-render/src/components/docs/layout/shaping-engine/font-library.ts b/packages/engine-render/src/components/docs/layout/shaping-engine/font-library.ts
new file mode 100644
index 0000000000..536aff958c
--- /dev/null
+++ b/packages/engine-render/src/components/docs/layout/shaping-engine/font-library.ts
@@ -0,0 +1,306 @@
+/**
+ * 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 { BooleanNumber, type IStyleBase, type Nullable } from '@univerjs/core';
+
+interface IFontData {
+ readonly family: string;
+ readonly fullName: string;
+ readonly postscriptName: string;
+ readonly style: string;
+}
+
+interface IFontWithBuffer {
+ readonly font: IFontData;
+ readonly buffer: ArrayBuffer;
+}
+
+type FontDistance = [number, number];
+
+enum CompareResult {
+ // a is equal to b.
+ EQUAL,
+
+ // a is greater than b.
+ GREATER,
+
+ // a is less than b.
+ LESS,
+}
+
+enum FontStyle {
+ // The default, typically upright style.
+ Normal,
+
+ // A cursive style with custom letterform.
+ Italic,
+
+ // Just a slanted version of the normal style.
+ Oblique,
+}
+
+enum FontWeight {
+ // Thin weight (100).
+ THIN = 100,
+
+ // Extra light weight (200).
+ EXTRALIGHT = 200,
+
+ // Light weight (300).
+ LIGHT = 300,
+
+ // Regular weight (400).
+ REGULAR = 400,
+
+ // Medium weight (500).
+ MEDIUM = 500,
+
+ // Semibold weight (600).
+ SEMIBOLD = 600,
+
+ // Bold weight (700).
+ BOLD = 700,
+
+ // Extrabold weight (800).
+ EXTRABOLD = 800,
+
+ // Black weight (900).
+ BLACK = 900,
+}
+
+interface IFontVariant {
+ // The style of the font (normal / italic).
+ style: FontStyle;
+ /// How heavy the font is normal / bold.
+ weight: FontWeight;
+ // How condensed or expanded the font is (0.5 - 2.0).
+ // stretch: FontStretch,
+}
+
+export interface IFontInfo {
+ // The typographic font family this font is part of.
+ family: string;
+ // Properties that distinguish this font from other fonts in the same family.
+ variant: IFontVariant;
+}
+
+function getFontInfoFromFontData(fontData: IFontData): IFontInfo {
+ const { family, style: styleString } = fontData;
+
+ let style = FontStyle.Normal;
+ let weight = FontWeight.REGULAR;
+
+ if (/italic/i.test(styleString)) {
+ style = FontStyle.Italic;
+ }
+
+ switch (true) {
+ case /thin|hairline/i.test(styleString): {
+ weight = FontWeight.THIN;
+ break;
+ }
+
+ case /(extra|ultra) *light/i.test(styleString): {
+ weight = FontWeight.EXTRALIGHT;
+ break;
+ }
+
+ case /light/i.test(styleString): {
+ weight = FontWeight.LIGHT;
+ break;
+ }
+
+ case /medium/i.test(styleString): {
+ weight = FontWeight.MEDIUM;
+ break;
+ }
+
+ case /(semi|demi) *bold/i.test(styleString): {
+ weight = FontWeight.SEMIBOLD;
+ break;
+ }
+
+ case /bold/i.test(styleString): {
+ weight = FontWeight.BOLD;
+ break;
+ }
+
+ case /(extra|ultra) *bold/i.test(styleString): {
+ weight = FontWeight.EXTRABOLD;
+ break;
+ }
+
+ case /black|heavy/i.test(styleString): {
+ weight = FontWeight.BLACK;
+ break;
+ }
+ }
+
+ return {
+ family,
+ variant: {
+ style,
+ weight,
+ },
+ };
+}
+
+function getFontInfoFromTextStyle(style: IStyleBase): IFontInfo {
+ const { ff, bl = BooleanNumber.FALSE, it = BooleanNumber.FALSE } = style;
+
+ return {
+ family: ff ?? 'Arial',
+ variant: {
+ style: it === BooleanNumber.TRUE ? FontStyle.Italic : FontStyle.Normal,
+ weight: bl === BooleanNumber.TRUE ? FontWeight.BOLD : FontWeight.REGULAR,
+ },
+ };
+}
+
+function fontInfoDistance(a: IFontInfo, b: IFontInfo): FontDistance {
+ let styleDistance = Number.POSITIVE_INFINITY;
+
+ if (a.variant.style === b.variant.style) {
+ styleDistance = 0;
+ } else if (a.variant.style !== FontStyle.Normal && b.variant.style !== FontStyle.Normal) {
+ styleDistance = 1;
+ } else {
+ styleDistance = 2;
+ }
+
+ const weightDistance = Math.abs(a.variant.weight - b.variant.weight);
+
+ return [
+ styleDistance,
+ weightDistance,
+ ];
+}
+
+function compareFontInfoDistance(a: FontDistance, b: FontDistance) {
+ if (a[0] === b[0] && a[1] === b[1]) {
+ return CompareResult.EQUAL;
+ }
+
+ if (a[0] === b[0]) {
+ return a[1] > b[1] ? CompareResult.GREATER : CompareResult.LESS;
+ }
+
+ return a[0] > b[0] ? CompareResult.GREATER : CompareResult.LESS;
+}
+
+async function checkLocalFontsPermission() {
+ if (typeof window === 'undefined') {
+ return;
+ }
+ if (window.navigator == null || window.navigator?.permissions == null) {
+ return false;
+ }
+
+ const status = await window.navigator.permissions.query({ name: 'local-fonts' as PermissionName });
+
+ return status.state === 'granted';
+}
+
+class FontLibrary {
+ isReady = false;
+ private _fontBook: Map<string, Map<string, IFontWithBuffer>> = new Map();
+
+ constructor() {
+ this._loadFontsToBook();
+ }
+
+ private async _loadFontsToBook() {
+ if (this.isReady) {
+ return;
+ }
+
+ const permissionStatus = await checkLocalFontsPermission();
+
+ if (!permissionStatus) {
+ return;
+ }
+
+ if (!('queryLocalFonts' in window)) {
+ return;
+ }
+
+ try {
+ const availableFonts = await (window as any).queryLocalFonts();
+
+ for (const font of availableFonts) {
+ const { family, style } = font;
+ let fontMap = this._fontBook.get(family);
+
+ if (fontMap == null) {
+ fontMap = new Map();
+ this._fontBook.set(family, fontMap);
+ }
+
+ const blob = await font.blob();
+ const buffer = await blob.arrayBuffer();
+
+ fontMap.set(style, {
+ font,
+ buffer,
+ });
+ }
+
+ this.isReady = true;
+ } catch (err) {
+ console.error(err);
+ }
+ }
+
+ findBestMatchFontByStyle(style: IStyleBase): Nullable<IFontWithBuffer> {
+ const ff = style.ff!;
+ const fontMap = this._fontBook.get(ff);
+
+ if (fontMap == null) {
+ // TODO: @jocs use font family to match the best.
+ return;
+ }
+
+ let bestFont: Nullable<IFontWithBuffer> = null;
+ let bestDistance: FontDistance = [Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY];
+
+ for (const fontWithBuffer of fontMap.values()) {
+ const { font } = fontWithBuffer;
+ const currentFontInfo = getFontInfoFromFontData(font);
+ const targetFontInfo = getFontInfoFromTextStyle(style);
+ const distance = fontInfoDistance(currentFontInfo, targetFontInfo);
+
+ if (bestFont == null) {
+ bestFont = fontWithBuffer;
+ bestDistance = distance;
+ } else {
+ const result = compareFontInfoDistance(bestDistance, distance);
+
+ if (result === CompareResult.GREATER) {
+ bestFont = fontWithBuffer;
+ bestDistance = distance;
+ }
+ }
+ }
+
+ return bestFont;
+ }
+
+ getValidFontFamilies(families: string[]): string[] {
+ return families.filter((family) => this._fontBook.has(family));
+ }
+}
+
+export const fontLibrary = new FontLibrary();
diff --git a/packages/engine-render/src/components/docs/layout/shaping-engine/text-shaping.ts b/packages/engine-render/src/components/docs/layout/shaping-engine/text-shaping.ts
new file mode 100644
index 0000000000..3dfdbca76f
--- /dev/null
+++ b/packages/engine-render/src/components/docs/layout/shaping-engine/text-shaping.ts
@@ -0,0 +1,218 @@
+/**
+ * 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 { BooleanNumber, type IDocumentBody, type IStyleBase } from '@univerjs/core';
+// @ts-ignore
+import opentype from 'opentype.js/dist/opentype.module';
+import type Opentype from 'opentype.js';
+import type { Nullable } from 'vitest';
+import { DEFAULT_FONTFACE_PLANE } from '../../../../basics/const';
+import { EMOJI_REG } from '../../../../basics/tools';
+import { fontLibrary } from './font-library';
+import { prepareTextChunks } from './utils';
+
+interface IBoundingBox {
+ x1: number;
+ y1: number;
+ x2: number;
+ y2: number;
+
+}
+
+export interface IOpenTypeGlyphInfo {
+ char: string;
+ start: number;
+ end: number;
+ glyph: Nullable<Opentype.Glyph>;
+ font: Nullable<Opentype.Font>;
+ kerning: number;
+ boundingBox: Nullable<IBoundingBox>;
+}
+
+const fontCache = new Map<string, Opentype.Font>();
+const glyphCache: Map<string, IOpenTypeGlyphInfo[]> = new Map();
+
+
+function shapeChunk(
+ content: string,
+ charPosition: number,
+ used: Set<string>,
+ families: string[],
+ style: IStyleBase
+): IOpenTypeGlyphInfo[] {
+ let fi = 0;
+ let fontFamily = families[fi];
+
+ while (used.has(fontFamily)) {
+ fi++;
+ fontFamily = families[fi];
+ }
+
+ if (!fontFamily) {
+ return [{
+ char: content,
+ start: charPosition,
+ end: charPosition + content.length,
+ glyph: null,
+ font: null,
+ kerning: 0,
+ boundingBox: null,
+ }];
+ }
+
+ used.add(fontFamily);
+
+ const { font: fontInfo, buffer: fontBuffer } = fontLibrary.findBestMatchFontByStyle({
+ ff: fontFamily,
+ bl: style.bl ?? BooleanNumber.FALSE,
+ it: style.it ?? BooleanNumber.FALSE,
+ })!;
+
+ let font = fontCache.get(fontInfo.fullName);
+ if (!font) {
+ font = opentype.parse(fontBuffer) as Opentype.Font;
+ fontCache.set(fontInfo.fullName, font);
+ }
+
+ // const option = {
+ // kerning: true,
+ // features: {
+ // liga: false,
+ // },
+ // };
+
+ const results = [];
+
+ const glyphs = font.stringToGlyphs(content);
+ const chars = content.match(/[\s\S]/gu) ?? [];
+
+ let gi = 0;
+ let startIndex = 0;
+
+ while (gi < glyphs.length) {
+ const glyph = glyphs[gi];
+ if (glyph.index !== 0) {
+ results.push({
+ char: chars[gi],
+ start: startIndex + charPosition,
+ end: startIndex + charPosition + chars[gi].length,
+ glyph,
+ font,
+ kerning: 0,
+ boundingBox: glyph.getBoundingBox(),
+ });
+ } else {
+ const start = startIndex;
+ const subStr = content.substring(start);
+ const emojiMatch = subStr.match(EMOJI_REG);
+
+ if (emojiMatch) {
+ let acc = 0;
+ do {
+ acc += chars[gi].length;
+ startIndex += chars[gi].length;
+ gi++;
+ } while (acc < emojiMatch[0].length);
+
+ results.push(...shapeChunk(content.slice(start, start + emojiMatch[0].length), charPosition + start, used, families, style));
+
+ continue;
+ } else {
+ let nextGlyph = glyphs[gi + 1];
+ let nextChar = chars[gi + 1];
+
+ while (nextGlyph?.index === 0 && !EMOJI_REG.test(nextChar)) {
+ startIndex += chars[gi].length;
+ gi++;
+ nextGlyph = glyphs[gi + 1];
+ nextChar = chars[gi + 1];
+ }
+
+ results.push(...shapeChunk(content.slice(start, startIndex + chars[gi].length), charPosition + start, used, families, style));
+ }
+ }
+
+ startIndex += chars[gi]?.length;
+ gi++;
+ }
+
+ used.delete(fontFamily);
+
+ return results;
+}
+
+function kerningAdjustment(glyphs: IOpenTypeGlyphInfo[]) {
+ if (glyphs.length < 2) {
+ return;
+ }
+
+ let lastFont = glyphs[0].font;
+ let lastGlyph = glyphs[0].glyph;
+
+ for (let i = 1; i < glyphs.length; i++) {
+ const { font, glyph } = glyphs[i];
+ if (lastFont !== font || font == null || lastGlyph == null || glyph == null) {
+ lastFont = font;
+ lastGlyph = glyph;
+ continue;
+ }
+
+ const kerning = font.getKerningValue(lastGlyph, glyph);
+
+ if (kerning !== 0) {
+ glyphs[i].kerning = kerning;
+ }
+
+ lastFont = font;
+ lastGlyph = glyph;
+ }
+}
+
+export function textShape(body: IDocumentBody) {
+ if (!fontLibrary.isReady) {
+ return [];
+ }
+
+ const key = JSON.stringify(body);
+
+ if (glyphCache.has(key)) {
+ return glyphCache.get(key)!;
+ }
+
+ const chunks = prepareTextChunks(body);
+
+ const glyphs = [];
+ let charPosition = 0;
+
+ for (const chunk of chunks) {
+ const { content, style = {} } = chunk;
+ let fontFamilies = DEFAULT_FONTFACE_PLANE.split(',').map((family) => family.trim().replace(/["']/g, ''));
+
+ fontFamilies.unshift(style.ff ?? 'Arial');
+
+ fontFamilies = fontLibrary.getValidFontFamilies(fontFamilies);
+
+ glyphs.push(...shapeChunk(content, charPosition, new Set(), fontFamilies, style));
+
+ charPosition += content.length;
+ }
+
+ kerningAdjustment(glyphs);
+
+ glyphCache.set(key, glyphs);
+
+ return glyphs;
+}
diff --git a/packages/engine-render/src/components/docs/layout/shaping-engine/utils.ts b/packages/engine-render/src/components/docs/layout/shaping-engine/utils.ts
new file mode 100644
index 0000000000..47777cfa22
--- /dev/null
+++ b/packages/engine-render/src/components/docs/layout/shaping-engine/utils.ts
@@ -0,0 +1,94 @@
+/**
+ * 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 { IDocumentBody, IStyleBase } from '@univerjs/core';
+
+interface ITextChunk {
+ content: string;
+ style?: IStyleBase;
+}
+
+export function prepareParagraphBody(body: IDocumentBody, paragraphIndex: number): IDocumentBody {
+ const { dataStream, paragraphs = [], textRuns = [] } = body;
+
+ let last = 0;
+ for (let i = 0; i < paragraphs.length; i++) {
+ const paragraph = paragraphs[i];
+ const { startIndex } = paragraph;
+
+ if (startIndex === paragraphIndex) {
+ break;
+ }
+
+ last = startIndex + 1;
+ }
+
+ const textRunChunks = [];
+
+ for (const textRun of textRuns) {
+ const { st, ed } = textRun;
+
+ if (st >= last && st <= paragraphIndex) {
+ textRunChunks.push({
+ ...textRun,
+ st: st - last,
+ ed: Math.min(ed, paragraphIndex) - last,
+ });
+ } else if (ed >= last && ed <= paragraphIndex) {
+ textRunChunks.push({
+ ...textRun,
+ st: Math.max(st, last) - last,
+ ed: ed - last,
+ });
+ }
+ }
+
+ return {
+ dataStream: dataStream.substring(last, paragraphIndex + 1),
+ textRuns: textRunChunks,
+ };
+}
+
+// Split the paragraph content into text chunks, and each chunk has the same style and font family.
+export function prepareTextChunks(body: IDocumentBody) {
+ const { dataStream, textRuns = [] } = body;
+ let offset = 0;
+ const chunks: ITextChunk[] = [];
+
+ for (const textRun of textRuns) {
+ const { st, ed, ts = {} } = textRun;
+ if (st !== offset) {
+ chunks.push({
+ content: dataStream.substring(offset, st),
+ });
+ }
+
+ chunks.push({
+ content: dataStream.substring(st, ed),
+ style: ts,
+ });
+
+ offset = ed;
+ }
+
+ if (offset !== dataStream.length) {
+ chunks.push({
+ content: dataStream.substring(offset),
+ });
+ }
+
+ return chunks;
+}
diff --git a/packages/engine-render/tsconfig.json b/packages/engine-render/tsconfig.json
index d676ad2a20..b8adb8ddd0 100644
--- a/packages/engine-render/tsconfig.json
+++ b/packages/engine-render/tsconfig.json
@@ -5,5 +5,5 @@
"outDir": "lib/types"
},
"references": [{ "path": "./tsconfig.node.json" }],
- "include": ["src"]
+ "include": ["src", "types"]
}
diff --git a/packages/engine-render/vite.config.ts b/packages/engine-render/vite.config.ts
index 67b2fff8f2..f13d09f1c7 100644
--- a/packages/engine-render/vite.config.ts
+++ b/packages/engine-render/vite.config.ts
@@ -4,4 +4,7 @@ import pkg from './package.json';
export default ({ mode }) => createViteConfig({}, {
mode,
pkg,
+ features: {
+ dom: true,
+ },
});
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index fd41cc878c..c02563fc03 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -612,10 +612,13 @@ importers:
cjk-regex:
specifier: ^3.1.0
version: 3.1.0
- linebreak:
- specifier: ^1.1.0
- version: 1.1.0
+ opentype.js:
+ specifier: ^1.3.4
+ version: 1.3.4
devDependencies:
+ '@types/opentype.js':
+ specifier: ^1.3.8
+ version: 1.3.8
'@univerjs/core':
specifier: workspace:*
version: link:../core
@@ -5570,6 +5573,10 @@ packages:
resolution: {integrity: sha512-kH8I7OSSwQu9DS9JYdFWbuvhVzvFRoCPCkGxNwoGgaPeDfEPJlcxNvEOypZhQ3XXHsGbfIuYcxcJxKUfJHnRfw==}
dev: true
+ resolution: {integrity: sha512-H6qeTp03jrknklSn4bpT1/9+1xCAEIU2CnjcWPkicJy8A1SKuthanbvoHYMiv79/2W3Xn1XE4gfSJFzt2U3JSw==}
+ dev: true
+
resolution: {integrity: sha512-dISoDXWWQwUquiKsyZ4Ng+HX2KsPL7LyHKHQwgGFEA3IaKac4Obd+h2a/a6waisAoepJlBcx9paWqjA8/HVjCw==}
dev: false
@@ -6676,11 +6683,6 @@ packages:
resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==}
- resolution: {integrity: sha512-3XSA2cR/h/73EzlXXdU6YNycmYI7+kicTxks4eJg2g39biHR84slg2+des+p7iHYhbRg/udIS4TD53WabcOUkw==}
- engines: {node: '>= 0.4'}
- dev: false
-
resolution: {integrity: sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==}
@@ -10844,13 +10846,6 @@ packages:
engines: {node: '>=14'}
dev: true
- resolution: {integrity: sha512-MHp03UImeVhB7XZtjd0E4n6+3xr5Dq/9xI/5FptGk5FrbDR3zagPa2DS6U8ks/3HjbKWG9Q1M2ufOzxV2qLYSQ==}
- dependencies:
- base64-js: 0.0.8
- unicode-trie: 2.0.0
- dev: false
-
resolution: {integrity: sha512-7ylylesZQ/PV29jhEDl3Ufjo6ZX7gCqJr5F7PKrqc93v7fzSymt1BpwEU8nAUXs8qzzvqhbjhK5QZg6Mt/HkBg==}
@@ -11641,6 +11636,15 @@ packages:
is-wsl: 2.2.0
dev: false
+ resolution: {integrity: sha512-d2JE9RP/6uagpQAVtJoF0pJJA/fgai89Cc50Yp0EJHk+eLp6QQ7gBoblsnubRULNY132I0J1QKMJ+JTbMqz4sw==}
+ engines: {node: '>= 8.0.0'}
+ hasBin: true
+ dependencies:
+ string.prototype.codepointat: 0.2.1
+ tiny-inflate: 1.0.3
+ dev: false
+
resolution: {integrity: sha512-JjCoypp+jKn1ttEFExxhetCKeJt9zhAgAve5FXHixTvFDW/5aEktX9bufBKLRRMdU7bNtpLfcGu94B3cdEJgjg==}
engines: {node: '>= 0.8.0'}
@@ -13711,6 +13715,10 @@ packages:
strip-ansi: 7.1.0
dev: true
+ resolution: {integrity: sha512-2cBVCj6I4IOvEnjgO/hWqXjqBGsY+zwPmHl12Srk9IXSZ56Jwwmy+66XO5Iut/oQVR7t5ihYdLB0GMa4alEUcg==}
+ dev: false
+
resolution: {integrity: sha512-NUdh0aDavY2og7IbBPenWqR9exH+E26Sv8e0/eTe1tltDGZL+GtBkDAnnyBtmekfK6/Dq3MkcGtzXFEd1LQrtg==}
engines: {node: '>= 0.4'}
@@ -14370,13 +14378,6 @@ packages:
regexp-util: 2.0.0
dev: false
- resolution: {integrity: sha512-x7bc76x0bm4prf1VLg79uhAzKw8DVboClSN5VxJuQ+LKDOVEW9CdH+VY7SP+vX7xCYQqzzgQpFqz15zeLvAtZQ==}
- dependencies:
- pako: 0.2.9
- tiny-inflate: 1.0.3
- dev: false
-
resolution: {integrity: sha512-lRfVq8fE8gz6QMBuDM6a+LO3IAzTi05H6gCVaUpir2E1Rwpo4ZUog45KpNXKC/Mn3Yb9UDuHumeFTo9iV/D9FQ==}
engines: {node: '>=18'}