[GRASS-dev] Cairo monitor driver

Dylan Beaudette dylan.beaudette at gmail.com
Sat Oct 13 21:00:14 EDT 2007

On Saturday 13 October 2007 16:20, Lars Ahlzen wrote:
> Hi!
> My apologies if this has been done and/or discussed before, but a search
> of grass-dev came up empty.

This has not... although other back-end drivers have been discussed... kind of 
like how R can use a wide variety "output devices".

> Since the Cairo graphics library (http://www.cairographics.org, LGPL
> licensed) provides very high-quality graphics output in several vector
> and raster formats, I thought it would make sense to create a "pseudo"
> monitor driver for it (similar to the PNG and PS drivers). So I did.
> Cairo does all of the hard work, so it's really mostly simple "glue" code.

Indeed. I have been using it for all of my R work lately. I don't know why 
this hasn't come up before, but something like Cairo actually solves a lot of 
the problems we are facing: high quality on-screen display, output to PDF...

This would also solve the translucency problem, as Cairo can deal with that 
quite nicely. 

> It seems stable, and is fairly complete in terms of features. I've used
> for most of my own work recently.

Yeah... seems to work quite well with R.

> Benefits include:
> * High quality antialiased output. See
> http://lars.ahlzen.com/cairograss/ for a few simple examples and a
> comparison with the PNG driver.
> * Several output format options, both vector and bitmap. The driver
> currently supports PNG, PDF, PS and SVG. Output to X or Win32 windows
> might be possible in the future, since Cairo supports such formats as well.
> Of course, such niceness comes at a price. It takes longer to draw
> complex vector data, compared to the PNG driver. However, I imagine that
> in most cases drawing is not the main bottleneck anyway.

For hard copy output like PDF this isn't a problem.

> Also, it obviously pulls in Cairo as an additional dependency. Cairo is
> probably found on most systems nowadays, though, since many other
> applications (including some mapping and GIS software) already use it.

If it is an additional feature, then an additional dep. isn't always a bad 

> Additionally, the fact that GRASS monitors (unfortunately) receive
> integer data (screen coordinates, line widths, etc) somewhat limits the
> effectiveness of the high-precision output from the CAIRO driver. For
> example, in the "Massachusetts Counties and roads" example, the
> antialiasing breaks down for certain lines because they are divided into
> smaller segments whose coordinates are rounded before they are drawn.
> Similarly, zooming in on vector output will also reveal this drawback.

Perhaps that rounding can be toggled based on the output device...

> My main question is: Does all of this seem useful to anyone else? I do
> realize that most of these things can be achieved in other ways, but
> I've personally found this driver to produce high quality output in a
> very convenient way. Feedback is appreciated!

In the past I would approximate this type of output by rendering a PNG at 2x 
size and then shrink it down with imagemagick. This would give me nice 
looking lines, but not as nice as what Cairo does. It would also be nice to 
have an output device which can deal with alpha transparency and PDF versions 
>= 1.3, which would allow translucency in PDF files.

> I can of course post code too, if anyone would be interested in actually
> trying it.
> / Lars

Posting the code would be great - which version of GRASS was this built 

I am not a developer, but since this is close to something that I would use on 
a regular basis I can certainly test it out.

Cheers, and thanks for the innovative work!


More information about the grass-dev mailing list