[cairo] wrapping a complete surface at a given width

Carl Worth cworth at cworth.org
Mon Feb 18 12:48:57 PST 2008

On Mon, 18 Feb 2008 20:32:37 -0000, "jan aerts (RI)" wrote:
> I have been happily coding cairo (using the ruby bindings) to develop a
> genetics visualization toolkit. At the moment I'm trying to add some new
> functionality for which I need your help...

I'm quite glad to hear that you are having fun using cairo!

> Many of the pictures generated by my toolkit are _very_ wide but have a
> very limited height. Is there a way to basically wrap a whole picture at
> e.g. 800 pixels? So suppose my ImageSurface is 2000 pixels wide and 200
> pixels high, is there a transformation that can cut it in pieces of 800,
> 800 and 400 pixels wide and put those pieces underneath each other? So
> the end result would be a picture of 800 pixels wide and 600 pixels
> high...

There's not really anything in cairo to support that kind of thing. It
would have to be something that you would implement on top of cairo.

That is, if you have some draw_something() function, then you could
certainly call it multiple times something like this:

	surface = cairo_image_surface_create (format, 800, 600);
	cr = cairo_create (surface);

	/* Draw the first section */
	cairo_save (cr);
	    cairo_rectangle (cr, 0, 0, 800, 200);
	    cairo_clip (cr);

	    draw_something (cr);
	cairo_restore (cr);

	/* And the second section */
	cairo_translate (cr, -800, 200);
	cairo_save (cr);
	    cairo_rectangle (cr, 800, 200, 800, 200);
	    cairo_clip (cr);

	    draw_something (cr);
	cairo_restore (cr);

	/* And the third section */
	cairo_translate (cr, -800, 200);
	cairo_save (cr);
	    cairo_rectangle (cr, 1600, 400, 800, 200);
	    cairo_clip (cr);

	    draw_something (cr);
	cairo_restore (cr);

I haven't tested that, but hopefully it's correct, and hopefully
you'll find that useful. Of course, you'd likely end up wanting to
make a loop out of that rather than just open-coding it like that, but
hopefully you know how to do that.

> The information contained in this e-mail (including any attachments) is
> confidential and is intended for the use of  the addressee only.

Do note that the addressee, "cairo at cairographics.org", is a public
mailing-list with public and permanent archives. So there is
explicitly no confidentiality here. That means that one of the
following holds:

	1. The message is actually confidential, in which case you're
           doing something wrong by posting confidential material to a
           public list.

	2. The message is not at all confidential, so you shouldn't be
           claiming that it is. In which case, please find a way to
           use an email system that doesn't put such bogus claims of
           confidentiality on your messages. Thanks!

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.cairographics.org/archives/cairo/attachments/20080218/d12331de/attachment.pgp 

More information about the cairo mailing list