diff --git a/packages/engine-render/src/components/docs/layout/block/paragraph/layout-ruler.ts b/packages/engine-render/src/components/docs/layout/block/paragraph/layout-ruler.ts index 4c1f64ad724..3ec132cd142 100644 --- a/packages/engine-render/src/components/docs/layout/block/paragraph/layout-ruler.ts +++ b/packages/engine-render/src/components/docs/layout/block/paragraph/layout-ruler.ts @@ -30,7 +30,7 @@ import type { IFloatObject, ILayoutContext, } from '../../tools'; -import { BooleanNumber, DataStreamTreeTokenType, GridType, ObjectRelativeFromV, PositionedObjectLayoutType, SpacingRule, TableTextWrapType } from '@univerjs/core'; +import { BooleanNumber, DataStreamTreeTokenType, GridType, ObjectRelativeFromV, PositionedObjectLayoutType, SpacingRule, TableTextWrapType, Tools } from '@univerjs/core'; import { GlyphType, LineType } from '../../../../../basics/i-document-skeleton-cached'; import { BreakPointType } from '../../line-breaker/break'; import { addGlyphToDivide, createSkeletonBulletGlyph } from '../../model/glyph'; @@ -1246,19 +1246,20 @@ export function updateInlineDrawingPosition( const { size, angle } = docTransform; const { width = 0, height = 0 } = size; const glyphHeight = glyph.bBox.bd + glyph.bBox.ba; - - drawing.aLeft = page.marginLeft + column.left + divide.left + divide.paddingLeft + glyph.left + 0.5 * glyph.width - 0.5 * width || 0; - drawing.aTop = page.marginTop + top + lineHeight - 0.5 * glyphHeight - 0.5 * height - marginBottom; - drawing.width = width; - drawing.height = height; - drawing.angle = angle; - drawing.isPageBreak = isPageBreak; - drawing.lineTop = top; - drawing.columnLeft = column.left; - drawing.blockAnchorTop = blockAnchorTop ?? top; - drawing.lineHeight = line.lineHeight; - - drawings.set(drawing.drawingId, drawing); + const copyDrawing = Tools.deepClone(drawing); + + copyDrawing.aLeft = page.marginLeft + column.left + divide.left + divide.paddingLeft + glyph.left + 0.5 * glyph.width - 0.5 * width || 0; + copyDrawing.aTop = page.marginTop + top + lineHeight - 0.5 * glyphHeight - 0.5 * height - marginBottom; + copyDrawing.width = width; + copyDrawing.height = height; + copyDrawing.angle = angle; + copyDrawing.isPageBreak = isPageBreak; + copyDrawing.lineTop = top; + copyDrawing.columnLeft = column.left; + copyDrawing.blockAnchorTop = blockAnchorTop ?? top; + copyDrawing.lineHeight = line.lineHeight; + + drawings.set(copyDrawing.drawingId, copyDrawing); } } } diff --git a/packages/engine-render/src/components/docs/layout/doc-skeleton.ts b/packages/engine-render/src/components/docs/layout/doc-skeleton.ts index f0b32ed4dce..2c4cacbda89 100644 --- a/packages/engine-render/src/components/docs/layout/doc-skeleton.ts +++ b/packages/engine-render/src/components/docs/layout/doc-skeleton.ts @@ -1167,7 +1167,11 @@ export class DocumentSkeleton extends Skeleton { spaceBetweenEqualWidthColumns ); isContinuous = true; - } else if (layoutAnchor == null || curSkeletonPage == null) { + } else if ( + layoutAnchor == null || + curSkeletonPage == null || + (sectionType === SectionType.NEXT_PAGE && layoutAnchor && startSectionIndex !== i) + ) { curSkeletonPage = createSkeletonPage( ctx, sectionBreakConfig, @@ -1217,6 +1221,8 @@ export class DocumentSkeleton extends Skeleton { updatePagesLeft(skeleton.pages); // Calculate inline drawing position and update. updateInlineDrawingCoords(ctx, skeleton.pages); + + // Update the position of inline drawing in header and footer. for (const hSkeMap of skeleton.skeHeaders.values()) { for (const page of hSkeMap.values()) { updateInlineDrawingCoords(ctx, [page]); @@ -1227,6 +1233,7 @@ export class DocumentSkeleton extends Skeleton { updateInlineDrawingCoords(ctx, [page]); } } + setPageParent(skeleton.pages, skeleton); return skeleton; diff --git a/packages/engine-render/src/components/docs/layout/model/line.ts b/packages/engine-render/src/components/docs/layout/model/line.ts index 324f3b1a957..6a64015667f 100644 --- a/packages/engine-render/src/components/docs/layout/model/line.ts +++ b/packages/engine-render/src/components/docs/layout/model/line.ts @@ -152,7 +152,7 @@ export function calculateLineTopByDrawings( if (headerPage && headersDrawings) { headersDrawings.forEach((drawing) => { const transformedDrawing = translateHeaderFooterDrawingPosition(drawing, headerPage, page, true); - const top = _getLineTopWidthWrapTopBottom(transformedDrawing, lineHeight, lineTop, column); + const top = _getLineTopWidthWrapTopBottom(transformedDrawing, lineHeight, lineTop, column, page); if (top) { maxTop = Math.max(maxTop, top); } @@ -162,7 +162,7 @@ export function calculateLineTopByDrawings( if (footerPage && footersDrawings) { footersDrawings.forEach((drawing) => { const transformedDrawing = translateHeaderFooterDrawingPosition(drawing, footerPage, page, false); - const top = _getLineTopWidthWrapTopBottom(transformedDrawing, lineHeight, lineTop, column); + const top = _getLineTopWidthWrapTopBottom(transformedDrawing, lineHeight, lineTop, column, page); if (top) { maxTop = Math.max(maxTop, top); } @@ -170,7 +170,7 @@ export function calculateLineTopByDrawings( } pageSkeDrawings?.forEach((drawing) => { - const top = _getLineTopWidthWrapTopBottom(drawing, lineHeight, lineTop, column); + const top = _getLineTopWidthWrapTopBottom(drawing, lineHeight, lineTop, column, page); if (top) { maxTop = Math.max(maxTop, top); } @@ -188,7 +188,8 @@ export function calculateLineTopByDrawings( function _getLineTopWidthWrapNone( table: IDocumentSkeletonTable, - lineHeight: number, lineTop: number, + lineHeight: number, + lineTop: number, column: IDocumentSkeletonColumn ) { const { top, height, left, width } = table; @@ -206,11 +207,13 @@ function _getLineTopWidthWrapTopBottom( drawing: IDocumentSkeletonDrawing, lineHeight: number, lineTop: number, - column: IDocumentSkeletonColumn + column: IDocumentSkeletonColumn, + page: IDocumentSkeletonPage ) { const { aTop, height, aLeft, width, angle = 0, drawingOrigin } = drawing; const { layoutType, distT = 0, distB = 0, distL = 0, distR = 0 } = drawingOrigin; const { left: colLeft, width: colWidth } = column; + const { marginTop, marginLeft } = page; if (layoutType !== PositionedObjectLayoutType.WRAP_TOP_AND_BOTTOM) { return; @@ -223,9 +226,9 @@ function _getLineTopWidthWrapTopBottom( // } if (angle === 0) { - const newAtop = aTop - distT; + const newAtop = aTop - distT - marginTop; const newHeight = distT + height + distB; - const newALeft = aLeft - distL; + const newALeft = aLeft - distL - marginLeft; const newWidth = distL + width + distR; if (newAtop + newHeight < lineTop || newAtop > lineHeight + lineTop || colLeft + colWidth < newALeft || colLeft > newALeft + newWidth) { @@ -237,9 +240,9 @@ function _getLineTopWidthWrapTopBottom( // 旋转的情况,要考虑行首位与 drawing 旋转后得到的最大区域 let { top: sTop = 0, height: sHeight = 0, width: sWidth = 0, left: sLeft = 0 } = getBoundingBox(angle, aLeft, width, aTop, height); - sTop -= distT; + sTop = sTop - distT - marginTop; sHeight += distT + distB; - sLeft = sLeft - distL; + sLeft = sLeft - distL - marginLeft; sWidth += distL + distR; if (sTop + sHeight < lineTop || sTop > lineHeight + lineTop || colLeft + colWidth < sLeft || colLeft > sLeft + sWidth) { diff --git a/packages/engine-render/src/components/docs/layout/model/page.ts b/packages/engine-render/src/components/docs/layout/model/page.ts index 9242f6dfc62..707745469b2 100644 --- a/packages/engine-render/src/components/docs/layout/model/page.ts +++ b/packages/engine-render/src/components/docs/layout/model/page.ts @@ -242,9 +242,11 @@ function _createSkeletonHeaderFooter( footerTreeMap, headerTreeMap, pageSize: { - width: pageWidth - marginLeft - marginRight, + width: pageWidth, height: getHeaderFooterMaxHeight(pageHeight) - (isHeader ? marginHeader : marginFooter) - 5, }, + marginLeft, + marginRight, localeService, drawings, };