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

FontAwesome icons are not rendered in firefox only #314

Closed
akhil-uddemarri opened this issue Dec 18, 2013 · 20 comments
Closed

FontAwesome icons are not rendered in firefox only #314

akhil-uddemarri opened this issue Dec 18, 2013 · 20 comments

Comments

@akhil-uddemarri
Copy link

FontAwesome http://fontawesome.io/ icons are rendering fine in chrome but not in firefox. It just renders a box.
rendering font awesome icons

@niklasvh
Copy link
Owner

Could you setup an example on jsfiddle?

@akhil-uddemarri
Copy link
Author

@Enome
Copy link

Enome commented Jan 6, 2014

Ran into the same problem with a custom icon font. It works in Safari and Chrome but doesn't work in Firefox and IE.

@Enome
Copy link

Enome commented Jan 6, 2014

Did some digging and made it work in Firefox 26 and IE 11. The problem is the following line:

https://github.com/niklasvh/html2canvas/blob/master/src/Parse.js#L951

I'll try to explain why it's happening. Some of my assumptions might be wrong so feel free to correct me.

It seems that in non-webkitbrowser the object that gets returned by getComputedStyles only sets the numeric properties { 0: 'fontFamily' } on the object and the key value pairs { fontFamily: 'fontawesome' } on the prototype. Because Object.keys works like a for in loop with Object.hasOwnProperty it's leaving out the value pairs so it seems no css style is copied.

To fix it you can replace the Object.keys(), the filter method and forEach method with a for in loop.

for (var prop in elStyle) {
  if (indexedProperty(prop) && prop !== 'cssText') {
    // Prevent assigning of read only CSS Rules, ex. length, parentRule
    try {
      elps.style[prop] = elStyle[prop];
    } catch (e) {
      h2clog(['Tried to assign readonly property ', prop, 'Error:', e]);
    }
  }
}

The reason why I am checking prop !== 'cssText' is because in Firefox it's always an empty string (bug?). It seems if you copy that empty string onto the pseudo element it will reset fontFamily again.

Hope this helps.

@brcontainer
Copy link
Contributor

@Enome this is very good, although I still have not tested, please send an "Pull Request".

Thanks! 👍

kabushi added a commit to kabushi/html2canvas that referenced this issue May 5, 2014
Font icons are rendering fine in chrome but not in firefox. It just renders as a box.
niklasvh#314
@fpslater
Copy link

Did @Enome ever make a pull request on this topic? I'm currently using his code as a workaround.

@Enome
Copy link

Enome commented Aug 22, 2014

@fpslater I never made a pull request. If I remember correctly I went away from trying to convert html -> canvas and started using svg instead.

@niklasvh niklasvh added this to the 0.5.0 milestone Aug 29, 2014
@kmdavis
Copy link

kmdavis commented Nov 10, 2014

FontAwesome also fails to render for me in webkit browsers like Chrome and PhantomJS

@niklasvh
Copy link
Owner

@kmdavis Have you tried html2canvas v0.5?

@kmdavis
Copy link

kmdavis commented Nov 25, 2014

We are currently using html2canvas v0.5.0-alpha

@niklasvh
Copy link
Owner

Could you provide a simple example on jsfiddle where the issue can be replicated or does http://jsfiddle.net/3ub69/52/ not work for you?

@sweetleon
Copy link

I'm having this problem also. How do I upgrade to html2canvas v0.5? I feel silly asking this, but I don't see such a branch or tag on this repo.

Thanks in advance.

@sweetleon
Copy link

PS I'm using html2canvas via rails-assets with gem 'rails-assets-html2canvas and the following bower.json file:

{
  "name": "My-App",
  "dependencies": {
    "html2canvas": "https://github.com/niklasvh/html2canvas"
  }
}

@sweetleon
Copy link

From what I see at https://rails-assets.org/components only versions <= 0.4.1 are available for rails-assets. So I've simply added the latest dist/html2canvas.js to my app/assets/javascripts/vendor/ folder and will use it like that for the time being. Thanks for making this incredibly useful library!

@fpslater
Copy link

@sweetleon Try swapping your html2canvas.js file for the one I modified here. It worked for me.

https://github.com/fpslater/fix-html2canvas-webkit-font-conversion

@fpslater
Copy link

@sweetleon Oh nevermind, you've already found a workaround ;-)

@schirrel
Copy link

I'mhaving the same problem

@dpadula
Copy link

dpadula commented Oct 30, 2018

The problem with fontawesome still happens in version 'html2canvas 1.0.0-alpha.12'

@vicdaran
Copy link

Any solution? Thanks

@IAmRC1
Copy link

IAmRC1 commented May 13, 2020

The problem with fontawesome still happens in version 'html2canvas 1.0.0-rc.5

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

No branches or pull requests