Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sheets): the text is aligned at editorial and non-editorial states #1874

Merged
merged 3 commits into from
Apr 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions examples/src/data/docs/default-document-data-cn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export const DEFAULT_DOCUMENT_DATA_CN: IDocumentData = {
{
startIndex: 4,
paragraphStyle: {
spaceAbove: 10,
spaceAbove: 0,
lineSpacing: 2,
spaceBelow: 0,
},
Expand Down Expand Up @@ -601,8 +601,8 @@ export const DEFAULT_DOCUMENT_DATA_CN: IDocumentData = {
},
marginTop: ptToPixel(50),
marginBottom: ptToPixel(50),
marginRight: ptToPixel(40),
marginLeft: ptToPixel(40),
marginRight: ptToPixel(50),
marginLeft: ptToPixel(50),
renderConfig: {
vertexAngle: 0,
centerAngle: 0,
Expand Down
5 changes: 3 additions & 2 deletions packages/docs-ui/src/controllers/page-render.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,15 @@ export class PageRenderController extends Disposable {
ctx.save();

ctx.translate(pageLeft - 0.5, pageTop - 0.5);
Rect.drawWith(ctx, {
const options = {
width: pageSize?.width ?? pageWidth ?? width,
height: pageSize?.height ?? pageHeight ?? height,
strokeWidth: 1,
stroke: PAGE_STROKE_COLOR,
fill: PAGE_FILL_COLOR,
zIndex: 3,
});
};
Rect.drawWith(ctx, options);
ctx.restore();
})
)
Expand Down
1 change: 1 addition & 0 deletions packages/docs-ui/src/views/doc-canvas-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export class DocCanvasView extends RxDisposable {
}
}

