printing and WYSIWYG

PDF and Postscript generators

With the release of 4.1 Qt has gained the ability to generate PDF natively. We have put special care trying to make sure all features of Arthur are also supported in our PDF generator.

This implies that we can do alpha transparency and gradients in the generated PDF. One main issue I found while bugfixing the implementation is that our open source PDF renderers (ghostscript and poppler) still have a large way to go to support more advanced PDF features. poppler wasn't even able to handle masked images (something that apparently has been fixed a few weeks ago), while both of them had rather large problems with real transparency.

We have written code to generate native gradients in PDF that are semitransparent. The only problem is that the only viewer that can render them correctly is adobe's acrobat reader. So for the moment that code is disabled and we embed the gradient as a pixmap. The resulting PDFs are quite a bit bigger and slower, but at least they render correct on all three PDF viewers.

The only small drawback of our PDF generator in Qt 4.1.0 is that the generated PDF is not searchable. But this is only because the code needed to implement this has missed the 4.1.0 deadline. It's written and tested, and Qt 4.1.1 will thus generate searchable and Unicode compliant PDF .

At the same time I've took the opportunity and have rewritten parts of the Postscript backend. We now embed fonts as Type1 fonts (it used to be Type3), something that will make the size of the generated Postscript quite a bit smaller. At the same time I've fixed a few bugs in the Postscript generator that where outstanding since Qt 4.0.0.

Qt can do WYSIWYG layouting!

While I'm writing about printing, let me also say that the myth that Qt can't do WYSIWYG text layouting is wrong. I saw this being repeated quite a few times on the dot, see for example James comment.

Qt 4 has support for using design metrics of fonts. If you're layouting text on a per paragraph level, QTextOption has a flag to enable this. If you use Qt's build in rich text support, you can set a flag on a complete QTextDocument.

When using these flags, all text layouting calculations will be done with subpixel precision using the linear/design metrics from the font.

The fact that QPrinter::supportedResolutions() returns 72 for postscript has nothing to say in this respect. All the number gives you is a conversion factor between units on a QPainter and millimeters on the output device. QPainter has since Qt 4.0 a floating point API that allows you to place objects at arbitrary positions inside a postscript (or for that respect PDF) document.

So in the end there should be no real problem for kword or any other Qt application to do WYSIWYG text layouting and printing.

Have a nice christmas and a happy new year!


Blog Topics:

Comments