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

Stefan Salewski mail at ssalewski.de
Mon Oct 18 19:18:13 PDT 2010

On Mon, 2010-10-18 at 18:18 -0500, Peter Groves wrote:
> 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

I wanted to do something similar and was confused. Seems that your idea
with negative coordinates is correct, I found this with google:


More information about the cairo mailing list