|
|
|
|
@ -1,10 +1,12 @@
|
|
|
|
|
import { ElementType, RowFlex, VerticalAlign } from '../..'
|
|
|
|
|
import { ZERO } from '../../dataset/constant/Common'
|
|
|
|
|
import { ControlComponent, ImageDisplay } from '../../dataset/enum/Control'
|
|
|
|
|
import { ControlComponent } from '../../dataset/enum/Control'
|
|
|
|
|
import {
|
|
|
|
|
IComputePageRowPositionPayload,
|
|
|
|
|
IComputePageRowPositionResult,
|
|
|
|
|
IComputeRowPositionPayload
|
|
|
|
|
IComputeRowPositionPayload,
|
|
|
|
|
IFloatPosition,
|
|
|
|
|
IGetFloatPositionByXYPayload
|
|
|
|
|
} from '../../interface/Position'
|
|
|
|
|
import { IEditorOption } from '../../interface/Editor'
|
|
|
|
|
import { IElement, IElementPosition } from '../../interface/Element'
|
|
|
|
|
@ -16,17 +18,20 @@ import {
|
|
|
|
|
import { Draw } from '../draw/Draw'
|
|
|
|
|
import { EditorMode, EditorZone } from '../../dataset/enum/Editor'
|
|
|
|
|
import { deepClone } from '../../utils'
|
|
|
|
|
import { ImageDisplay } from '../../dataset/enum/Common'
|
|
|
|
|
|
|
|
|
|
export class Position {
|
|
|
|
|
private cursorPosition: IElementPosition | null
|
|
|
|
|
private positionContext: IPositionContext
|
|
|
|
|
private positionList: IElementPosition[]
|
|
|
|
|
private floatPositionList: IFloatPosition[]
|
|
|
|
|
|
|
|
|
|
private draw: Draw
|
|
|
|
|
private options: Required<IEditorOption>
|
|
|
|
|
|
|
|
|
|
constructor(draw: Draw) {
|
|
|
|
|
this.positionList = []
|
|
|
|
|
this.floatPositionList = []
|
|
|
|
|
this.cursorPosition = null
|
|
|
|
|
this.positionContext = {
|
|
|
|
|
isTable: false,
|
|
|
|
|
@ -37,6 +42,10 @@ export class Position {
|
|
|
|
|
this.options = draw.getOptions()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public getFloatPositionList(): IFloatPosition[] {
|
|
|
|
|
return this.floatPositionList
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public getTablePositionList(
|
|
|
|
|
sourceElementList: IElement[]
|
|
|
|
|
): IElementPosition[] {
|
|
|
|
|
@ -149,6 +158,28 @@ export class Position {
|
|
|
|
|
rightBottom: [x + metrics.width, y + curRow.height]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 缓存浮动元素信息
|
|
|
|
|
if (
|
|
|
|
|
element.imgDisplay === ImageDisplay.FLOAT_TOP ||
|
|
|
|
|
element.imgDisplay === ImageDisplay.FLOAT_BOTTOM
|
|
|
|
|
) {
|
|
|
|
|
// 浮动元素使用上一位置信息
|
|
|
|
|
const prePosition = positionList[positionList.length - 1]
|
|
|
|
|
if (prePosition) {
|
|
|
|
|
positionItem.metrics = prePosition.metrics
|
|
|
|
|
positionItem.coordinate = prePosition.coordinate
|
|
|
|
|
}
|
|
|
|
|
this.floatPositionList.push({
|
|
|
|
|
pageNo,
|
|
|
|
|
element,
|
|
|
|
|
position: positionItem,
|
|
|
|
|
isTable: payload.isTable,
|
|
|
|
|
index: payload.index,
|
|
|
|
|
tdIndex: payload.tdIndex,
|
|
|
|
|
trIndex: payload.trIndex,
|
|
|
|
|
tdValueIndex: index
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
positionList.push(positionItem)
|
|
|
|
|
index++
|
|
|
|
|
x += metrics.width
|
|
|
|
|
@ -170,7 +201,11 @@ export class Position {
|
|
|
|
|
startIndex: 0,
|
|
|
|
|
startX: (td.x! + tdPadding[3]) * scale + tablePreX,
|
|
|
|
|
startY: (td.y! + tdPadding[0]) * scale + tablePreY,
|
|
|
|
|
innerWidth: (td.width! - tdPaddingWidth) * scale
|
|
|
|
|
innerWidth: (td.width! - tdPaddingWidth) * scale,
|
|
|
|
|
isTable: true,
|
|
|
|
|
index: index - 1,
|
|
|
|
|
tdIndex: d,
|
|
|
|
|
trIndex: t
|
|
|
|
|
})
|
|
|
|
|
// 垂直对齐方式
|
|
|
|
|
if (
|
|
|
|
|
@ -217,6 +252,7 @@ export class Position {
|
|
|
|
|
public computePositionList() {
|
|
|
|
|
// 置空原位置信息
|
|
|
|
|
this.positionList = []
|
|
|
|
|
this.floatPositionList = []
|
|
|
|
|
// 按每页行计算
|
|
|
|
|
const innerWidth = this.draw.getInnerWidth()
|
|
|
|
|
const pageRowList = this.draw.getPageRowList()
|
|
|
|
|
@ -291,6 +327,15 @@ export class Position {
|
|
|
|
|
const curPageNo = payload.pageNo ?? this.draw.getPageNo()
|
|
|
|
|
const isMainActive = zoneManager.isMainActive()
|
|
|
|
|
const positionNo = isMainActive ? curPageNo : 0
|
|
|
|
|
// 验证浮于文字上方元素
|
|
|
|
|
if (!isTable) {
|
|
|
|
|
const floatTopPosition = this.getFloatPositionByXY({
|
|
|
|
|
...payload,
|
|
|
|
|
imgDisplay: ImageDisplay.FLOAT_TOP
|
|
|
|
|
})
|
|
|
|
|
if (floatTopPosition) return floatTopPosition
|
|
|
|
|
}
|
|
|
|
|
// 普通元素
|
|
|
|
|
for (let j = 0; j < positionList.length; j++) {
|
|
|
|
|
const {
|
|
|
|
|
index,
|
|
|
|
|
@ -388,6 +433,14 @@ export class Position {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 验证衬于文字下方元素
|
|
|
|
|
if (!isTable) {
|
|
|
|
|
const floatBottomPosition = this.getFloatPositionByXY({
|
|
|
|
|
...payload,
|
|
|
|
|
imgDisplay: ImageDisplay.FLOAT_BOTTOM
|
|
|
|
|
})
|
|
|
|
|
if (floatBottomPosition) return floatBottomPosition
|
|
|
|
|
}
|
|
|
|
|
// 非命中区域
|
|
|
|
|
let isLastArea = false
|
|
|
|
|
let curPositionIndex = -1
|
|
|
|
|
@ -493,6 +546,55 @@ export class Position {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public getFloatPositionByXY(
|
|
|
|
|
payload: IGetFloatPositionByXYPayload
|
|
|
|
|
): ICurrentPosition | void {
|
|
|
|
|
const { x, y } = payload
|
|
|
|
|
for (let f = 0; f < this.floatPositionList.length; f++) {
|
|
|
|
|
const {
|
|
|
|
|
position,
|
|
|
|
|
element,
|
|
|
|
|
isTable,
|
|
|
|
|
index,
|
|
|
|
|
trIndex,
|
|
|
|
|
tdIndex,
|
|
|
|
|
tdValueIndex
|
|
|
|
|
} = this.floatPositionList[f]
|
|
|
|
|
if (
|
|
|
|
|
element.type === ElementType.IMAGE &&
|
|
|
|
|
element.imgDisplay === payload.imgDisplay
|
|
|
|
|
) {
|
|
|
|
|
const imgFloatPosition = element.imgFloatPosition!
|
|
|
|
|
if (
|
|
|
|
|
x >= imgFloatPosition.x &&
|
|
|
|
|
x <= imgFloatPosition.x + element.width! &&
|
|
|
|
|
y >= imgFloatPosition.y &&
|
|
|
|
|
y <= imgFloatPosition.y + element.height!
|
|
|
|
|
) {
|
|
|
|
|
if (isTable) {
|
|
|
|
|
return {
|
|
|
|
|
index: index!,
|
|
|
|
|
isDirectHit: true,
|
|
|
|
|
isImage: true,
|
|
|
|
|
isTable,
|
|
|
|
|
trIndex,
|
|
|
|
|
tdIndex,
|
|
|
|
|
tdValueIndex,
|
|
|
|
|
tdId: element.tdId,
|
|
|
|
|
trId: element.trId,
|
|
|
|
|
tableId: element.tableId
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return {
|
|
|
|
|
index: position.index,
|
|
|
|
|
isDirectHit: true,
|
|
|
|
|
isImage: true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public adjustPositionContext(
|
|
|
|
|
payload: IGetPositionByXYPayload
|
|
|
|
|
): ICurrentPosition | null {
|
|
|
|
|
|