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
fix: columns is not render properly (#1952)
Ran Luo039e5e2f6c6a
diff --git a/examples/src/data/docs/default-document-data-cn.ts b/examples/src/data/docs/default-document-data-cn.tsindex 721b335d37..aa38dfc8cc 100644--- a/examples/src/data/docs/default-document-data-cn.ts+++ b/examples/src/data/docs/default-document-data-cn.ts@@ -15,7 +15,7 @@*/import type { IDocumentData } from '@univerjs/core';-import { BooleanNumber } from '@univerjs/core';+import { BooleanNumber, ColumnSeparatorType, SectionType } from '@univerjs/core';import { ptToPixel } from '@univerjs/engine-render';export const DEFAULT_DOCUMENT_DATA_CN: IDocumentData = {@@ -581,15 +581,15 @@ export const DEFAULT_DOCUMENT_DATA_CN: IDocumentData = {],sectionBreaks: [{- startIndex: 3058,- // columnProperties: [- // {- // width: 250,- // paddingEnd: 15,- // },- // ],- // columnSeparatorType: ColumnSeparatorType.NONE,- // sectionType: SectionType.SECTION_TYPE_UNSPECIFIED,+ startIndex: 3066,+ columnProperties: [+ {+ width: ptToPixel(240),+ paddingEnd: ptToPixel(15),+ },+ ],+ columnSeparatorType: ColumnSeparatorType.NONE,+ sectionType: SectionType.SECTION_TYPE_UNSPECIFIED,// textDirection: textDirectionDocument,// contentDirection: textDirection!,},diff --git a/examples/src/data/docs/default-document-data-dreamer.ts b/examples/src/data/docs/default-document-data-dreamer.tsnew file mode 100644index 0000000000..03622077ba--- /dev/null+++ b/examples/src/data/docs/default-document-data-dreamer.ts@@ -0,0 +1,281 @@+/**+ * 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 { IDocumentData } from '@univerjs/core';+import {+ BooleanNumber,+ ColumnSeparatorType,+ ObjectRelativeFromH,+ ObjectRelativeFromV,+ PositionedObjectLayoutType,+ SectionType,+ WrapTextType,+} from '@univerjs/core';+import { ptToPixel } from '@univerjs/engine-render';++export const DEFAULT_DOCUMENT_DATA_DREAMER: IDocumentData = {+ id: 'd',+ drawings: {+ shapeTest1: {+ objectId: 'shapeTest1',+ title: 'test shape',+ description: 'test shape',+ objectTransform: {+ size: {+ width: 1484 * 0.15,+ height: 864 * 0.15,+ },+ positionH: {+ relativeFrom: ObjectRelativeFromH.COLUMN,+ posOffset: 130,+ },+ positionV: {+ relativeFrom: ObjectRelativeFromV.PAGE,+ posOffset: 510,+ },+ angle: 0,+ },+ layoutType: PositionedObjectLayoutType.WRAP_SQUARE,+ behindDoc: BooleanNumber.FALSE,+ wrapText: WrapTextType.BOTH_SIDES,+ },+ shapeTest2: {+ objectId: 'shapeTest2',+ title: 'test shape',+ description: 'test shape',+ objectTransform: {+ size: {+ width: 2548 * 0.1,+ height: 2343 * 0.1,+ },+ positionH: {+ relativeFrom: ObjectRelativeFromH.COLUMN,+ posOffset: 130,+ },+ positionV: {+ relativeFrom: ObjectRelativeFromV.PAGE,+ posOffset: 200,+ },+ angle: 0,+ },+ layoutType: PositionedObjectLayoutType.WRAP_SQUARE,+ behindDoc: BooleanNumber.FALSE,+ wrapText: WrapTextType.BOTH_SIDES,+ },+ },+ body: {+ dataStream:+ 'The Dreamer\r\rGo with your passion.It has been said that who see the invisible can do the impossible.\r\rWhen I was nine years old living in a smaIl town in North Carolina I found an ad for selling greeting cards in the back of a children\'s magazine.I thought to myself I can do this.I begged my mother to let me send for the kit.Two weeks later when the kit arrived,I ripped off the brown paper wrapper,grabbed the cards and dashed from the house.Three hours later.I returned home with no card and a pocket full of money proclaiming,“Mama.all the people couldn\'t wait to buy my cards!”A salesperson was born.when I was twelve years old,my father took me to see Zig Ziegler.I remember sitting in that dark auditorium listening to Mr,Zigler raise everyone\'s spirits up to the ceiling,I left there feeling like I could do anything.When we got to the car,I turned to my father and said.“Dad.I want to make people feel like that.”My father asked me what I meant."I want to be a motivational speaker just like Mr.Zigler,“I replied.A dream was born.\r\rRecently,I began pursuing my dream of motivating others.After a four-year relationship with a major furtune 100company beginning as a salestrainer and ending as a regional sales manager,I left the company at the height of my career,Many people were astounded that I would leave after earning a six-figure income.And they asked why I would risk everything for a dream.\r\rI made my decision to start my own company and leave my secure position after attending a regional sales meeting.The vice-president of our company delivered a speech that changed my life.He asked us,“If a genie would grant you three wishes what would they be?”After giving us a moment to write down the three wishes.he then asked us,"why do you need a genie ?"I would never forget the empowerment I felt at that moment.\r\rI realized that everything I had accomplished一the graduate degree,the successful sales career,speaking engagements,training and managing for a fortune l00company had prepared me for this moment.I was ready and did not need a genie\'s help to become a motivational speaker.\r\rWhen I tearfully told my boss my plans this incredible leader whom Irespect so much replied,"Precede with reckless abandon and you will be successful“\r\rHaving made that decision,I was immediately tested.One week after I gave notice,my husband was“laid off from his job.We had recently bought a new home and needed both incomes to make the monthly mortgage payment and now we were done to no income.It was tempting to turn back to my former company,knowing they wanted me to stays but l was certain that if I went back,I would never leave.I decided I still wanted to move forward rather than end up with a mouth full of”if onlys"later on.A motivational speaker was born.\r\rWhen l held fast to my dream,even during the tough times.The miracles really began to happen.In a short time period my husband found a better job.We didn\'t miss a mortgage payment.And I was able to book several speaking engagements with new clients.I discovered the incredible power of dreams.I loved my old job,my peers and the company I left,but it was time to get on with my dream.To celebrate my success I had a local artist paint my new offlce as a garden.At the top of one wall she stenciled,“The world always makes way for the dreamer.\r\n”',+ textRuns: [+ {+ st: 0,+ ed: 11,+ ts: {+ bl: BooleanNumber.TRUE,+ fs: 24 * 0.75,+ cl: {+ rgb: 'rgb(0, 40, 86)',+ },+ },+ },+ {+ st: 13,+ ed: 3318,+ ts: {+ fs: 14 * 0.75,+ ff: 'Times New Roman',+ cl: {+ rgb: 'rgb(0, 0, 0)',+ },+ },+ },+ ],+ paragraphs: [+ {+ startIndex: 11,+ paragraphStyle: {+ spaceAbove: 10,+ lineSpacing: 2,+ spaceBelow: 0,+ },+ },+ {+ startIndex: 12,+ paragraphStyle: {+ spaceAbove: 10,+ lineSpacing: 2,+ spaceBelow: 0,+ },+ },+ {+ startIndex: 100,+ paragraphStyle: {+ spaceAbove: 10,+ lineSpacing: 2,+ spaceBelow: 0,+ },+ },+ {+ startIndex: 101,+ paragraphStyle: {+ spaceAbove: 10,+ lineSpacing: 2,+ spaceBelow: 0,+ },+ },+ {+ startIndex: 1040,+ paragraphStyle: {+ spaceAbove: 10,+ lineSpacing: 2,+ spaceBelow: 0,+ },+ },+ {+ startIndex: 1041,+ paragraphStyle: {+ spaceAbove: 10,+ lineSpacing: 2,+ spaceBelow: 0,+ },+ },+ {+ startIndex: 1409,+ paragraphStyle: {+ spaceAbove: 10,+ lineSpacing: 2,+ spaceBelow: 0,+ },+ },+ {+ startIndex: 1410,+ paragraphStyle: {+ spaceAbove: 10,+ lineSpacing: 2,+ spaceBelow: 0,+ },+ },+ {+ startIndex: 1830,+ paragraphStyle: {+ spaceAbove: 10,+ lineSpacing: 2,+ spaceBelow: 0,+ },+ },+ {+ startIndex: 1831,+ paragraphStyle: {+ spaceAbove: 10,+ lineSpacing: 2,+ spaceBelow: 0,+ },+ },+ {+ startIndex: 2103,+ paragraphStyle: {+ spaceAbove: 10,+ lineSpacing: 2,+ spaceBelow: 0,+ },+ },+ {+ startIndex: 2104,+ paragraphStyle: {+ spaceAbove: 10,+ lineSpacing: 2,+ spaceBelow: 0,+ },+ },+ {+ startIndex: 2255,+ paragraphStyle: {+ spaceAbove: 10,+ lineSpacing: 2,+ spaceBelow: 0,+ },+ },+ {+ startIndex: 2256,+ paragraphStyle: {+ spaceAbove: 10,+ lineSpacing: 2,+ spaceBelow: 0,+ },+ },+ {+ startIndex: 2774,+ paragraphStyle: {+ spaceAbove: 10,+ lineSpacing: 2,+ spaceBelow: 0,+ },+ },+ {+ startIndex: 2775,+ paragraphStyle: {+ spaceAbove: 10,+ lineSpacing: 2,+ spaceBelow: 0,+ },+ },+ {+ startIndex: 3318,+ paragraphStyle: {+ spaceAbove: 10,+ lineSpacing: 2,+ spaceBelow: 0,+ },+ },+ ],+ sectionBreaks: [+ {+ startIndex: 3319,+ columnProperties: [+ {+ width: ptToPixel(240),+ paddingEnd: ptToPixel(15),+ },+ ],+ columnSeparatorType: ColumnSeparatorType.NONE,+ sectionType: SectionType.SECTION_TYPE_UNSPECIFIED,+ // textDirection: textDirectionDocument,+ // contentDirection: textDirection!,+ },+ ],+ customBlocks: [+ {+ startIndex: 1243,+ blockId: 'shapeTest1',+ },+ ],+ },+ documentStyle: {+ pageSize: {+ width: ptToPixel(595),+ height: ptToPixel(842),+ },+ marginTop: ptToPixel(50),+ marginBottom: ptToPixel(50),+ marginRight: ptToPixel(50),+ marginLeft: ptToPixel(50),+ renderConfig: {+ vertexAngle: 0,+ centerAngle: 0,+ },+ },+};diff --git a/examples/src/data/docs/default-document-data-en.ts b/examples/src/data/docs/default-document-data-en.tsindex adffa67b71..3bb5d27d5c 100644--- a/examples/src/data/docs/default-document-data-en.ts+++ b/examples/src/data/docs/default-document-data-en.ts@@ -251,8 +251,8 @@ export const DEFAULT_DOCUMENT_DATA_EN: IDocumentData = {{startIndex: 253,paragraphStyle: {- spaceAbove: 20,- indentFirstLine: 20,+ spaceAbove: 30,+ lineSpacing: 1.5,},},{@@ -260,6 +260,7 @@ export const DEFAULT_DOCUMENT_DATA_EN: IDocumentData = {paragraphStyle: {spaceAbove: 20,indentFirstLine: 20,+ lineSpacing: 1.5,},},{@@ -277,6 +278,7 @@ export const DEFAULT_DOCUMENT_DATA_EN: IDocumentData = {},paragraphStyle: {lineSpacing: 1.5,+ spaceAbove: 20,},},{@@ -290,6 +292,7 @@ export const DEFAULT_DOCUMENT_DATA_EN: IDocumentData = {},},paragraphStyle: {+ spaceAbove: 10,lineSpacing: 1.5,},},@@ -304,25 +307,30 @@ export const DEFAULT_DOCUMENT_DATA_EN: IDocumentData = {},},paragraphStyle: {+ spaceAbove: 10,lineSpacing: 1.5,},},{startIndex: 713,paragraphStyle: {+ spaceAbove: 20,indentFirstLine: 20,+ lineSpacing: 1.5,},},{startIndex: 771,paragraphStyle: {spaceAbove: 20,+ lineSpacing: 1.5,},},{startIndex: 1244,paragraphStyle: {spaceAbove: 20,+ lineSpacing: 1.5,indentFirstLine: 20,},},@@ -330,24 +338,28 @@ export const DEFAULT_DOCUMENT_DATA_EN: IDocumentData = {startIndex: 1589,paragraphStyle: {indentFirstLine: 20,+ lineSpacing: 1.5,},},{startIndex: 1986,paragraphStyle: {indentFirstLine: 20,+ lineSpacing: 1.5,},},{startIndex: 2062,paragraphStyle: {indentFirstLine: 20,+ lineSpacing: 1.5,},},{startIndex: 2294,paragraphStyle: {indentFirstLine: 20,+ lineSpacing: 1.5,},bullet: {listType: PresetListType.BULLET_LIST,@@ -362,6 +374,7 @@ export const DEFAULT_DOCUMENT_DATA_EN: IDocumentData = {startIndex: 2438,paragraphStyle: {indentFirstLine: 20,+ lineSpacing: 1.5,},bullet: {listType: PresetListType.BULLET_LIST,@@ -376,6 +389,7 @@ export const DEFAULT_DOCUMENT_DATA_EN: IDocumentData = {startIndex: 2628,paragraphStyle: {indentFirstLine: 20,+ lineSpacing: 1.5,},bullet: {listType: PresetListType.BULLET_LIST,@@ -390,9 +404,6 @@ export const DEFAULT_DOCUMENT_DATA_EN: IDocumentData = {sectionBreaks: [{startIndex: 1245,- columnProperties: [],- columnSeparatorType: ColumnSeparatorType.NONE,- sectionType: SectionType.SECTION_TYPE_UNSPECIFIED,// textDirection: textDirectionDocument,// contentDirection: textDirection!,},diff --git a/examples/src/docs/main.ts b/examples/src/docs/main.tsindex 6556c32a0d..7bcafac6dd 100644--- a/examples/src/docs/main.ts+++ b/examples/src/docs/main.ts@@ -24,7 +24,7 @@ import { UniverUIPlugin } from '@univerjs/ui';import { UniverFormulaEnginePlugin } from '@univerjs/engine-formula';-import { DEFAULT_DOCUMENT_DATA_SIMPLE } from '../data';+import { DEFAULT_DOCUMENT_DATA_CN } from '../data';import { DebuggerPlugin } from '../plugins/debugger';@@ -64,7 +64,7 @@ univer.registerPlugin(UniverDocsUIPlugin, {},});-univer.createUniverDoc(DEFAULT_DOCUMENT_DATA_SIMPLE);+univer.createUniverDoc(DEFAULT_DOCUMENT_DATA_CN);// use for console testdeclare global {diff --git a/packages/engine-render/src/components/docs/document.ts b/packages/engine-render/src/components/docs/document.tsindex 980d888348..71d9e17568 100644--- a/packages/engine-render/src/components/docs/document.ts+++ b/packages/engine-render/src/components/docs/document.ts@@ -304,6 +304,7 @@ export class Documents extends DocComponent {for (const column of columns) {const { lines, width: columnWidth } = column;+ this._drawLiquid.translateSave();this._drawLiquid.translateColumn(column);const linesCount = lines.length;@@ -480,6 +481,8 @@ export class Documents extends DocComponent {this._drawLiquid.translateRestore();}}++ this._drawLiquid.translateRestore();}}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 73df9fcc40..3cf1885141 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@@ -14,9 +14,6 @@* limitations under the License.*/-/* eslint-disable max-lines-per-function */-/* eslint-disable complexity */-import type { INumberUnit } from '@univerjs/core';import { BooleanNumber, DataStreamTreeTokenType, GridType, SpacingRule } from '@univerjs/core';@@ -103,7 +100,34 @@ function isGlyphGroupEndWithWhiteSpaces(glyphGroup: IDocumentSkeletonGlyph[]) {}}- return true;+ return isInWhiteSpace;+}++function isGlyphGroupBeyondContentBox(glyphGroup: IDocumentSkeletonGlyph[], left: number, divideWidth: number) {+ if (glyphGroup.length <= 1) {+ return false;+ }++ let width = left;+ let isBeyondContentBox = false;++ for (const g of glyphGroup) {+ if (+ g.content === DataStreamTreeTokenType.SPACE ||+ g.content === DataStreamTreeTokenType.PARAGRAPH ||+ g.streamType === DataStreamTreeTokenType.SECTION_BREAK+ ) {+ break;+ }+ width += g.width;++ if (width > divideWidth) {+ isBeyondContentBox = true;+ break;+ }+ }++ return isBeyondContentBox;}function _divideOperator(@@ -145,7 +169,7 @@ function _divideOperator(addGlyphToDivide(divide, glyphGroup, preOffsetLeft);} else if (// If a line of text ends with consecutive spaces, the spaces should not be placed on the second line.- divideInfo.isLast && isGlyphGroupEndWithWhiteSpaces(glyphGroup)+ divideInfo.isLast && !isGlyphGroupBeyondContentBox(glyphGroup, preOffsetLeft, divide.width) && isGlyphGroupEndWithWhiteSpaces(glyphGroup)) {addGlyphToDivide(divide, glyphGroup, preOffsetLeft);} else if (divide?.glyphGroup.length === 0) {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.tsindex a5443668ef..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@@ -109,7 +109,6 @@ function _getNextPageNumber(lastPage: IDocumentSkeletonPage) {return lastPage.pageNumber + 1;}-// eslint-disable-next-line max-lines-per-functionexport function lineBreaking(shapedTextList: IShapedText[],curPage: IDocumentSkeletonPage,diff --git a/packages/engine-render/src/components/docs/layout/doc-skeleton.ts b/packages/engine-render/src/components/docs/layout/doc-skeleton.tsindex 2e2fbc3fbe..7af4eaaa8c 100644--- a/packages/engine-render/src/components/docs/layout/doc-skeleton.ts+++ b/packages/engine-render/src/components/docs/layout/doc-skeleton.ts@@ -240,7 +240,7 @@ export class DocumentSkeleton extends Skeleton {return glyphGroup[glyph];}- // eslint-disable-next-line max-lines-per-function+findNodeByCoord(coord: Vector2,pageLayoutType: PageLayoutType,@@ -473,7 +473,7 @@ export class DocumentSkeleton extends Skeleton {* Split the document according to SectionBreak and perform layout calculations.* @returns view model: skeleton*/- // eslint-disable-next-line max-lines-per-function+private _createSkeleton(_bounds?: IViewportBound) {// 每一个布局const DEFAULT_PAGE_SIZE = { width: Number.POSITIVE_INFINITY, height: Number.POSITIVE_INFINITY };