From ca5c4be9c39f374ccbb1bb6ea126b06fa978c885 Mon Sep 17 00:00:00 2001 From: Hufe921 Date: Sat, 25 Mar 2023 20:23:56 +0800 Subject: [PATCH] fix: position header and footer zone --- src/editor/core/position/Position.ts | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/editor/core/position/Position.ts b/src/editor/core/position/Position.ts index 77ffc05..71035c2 100644 --- a/src/editor/core/position/Position.ts +++ b/src/editor/core/position/Position.ts @@ -332,30 +332,32 @@ export class Position { } } if (!isLastArea) { - const mainLastLetterList = isMainActive - ? lastLetterList - : this.getOriginalMainPositionList().filter(p => p.isLastLetter && p.pageNo === positionNo) - const firstPosition = mainLastLetterList[0] - const lastPosition = mainLastLetterList[mainLastLetterList.length - 1] + // 页眉底部距离页面顶部距离 + const header = this.draw.getHeader() + const headerBottomY = header.getHeaderTop() + header.getHeight() + // 页脚上部距离页面顶部距离 + const footer = this.draw.getFooter() + const pageHeight = this.draw.getHeight() + const footerTopY = pageHeight - (footer.getFooterBottom() + footer.getHeight()) // 判断所属位置是否属于页眉页脚区域 if (isMainActive) { - // 页眉:当前位置小于第一行的上边距 - if (y < firstPosition.coordinate.leftTop[1]) { + // 页眉:当前位置小于页眉底部位置 + if (y < headerBottomY) { return { index: -1, zone: EditorZone.HEADER } } - // 页脚:当前位置大于最后一行的下边距 - if (y > lastPosition.coordinate.leftBottom[1]) { + // 页脚:当前位置大于页脚顶部位置 + if (y > footerTopY) { return { index: -1, zone: EditorZone.FOOTER } } } else { - // main区域:当前位置大于第一行的上边距 && 小于最后一行的下边距 - if (y >= firstPosition.coordinate.leftTop[1] && y <= lastPosition.coordinate.leftBottom[1]) { + // main区域:当前位置小于页眉底部位置 && 大于页脚顶部位置 + if (y <= footerTopY && y >= headerBottomY) { return { index: -1, zone: EditorZone.MAIN