[cairo-commit] pycairo/cairo cairogtkmodule.c,1.31,1.32

Steve Chaplin commit at pdx.freedesktop.org
Tue Aug 9 07:37:57 PDT 2005


Committed by: stevech1097

Update of /cvs/cairo/pycairo/cairo
In directory gabe:/tmp/cvs-serv752/cairo

Modified Files:
	cairogtkmodule.c 
Log Message:
'SC'

Index: cairogtkmodule.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/cairogtkmodule.c,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -d -r1.31 -r1.32
--- cairogtkmodule.c	1 Aug 2005 10:25:47 -0000	1.31
+++ cairogtkmodule.c	9 Aug 2005 14:37:55 -0000	1.32
@@ -1,4 +1,4 @@
-/* -*- mode: C; c-basic-offset: 4 -*- 
+/* -*- mode: C; c-basic-offset: 4 -*-
  *
  * Pycairo - Python bindings for cairo
  *
@@ -91,26 +91,36 @@
  * gdk_cairo_create() will be available in gtk 2.8
  */
 static cairo_t *
-gdk_cairo_create (GdkDrawable *drawable)
+gdk_cairo_create (GdkDrawable *target)
 {
     int width, height;
-    cairo_t *cr = NULL;
-    cairo_surface_t *surface = NULL;
-    GdkVisual *visual = gdk_drawable_get_visual (drawable);
+    int x_off=0, y_off=0;
+    cairo_t *cr;
+    cairo_surface_t *surface;
+    GdkDrawable *drawable = target;
+    GdkVisual *visual;
 
+    if (GDK_IS_WINDOW(target)) {
+        /* query the window's backbuffer if it has one */
+	GdkWindow *window = GDK_WINDOW(target);
+	gdk_window_get_internal_paint_info (window,
+					    &drawable, &x_off, &y_off);
+    }
+    visual = gdk_drawable_get_visual (drawable);
     gdk_drawable_get_size (drawable, &width, &height);
-    if (visual) 
+
+    if (visual) {
 	surface = cairo_xlib_surface_create (GDK_DRAWABLE_XDISPLAY (drawable),
 					     GDK_DRAWABLE_XID (drawable),
 					     GDK_VISUAL_XVISUAL (visual),
 					     width, height);
-    else if (gdk_drawable_get_depth (drawable) == 1)
-	surface = cairo_xlib_surface_create_for_bitmap 
+    } else if (gdk_drawable_get_depth (drawable) == 1) {
+	surface = cairo_xlib_surface_create_for_bitmap
 	    (GDK_PIXMAP_XDISPLAY (drawable),
 	     GDK_PIXMAP_XID (drawable),
 	     GDK_SCREEN_XSCREEN (gdk_drawable_get_screen (drawable)),
 	     width, height);
-    else {
+    } else {
 	g_warning ("Using Cairo rendering requires the drawable argument to\n"
 		   "have a specified colormap. All windows have a colormap,\n"
 		   "however, pixmaps only have colormap by default if they\n"
@@ -119,10 +129,9 @@
 		   "gdk_drawable_set_colormap");
 	return NULL;
     }
-    if (surface) {
-	cr = cairo_create (surface);
-	cairo_surface_destroy (surface);
-    }
+    cairo_surface_set_device_offset (surface, -x_off, -y_off);
+    cr = cairo_create (surface);
+    cairo_surface_destroy (surface);
     return cr;
 }
 #endif
@@ -144,7 +153,7 @@
 
 static PyMethodDef cairogtk_functions[] = {
     { "gdk_cairo_create", (PyCFunction)pygdk_cairo_create,     METH_VARARGS },
-    { "surface_create_for_pixbuf", 
+    { "surface_create_for_pixbuf",
       (PyCFunction)surface_create_for_pixbuf,                  METH_VARARGS },
     { NULL, NULL, 0 }
 };
@@ -163,8 +172,8 @@
     mod = PyImport_ImportModule("gtk.gdk");
     if (!mod)
 	return;
-    _PyGdkDrawable_Type = (PyTypeObject *)PyObject_GetAttrString(mod, 
+    _PyGdkDrawable_Type = (PyTypeObject *)PyObject_GetAttrString(mod,
 								 "Drawable");
-    _PyGdkPixbuf_Type   = (PyTypeObject *)PyObject_GetAttrString(mod, 
+    _PyGdkPixbuf_Type   = (PyTypeObject *)PyObject_GetAttrString(mod,
 								 "Pixbuf");
 }




More information about the cairo-commit mailing list