Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SVG text element with @font-face family renders with incorrect font #1709

Closed
2 tasks done
sgmccli opened this issue Nov 21, 2018 · 5 comments · Fixed by #2320
Closed
2 tasks done

SVG text element with @font-face family renders with incorrect font #1709

sgmccli opened this issue Nov 21, 2018 · 5 comments · Fixed by #2320

Comments

@sgmccli
Copy link

sgmccli commented Nov 21, 2018

Please follow the general troubleshooting steps first:

  • You are using the latest version
  • You are testing using the non-minified version of html2canvas and checked any potential issues reported in the console

Bug reports:

When a font-face is defined in CSS and applied to an SVG text element it renders correctly within the browser but is ignored by html2canvas when creating an image. This is demonstrated in the following fiddle.

https://jsfiddle.net/y937mxnv/

Specifications:

  • html2canvas version tested with: 1.0.0-alpha-12
  • Browser & version: Chrome Version 70.0.3538.102
  • Operating system: OSX Mojave 10.14
@onEnterFrame
Copy link

+1

@iantrudell
Copy link

Also having this issue

@maximgeerinck
Copy link

Submitted a pull request, to bypass this for now you can use the following:

    function svgToCanvas(targetElem) {
        var svgElem = targetElem.getElementsByTagName("svg");
        for (const node of svgElem) {
          node.setAttribute("font-family", window.getComputedStyle(node, null).getPropertyValue("font-family"));
          node.replaceWith(node);
        }
    }
    svgToCanvas(yourElement);

which you call just before html2canvas(yourElement)

@maximgeerinck
Copy link

possible duplicate? #1463

@bakku
Copy link

bakku commented Feb 11, 2019

Thanks @maximgeerinck ! Just a small addition, I was using a Google Font and I had to have the font served from the same domain as everything else...getting the font directly from google produced the same output as before even with your solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants