[gs-devel] ghostscript vector devices

Ralph Giles giles at ghostscript.com
Tue Oct 2 18:17:36 PDT 2007


Behdad,

You asked about where to start with a ghostscript output layer using 
cairo, but we didn't get a chance to go over the details. Here's mostly 
what I said, but in writing. :)

Output back-ends in Ghostscript are called "devices". See 
http://ghostscript.com/doc/current/Drivers.htm#Structure
for general life cycle information.

To do a vector output device you want to subclass gx_device_vector,
which provides an callback vector for when any of the path stuff
changes, which I think will be a good match for cairo's immediate
mode api.

The class is in gdevvec.h, reading the implementation in gdevvec.c will 
be necessary on some points to get the calling convention right. The 
simplest device to start cloning is the pxlcolor device (gdevpx*). The 
most sophisticated is the pdfwrite device. You'll ultimately have to 
look there for how to do fonts, etc.

Probably a lot of the pdfwrite stuff could be moved into 
gx_device_vector or an intermediate class if it ends up
being shared. Ken's the one to talk about that (later).

Some general notes on the gs source. Like all object oriented
programming in C schemes, it's a bit messy. Objects are structs,
"inheritance" is done by using macros to define the struct fields
the class, which is the used to instantiate the same fields at
the head of the struct defining any subclasses, so casting works.
All pointer fields are enumerated in a special struct so the 
garbage collector can update them after object relocation. Strings
and few other things are special cased.

Good luck, and let us know if you have any questions. I'd really
like to see a gdevcairo!

Cheers,
 -r



More information about the gs-devel mailing list