From b3354ac35ff34031b3dcbeab293b69b7686afdf2 Mon Sep 17 00:00:00 2001 From: Hufe921 Date: Thu, 23 Nov 2023 22:00:21 +0800 Subject: [PATCH] fix: scaling table and separator elements error #326 --- src/editor/core/draw/Draw.ts | 4 ++-- src/editor/core/draw/particle/CheckboxParticle.ts | 2 +- src/editor/core/draw/particle/Separator.ts | 10 ++++++++++ src/editor/core/draw/particle/table/TableParticle.ts | 1 + 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/editor/core/draw/Draw.ts b/src/editor/core/draw/Draw.ts index 92ab943..ea39f77 100644 --- a/src/editor/core/draw/Draw.ts +++ b/src/editor/core/draw/Draw.ts @@ -199,7 +199,7 @@ export class Draw { this.footer = new Footer(this, data.footer) this.hyperlinkParticle = new HyperlinkParticle(this) this.dateParticle = new DateParticle(this) - this.separatorParticle = new SeparatorParticle() + this.separatorParticle = new SeparatorParticle(this) this.pageBreakParticle = new PageBreakParticle(this) this.superscriptParticle = new SuperscriptParticle() this.subscriptParticle = new SubscriptParticle() @@ -1128,7 +1128,7 @@ export class Draw { const rowHeight = rowList.reduce((pre, cur) => pre + cur.height, 0) td.rowList = rowList // 移除缩放导致的行高变化-渲染时会进行缩放调整 - const curTdHeight = (rowHeight + tdPaddingHeight) / scale + const curTdHeight = rowHeight / scale + tdPaddingHeight // 内容高度大于当前单元格高度需增加 if (td.height! < curTdHeight) { const extraHeight = curTdHeight - td.height! diff --git a/src/editor/core/draw/particle/CheckboxParticle.ts b/src/editor/core/draw/particle/CheckboxParticle.ts index 38dd37b..ff02ed7 100644 --- a/src/editor/core/draw/particle/CheckboxParticle.ts +++ b/src/editor/core/draw/particle/CheckboxParticle.ts @@ -22,7 +22,7 @@ export class CheckboxParticle { } = this.options const { metrics, checkbox } = element // left top 四舍五入避免1像素问题 - const left = Math.round(x + gap) + const left = Math.round(x + gap * scale) const top = Math.round(y - metrics.height + lineWidth) const width = metrics.width - gap * 2 * scale const height = metrics.height diff --git a/src/editor/core/draw/particle/Separator.ts b/src/editor/core/draw/particle/Separator.ts index 7c6e9dd..69d860c 100644 --- a/src/editor/core/draw/particle/Separator.ts +++ b/src/editor/core/draw/particle/Separator.ts @@ -1,5 +1,14 @@ +import { DeepRequired } from '../../../interface/Common' +import { IEditorOption } from '../../../interface/Editor' import { IRowElement } from '../../../interface/Row' +import { Draw } from '../Draw' export class SeparatorParticle { + private options: DeepRequired + + constructor(draw: Draw) { + this.options = draw.getOptions() + } + public render( ctx: CanvasRenderingContext2D, element: IRowElement, @@ -7,6 +16,7 @@ export class SeparatorParticle { y: number ) { ctx.save() + ctx.lineWidth = this.options.scale if (element.color) { ctx.strokeStyle = element.color } diff --git a/src/editor/core/draw/particle/table/TableParticle.ts b/src/editor/core/draw/particle/table/TableParticle.ts index 78fae99..a4beb99 100644 --- a/src/editor/core/draw/particle/table/TableParticle.ts +++ b/src/editor/core/draw/particle/table/TableParticle.ts @@ -157,6 +157,7 @@ export class TableParticle { // 仅外边框 const isExternalBorderType = borderType === TableBorder.EXTERNAL ctx.save() + ctx.lineWidth = scale // 渲染边框 if (!isEmptyBorderType) { this._drawOuterBorder({