feat:zoom page header

pr675
Hufe921 3 years ago
parent debc6c1283
commit c0fee3ea14

@ -405,7 +405,7 @@ export class CommandAdapt {
const { startIndex, endIndex } = this.range.getRange() const { startIndex, endIndex } = this.range.getRange()
if (!~startIndex && !~endIndex) return if (!~startIndex && !~endIndex) return
const elementList = this.draw.getElementList() const elementList = this.draw.getElementList()
const innerWidth = this.draw.getInnerWidth() const innerWidth = this.draw.getOriginalInnerWidth()
// colgroup // colgroup
const colgroup: IColgroup[] = [] const colgroup: IColgroup[] = []
const colWidth = innerWidth / col const colWidth = innerWidth / col

@ -135,7 +135,7 @@ export class Draw {
this.i18n = new I18n() this.i18n = new I18n()
this.historyManager = new HistoryManager() this.historyManager = new HistoryManager()
this.position = new Position(this) this.position = new Position(this)
this.zone = new Zone() this.zone = new Zone(this)
this.range = new RangeManager(this) this.range = new RangeManager(this)
this.margin = new Margin(this) this.margin = new Margin(this)
this.background = new Background(this) this.background = new Background(this)
@ -215,10 +215,11 @@ export class Draw {
return Math.floor(this.getOriginalHeight() * this.options.scale) return Math.floor(this.getOriginalHeight() * this.options.scale)
} }
public getOriginalMainHeight(): number { public getMainHeight(): number {
const mainHeight = this.getOriginalHeight() const pageHeight = this.getHeight()
const margins = this.getMargins()
const extraHeight = this.header.getExtraHeight() const extraHeight = this.header.getExtraHeight()
return mainHeight - extraHeight return pageHeight - margins[0] - margins[2] - extraHeight
} }
public getCanvasWidth(pageNo = -1): number { public getCanvasWidth(pageNo = -1): number {
@ -804,8 +805,9 @@ export class Draw {
metrics.boundingBoxAscent = 0 metrics.boundingBoxAscent = 0
// 表格分页处理(拆分表格) // 表格分页处理(拆分表格)
const margins = this.getMargins() const margins = this.getMargins()
const height = this.getOriginalMainHeight() const height = this.getHeight()
const marginHeight = margins[0] + margins[2] const headerExtraHeight = this.header.getExtraHeight()
const marginHeight = margins[0] + margins[2] + headerExtraHeight
let curPagePreHeight = marginHeight let curPagePreHeight = marginHeight
for (let r = 0; r < rowList.length; r++) { for (let r = 0; r < rowList.length; r++) {
const row = rowList[r] const row = rowList[r]
@ -816,7 +818,7 @@ export class Draw {
} }
} }
// 表格高度超过页面高度 // 表格高度超过页面高度
const rowMarginHeight = rowMargin * 2 const rowMarginHeight = rowMargin * 2 * scale
if (curPagePreHeight + rowMarginHeight + elementHeight > height) { if (curPagePreHeight + rowMarginHeight + elementHeight > height) {
const trList = element.trList! const trList = element.trList!
// 计算需要移除的行数 // 计算需要移除的行数
@ -826,7 +828,8 @@ export class Draw {
if (trList.length > 1) { if (trList.length > 1) {
for (let r = 0; r < trList.length; r++) { for (let r = 0; r < trList.length; r++) {
const tr = trList[r] const tr = trList[r]
if (curPagePreHeight + rowMarginHeight + preTrHeight + tr.height > height) { const trHeight = tr.height * scale
if (curPagePreHeight + rowMarginHeight + preTrHeight + trHeight > height) {
// 是否跨列 // 是否跨列
if (element.colgroup?.length !== tr.tdList.length) { if (element.colgroup?.length !== tr.tdList.length) {
deleteCount = 0 deleteCount = 0
@ -835,7 +838,7 @@ export class Draw {
} else { } else {
deleteStart = r + 1 deleteStart = r + 1
deleteCount = trList.length - deleteStart deleteCount = trList.length - deleteStart
preTrHeight += tr.height preTrHeight += trHeight
} }
} }
} }
@ -970,9 +973,10 @@ export class Draw {
private _computePageList(): IRow[][] { private _computePageList(): IRow[][] {
const pageRowList: IRow[][] = [[]] const pageRowList: IRow[][] = [[]]
const { pageMode } = this.options const { pageMode } = this.options
const height = this.getOriginalMainHeight() const height = this.getHeight()
const margins = this.getMargins() const margins = this.getMargins()
const marginHeight = margins[0] + margins[2] const headerExtraHeight = this.header.getExtraHeight()
const marginHeight = margins[0] + margins[2] + headerExtraHeight
let pageHeight = marginHeight let pageHeight = marginHeight
let pageNo = 0 let pageNo = 0
if (pageMode === PageMode.CONTINUITY) { if (pageMode === PageMode.CONTINUITY) {

@ -56,11 +56,11 @@ export class Header {
} }
private _computePositionList() { private _computePositionList() {
const { header: { top } } = this.options const headerTop = this.getHeaderTop()
const innerWidth = this.draw.getInnerWidth() const innerWidth = this.draw.getInnerWidth()
const margins = this.draw.getMargins() const margins = this.draw.getMargins()
const startX = margins[3] const startX = margins[3]
const startY = top const startY = headerTop
this.position.computePageRowPosition({ this.position.computePageRowPosition({
positionList: this.positionList, positionList: this.positionList,
rowList: this.rowList, rowList: this.rowList,
@ -72,9 +72,14 @@ export class Header {
}) })
} }
public getHeaderTop(): number {
const { header: { top }, scale } = this.options
return Math.floor(top * scale)
}
public getMaxHeight(): number { public getMaxHeight(): number {
const { header: { maxHeightRadio } } = this.options const { header: { maxHeightRadio } } = this.options
const height = this.draw.getOriginalHeight() const height = this.draw.getHeight()
return Math.floor(height * maxHeightRadioMapping[maxHeightRadio]) return Math.floor(height * maxHeightRadioMapping[maxHeightRadio])
} }
@ -89,10 +94,10 @@ export class Header {
} }
public getExtraHeight(): number { public getExtraHeight(): number {
const { header: { top: headerTop } } = this.options
// 页眉上边距 + 实际高 - 页面上边距 // 页眉上边距 + 实际高 - 页面上边距
const margins = this.draw.getOriginalMargins() const margins = this.draw.getMargins()
const headerHeight = this.getHeight() const headerHeight = this.getHeight()
const headerTop = this.getHeaderTop()
const extraHeight = headerTop + headerHeight - margins[0] const extraHeight = headerTop + headerHeight - margins[0]
return extraHeight <= 0 ? 0 : extraHeight return extraHeight <= 0 ? 0 : extraHeight
} }

@ -12,12 +12,6 @@ function dblclick(host: CanvasEvent, evt: MouseEvent) {
}) })
if (!~positionContext.index && positionContext.zone) { if (!~positionContext.index && positionContext.zone) {
draw.getZone().setZone(positionContext.zone) draw.getZone().setZone(positionContext.zone)
draw.getRange().clearRange()
draw.render({
isSubmitHistory: false,
isSetCursor: false,
isCompute: false
})
return return
} }
// 自动扩选文字 // 自动扩选文字

Loading…
Cancel
Save