fix(aligan): update (#6798)

This commit is contained in:
Univer
2026-04-12 13:05:52 +08:00
committed by GitHub
parent c149583029
commit f5db141bbe
4 changed files with 31 additions and 10 deletions
@@ -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 {
@@ -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) {
@@ -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;
}
}
@@ -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 {