Skip to content

Commit

Permalink
refactor: date element renderer #460
Browse files Browse the repository at this point in the history
  • Loading branch information
HerbertHe authored Mar 14, 2024
1 parent 0003686 commit 788f96a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 18 deletions.
12 changes: 10 additions & 2 deletions src/editor/core/draw/Draw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1640,8 +1640,16 @@ export class Draw {
this._drawRichText(ctx)
this.hyperlinkParticle.render(ctx, element, x, y + offsetY)
} else if (element.type === ElementType.DATE) {
this._drawRichText(ctx)
this.dateParticle.render(ctx, element, x, y + offsetY)
const nextElement = curRow.elementList[j + 1]
// 释放之前的
if (!preElement || preElement.dateId !== element.dateId) {
this._drawRichText(ctx)
}
this.textParticle.record(ctx, element, x, y + offsetY)
if (!nextElement || nextElement.dateId !== element.dateId) {
// 手动触发渲染
this._drawRichText(ctx)
}
} else if (element.type === ElementType.SUPERSCRIPT) {
this._drawRichText(ctx)
this.superscriptParticle.render(ctx, element, x, y + offsetY)
Expand Down
16 changes: 0 additions & 16 deletions src/editor/core/draw/particle/date/DateParticle.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { ElementType } from '../../../../dataset/enum/Element'
import { IElement, IElementPosition } from '../../../../interface/Element'
import { IRowElement } from '../../../../interface/Row'
import { formatElementContext } from '../../../../utils/element'
import { RangeManager } from '../../../range/RangeManager'
import { Draw } from '../../Draw'
Expand Down Expand Up @@ -130,19 +129,4 @@ export class DateParticle {
startTop
})
}

public render(
ctx: CanvasRenderingContext2D,
element: IRowElement,
x: number,
y: number
) {
ctx.save()
ctx.font = element.style
if (element.color) {
ctx.fillStyle = element.color
}
ctx.fillText(element.value, x, y)
ctx.restore()
}
}

0 comments on commit 788f96a

Please sign in to comment.