Skip to content

Commit 80b2ae8

Browse files
authored
Merge pull request #700 from hippo2cat/dev
fix: 修复富文本元素宽高不正确的问题
2 parents 56bf411 + ac21394 commit 80b2ae8

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

src/utils/index.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,12 @@ export const createCustomContentSVG = async (ctx: CanvasRenderingContext2D, opti
5959
document.body.appendChild(bodyElement)
6060
// convert all images to base64
6161
await convertImgToBase64(bodyElement)
62-
const { offsetHeight, offsetWidth } = <HTMLElement>bodyElement.querySelector('.rich-text-content')
62+
const rect = bodyElement.querySelector('.rich-text-content')?.getBoundingClientRect()
63+
const rectWidth = rect?.width
64+
const rectHeight = rect?.height
6365
document.body.removeChild(bodyElement)
64-
const width = options.richTextWidth || offsetWidth || options.width
65-
const height = options.richTextHeight || offsetHeight || options.height
66+
const width = options.richTextWidth || rectWidth || options.width
67+
const height = options.richTextHeight || rectHeight || options.height
6668
svgElement.setAttribute('width', width.toString())
6769
svgElement.setAttribute('height', height.toString())
6870
const foreignObjectElement = createSVGElement('foreignObject', {

0 commit comments

Comments
 (0)