[cairo] How do you get tight bounding boxes and/or unused margins cropped for final libcairo results?

Alan W. Irwin irwin at beluga.phys.uvic.ca
Mon Sep 10 13:47:08 PDT 2007


On 2007-09-10 11:26-0700 Vladimir Vukicevic wrote:

> Alan W. Irwin wrote:
>> [...]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. [...]

> Since you just need to figure out the bounding box for the entire rendering, 
> it seems like you could do that on the PLplot side -- that is, you know the 
> extents of your rendering (plus a little extra measurement for text that 
> might stick out of any of the four sides).

PLplot has a viewport corresponding to the plot area where the graphics
(filled areas, lines) are plotted for the plot.  However, as you have
inferred that plot area has annotations (numerical tick labels, axis labels,
overall titles) which extend beyond the viewport.  So to make room for those
annotations the viewport dimensions are specified in relative surface
coordinates which correspond to some relative subset of the Cairo surface area.

> Cairo can certainly help you do 
> those measurements (e.g. via fill_extents and text metrics), but eventually 
> your application code has to decide how big of a final surface to create. 
> How do you currently decide how big of a surface to create?

The Plplot user can specify a -geometry option which gets translated into
the width_in_points and height_in_points in the
cairo_ps_surface_create_for_stream call noted above.  But that of course is
the problem because that all happens before the plotting occurs and libcairo
can help us figure out the maximum global extent size for that surface to
allow removal of the unused margins from the original space specified
by width_in_points and height_in_points.

As Behdad said, it is a chicken-egg problem
(http://en.wikipedia.org/wiki/Chicken-and-egg_problem for those on
list who are not familiar with this).

Alan
__________________________
Alan W. Irwin

Astronomical research affiliation with Department of Physics and Astronomy,
University of Victoria (astrowww.phys.uvic.ca).

Programming affiliations with the FreeEOS equation-of-state implementation
for stellar interiors (freeeos.sf.net); PLplot scientific plotting software
package (plplot.org); the libLASi project (unifont.org/lasi); the Loads of
Linux Links project (loll.sf.net); and the Linux Brochure Project
(lbproject.sf.net).
__________________________

Linux-powered Science
__________________________


More information about the cairo mailing list