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
Abnormal letter spacing in Chrome / Chromium #1272
Comments
The letter spacing (word spacing in this case) looks correct actually, what doesn't appear to be correct is the font family. Which version of html2canvas are you using? Can you replicate the issue on jsfiddle? Edit: with letterRendering it should render differently as you mentioned. |
Thanks for your reply, I'm using the version What do you mean the work spacing looks correct? Are you referring to the first picture I have shared? Would the font create such spacing between words? Note that I'm using CodeMirror for the text editor that is rendered, specifically an Angular wrapper: ng2-codemirror. I tried reproducing the issue to no avail here. |
I also found the same problem in firefox and chrome. If you have a letter-spacing css rule on the text it will render the text with large gaps between each word. This was not the case in version 0.4.1 it used to render text perfectly but it was missing pseudo elements(:before :after) |
Once you remove the |
Yes After removing the letter-spacing rule from the CSS the issue is gone. there are no large spaces between words. it's something in the rendering of the page at the part of the letter-spacing that is messing it up. |
Update! I just built the library from the latest sources on master and it works perfectly. everything looks really good so far. Previously I tried with the v0.5.0-beta4 release. Edit: Found 1 issue on firefox. background-images aren't being clipped to text when |
I don't use any |
Try building from the latest master sources. |
Done, and yet this does not solve the problem, the display remains the same. |
Should be fixed with 77d258f |
@christopherkade does it fix it if you set the option |
Sadly it does not, here's how I do it: let element = document.getElementById('console');
const options = {
letterRendering: true
};
html2canvas(element, options).then(function(canvas) {
document.body.appendChild(canvas);
var url = canvas.toDataURL();
var img = '<img src="' + url + '" style="border:0;"></img>'
var x = window.open();
x.document.open();
x.document.write(img);
x.document.close();
}); Same result if I try the example given in the repository. |
I have found a workaround for the matter (and it's not very clean): // Package used to detect the browser used by the user
const browser = detect();
const element = document.getElementById('console');
// Set up my options
let options = {};
// For some reason foreignObjectRendering solves the spacing issue on Chrome but gives an error on Firefox, so I detect the browser and apply the adequate options.
if (browser && browser.name === 'chrome') {
options = {
useCORS: true,
foreignObjectRendering: true
};
}
// Open the canvas in a new window
html2canvas(element, options).then(function(canvas) {
const url = canvas.toDataURL();
const img = '<img src="' + url + '" style="border:0;"></img>'
const x = window.open();
x.document.open();
x.document.write(img);
x.document.close();
}); Note that the error I get on Firefox when using the second option is as follows:
|
Same problem!! |
Solved here by removing CSS attribute font-variant-numeric: proportional-nums from HTML body. |
same problem with Arabic language any suggestion please ? |
@mohafouad +1 Have you found any fix for this? Thank you. |
@2xSamurai no :( |
I have fixed this also by going to the div I want to screenshot and then I set the " |
fixed if I add |
@Malarkey-Jhu's and @maaoui's answer solved my problem. The problem I had: Font family wasn't working and spacing was very wonky. Sometimes I would have overlapping letters. What I do: During export I call element.style.setProperty('font-variant', 'normal') on the element with the text, and this allows the font-family to show properly, and the spacing to not be all wonky. Then I remove that property after I've finished exporting. |
Based on the above solutions, this issue is fixed for me by changing |
For me, this problem was caused by trying to take screenshots of text that was using a custom font (even if the fonts were loaded from the same domain). I had to change the font back to something built-in in the interim clone h2c creates, then everything worked perfectly (minus the custom fonts...):
|
When calling:
Both with or without
letterRendering
, this is what Chrome outputs:When the output in Firefox is:
Any specific reason why it renders it like that?
The text was updated successfully, but these errors were encountered: