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: cal page size in modern mode #4128

Merged
merged 1 commit into from
Nov 23, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import type { DocumentDataModel, EventState, ICommandInfo, Nullable } from '@univerjs/core';
import type { IRichTextEditingMutationParams } from '@univerjs/docs';
import type { DocumentSkeleton, IRenderContext, IRenderModule, IWheelEvent } from '@univerjs/engine-render';
import type { DocumentSkeleton, IDocumentSkeletonPage, IRenderContext, IRenderModule, IWheelEvent } from '@univerjs/engine-render';
import { DocumentFlavor, ICommandService, Inject, IUniverInstanceService, RxDisposable, UniverInstanceType } from '@univerjs/core';
import { DocSkeletonManagerService, RichTextEditingMutation } from '@univerjs/docs';
import { DocBackground, Documents, IRenderManagerService, Layer, PageLayoutType, ScrollBar, Viewport } from '@univerjs/engine-render';
Expand Down Expand Up @@ -216,17 +216,14 @@ export class DocRenderController extends RxDisposable implements IRenderModule {

for (let i = 0, len = pages.length; i < len; i++) {
const page = pages[i];
let { pageWidth, pageHeight, marginLeft, marginRight, marginTop, marginBottom } = page;
let { pageWidth, pageHeight } = page;

// Mainly for modern mode, because pageHeight will be INFINITY in modern mode.
if (documentFlavor === DocumentFlavor.MODERN) {
if (pageWidth === Number.POSITIVE_INFINITY) {
pageWidth = page.width + marginLeft + marginRight;
}
const modernPageSize = getPageSizeInModernMode(page);

if (pageHeight === Number.POSITIVE_INFINITY) {
pageHeight = page.height + marginTop + marginBottom;
}
pageWidth = modernPageSize.pageWidth;
pageHeight = modernPageSize.pageHeight;
}

if (docsComponent.pageLayoutType === PageLayoutType.VERTICAL) {
Expand Down Expand Up @@ -260,3 +257,28 @@ export class DocRenderController extends RxDisposable implements IRenderModule {
}
}
}

function getPageSizeInModernMode(page: IDocumentSkeletonPage) {
let { pageWidth, pageHeight } = page;
const { marginLeft, marginRight, marginTop, marginBottom, skeDrawings, skeTables } = page;

if (pageWidth === Number.POSITIVE_INFINITY) {
pageWidth = page.width + marginLeft + marginRight;
}

if (pageHeight === Number.POSITIVE_INFINITY) {
pageHeight = page.height + marginTop + marginBottom;
}

for (const drawing of skeDrawings.values()) {
pageWidth = Math.max(pageWidth, drawing.aLeft + drawing.width + marginLeft + marginRight);
pageHeight = Math.max(pageHeight, drawing.aTop + drawing.height + marginTop + marginBottom);
}

for (const table of skeTables.values()) {
pageWidth = Math.max(pageWidth, table.left + table.width + marginLeft + marginRight);
pageHeight = Math.max(pageHeight, table.top + table.height + marginTop + marginBottom);
}

return { pageWidth, pageHeight };
}
Loading