// eslint-disable-next-line max-lines-per-function
private _addNewRender() {
const documentModel = this._currentDocumentModel;

Expand Down
7 changes: 5 additions & 2 deletions packages/engine-render/src/components/docs/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/


import './extensions';

import type { Nullable, Observer } from '@univerjs/core';
Expand Down Expand Up @@ -189,6 +190,7 @@ export class Documents extends DocComponent {
return (this.getScene() as Scene).getEngine();
}


override draw(ctx: UniverRenderingContext, bounds?: IViewportBound) {
const documentSkeleton = this.getSkeleton();

Expand Down Expand Up @@ -529,10 +531,11 @@ export class Documents extends DocComponent {
if (verticalAlign === VerticalAlign.MIDDLE) {
offsetTop = (this.height - pageHeight) / 2;
} else if (verticalAlign === VerticalAlign.TOP) {
offsetTop = pagePaddingTop;
} else {
offsetTop = 0;
} else { // VerticalAlign.UNSPECIFIED follow the same rule as HorizontalAlign.BOTTOM.
offsetTop = this.height - pageHeight - pagePaddingBottom;
}

return offsetTop;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ export class DocumentSkeleton extends Skeleton {
return glyphGroup[glyph];
}

// eslint-disable-next-line max-lines-per-function
findNodeByCoord(
coord: Vector2,
pageLayoutType: PageLayoutType,
Expand Down Expand Up @@ -470,6 +471,7 @@ export class DocumentSkeleton extends Skeleton {
* Split the document according to SectionBreak and perform layout calculations.
* @returns view model: skeleton
*/
// eslint-disable-next-line max-lines-per-function
private _createSkeleton(_bounds?: IViewportBound) {
// 每一个布局
const DEFAULT_PAGE_SIZE = { width: Number.POSITIVE_INFINITY, height: Number.POSITIVE_INFINITY };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* limitations under the License.
*/

/* eslint-disable max-lines-per-function */

import type { ICellData, IRange, IScale, ObjectMatrix } from '@univerjs/core';
import { HorizontalAlign, WrapStrategy } from '@univerjs/core';

Expand All @@ -24,6 +26,7 @@ import type { IFontCacheItem } from '../interfaces';
import type { SheetComponent } from '../sheet-component';
import { getDocsSkeletonPageSize, type SpreadsheetSkeleton } from '../sheet-skeleton';
import { VERTICAL_ROTATE_ANGLE } from '../../../basics/text-rotation';
import { FIX_ONE_PIXEL_BLUR_OFFSET } from '../../../basics';
import { SheetExtension } from './sheet-extension';

const UNIQUE_KEY = 'DefaultFontExtension';
Expand Down Expand Up @@ -80,6 +83,7 @@ export class Font extends SheetExtension {
Object.keys(fontList).forEach((fontFormat: string) => {
const fontObjectArray = fontList[fontFormat];

// eslint-disable-next-line complexity
fontObjectArray.forValue((rowIndex, columnIndex, docsConfig) => {
const cellInfo = this.getCellIndex(
rowIndex,
Expand Down Expand Up @@ -225,7 +229,7 @@ export class Font extends SheetExtension {
);
}

ctx.translate(startX, startY);
ctx.translate(startX + FIX_ONE_PIXEL_BLUR_OFFSET, startY + FIX_ONE_PIXEL_BLUR_OFFSET);
this._renderDocuments(ctx, docsConfig, startX, startY, endX, endY, rowIndex, columnIndex, overflowCache);
ctx.restore();
});
Expand Down
11 changes: 7 additions & 4 deletions packages/engine-render/src/components/sheets/sheet-skeleton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* limitations under the License.
*/

/* eslint-disable max-lines-per-function */

import type {
BorderStyleTypes,
IBorderStyleData,
Expand Down Expand Up @@ -199,8 +201,8 @@ export interface IDocumentLayoutObject {
}

const DEFAULT_PADDING_DATA = {
t: 0,
b: 0,
t: 1,
b: 1,
l: 2,
r: 2,
};
Expand Down Expand Up @@ -1625,6 +1627,7 @@ export class SpreadsheetSkeleton extends Skeleton {
}
}

// eslint-disable-next-line complexity
private _setCellCache(r: number, c: number, skipBackgroundAndBorder: boolean, mergeRange?: IRange) {
const needsRendering = this._renderedCellCache.getValue(r, c);

Expand Down Expand Up @@ -1808,9 +1811,9 @@ export class SpreadsheetSkeleton extends Skeleton {
const {
textRotation,
paddingData = {
t: 2,
t: 1,
r: 2,
b: 0,
b: 1,
l: 2,
},
horizontalAlign = HorizontalAlign.UNSPECIFIED,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,16 +236,19 @@ export class StartEditController extends Disposable {
documentDataModel.updateDocumentDataMargin(paddingData);
} else {
// Set the top margin under vertical alignment.
let offsetTop = (editorHeight - actualHeight) || 0;
let offsetTop = 0;

if (verticalAlign === VerticalAlign.MIDDLE) {
offsetTop = (editorHeight - actualHeight) / 2;
offsetTop = (editorHeight - actualHeight) / 2 / scaleY;
} else if (verticalAlign === VerticalAlign.TOP) {
offsetTop = paddingData.t || 0;
offsetTop = 0;
} else { // VerticalAlign.UNSPECIFIED follow the same rule as HorizontalAlign.BOTTOM.
offsetTop = (editorHeight - actualHeight) / scaleY - (paddingData.b || 0);
}

offsetTop /= scaleY;
// offsetTop /= scaleY;
offsetTop = offsetTop < (paddingData.t || 0) ? paddingData.t || 0 : offsetTop;

documentDataModel.updateDocumentDataMargin({
t: offsetTop,
});
Expand Down Expand Up @@ -322,6 +325,7 @@ export class StartEditController extends Disposable {
* determine whether a scrollbar appears,
* and calculate the editor's boundaries relative to the browser.
*/
// eslint-disable-next-line max-lines-per-function
private _editAreaProcessing(
editorWidth: number,
editorHeight: number,
Expand Down Expand Up @@ -453,8 +457,10 @@ export class StartEditController extends Disposable {
}

// You can double-click on the cell or input content by keyboard to put the cell into the edit state.
// eslint-disable-next-line max-lines-per-function
private _initialStartEdit() {
this.disposeWithMe(
// eslint-disable-next-line max-lines-per-function
this._editorBridgeService.visible$.subscribe((param) => {
const { visible, eventType, keycode } = param;

Expand Down
1 change: 1 addition & 0 deletions packages/sheets-ui/src/services/editor-bridge.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ export class EditorBridgeService extends Disposable implements IEditorBridgeServ
return this._currentEditCellState;
}

// eslint-disable-next-line max-lines-per-function
getLatestEditCellState() {
const currentEditCell = this._currentEditCell;
if (currentEditCell == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const EDITOR_DEFAULT_POSITION = {
* Floating editor's container.
* @returns
*/
// eslint-disable-next-line max-lines-per-function
export const EditorContainer: React.FC<ICellIEditorProps> = () => {
const [state, setState] = useState({
...EDITOR_DEFAULT_POSITION,
Expand Down Expand Up @@ -89,8 +90,8 @@ export const EditorContainer: React.FC<ICellIEditorProps> = () => {
});
} else {
setState({
width: endX - startX - FIX_ONE_PIXEL_BLUR_OFFSET,
height: endY - startY - FIX_ONE_PIXEL_BLUR_OFFSET,
width: endX - startX - FIX_ONE_PIXEL_BLUR_OFFSET + 2,
height: endY - startY - FIX_ONE_PIXEL_BLUR_OFFSET + 2,
left: startX + FIX_ONE_PIXEL_BLUR_OFFSET,
top: startY + FIX_ONE_PIXEL_BLUR_OFFSET,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

border: 1px solid rgb(var(--primary-color));
box-shadow: none;
box-sizing: border-box;

.editor-input {
position: relative;
Expand All @@ -21,5 +22,11 @@
height: 100%;

background: white;

canvas {
position: absolute;
top: -1px !important;
left: -1px !important;
}
}
}
3 changes: 2 additions & 1 deletion packages/sheets-ui/src/views/formula-bar/FormulaBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ enum ArrowDirection {
Up,
}

// eslint-disable-next-line max-lines-per-function
export function FormulaBar() {
const [iconStyle, setIconStyle] = useState<string>(styles.formulaGrey);
const [arrowDirection, setArrowDirection] = useState<ArrowDirection>(ArrowDirection.Down);
Expand Down Expand Up @@ -65,7 +66,7 @@ export function FormulaBar() {
paragraphLineGapDefault: 0,
renderConfig: {
horizontalAlign: HorizontalAlign.UNSPECIFIED,
verticalAlign: VerticalAlign.TOP,
verticalAlign: VerticalAlign.UNSPECIFIED,
centerAngle: 0,
vertexAngle: 0,
wrapStrategy: WrapStrategy.WRAP,
Expand Down
Loading