From f5db141bbe2dafe7e146a1d3bf64100ea072c3b0 Mon Sep 17 00:00:00 2001 From: Univer <68851825+DR-Univer@users.noreply.github.com> Date: Sun, 12 Apr 2026 13:05:52 +0800 Subject: [PATCH] fix(aligan): update (#6798) --- .../src/basics/i-document-skeleton-cached.ts | 11 ++++++----- .../src/components/docs/document.ts | 9 +++++++-- .../layout/block/paragraph/line-adjustment.ts | 3 +++ .../src/components/docs/liquid.ts | 18 +++++++++++++++--- 4 files changed, 31 insertions(+), 10 deletions(-) diff --git a/packages/engine-render/src/basics/i-document-skeleton-cached.ts b/packages/engine-render/src/basics/i-document-skeleton-cached.ts index ced396ab73..4cb14e5aac 100644 --- a/packages/engine-render/src/basics/i-document-skeleton-cached.ts +++ b/packages/engine-render/src/basics/i-document-skeleton-cached.ts @@ -195,16 +195,17 @@ export interface IDocumentSkeletonLine { } export interface IDocumentSkeletonDivide { - // divide 分割,为了适配插入对象、图片、表格等,图文混排 + // divide: Used to adapt to inserted objects, images, tables, etc., for mixed text and graphics layout glyphGroup: IDocumentSkeletonGlyph[]; // glyphGroup - width: number; // width 被分割后的总宽度 - left: number; // left 被对象分割后的偏移位置 | d1 | | d2 | - paddingLeft: number; // paddingLeft 根据horizonAlign和width计算对齐偏移 - isFull: boolean; // isFull, // 内容是否装满 + width: number; // width: Total width after division + left: number; // left: Offset position after division by objects | d1 | | d2 | + paddingLeft: number; // paddingLeft: Alignment offset calculated based on horizonAlign and width + isFull: boolean; // isFull: Whether content is full st: number; // startIndex ed: number; // endIndex breakType?: BreakPointType; parent?: IDocumentSkeletonLine; + glyphGroupWidth?: number; // glyphGroupWidth: Total width of glyphGroup, pre-calculated to avoid recalculation each time } export interface IAdjustability { diff --git a/packages/engine-render/src/components/docs/document.ts b/packages/engine-render/src/components/docs/document.ts index 8c16055ec3..4663ad1147 100644 --- a/packages/engine-render/src/components/docs/document.ts +++ b/packages/engine-render/src/components/docs/document.ts @@ -168,6 +168,7 @@ export class Documents extends DocComponent { cellValueType, // isRotateNonEastAsian = BooleanNumber.FALSE, } = renderConfig; + const isVertical = vertexAngleDeg === VERTICAL_ROTATE_ANGLE && centerAngleDeg === VERTICAL_ROTATE_ANGLE; const horizontalOffsetNoAngle = this._horizontalHandler( actualWidth, pagePaddingLeft, @@ -260,6 +261,8 @@ export class Documents extends DocComponent { let alignOffset = alignOffsetNoAngle; let rotateTranslateXListApply = null; + let rotatedHeightStore = 0; + if (vertexAngle !== 0) { const { rotateTranslateXList, @@ -270,6 +273,8 @@ export class Documents extends DocComponent { rotateTranslateY, } = getRotateOffsetAndFarthestHypotenuse(lines, columnWidth, vertexAngle); + rotatedHeightStore = rotatedHeight; + let exceedWidthFix = rotatedWidth; if (rotatedHeight > this.height && wrapStrategy !== WrapStrategy.WRAP) { if (wrapStrategy === WrapStrategy.OVERFLOW || vertexAngle > 0) { @@ -294,7 +299,7 @@ export class Documents extends DocComponent { ); let exceedHeightFix = verticalOffset - fixOffsetY; - if (rotatedHeight > this.height) { + if (rotatedHeight > this.height && !isVertical) { if (vertexAngle < 0) { exceedHeightFix = this.height - (rotatedHeight + fixOffsetY); } else { @@ -360,7 +365,7 @@ export class Documents extends DocComponent { const { glyphGroup } = divide; this._drawLiquid.translateSave(); - this._drawLiquid.translateDivide(divide); + this._drawLiquid.translateDivide(divide, isVertical && wrapStrategy === WrapStrategy.WRAP, verticalAlign, rotatedHeightStore); // Draw text background. for (const glyph of glyphGroup) { 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 bf4c2deebd..a10aed8479 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 @@ -132,6 +132,8 @@ function horizontalAlignHandler(line: IDocumentSkeletonLine, horizontalAlign: Ho const { width } = divide; let glyphGroupWidth = getGlyphGroupWidth(divide); + divide.glyphGroupWidth = glyphGroupWidth; + if (width === Number.POSITIVE_INFINITY) { continue; } @@ -178,6 +180,7 @@ function horizontalAlignHandler(line: IDocumentSkeletonLine, horizontalAlign: Ho adjustGlyphsInDivide(divide, justificationRatio, extraJustification); // Recalculate the glyph group width, because we adjust the width and xOffset of glyphs. glyphGroupWidth = getGlyphGroupWidth(divide); + divide.glyphGroupWidth = glyphGroupWidth; } } diff --git a/packages/engine-render/src/components/docs/liquid.ts b/packages/engine-render/src/components/docs/liquid.ts index f7612421e3..3dd1bc0fed 100644 --- a/packages/engine-render/src/components/docs/liquid.ts +++ b/packages/engine-render/src/components/docs/liquid.ts @@ -22,6 +22,7 @@ import type { IDocumentSkeletonPage, IDocumentSkeletonSection, } from '../../basics/i-document-skeleton-cached'; +import { VerticalAlign } from '@univerjs/core'; import { PageLayoutType } from '../../basics/i-document-skeleton-cached'; export class Liquid { @@ -171,9 +172,20 @@ export class Liquid { }; } - translateDivide(divide: IDocumentSkeletonDivide) { - const { left: divideLeft, paddingLeft: dividePaddingLeft } = divide; - const left = divideLeft + dividePaddingLeft; + translateDivide(divide: IDocumentSkeletonDivide, isVerticalAndWrap = false, verticalAlign = VerticalAlign.UNSPECIFIED, rotatedHeight = 0) { + const { left: divideLeft, paddingLeft: dividePaddingLeft, glyphGroupWidth = 0 } = divide; + let left = divideLeft; + if (!isVerticalAndWrap) { + left += dividePaddingLeft; + } else { + if (verticalAlign === VerticalAlign.MIDDLE) { + left += (rotatedHeight - glyphGroupWidth) / 2; + } else if (verticalAlign === VerticalAlign.BOTTOM) { + left += rotatedHeight - glyphGroupWidth - 2; + } else { + left += 2; + } + } this.translate(left, 0); return {