[Cairo] Preliminary PostScript output support in cairo-0.1.11
Carl Worth
cworth at east.isi.edu
Mon Nov 3 19:42:23 PST 2003
I've just committed some proof-of-concept code for PostScript output
from cairo-0.1.11. (Have I mentioned yet that I have started posting
versioned tar files to http://cairographics.org/snapshots/ ? I guess I
have now.)
The essential new API functions are:
void
cairo_set_target_ps (cairo_t *cr,
FILE *file,
double width_inches,
double height_inches,
double x_pixels_per_inch,
double y_pixels_per_inch);
void
cairo_show_page (cairo_t *cr);
There's a very simple demonstration program in cairo-demo/PS/basket.c
that demonstrates how easy it is to get matching PNG and PostScript
output. The PostScript output has multiple pages suitable for low-tech
flipbook animation. (Yes, this is proof that I shouldn't be writing
applications --- somebody, please put me out of the demo writing
business by writing better demos).
There are a few things to note about the current implementation (which
could definitely be improved on):
1) The output should have high-fidelity. Cairo doesn't depend on the
PostScript interpreter to do anymore than display an image, and
actually does all of its own drawing. This means that things like
translucency still work even though PostScript doesn't support that
directly.
2) As a side effect of (1), cairo has to compute rather large
images. In order ease your pain, cairo uses zlib-based image
compression in the PostScript output.
3) As a side effect of (2), current cairo-generated PostScript
requires a LanguageLevel 3 PostScript interpreter. In my personal
experience, I found that my laser printer does not like this input,
but ghostscript is happy to accept it. (Also CUPS is even kind
enough to provide an option to automatically down-convert to
LanguageLevel 2 on the fly at printing time).
4) There really is just one big image per page in the output. There is
no PostScript text, (nor any geometry), in the output at all. Yes,
this is rather specious. Any help improving this will be gratefully
accepted.
There are also a couple of other less important API functions that
have been added as part of this same work:
void
cairo_copy_page (cairo_t *cr);
cairo_surface_t *
cairo_ps_surface_create (FILE *file,
double width_inches,
double height_inches,
double x_pixels_per_inch,
double y_pixels_per_inch);
Have fun and Happy Printing!
-Carl
More information about the cairo
mailing list