Skip to content

Commit

Permalink
fix: cal page size in modern mode (#4128)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jocs authored Nov 23, 2024
1 parent 814bc84 commit a58350b
Showing 1 changed file with 30 additions and 8 deletions.
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 };
}

0 comments on commit a58350b

Please sign in to comment.