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(render): fix horizontal alignment (#5887)
wpxp123456f3d3b2096a59
diff --git a/packages/engine-render/src/shape/text.ts b/packages/engine-render/src/shape/text.tsindex 4c95814491..cf521ec2de 100644--- a/packages/engine-render/src/shape/text.ts+++ b/packages/engine-render/src/shape/text.ts@@ -91,15 +91,20 @@ export class Text extends Shape<ITextProps> {* - WPS: As the cell width decreases, the excess number will be displayed as "...", so the text width will always be less than the cell width.* We use google sheets behavior here, which is to left-align the text when the cell width is less than the text width and not wrapped.*/- const lineX = (- hAlign === HorizontalAlign.LEFT ||- hAlign === HorizontalAlign.UNSPECIFIED ||- (!warp && width < lineWidth && cellValueType === CellValueType.NUMBER)- )- ? 0- : (hAlign === HorizontalAlign.CENTER- ? (width - lineWidth) / 2- : (width - lineWidth));+ let lineX: number = 0;+ if (!(!warp && width < lineWidth && cellValueType === CellValueType.NUMBER)) {+ switch (hAlign) {+ case HorizontalAlign.CENTER:+ lineX = (width - lineWidth) / 2;+ break;+ case HorizontalAlign.RIGHT:+ lineX = width - lineWidth;+ break;+ default:+ lineX = 0;+ }+ }+const baselineY = lineTop + line.baseline;// Draw the text