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(slides): fix slide text err when import (#7114)

VicKund179f247170e
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.ts
index 239eccb574..cac5501bf1 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
@@ -30,7 +30,7 @@ import type {
IFloatObject,
ILayoutContext,
} from '../../tools';
-import { BooleanNumber, DataStreamTreeTokenType, GridType, NAMED_STYLE_SPACE_MAP, ObjectRelativeFromV, PositionedObjectLayoutType, SpacingRule, TableTextWrapType } from '@univerjs/core';
+import { BooleanNumber, DataStreamTreeTokenType, GridType, NAMED_STYLE_SPACE_MAP, ObjectRelativeFromV, PositionedObjectLayoutType, SpacingRule, TableTextWrapType, WrapStrategy } from '@univerjs/core';
import { GlyphType, LineType } from '../../../../../basics/i-document-skeleton-cached';
import { BreakPointType } from '../../line-breaker/break';
import { addGlyphToDivide, createSkeletonBulletGlyph } from '../../model/glyph';
@@ -146,6 +146,12 @@ function isGlyphGroupBeyondContentBox(glyphGroup: IDocumentSkeletonGlyph[], left
return isBeyondContentBox;
}
+function shouldKeepOverflowingTextOnLine(sectionBreakConfig: ISectionBreakConfig): boolean {
+ const wrapStrategy = sectionBreakConfig.renderConfig?.wrapStrategy;
+
+ return wrapStrategy === WrapStrategy.CLIP || wrapStrategy === WrapStrategy.OVERFLOW;
+}
+
// Gets the number of consecutive lines ending with a hyphen.
function _getConsecutiveHyphenLineCount(divide: IDocumentSkeletonDivide) {
const column = divide.parent?.parent;
@@ -213,6 +219,12 @@ function _divideOperator(
const { hyphenationZone } = sectionBreakConfig;
if (preOffsetLeft + width > divide.width) {
+ if (shouldKeepOverflowingTextOnLine(sectionBreakConfig)) {
+ addGlyphToDivide(divide, glyphGroup, preOffsetLeft);
+ updateDivideInfo(divide, { breakType: breakPointType });
+ return;
+ }
+
// width exceeds divide width
updateDivideInfo(divide, {
isFull: true,
diff --git a/packages/engine-render/src/components/docs/layout/block/paragraph/line-adjustment.ts b/packages/engine-render/src/components/docs/layout/block/paragraph/line-adjustment.ts
index bea05369d9..2bd9309cf0 100644
--- a/packages/engine-render/src/components/docs/layout/block/paragraph/line-adjustment.ts
+++ b/packages/engine-render/src/components/docs/layout/block/paragraph/line-adjustment.ts
@@ -19,7 +19,7 @@ import type { ISectionBreakConfig } from '../../../../../basics';
import type { IDocumentSkeletonDivide, IDocumentSkeletonLine, IDocumentSkeletonPage } from '../../../../../basics/i-document-skeleton-cached';
import type { DataStreamTreeNode } from '../../../view-model/data-stream-tree-node';
import type { DocumentViewModel } from '../../../view-model/document-view-model';
-import { HorizontalAlign } from '@univerjs/core';
+import { HorizontalAlign, WrapStrategy } from '@univerjs/core';
import { hasCJK, hasCJKText, isCjkLeftAlignedPunctuation, isCjkRightAlignedPunctuation } from '../../../../../basics/tools';
import { BreakPointType } from '../../line-breaker/break';
import { isLetter } from '../../line-breaker/enhancers/utils';
@@ -124,7 +124,38 @@ function adjustGlyphsInDivide(divide: IDocumentSkeletonDivide, justificationRati
* Therefore, multiple calculations are performed, which may impact performance.
* Needs optimization for efficiency.
*/
-function horizontalAlignHandler(line: IDocumentSkeletonLine, horizontalAlign: HorizontalAlign) {
+function shouldAllowOverflowHorizontalOffset(sectionBreakConfig: ISectionBreakConfig): boolean {
+ const wrapStrategy = sectionBreakConfig.renderConfig?.wrapStrategy;
+
+ return wrapStrategy === WrapStrategy.OVERFLOW;
+}
+
+function getGlyphGroupInkBounds(divide: IDocumentSkeletonDivide): { left: number; right: number } | null {
+ if (divide.glyphGroup.length === 0) {
+ return null;
+ }
+
+ let left = Infinity;
+ let right = -Infinity;
+
+ for (const glyph of divide.glyphGroup) {
+ const glyphLeft = glyph.left + glyph.xOffset;
+ left = Math.min(left, glyphLeft);
+ right = Math.max(right, glyphLeft + glyph.bBox.width);
+ }
+
+ if (!Number.isFinite(left) || !Number.isFinite(right)) {
+ return null;
+ }
+
+ return { left, right };
+}
+
+function horizontalAlignHandler(
+ line: IDocumentSkeletonLine,
+ horizontalAlign: HorizontalAlign,
+ allowOverflowHorizontalOffset = false
+) {
const { divides } = line;
for (let i = 0; i < divides.length; i++) {
@@ -184,14 +215,22 @@ function horizontalAlignHandler(line: IDocumentSkeletonLine, horizontalAlign: Ho
}
}
- if (horizontalAlign === HorizontalAlign.CENTER) {
+ const inkBounds = allowOverflowHorizontalOffset ? getGlyphGroupInkBounds(divide) : null;
+
+ if (horizontalAlign === HorizontalAlign.CENTER && inkBounds) {
+ divide.paddingLeft = width / 2 - (inkBounds.left + inkBounds.right) / 2;
+ } else if (horizontalAlign === HorizontalAlign.RIGHT && inkBounds) {
+ divide.paddingLeft = width - inkBounds.right;
+ } else if (horizontalAlign === HorizontalAlign.CENTER) {
divide.paddingLeft = (width - glyphGroupWidth) / 2;
} else if (horizontalAlign === HorizontalAlign.RIGHT) {
divide.paddingLeft = width - glyphGroupWidth;
}
- // To fix https://github.com/dream-num/univer-pro/issues/2930
- divide.paddingLeft = Math.max(divide.paddingLeft, 0);
+ if (!allowOverflowHorizontalOffset) {
+ // To fix https://github.com/dream-num/univer-pro/issues/2930
+ divide.paddingLeft = Math.max(divide.paddingLeft, 0);
+ }
}
}
@@ -296,6 +335,6 @@ export function lineAdjustment(
// Add dash to the end of divide when divide is break by Hyphen.
addHyphenDash(line, viewModel, paragraphNode, sectionBreakConfig, paragraphStyle);
// Handle horizontal align: left\center\right\justified.
- horizontalAlignHandler(line, horizontalAlign);
+ horizontalAlignHandler(line, horizontalAlign, shouldAllowOverflowHorizontalOffset(sectionBreakConfig));
});
}