January 7, 2010

Know your limits

Thanks to OSGi one of the main qualities of Eclipse ecosystem is its modularity.
In a modular architecture, contract between components is fundamental. I called contract not only the features offered by a component but also its limitations. Quite often we tend to concentrate on features and and miss limitations.

To illustrate my point I will take as an example SWT Eclipse component
I recently needed to add printing support to a custom editor. SWT provides some printing API. I first tried an approach which consisted of printing a snapshot of my already drawn widget. I did it using the SWT faq and added quite easily header, footer and fit to page support but it remained a blocking bug. Sometimes, randomly, a white shadow (of the previously opened print dialog) appeared on my printed widget. I tried to hack by calling redraw and update methods on the control but as I am not a graphic guru I gave up and finally have implemented the printing feature with success using the excellent PaperClips library.

During my hack attempt I saw in code that Printer.getDPI() returns always 72X72 in SWT GTK implementation. I don't want to blame anyone neither SWT nor GTK, just remark that on linux print is not completely supported, and this information may be difficult to find until your get the bug or read concerned code.

So quick reminder for developers : think to document your component limitations !


  1. The Cairo API (which SWT uses on Linux to support printing) did not support querying the printer DPI for a while, which is why SWT couldn't report the right DPI. This has been fixed on the Cairo side for a while though so I think the SWT devs could fix this now.

    If you ask me though, what's worse than getting the wrong DPI is that when printing on Linux, fonts tend to scale according to the user-configured screen DPI.

    Thanks for the PaperClips plug! :)

    Matthew Hall

  2. The associated bug is, I have tried to provide a patch.

  3. This comment has been removed by a blog administrator.