5

In my application I'm using a QTextEdit to display some text, using HTML for formatting. The displayed document can be printed. And here's the issue: while on screen the kerning is correct, when printed the document has a very bad looking (mainly: too much space after some letters).

Trying to understand the problem I output the HTML in an external file, and tested it in real browsers. In Chrome there's exactly the same issue, while in Firefox the kerning is correct for printing too. The problem comes definitely from the HTML rendering engine, but I'm not using the QtWebkit module (I haven't even compiled it) which would have explained that the same problem occurs in Chrome.

How can I fix this ?

EDIT

Here's what it looks like:

First the text as it should be rendered (Firefox): kerning with Firefox

Then what is rendered with Qt/Chrome (particulary noticeable after the M and the p): kerning with Qt/Chrome

gregseth
  • 12,952
  • 15
  • 63
  • 96
  • Have you tried looking at it in IExplore? What OS are you on? – RedX Aug 17 '11 at 09:02
  • Yes, I tried with Internet Explorer 9. The result is better than the Qt/Chrome version but not as good as the Firefox one. My soft is developped for Windows. – gregseth Aug 17 '11 at 09:05
  • Why do your two sample texts have different point sizes? It is to be expected that kerning will not be as good at smaller font sizes. Perhaps if you make the Chrome text as big as the Firefox text, the problem will go away. It's worth trying, anyway. – TonyK May 16 '12 at 11:37
  • They do have the same size, the images are screenshots of the PDFs created with the print feature of the browser. Given the kerning is different, the lines don't have the same length, so I tried to align both texts in my captures. – gregseth May 16 '12 at 11:53

1 Answers1

0

Here is a simple workaround,

Use below function and draw your complete QTextEdit Widget on QImage, then print that QImage.

http://doc.qt.io/qt-5/qwidget.html#render

Qt uses different renderer for printing, I think this is an issue related to it.

http://doc.qt.io/qt-5/paintsystem-devices.html

Christophe Weis
  • 2,518
  • 4
  • 28
  • 32
SunnyShah
  • 28,934
  • 30
  • 90
  • 137
  • Yeah, creating an image is fine for a single page document. But for a mulipage document, I'll have to manage manually the pagebreaks, to ensure the break doesn't occurs in the middle of a line, an so on... – gregseth Aug 18 '11 at 09:51
  • Can you try QApplication::setGraphicsSystem("raster") (http://doc.qt.nokia.com/latest/qapplication.html#setGraphicsSystem)? I believe that It is something to do with multiple graphics systems. – SunnyShah Aug 18 '11 at 10:39
  • Please let me also know the result. – SunnyShah Aug 18 '11 at 10:40
  • It changes the appearance of the character on screen (the anti-aliasing, not the spacing) and it doesn't change a thing for the printed version. – gregseth Aug 18 '11 at 12:20
  • Can you upload the images of both Qt 's printing and firefox printing? so that I can get a clue on what to look for in QtGui Code. – SunnyShah Aug 18 '11 at 12:34
  • Ok, Have you checked with Qt 4.7.3? – SunnyShah Aug 18 '11 at 14:02
  • http://code.google.com/p/wkhtmltopdf/issues/detail?id=72 This bug looks same to your issue. – SunnyShah Aug 18 '11 at 14:10