Skip to content

Commit

Permalink
fix(sheet): string bool and number align (#1525)
Browse files Browse the repository at this point in the history
* fix(sheet): string bool and number align

* fix(doc): disappear
  • Loading branch information
DR-Univer committed Mar 9, 2024
1 parent 48c1ab8 commit 473cf6f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
5 changes: 3 additions & 2 deletions packages/core/src/types/interfaces/i-document-data.ts
Expand Up @@ -15,7 +15,7 @@
*/

import type { ISize } from '../../services/floating-object/floating-object-interfaces';
import type { BooleanNumber, HorizontalAlign, LocaleType, TextDirection, VerticalAlign, WrapStrategy } from '../enum';
import type { BooleanNumber, CellValueType, HorizontalAlign, LocaleType, TextDirection, VerticalAlign, WrapStrategy } from '../enum';
import type { IExtraModelData } from './i-extra-model-data';
import type { IColorStyle, IStyleBase } from './i-style-data';

Expand Down Expand Up @@ -364,7 +364,8 @@ export interface IDocumentRenderConfig {
horizontalAlign?: HorizontalAlign; // HorizontalAlignment, only valid for pages, word does not have this arrangement, used for secondary calculations
isRotateNonEastAsian?: BooleanNumber; // Word is not rotate non-eastAsian
background?: IColorStyle; // background
wrapStrategy?: WrapStrategy;
wrapStrategy?: WrapStrategy; // wrap to the next line, for sheet cell
cellValueType?: CellValueType; // sheet cell type, In a spreadsheet cell, without any alignment settings applied, text should be left-aligned, numbers should be right-aligned, and Boolean values should be center-aligned.
}

export interface ISectionBreakBase {
Expand Down
33 changes: 26 additions & 7 deletions packages/engine-render/src/components/docs/document.ts
Expand Up @@ -17,7 +17,7 @@
import './extensions';

import type { Nullable, Observer } from '@univerjs/core';
import { HorizontalAlign, Observable, VerticalAlign, WrapStrategy } from '@univerjs/core';
import { CellValueType, HorizontalAlign, Observable, VerticalAlign, WrapStrategy } from '@univerjs/core';

import { calculateRectRotate, getRotateOffsetAndFarthestHypotenuse } from '../../basics/draw';
import type { IDocumentSkeletonCached, IDocumentSkeletonPage } from '../../basics/i-document-skeleton-cached';
Expand Down Expand Up @@ -235,11 +235,12 @@ export class Documents extends DocComponent {
renderConfig = {},
} = page;
const {
verticalAlign = VerticalAlign.UNSPECIFIED,
horizontalAlign = HorizontalAlign.UNSPECIFIED,
verticalAlign = VerticalAlign.TOP, // Do not make changes, otherwise the document will not render.
horizontalAlign = HorizontalAlign.LEFT, // Do not make changes, otherwise the document will not render.
centerAngle: centerAngleDeg = 0,
vertexAngle: vertexAngleDeg = 0,
wrapStrategy = WrapStrategy.UNSPECIFIED,
cellValueType,
// isRotateNonEastAsian = BooleanNumber.FALSE,
} = renderConfig;

Expand All @@ -248,7 +249,8 @@ export class Documents extends DocComponent {
pagePaddingLeft,
pagePaddingRight,
horizontalAlign,
vertexAngleDeg
vertexAngleDeg,
cellValueType
);

const verticalOffsetNoAngle = this._verticalHandler(
Expand Down Expand Up @@ -457,7 +459,8 @@ export class Documents extends DocComponent {
pagePaddingLeft: number,
pagePaddingRight: number,
horizontalAlign: HorizontalAlign,
angle: number = 0
angle: number = 0,
cellValueType: Nullable<CellValueType>
) {
let offsetLeft = 0;
if (horizontalAlign === HorizontalAlign.CENTER) {
Expand All @@ -469,8 +472,24 @@ export class Documents extends DocComponent {
* In Excel, if horizontal alignment is not specified,
* rotated text aligns to the right when rotated downwards and aligns to the left when rotated upwards.
*/
if (horizontalAlign === HorizontalAlign.UNSPECIFIED && angle > 0) {
offsetLeft = this.width - pageWidth - pagePaddingRight;
if (horizontalAlign === HorizontalAlign.UNSPECIFIED) {
if (angle > 0) {
return this.width - pageWidth - pagePaddingRight;
}

/**
* sheet cell type, In a spreadsheet cell, without any alignment settings applied,
* text should be left-aligned,
* numbers should be right-aligned,
* and Boolean values should be center-aligned.
*/
if (cellValueType === CellValueType.NUMBER) {
offsetLeft = this.width - pageWidth - pagePaddingRight;
} else if (cellValueType === CellValueType.BOOLEAN) {
offsetLeft = (this.width - pageWidth) / 2;
} else {
offsetLeft = pagePaddingLeft;
}
} else {
offsetLeft = pagePaddingLeft;
}
Expand Down
Expand Up @@ -158,6 +158,8 @@ interface ICellOtherConfig {
* padding
*/
paddingData?: IPaddingData;

cellValueType?: CellValueType;
}

interface IRowColumnSegment {
Expand Down Expand Up @@ -1073,6 +1075,7 @@ export class SpreadsheetSkeleton extends Skeleton {
documentModel = this._getDocumentDataByStyle(cell.v.toString(), textStyle, {
...cellOtherConfig,
textRotation,
cellValueType: cell.t!,
});
}

Expand Down Expand Up @@ -1731,6 +1734,7 @@ export class SpreadsheetSkeleton extends Skeleton {
horizontalAlign = HorizontalAlign.UNSPECIFIED,
verticalAlign = VerticalAlign.UNSPECIFIED,
wrapStrategy = WrapStrategy.UNSPECIFIED,
cellValueType,
} = config;

const { a: angle = 0, v: isVertical = BooleanNumber.FALSE } = textRotation;
Expand Down Expand Up @@ -1777,6 +1781,7 @@ export class SpreadsheetSkeleton extends Skeleton {
centerAngle,
vertexAngle,
wrapStrategy,
cellValueType,
},
},
};
Expand Down

0 comments on commit 473cf6f

Please sign in to comment.