[cairo] measure needed canvas size

Andrea Canciani ranma42 at gmail.com
Tue Mar 15 10:41:04 PDT 2011


On Tue, Mar 15, 2011 at 6:36 PM, Sam Tygier <samtygier at yahoo.co.uk> wrote:
> hi
>
> i want to draw a diagram, 2d CAD layout sort of thing. i have a list of various
> shapes and lines and their positions and rotations in physical space. and i have
> a function that takes this list and draws it to a context of a surface (pdf or
> png).
>
> i'd like a way to know the maximum required space, so that i can choose a size
> for the canvas. currently i have a function that goes through the list and works
> out the coordinate of each point that needs to be drawn, and keeps a max_x,
> max_y, min_x, min_y. this function is very like my drawing function, which seems
> wasteful. also when the 2 functions diverge (when i add a new shape to the draw
> function) then the bounds get messed up.
>
> i am now wondering about making a dummy context object that ignored all but a
> few functions (move_to(), line_to()), and instead of drawing anything, just
> records  max_x, max_y, min_x, min_y.
>
> this seems to me like it must be a common problem. is there a better solution?
> is there already such a dummy context?

I believe this is what you're looking for:
http://cairographics.org/manual/cairo-Recording-Surfaces.html#cairo-recording-surface-ink-extents

Andrea

>
> i am using cairo  though python, if that makes a difference.
>
> thanks
>
> sam
>
>
>
>
> --
> cairo mailing list
> cairo at cairographics.org
> http://lists.cairographics.org/mailman/listinfo/cairo
>


More information about the cairo mailing list