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(engine-render): standardize default values for BlankCellDocumentModel (#2282)
白熱43e57fac7468
diff --git a/packages/engine-render/src/basics/tools.ts b/packages/engine-render/src/basics/tools.tsindex dcf6e9a63f..f5afd4564f 100644--- a/packages/engine-render/src/basics/tools.ts+++ b/packages/engine-render/src/basics/tools.ts@@ -24,7 +24,7 @@ import type {LocaleService,Nullable,} from '@univerjs/core';-import { BaselineOffset, FontStyleType, Tools } from '@univerjs/core';+import { BaselineOffset, DEFAULT_STYLES, FontStyleType, Tools } from '@univerjs/core';import * as cjk from 'cjk-regex';import { FontCache } from '../components/docs/layout/shaping-engine/font-cache';@@ -245,18 +245,14 @@ export function fixLineWidthByScale(num: number, scale: number) {return Math.round(num * scale) / scale;}-export const UNIVER_GLOBAL_DEFAULT_FONT_SIZE = 11;--export const UNIVER_GLOBAL_DEFAULT_FONT_FAMILY = 'Arial';-// eslint-disable-next-line max-lines-per-functionexport function getFontStyleString(textStyle?: IStyleBase,_localeService?: LocaleService): IDocumentSkeletonFontStyle {- const defaultFont = UNIVER_GLOBAL_DEFAULT_FONT_FAMILY;+ const defaultFont = DEFAULT_STYLES.ff;- const defaultFontSize = UNIVER_GLOBAL_DEFAULT_FONT_SIZE;+ const defaultFontSize = DEFAULT_STYLES.fs;if (!textStyle) {const fontString = `${defaultFontSize}pt ${defaultFont}`;diff --git a/packages/engine-render/src/components/sheets/sheet-skeleton.ts b/packages/engine-render/src/components/sheets/sheet-skeleton.tsindex c13cf6623e..bac07db16f 100644--- a/packages/engine-render/src/components/sheets/sheet-skeleton.ts+++ b/packages/engine-render/src/components/sheets/sheet-skeleton.ts@@ -20,6 +20,7 @@ import {BooleanNumber,CellValueType,DEFAULT_EMPTY_DOCUMENT_VALUE,+ DEFAULT_STYLES,DocumentDataModel,extractPureTextFromCell,getColorStyle,@@ -1081,10 +1082,10 @@ export class SpreadsheetSkeleton extends Skeleton {let fontString = 'document';- const textRotation: ITextRotation = { a: 0, v: BooleanNumber.FALSE };- const horizontalAlign: HorizontalAlign = HorizontalAlign.UNSPECIFIED;- const verticalAlign: VerticalAlign = VerticalAlign.UNSPECIFIED;- const wrapStrategy: WrapStrategy = WrapStrategy.UNSPECIFIED;+ const textRotation: ITextRotation = DEFAULT_STYLES.tr;+ const horizontalAlign: HorizontalAlign = DEFAULT_STYLES.ht;+ const verticalAlign: VerticalAlign = DEFAULT_STYLES.vt;+ const wrapStrategy: WrapStrategy = DEFAULT_STYLES.tb;const paddingData: IPaddingData = DEFAULT_PADDING_DATA;fontString = getFontStyleString({}, this._localService).fontCache;@@ -1131,17 +1132,17 @@ export class SpreadsheetSkeleton extends Skeleton {const cellOtherConfig = this._getOtherStyle(style) as ICellOtherConfig;const textRotation: ITextRotation = ignoreTextRotation- ? { a: 0, v: BooleanNumber.FALSE }- : cellOtherConfig.textRotation || { a: 0, v: BooleanNumber.FALSE };- let horizontalAlign: HorizontalAlign = cellOtherConfig.horizontalAlign || HorizontalAlign.UNSPECIFIED;- const verticalAlign: VerticalAlign = cellOtherConfig.verticalAlign || VerticalAlign.UNSPECIFIED;- const wrapStrategy: WrapStrategy = cellOtherConfig.wrapStrategy || WrapStrategy.UNSPECIFIED;+ ? DEFAULT_STYLES.tr+ : cellOtherConfig.textRotation || DEFAULT_STYLES.tr;+ let horizontalAlign: HorizontalAlign = cellOtherConfig.horizontalAlign || DEFAULT_STYLES.ht;+ const verticalAlign: VerticalAlign = cellOtherConfig.verticalAlign || DEFAULT_STYLES.vt;+ const wrapStrategy: WrapStrategy = cellOtherConfig.wrapStrategy || DEFAULT_STYLES.tb;const paddingData: IPaddingData = cellOtherConfig.paddingData || DEFAULT_PADDING_DATA;if (cell.f && displayRawFormula) {// The formula does not detect horizontal alignment and rotation.documentModel = this._getDocumentDataByStyle(cell.f.toString(), {}, { verticalAlign });- horizontalAlign = HorizontalAlign.UNSPECIFIED;+ horizontalAlign = DEFAULT_STYLES.ht;} else if (cell.p) {const { centerAngle, vertexAngle } = convertTextRotation(textRotation);documentModel = this._updateConfigAndGetDocumentModel(diff --git a/packages/ui/src/services/editor/editor.service.ts b/packages/ui/src/services/editor/editor.service.tsindex f6881022dc..1da1bfbf76 100644--- a/packages/ui/src/services/editor/editor.service.ts+++ b/packages/ui/src/services/editor/editor.service.ts@@ -15,13 +15,13 @@*/import type { DocumentDataModel, IDocumentBody, IDocumentData, IDocumentStyle, IPosition, Nullable, Workbook } from '@univerjs/core';-import { DEFAULT_EMPTY_DOCUMENT_VALUE, Disposable, EDITOR_ACTIVATED, FOCUSING_EDITOR_INPUT_FORMULA, FOCUSING_EDITOR_STANDALONE, FOCUSING_UNIVER_EDITOR_STANDALONE_SINGLE_MODE, HorizontalAlign, IContextService, IUniverInstanceService, toDisposable, UniverInstanceType, VerticalAlign } from '@univerjs/core';+import { DEFAULT_EMPTY_DOCUMENT_VALUE, DEFAULT_STYLES, Disposable, EDITOR_ACTIVATED, FOCUSING_EDITOR_INPUT_FORMULA, FOCUSING_EDITOR_STANDALONE, FOCUSING_UNIVER_EDITOR_STANDALONE_SINGLE_MODE, HorizontalAlign, IContextService, IUniverInstanceService, toDisposable, UniverInstanceType, VerticalAlign } from '@univerjs/core';import type { IDisposable } from '@wendellhu/redi';import { createIdentifier, Inject, Injector } from '@wendellhu/redi';import type { Observable } from 'rxjs';import { Subject } from 'rxjs';import type { IRender, ISuccinctTextRangeParam, Scene } from '@univerjs/engine-render';-import { IRenderManagerService, UNIVER_GLOBAL_DEFAULT_FONT_SIZE } from '@univerjs/engine-render';+import { IRenderManagerService } from '@univerjs/engine-render';import { isReferenceStrings, LexerTreeBuilder, operatorToken } from '@univerjs/engine-formula';export interface IEditorStateParam extends Partial<IPosition> {@@ -197,7 +197,7 @@ export class Editor {return;}- let fontSize = UNIVER_GLOBAL_DEFAULT_FONT_SIZE;+ let fontSize = DEFAULT_STYLES.fs;if (this._param.canvasStyle?.fontSize) {fontSize = this._param.canvasStyle.fontSize;