Words are overlapping when rendering the canvas

安稳与你 提交于 2021-01-04 05:52:45

问题


I have a long text to render to a canvas, and words are overlapping and scrambled in Safari. But works perfectly in Chrome. I'm using the latest version of html2canvas library. (v1.0.0-rc.3)

This is the output in safari

html2canvas(document.querySelector("#capture")).then(canvas => {

    var base64image = canvas.toDataURL("image/png");
    document.getElementById('export_img').src = base64image;
});



//html code
<div id='capture'>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi magna
            ligula, finibus eget purus quis, vulputate volutpat urna. Etiam vehicula<br> pellentesque justo, eget
            sodales diam ultricies sit amet. Duis pulvinar arcu ut nisl volutpat gravida. Aliquam viverra condimentum
            dui, nec eleifend lorem. Curabitur quis quam ac orci luctus tincidunt. Phasellus <br>ornare ultricies
            porttitor. Donec egestas, ex ut rutrum feugiat, justo libero vehicula ligula, eu auctor lectus nisi ut
            lorem. Phasellus elementum sed tortor non porttitor. Nunc ultricies mattis venenatis. Nam enim eros, rutrum
            aliquet sodales at, interdum eget magna. Sed ac dictum mi, eu efficitur sapien. Vestibulum augue tellus,
            dictum eu imperdiet ac, consectetur vitae libero. Vivamus ligula tellus, dapibus ut sem in, <br>tincidunt
            auctor elit. Ut bibendum augue sit amet tempor consectetur. Maecenas eget aliquam ex. Sed in orci nulla.
</div>

UPDATE: br tags generate the error in Safari. Added white-space:pre-wrap.

来源:https://stackoverflow.com/questions/56592511/words-are-overlapping-when-rendering-the-canvas

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!