[cairo] copying region of a large surface to a smaller surface

Peter Groves pdgroves at gmail.com
Mon Oct 18 16:18:31 PDT 2010


Hi,

I'm trying to implement a Gtk widget that is similar to a scroll
window, where there is a large off-screen surface that is drawn to, but
then a region of that surface is copied to a smaller surface that is
actually displayed in a gtk drawing area.

I'm finding this surprisingly difficult to find a simple way to
specify the coordinates of the upper left corner of the *source*
surface to copy to the origin (0,0) of the destination surface. I
normally do these kinds of image transfers using set_source_surface,
and then just drawing a rectangle then size of the destination surface.
However, the api has you specify the coordinates on the destination
surface, and automatically places the origin of the source there.

Is it legitimate to use negative coordinates when calling
set_source_surface so that the origin of the larger source
surface is way out of bounds of the destination (above and to the left
of the origin)? Even if I could get that to work I'd be worried that
doing that isn't officially supported and might break in later versions.

I could also try using a translation matrix, but again I don't
understand if there are restrictions on drawing out-of-bounds of a
surface.

-Peter


More information about the cairo mailing list