[GRASS-dev] Cairo monitor driver

Glynn Clements glynn at gclements.plus.com
Tue Oct 16 11:18:26 EDT 2007


Lars Ahlzen wrote:

> Anyhow, the code along with brief build and usage instructions are 
> available at:
> 
> http://lars.ahlzen.com/cairograss/
> 
> The makefiles are a bit of a hack and need to be fixed. Hopefully 
> they'll work, though. And the code in general is, as previously 
> mentioned, experimental. But it can always be cleaned up if it seems 
> worthwhile.

I've committed this to CVS, with a few changes; mostly, just
conforming to existing coding and formatting conventions.

The main one is that code should stick to ANSI C89, which means
variable declarations have to go at the beginning of a block (freely
mixing declarations and statements is a C99 feature).

Variables which aren't used outside of the file in which they are
defined should be declared "static".

There aren't currently any global formatting conventions (this will
change with 7.x, but for the time being we want to avoid polluting the
"cvs diff" output with reformatting changes). However, code should
normally try to follow the same conventions used by similar code; in
the case of a display driver, it should mimic the other drivers.

The only externally-visible change is that the driver and monitor
names have been changed from "CAIRO" to "cairo" (the web site treats
"cairo" as a normal word, i.e. all lower-case except in a title or at
the beginning of a sentence). PNG and PS are upper-case as they are
acronyms; XDRIVER is a historical artifact (and the monitor names are
"x0" etc).

A question about the set_drawing_op/finish_drawing_op stuff: is this
meant to merge distinct line segments into a single path? If so, I'll
remove it.

The lack of begin/end operations for paths (move/cont) is a flaw in
the interface, and is one of the planned interface changes for 7.x. 
Note that the PS driver doesn't attempt to hack around this; if you
want a single path, you have to use the polyline operation.

The global cairo_translate(cairo, 0.5, 0.5) is wrong. If you want to
work around the problems with lines having their endpoints on pixel
boundaries (rather than centres), apply the translation only to lines. 
Other operations (box/polygon fills, images, text) should *not* be
translated in this way. FWIW, the PS driver doesn't even translate
lines.

The use of pkg-config really belongs in the configure script. I've
left it in the Makefiles for now, although I've used := for the
assignment. The RHS of := is expanded when the definition is read,
rather than when the variable is expanded, so "expensive" expressions
such as $(shell ...) should use :=.

At present, the only way to enable the cairo driver is to manually set
USE_CAIRO=1, e.g. "make USE_CAIRO=1".

The raster library should be extended to allow direct rendering via
cairo, but we should get it working fully first.

I note that clipping isn't enabled, and that the bitmap primitive
(used for freetype text, amongst other things) is a no-op. Both of
these are relatively important; the bitmap primitive would be less
important if the driver implements the draw_text method using cairo's
built-in font rendering.

AFAICT, clipping should just be a matter of calling cairo_reset_clip()
and cairo_clip(). Ignore the encapsulation issues; again, that's an
interface flaw (which also affects the PS driver).

-- 
Glynn Clements <glynn at gclements.plus.com>




More information about the grass-dev mailing list