Skip to content

Commit

Permalink
fix: scaling table and separator elements error #326
Browse files Browse the repository at this point in the history
  • Loading branch information
Hufe921 committed Nov 23, 2023
1 parent f0823d7 commit b3354ac
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/editor/core/draw/Draw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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!
Expand Down
2 changes: 1 addition & 1 deletion src/editor/core/draw/particle/CheckboxParticle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions src/editor/core/draw/particle/Separator.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
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<IEditorOption>

constructor(draw: Draw) {
this.options = draw.getOptions()
}

public render(
ctx: CanvasRenderingContext2D,
element: IRowElement,
x: number,
y: number
) {
ctx.save()
ctx.lineWidth = this.options.scale
if (element.color) {
ctx.strokeStyle = element.color
}
Expand Down
1 change: 1 addition & 0 deletions src/editor/core/draw/particle/table/TableParticle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ export class TableParticle {
// 仅外边框
const isExternalBorderType = borderType === TableBorder.EXTERNAL
ctx.save()
ctx.lineWidth = scale
// 渲染边框
if (!isEmptyBorderType) {
this._drawOuterBorder({
Expand Down

0 comments on commit b3354ac

Please sign in to comment.