[cairo] simple surface size question

Peter Clifton pcjc2 at cam.ac.uk
Tue Jan 20 04:28:39 PST 2009


On Mon, 2009-01-19 at 22:37 -0500, Dan McMahill wrote:
> 
> 
> How do I handle not knowing the x/y limits of my drawing up front?
> In 
> fact, unless I do something drastic to the pstoedit driver, I might
> even 
> have negative x and y coordinates in my cairo calls.  Is that even 
> allowed (negative coordinates)?

Negative coordinates are allowed, but unless you've set the scale
matrix, your coordinate system will be in postscript points, *possibly*
with drawing outside your page size being clipped / culled.

Does the EPS backend for pstoedit calculate the bounding-box after, or
before rendering?

I'm wondering if you need to create a "similar" surface to the PDF,
render into that (whilst watching your coordinates to compute the
bounding box), then render from the "similar" surface into the PDF
surface.

One of the cairo gurus will be able to better answer this though..

Internally there is a thing called a "meta-surface" which caches the
drawing operations - so you should still get vector output. Calling
cairo_surface_create_similar() on the PDF one will get you a
meta-surface. You have to specify width / height, but I don't think that
really matters.

Looking at the code, I think the operations you want to get the extents
of a surface (meta or otherwise) are not exposed in the external APIs.
(Cairo even has an "analysis" surface internally, which sounds much like
what you want here - unfortunately not exposed).

There are, however APIs which can compute the extents for various
operations:

cairo_fill_extents
cairo_glyph_extents
cairo_path_extents
cairo_stroke_extents
cairo_text_extents


Hope that is of some help,

-- 
Peter Clifton

Electrical Engineering Division,
Engineering Department,
University of Cambridge,
9, JJ Thomson Avenue,
Cambridge
CB3 0FA

Tel: +44 (0)7729 980173 - (No signal in the lab!)



More information about the cairo mailing list