fix: insert image render error when scaling the page #433

pr675
Hufe921 2 years ago
parent 4015707025
commit acb0d3fc47

@ -1116,11 +1116,12 @@ export class Draw {
surplusWidth > 0 surplusWidth > 0
? surplusWidth ? surplusWidth
: Math.min(elementWidth, availableWidth) : Math.min(elementWidth, availableWidth)
element.width = adaptiveWidth const adaptiveHeight = (elementHeight * adaptiveWidth) / elementWidth
element.height = (elementHeight * adaptiveWidth) / elementWidth element.width = adaptiveWidth / scale
metrics.width = element.width element.height = adaptiveHeight / scale
metrics.height = element.height metrics.width = adaptiveWidth
metrics.boundingBoxDescent = element.height metrics.height = adaptiveHeight
metrics.boundingBoxDescent = adaptiveHeight
} else { } else {
metrics.width = elementWidth metrics.width = elementWidth
metrics.height = elementHeight metrics.height = elementHeight
@ -1280,13 +1281,13 @@ export class Draw {
} }
} }
} else if (element.type === ElementType.SEPARATOR) { } else if (element.type === ElementType.SEPARATOR) {
element.width = availableWidth element.width = availableWidth / scale
metrics.width = availableWidth metrics.width = availableWidth
metrics.height = defaultSize metrics.height = defaultSize
metrics.boundingBoxAscent = -rowMargin metrics.boundingBoxAscent = -rowMargin
metrics.boundingBoxDescent = -rowMargin metrics.boundingBoxDescent = -rowMargin
} else if (element.type === ElementType.PAGE_BREAK) { } else if (element.type === ElementType.PAGE_BREAK) {
element.width = availableWidth element.width = availableWidth / scale
metrics.width = availableWidth metrics.width = availableWidth
metrics.height = defaultSize metrics.height = defaultSize
} else if ( } else if (
@ -1294,9 +1295,9 @@ export class Draw {
element.controlComponent === ControlComponent.CHECKBOX element.controlComponent === ControlComponent.CHECKBOX
) { ) {
const { width, height, gap } = this.options.checkbox const { width, height, gap } = this.options.checkbox
const elementWidth = (width + gap * 2) * scale const elementWidth = width + gap * 2
element.width = elementWidth element.width = elementWidth
metrics.width = elementWidth metrics.width = elementWidth * scale
metrics.height = height * scale metrics.height = height * scale
} else if (element.type === ElementType.TAB) { } else if (element.type === ElementType.TAB) {
metrics.width = defaultTabWidth * scale metrics.width = defaultTabWidth * scale

@ -27,7 +27,7 @@ export class PageBreakParticle {
const displayName = this.i18n.t('pageBreak.displayName') const displayName = this.i18n.t('pageBreak.displayName')
const { scale, defaultRowMargin } = this.options const { scale, defaultRowMargin } = this.options
const size = fontSize * scale const size = fontSize * scale
const elementWidth = element.width! const elementWidth = element.width! * scale
const offsetY = const offsetY =
this.draw.getDefaultBasicRowMarginHeight() * defaultRowMargin this.draw.getDefaultBasicRowMarginHeight() * defaultRowMargin
ctx.save() ctx.save()

@ -16,7 +16,8 @@ export class SeparatorParticle {
y: number y: number
) { ) {
ctx.save() ctx.save()
ctx.lineWidth = this.options.scale const { scale } = this.options
ctx.lineWidth = scale
if (element.color) { if (element.color) {
ctx.strokeStyle = element.color ctx.strokeStyle = element.color
} }
@ -26,7 +27,7 @@ export class SeparatorParticle {
ctx.translate(0, 0.5) // 从1处渲染避免线宽度等于3 ctx.translate(0, 0.5) // 从1处渲染避免线宽度等于3
ctx.beginPath() ctx.beginPath()
ctx.moveTo(x, y) ctx.moveTo(x, y)
ctx.lineTo(x + element.width!, y) ctx.lineTo(x + element.width! * scale, y)
ctx.stroke() ctx.stroke()
ctx.restore() ctx.restore()
} }

Loading…
Cancel
Save