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

Font families being incorrectly identified. #3160

Open
2 tasks done
tascord opened this issue Apr 5, 2024 · 1 comment
Open
2 tasks done

Font families being incorrectly identified. #3160

tascord opened this issue Apr 5, 2024 · 1 comment

Comments

@tascord
Copy link

tascord commented Apr 5, 2024

Please make sure you are testing with the latest release of html2canvas.
Old versions are not supported and issues reported for them will be closed.

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:

The !important CSS selector seems to cause unexpected issues when h2c decides which font should be used. Fiddle.

When using the following selector to apply a font to all but font-awesome's icons, h2c fails to correctly identify which font should be used to render the icon's <i/> tags. This is in contrast to how the DOM correctly applies fonts.

*:not(i) {
    font-family: "Montserrat", sans-serif !important;
}

Html2Canvas Generated Image without !important

Html2Canvas Generated Image with !important

Specifications:

  • html2canvas version tested with: 1.4.1
  • Browser & version: Firefox 124.0, Edge 112.0.2365.92, Chrome 123.0.6312.86, Chromium 122.0.6261.128
  • Operating system: Linux (Fedora Silverblue 39.20240321.0)
@tascord
Copy link
Author

tascord commented Apr 5, 2024

parent.textNodes.push(new TextContainer(context, childNode, parent.styles));

The issue seems to be related to the fact that parent element, a <HTML2CANVASPSEUDOELEMENT/> fails to inherit correct styles that are then parsed to the TextContainer when the !important keyword is present.

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

No branches or pull requests

1 participant