Skip to content

Commit

Permalink
fix: header footer image position
Browse files Browse the repository at this point in the history
  • Loading branch information
Jocs committed Jan 3, 2025
1 parent 827046f commit 16f6021
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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]);
Expand All @@ -1227,6 +1233,7 @@ export class DocumentSkeleton extends Skeleton {
updateInlineDrawingCoords(ctx, [page]);
}
}

setPageParent(skeleton.pages, skeleton);

return skeleton;
Expand Down
21 changes: 12 additions & 9 deletions packages/engine-render/src/components/docs/layout/model/line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -162,15 +162,15 @@ 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);
}
});
}

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);
}
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down

0 comments on commit 16f6021

Please sign in to comment.