incorrect font kerning on Windows produces bad output #1527
Comments
Which version is this and what platform is this on, etc? This is what I get on OS X with the current development snapshot. The text rendering is by no means perfect, but perhaps it's better with the current development snapshot? The OS X version is now using the native platform PDF renderer, so there may be some differences there. Here's one rendered from the latest development snapshot on Ubuntu 12.04.4 LTS (displayed on OS X in Preview, the default PDF viewer - sorry I don't have anything else). |
Sorry about that, I forgot to mention it's Windows 7, Cygwin if relevant.
|
Your Mac versions all look far better than Windows, but the spacing in the development version snapshot you provided seemed to have fixed the serious spacing problem that the older Mac snapshots you showed. Did you notice the huge space between "mashed" and "potatoes"? Development snapshot (64-bit version) seems to have fixed the anti-aliasing, but the kerning still looks awful on Windows. Highlighting some of the more obvious problems: |
Looks like QTBUG-11387 to me, should investigate whether the patch in #1620 improves the kerning. |
This is the PDF generated by wkhtmltopdf or is it created by Chrome 35 on OS X?
I suppose you mean the result shown, when you open the generated PDF in Illustrator? Yes, HTML/CSS/JS is always helpful, thanks. |
Can you verify if the output is better with |
Definitely not better, just tested. Do you want images? |
Yeah, but it looks like a Qt issue because |
Actually I should retract my statement. I forgot this was about kerning, Browser: http://i.imgur.com/FI1C0MC.png |
A couple of other things, I realized I didn't include the "mashed potatoes" text in the screenshot. It's kerned correctly in the 0.13-alpha rendering. I see no kerning issues, but subjectively the quality of the rendering is the worst out of the four. |
The kerning in 0.13-alpha has certainly changed, but I wouldn't say it has improved. Previously the letters were mostly too close, with irregular spacing. Now they are too far, also with irregular spacing. Comparison: http://i.imgur.com/ud3T5RA.png I appreciate this is a Qt thing, thanks for trying to fix it but looks like Qt still can't do this right on Windows. |
I found a very nice workaround for this issue which might also shed some light on the problem (using wkhtmltopdf 0.12.2.1). Firstly I saw in some other thread that SVG fonts don't have these kerning issues which is correct. The problem is that the resulting PDF is much larger and the text in it isn't selectable, so using SVG wasn't a viable workaround for me. The trick is to convert the SVG font back to WOFF, which I did using Online Font Converter. This produces a WOFF that has perfect kerning just like the SVG. The only strange thing is the line height of the generated WOFF font is not the same as the original and can be many times higher than it should be, but this can be solved using line-height CSS (I just added line-height:1.25em everywhere I set the font-size). It might be possible to fix it by tinkering with the SVG instead but the CSS fix was good enough for me. One font I used for testing was Century Gothic from dailywf.com. Using their WOFF or TTF directly has kerning issues, with the most notable issue being a huge gap after the letter w. However the WOFF font generated by converting the SVG font using the Online Font Converter has perfect kerning, but with a huge line-height. I also tried converting the Century Gothic TTF from the Windows fonts folder to SVG and then converting the result of that to WOFF and that also works well, with a more reasonable line-height but still slightly higher than normal. Note that converting the Windows TTF directly to WOFF doesn't fix the kerning, it has to go through SVG first. The WOFF fonts generated by converting SVG fonts aren't good for the screen, so I include a fonts.css file on the wkhtmltopdf command line that contains @font-face declarations for all the affected fonts. These fonts can be named the same as local fonts and wkhtmltopdf will use the ones you supply, so you don't have to mess with your font names. Lastly, wkhtmltopdf doesn't like loading local URL assets from the command-line specified CSS file, so the @font-face declarations have to use data URLs. Someone with more knowledge of the WOFF format might be able to compare the WOFF files generated by converting TTF and SVG and see why the former has kerning problems and the latter doesn't. I hope this information helps someone! |
@mart9634: can you post an example HTML/CSS/command-line with your workflow? |
@ashkulz: Some sample files are available here: Here's the full workflow using the Windows Century Gothic font as an example:
To use the demo in the zip file:
The letters in the PDF without the workaround are too big and all squished together. I also included a file called wkhtmltopdf.css in the zip file. I normally include that file on the command line which includes the fonts-data.css file but I couldn't get it to work in this demo. Yet another wkhtmltopdf bug but not relevant to this issue. |
@mart9634 Thanks for the detailed post, i tried to follow your instructions for Arial and it really improved the output, but to me the kerning still seems wrong. Looking at "Gothic" in your demo, the "o" is too far on the left and the word "This" seems a lot denser than "Century" (compared it to a browser rendering which looks more balanced in my opinion). It's a pity that the two most promising free html2pdf approaches (wkhtmltopdf and phantomjs) both can't solve this issue, which makes them effectively unusable for professional applications. |
@johannesspohr You're right I hadn't noticed is still isn't quite right. That problem seems to be only with small fonts. The font in my sample PDF is the equivalent of 6pt because my display is set to 150% scaling. There are a couple of ways you can improve kerning of smaller fonts:
If your professional application is front-end and you're concerned about precision kerning issues then wkhtmltopdf isn't of much use to you, simply because results depend on the Windows font scaling setting so you'll never be able to produce consistent results on all installations. |
@mart9634 Thanks, it's backend, and after deploying it to the production system (ubuntu 14) i noticed it works perfectly on it (my local installation runs on windows 7 x64). Weird problem though, i hope it will be fixed to work on any platform and zoom level. |
I had the same issue on Windows with latest wkhtmltopdf (0.12.4), and the only workaround was to increase the dpi to 200 or more (I picked 300). Here's the **very very simple ** test case:
Calling wkhtmltopdf with no options: Here's the result: Zooming on a word, you see the issue: Calling the program with option --dpi 300 produces a good workaround: Here's the result: Zooming on the same word, it's much better: I'm fine using 300 dpi - we generate PDF for printing - but this font rendering issue is a pain. Regards, E. |
I'm not sure I would call this a "kerning" issue... it looks to me more like poor character width management. Note in the previous post that they appear to be using the same typeface, but something's wrong with where the next glyph starts, even on letters where you would normally expect no kerning adjustments (such as "m" followed by "a"). Could WebKit be using different font width tables than the PDF reader is (same typeface, but different widths)? Is it possible to embed the font in the PDF, and see if that changes anything? |
Due to the behaviour of wkhtmltopdf with dynamically created SVGs with foreignObjects containing HTML, I'm working on a project where we can't increase the DPI without messing up the page entirely, as not all elements are scaled in the same way. Furthermore, the project runs in the cloud and the GDI APIs aren't available, which restricts us from using custom fonts. As such, we're stuck with a kerning issue and a horrible letter-spacing workaround. Is there any plan to fix this issue in the coming months ? Any pointer as to how to fix it ? We could invest some time, but we don't really know where to start. It's a bit of a deal breaker for us. |
@pierluca I ended up switching to a different library https://github.com/danfickle/openhtmltopdf which doesn't have any of these issues. |
@MartyMcMartface That won't cut it for us as we're rendering an AngularJS application which dynamically generates the SVG content :-/ |
I might have just found out some important complementary information to what @MartyMcMartface mentioned, which is the solution we went with. We were in the situation where Windows fonts were working more or less correctly but not free fonts. This wasn't acceptable. I compared the svg generated from Windows TTF fonts and another SVG font (Liberation Sans) - converted to WOFF and then DataURL - that resulted in the wrong kerning. Here's how I changed Liberation Sans for it to work (some changes may not be needed for it to work, I just went the full way):
It's not perfect but this actually works ! |
Sorry but i have the same problem |
Take the following page: http://www.myrecipes.com/recipe/chicken-braised-wine-rosemary-50400000126800/print/
It's especially apparent when zoomed out. It's as if there's no font smoothing or something.
Rendered with wkhtmltopdf:
Rendered with Acrobat:
Rendered with wkhtmltopdf:
Rendered with Acrobat:
The text was updated successfully, but these errors were encountered: