[cairo] How do you get tight bounding boxes and/or unused margins cropped for final libcairo results?
Adrian Johnson
ajohnson at redneon.com
Mon Sep 10 15:43:54 PDT 2007
Alan W. Irwin wrote:
> To give you some quick background, a set of devices (pscairo, pdfcairo,
> pngcairo, xcairo, and svgcairo) that are based on libcairo/libpango has just
> been developed for the PLplot scientific plotting library. This device
> driver code was developed by another PLplot developer (Hazen Babcock). He is
> fairly new to libcairo and I am completely new to libcairo so please excuse
> any mistakes when I discuss the tight bounding-box/crop unused margins issue
> below.
>
> Currently pscairo produces outstanding looking results both for graphics and
> text so we are quite pleased with it. However, there is one remaining issue
> which is the loose bounding box in the generated PostScript file. The
> postscript backend to libcairo simply sets that bounding box to the
> width_in_points and height_in_points specified by the call to
> cairo_ps_surface_create_for_stream. What we would like to do is modify this
> device code so that PLplot users have the option of using an automatically
> calculated tight bounding box corresponding to the maximum rectangular
> extent of the graphics plus text in the plot. (Tight bounding boxes for the
> devices that support bounding boxes or the corresponding removal of unused
> margins for those devices that do not support bounding boxes are useful when
> including plots in other documents.)
>
The currently set bounding box does not comply with the PostScript
Document Structuring Convention specifications which requires a tight
bounding box for each page. I have been working on fixing this while
working on extending the PostScript backend to generated Encapsulated
PostScript. EPS requires the correct bounding bounding box to ensure an
imported EPS file is embedded at the correct size.
The recent changes to the analysis surface to support finer-grained
fallbacks make it easy to also calculate the tight bounding box of each
page.
My Encapsulated PostScript git branch is available here:
http://gitweb.freedesktop.org/?p=users/ajohnson/cairo.git;a=shortlog;h=eps
While the EPS output is not yet finished the changes to enable tight
bounding box calculation for PostScript output should work.
More information about the cairo
mailing list