[cairo-commit] pycairo/cairo pycairo-context.c, 1.20, 1.21 cairogtkmodule.c, 1.10, 1.11

Steve Chaplin commit at pdx.freedesktop.org
Fri Mar 18 01:55:54 PST 2005


Committed by: stevech1097

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

Modified Files:
	pycairo-context.c cairogtkmodule.c 
Log Message:
SC 2005/03/18

Index: pycairo-context.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo-context.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- pycairo-context.c	14 Mar 2005 16:43:41 -0000	1.20
+++ pycairo-context.c	18 Mar 2005 09:55:52 -0000	1.21
@@ -1019,12 +1019,7 @@
 static PyObject *
 pycairo_get_pattern(PyCairoContext *self)
 {
-    cairo_pattern_t *pattern;
-
-    pattern = cairo_get_pattern(self->ctx);
-    if (pattern)
-	return pycairo_pattern_wrap(pattern);
-    Py_RETURN_NONE;
+    return pycairo_pattern_wrap(cairo_get_pattern(self->ctx));
 }
 
 /* struct and wrappers for cairo_get_path() */ 
@@ -1092,8 +1087,8 @@
 {
     py_path_callbacks callbacks;
 
-    if(!PyArg_ParseTuple(args, "OOOO:Context.get_path_flat",
-			  &callbacks.move_to, &callbacks.line_to, &callbacks.curve_to, &callbacks.close_path))
+    if(!PyArg_ParseTuple(args, "OOOO:Context.get_path",
+			 &callbacks.move_to, &callbacks.line_to, &callbacks.curve_to, &callbacks.close_path))
 	return NULL;
 
     if(!PyCallable_Check(callbacks.move_to)) {
@@ -1149,79 +1144,79 @@
 
 static PyMethodDef pycairo_methods[] = {
     /* append_path_data */
-    { "arc",          (PyCFunction)pycairo_arc, METH_VARARGS },
-    { "arc_negative", (PyCFunction)pycairo_arc_negative, METH_VARARGS },
-    { "clip",         (PyCFunction)pycairo_clip, METH_NOARGS },
-    { "close_path",   (PyCFunction)pycairo_close_path, METH_NOARGS },
+    { "arc",          (PyCFunction)pycairo_arc,           METH_VARARGS },
+    { "arc_negative", (PyCFunction)pycairo_arc_negative,  METH_VARARGS },
+    { "clip",         (PyCFunction)pycairo_clip,          METH_NOARGS },
+    { "close_path",   (PyCFunction)pycairo_close_path,    METH_NOARGS },
     { "concat_matrix", (PyCFunction)pycairo_concat_matrix, METH_VARARGS },
-    { "copy",         (PyCFunction)pycairo_copy, METH_VARARGS },
-    { "copy_page",    (PyCFunction)pycairo_copy_page, METH_NOARGS },
+    { "copy",         (PyCFunction)pycairo_copy,          METH_VARARGS },
+    { "copy_page",    (PyCFunction)pycairo_copy_page,     METH_NOARGS },
     /* copy_path_data */
     /* copy_path_data_flat */
-    { "curve_to",     (PyCFunction)pycairo_curve_to, METH_VARARGS },
+    { "curve_to",     (PyCFunction)pycairo_curve_to,      METH_VARARGS },
     { "default_matrix", (PyCFunction)pycairo_default_matrix, METH_NOARGS },
-    { "fill",         (PyCFunction)pycairo_fill, METH_NOARGS },
-    { "get_path",     (PyCFunction)pycairo_get_path, METH_VARARGS },
+    { "fill",         (PyCFunction)pycairo_fill,          METH_NOARGS },
+    { "get_path",     (PyCFunction)pycairo_get_path,      METH_VARARGS },
     { "get_path_flat", (PyCFunction)pycairo_get_path_flat, METH_VARARGS },
-    /* TODO: { "glyph_extents", (PyCFunction)pycairo_glyph_extents, METH_NOARGS }, */
-    /* TODO: { "glyph_path", (PyCFunction)pycairo_glyph_path, METH_VARARGS }, */
+    /* glyph_extents */
+    /* glyph_path */
     { "identity_matrix", (PyCFunction)pycairo_identity_matrix, METH_NOARGS },
-    { "in_fill",      (PyCFunction)pycairo_in_fill, METH_VARARGS },
-    { "in_stroke",    (PyCFunction)pycairo_in_stroke, METH_VARARGS },
-    { "init_clip",    (PyCFunction)pycairo_init_clip, METH_NOARGS },
+    { "in_fill",      (PyCFunction)pycairo_in_fill,       METH_VARARGS },
+    { "in_stroke",    (PyCFunction)pycairo_in_stroke,     METH_VARARGS },
+    { "init_clip",    (PyCFunction)pycairo_init_clip,     METH_NOARGS },
     { "inverse_transform_distance",
-      (PyCFunction)pycairo_inverse_transform_distance, METH_VARARGS },
-    { "inverse_transform_point", (PyCFunction)pycairo_inverse_transform_point,
-      METH_VARARGS },
-    { "line_to",      (PyCFunction)pycairo_line_to, METH_VARARGS },
-    { "move_to",      (PyCFunction)pycairo_move_to, METH_VARARGS },
-    { "new_path",     (PyCFunction)pycairo_new_path, METH_NOARGS },
-    { "rectangle",    (PyCFunction)pycairo_rectangle, METH_VARARGS },
-    { "rel_curve_to", (PyCFunction)pycairo_rel_curve_to, METH_VARARGS },
-    { "rel_line_to",  (PyCFunction)pycairo_rel_line_to, METH_VARARGS },
-    { "rel_move_to",  (PyCFunction)pycairo_rel_move_to, METH_VARARGS },
-    { "restore", (PyCFunction)pycairo_restore, METH_NOARGS },
-    { "rotate", (PyCFunction)pycairo_rotate, METH_VARARGS },
-    { "save", (PyCFunction)pycairo_save, METH_NOARGS },
-    { "scale", (PyCFunction)pycairo_scale, METH_VARARGS },
-    { "scale_font", (PyCFunction)pycairo_scale_font, METH_VARARGS },
-    { "select_font", (PyCFunction)pycairo_select_font, METH_VARARGS },
-    { "set_alpha", (PyCFunction)pycairo_set_alpha, METH_VARARGS },
-    { "set_dash", (PyCFunction)pycairo_set_dash, METH_VARARGS },
-    { "set_fill_rule", (PyCFunction)pycairo_set_fill_rule, METH_VARARGS },
-    { "set_font", (PyCFunction)pycairo_set_font, METH_VARARGS },
-    { "set_line_cap", (PyCFunction)pycairo_set_line_cap, METH_VARARGS },
-    { "set_line_join", (PyCFunction)pycairo_set_line_join, METH_VARARGS },
-    { "set_line_width", (PyCFunction)pycairo_set_line_width, METH_VARARGS },
-    { "set_matrix", (PyCFunction)pycairo_set_matrix, METH_VARARGS },
-    { "set_miter_limit", (PyCFunction)pycairo_set_miter_limit, METH_VARARGS },
-    { "set_operator", (PyCFunction)pycairo_set_operator, METH_VARARGS },
-    { "set_pattern", (PyCFunction)pycairo_set_pattern, METH_VARARGS },
-    { "set_rgb_color", (PyCFunction)pycairo_set_rgb_color, METH_VARARGS },
+      (PyCFunction)pycairo_inverse_transform_distance,    METH_VARARGS },
+    { "inverse_transform_point", 
+      (PyCFunction)pycairo_inverse_transform_point,       METH_VARARGS },
+    { "line_to",      (PyCFunction)pycairo_line_to,       METH_VARARGS },
+    { "move_to",      (PyCFunction)pycairo_move_to,       METH_VARARGS },
+    { "new_path",     (PyCFunction)pycairo_new_path,      METH_NOARGS },
+    { "rectangle",    (PyCFunction)pycairo_rectangle,     METH_VARARGS },
+    { "rel_curve_to", (PyCFunction)pycairo_rel_curve_to,  METH_VARARGS },
+    { "rel_line_to",  (PyCFunction)pycairo_rel_line_to,   METH_VARARGS },
+    { "rel_move_to",  (PyCFunction)pycairo_rel_move_to,   METH_VARARGS },
+    { "restore",      (PyCFunction)pycairo_restore,       METH_NOARGS },
+    { "rotate",       (PyCFunction)pycairo_rotate,        METH_VARARGS },
+    { "save",         (PyCFunction)pycairo_save,          METH_NOARGS },
+    { "scale",        (PyCFunction)pycairo_scale,         METH_VARARGS },
+    { "scale_font",   (PyCFunction)pycairo_scale_font,    METH_VARARGS },
+    { "select_font",  (PyCFunction)pycairo_select_font,   METH_VARARGS },
+    { "set_alpha",    (PyCFunction)pycairo_set_alpha,     METH_VARARGS },
+    { "set_dash",     (PyCFunction)pycairo_set_dash,      METH_VARARGS },
+    { "set_fill_rule", (PyCFunction)pycairo_set_fill_rule,METH_VARARGS },
+    { "set_font",     (PyCFunction)pycairo_set_font,      METH_VARARGS },
+    { "set_line_cap", (PyCFunction)pycairo_set_line_cap,  METH_VARARGS },
+    { "set_line_join",(PyCFunction)pycairo_set_line_join, METH_VARARGS },
+    { "set_line_width",(PyCFunction)pycairo_set_line_width,METH_VARARGS },
+    { "set_matrix",   (PyCFunction)pycairo_set_matrix,    METH_VARARGS },
+    { "set_miter_limit",(PyCFunction)pycairo_set_miter_limit, METH_VARARGS },
+    { "set_operator", (PyCFunction)pycairo_set_operator,  METH_VARARGS },
+    { "set_pattern",  (PyCFunction)pycairo_set_pattern,   METH_VARARGS },
+    { "set_rgb_color",(PyCFunction)pycairo_set_rgb_color, METH_VARARGS },
 #ifdef CAIRO_HAS_PDF_SURFACE
-    { "set_target_pdf", (PyCFunction)pycairo_set_target_pdf, METH_VARARGS},
+    { "set_target_pdf",(PyCFunction)pycairo_set_target_pdf,METH_VARARGS},
 #endif
 #ifdef CAIRO_HAS_PS_SURFACE
-    { "set_target_ps", (PyCFunction)pycairo_set_target_ps, METH_VARARGS},
+    { "set_target_ps",(PyCFunction)pycairo_set_target_ps, METH_VARARGS},
 #endif
 #ifdef CAIRO_HAS_PNG_SURFACE
-    { "set_target_png", (PyCFunction)pycairo_set_target_png, METH_VARARGS },
+    { "set_target_png",(PyCFunction)pycairo_set_target_png,METH_VARARGS },
 #endif
-    { "set_target_surface", (PyCFunction)pycairo_set_target_surface,
+    { "set_target_surface",(PyCFunction)pycairo_set_target_surface,
       METH_VARARGS },
-    { "set_tolerance", (PyCFunction)pycairo_set_tolerance, METH_VARARGS },
-    /* TODO: { "show_glyphs", (PyCFunction)pycairo_show_glyphs, METH_NOARGS }, */
-    { "show_page", (PyCFunction)pycairo_show_page, METH_NOARGS },
-    { "show_surface", (PyCFunction)pycairo_show_surface, METH_VARARGS },
-    { "show_text", (PyCFunction)pycairo_show_text, METH_VARARGS },
-    { "stroke", (PyCFunction)pycairo_stroke, METH_NOARGS },
-    { "text_extents", (PyCFunction)pycairo_text_extents, METH_VARARGS },
-    { "text_path", (PyCFunction)pycairo_text_path, METH_VARARGS },
-    { "transform_font", (PyCFunction)pycairo_transform_font, METH_VARARGS },
-    { "transform_point", (PyCFunction)pycairo_transform_point, METH_VARARGS },
-    { "transform_distance", (PyCFunction)pycairo_transform_distance,
+    { "set_tolerance", (PyCFunction)pycairo_set_tolerance,METH_VARARGS },
+    /* show_glyphs */
+    { "show_page",    (PyCFunction)pycairo_show_page,     METH_NOARGS },
+    { "show_surface", (PyCFunction)pycairo_show_surface,  METH_VARARGS },
+    { "show_text",    (PyCFunction)pycairo_show_text,     METH_VARARGS },
+    { "stroke",       (PyCFunction)pycairo_stroke,        METH_NOARGS },
+    { "text_extents", (PyCFunction)pycairo_text_extents,  METH_VARARGS },
+    { "text_path",    (PyCFunction)pycairo_text_path,     METH_VARARGS },
+    { "transform_font",(PyCFunction)pycairo_transform_font,METH_VARARGS },
+    { "transform_point",(PyCFunction)pycairo_transform_point,METH_VARARGS },
+    { "transform_distance",(PyCFunction)pycairo_transform_distance,
       METH_VARARGS },
-    { "translate", (PyCFunction)pycairo_translate, METH_VARARGS },
+    { "translate",    (PyCFunction)pycairo_translate,     METH_VARARGS },
     { NULL, NULL, 0 }
 };
 

Index: cairogtkmodule.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/cairogtkmodule.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- cairogtkmodule.c	16 Mar 2005 11:03:19 -0000	1.10
+++ cairogtkmodule.c	18 Mar 2005 09:55:52 -0000	1.11
@@ -52,6 +52,22 @@
 static PyTypeObject *_PyGdkWindow_Type;
 #define PyGdkWindow_Type (*_PyGdkWindow_Type)
 
+static cairo_format_t
+_DEPTH_TO_CAIRO_FORMAT (gint depth)
+{
+    switch (depth) {
+    case 1:
+	return CAIRO_FORMAT_A1;
+    case 8:
+	return CAIRO_FORMAT_A8;
+    case 24:
+	return CAIRO_FORMAT_RGB24;
+    case 32:
+    default:
+	return CAIRO_FORMAT_ARGB32;
+    }
+}
+
 static PyObject *
 set_target_drawable(PyObject *self, PyObject *args)
 {
@@ -116,19 +132,19 @@
 {
     PyGObject *py_pixmap;
     GdkDrawable *gdk_pixmap;
-    cairo_format_t format;
     cairo_surface_t *surface;
 
-    if (!PyArg_ParseTuple(args, "O!i:surface_create_for_pixmap",
-			  &PyGdkPixmap_Type, &py_pixmap, &format))
+    if (!PyArg_ParseTuple(args, "O!:surface_create_for_pixmap",
+			  &PyGdkPixmap_Type, &py_pixmap))
 	return NULL;
 
     gdk_pixmap = GDK_PIXMAP(py_pixmap->obj);
-
+    /* auto determine format by using gdk_drawable_get_depth() to read
+       Pixmap info from the GTK+ cache */
     surface = cairo_xlib_surface_create_for_pixmap
 	(GDK_PIXMAP_XDISPLAY(gdk_pixmap),
 	 GDK_PIXMAP_XID(gdk_pixmap),
-	 format);
+	 _DEPTH_TO_CAIRO_FORMAT(gdk_drawable_get_depth(gdk_pixmap)));
     if (!surface)
 	return PyErr_NoMemory();
 
@@ -191,32 +207,32 @@
 surface_create_for_pixbuf(PyObject *self, PyObject *args)
 {
     PyGObject *py_pixbuf;
-    GdkPixbuf *pixbuf;
+    GdkPixbuf *gdk_pixbuf;
     cairo_surface_t *surface;
 
     if (!PyArg_ParseTuple(args, "O!:surface_create_for_pixbuf",
 			  &PyGdkPixbuf_Type, &py_pixbuf))
 	return NULL;
 
-    pixbuf = GDK_PIXBUF(py_pixbuf->obj);
+    gdk_pixbuf = GDK_PIXBUF(py_pixbuf->obj);
 
     /* this is the only format that matches cairo's image format.
      * GdkPixbuf uses RGBA, while Cairo uses ARGB, so we can't handle
      * pixbufs with alpha. */
-    if (gdk_pixbuf_get_colorspace(pixbuf) != GDK_COLORSPACE_RGB ||
-	gdk_pixbuf_get_bits_per_sample(pixbuf) != 8 ||
-	gdk_pixbuf_get_n_channels(pixbuf) != 4) {
+    if (gdk_pixbuf_get_colorspace(gdk_pixbuf) != GDK_COLORSPACE_RGB ||
+	gdk_pixbuf_get_bits_per_sample(gdk_pixbuf) != 8 ||
+	gdk_pixbuf_get_n_channels(gdk_pixbuf) != 4) {
 	PyErr_SetString(PyExc_ValueError,
 			"can only create a surface from a 24-bit RGB pixbuf "
 			"(ie. no alpha)");
 	return NULL;
     }
-    surface = cairo_image_surface_create_for_data(
-					     gdk_pixbuf_get_pixels(pixbuf),
-					     CAIRO_FORMAT_RGB24,
-					     gdk_pixbuf_get_width(pixbuf),
-					     gdk_pixbuf_get_height(pixbuf),
-					     gdk_pixbuf_get_rowstride(pixbuf));
+    surface = cairo_image_surface_create_for_data
+	(gdk_pixbuf_get_pixels(gdk_pixbuf),
+	 CAIRO_FORMAT_RGB24,
+	 gdk_pixbuf_get_width(gdk_pixbuf),
+	 gdk_pixbuf_get_height(gdk_pixbuf),
+	 gdk_pixbuf_get_rowstride(gdk_pixbuf));
     if (!surface)
 	return PyErr_NoMemory();
 
@@ -231,17 +247,16 @@
 
 static PyMethodDef cairogtk_functions[] = {
     { "set_target_drawable", (PyCFunction)set_target_drawable, METH_VARARGS },
-    /* deprecated */
-    { "surface_create_for_drawable", (PyCFunction)surface_create_for_drawable,
-      METH_VARARGS },
-    { "surface_create_for_pixbuf", (PyCFunction)surface_create_for_pixbuf,
-      METH_VARARGS },
-    { "surface_create_for_pixmap", (PyCFunction)surface_create_for_pixmap,
-      METH_VARARGS },
-    { "surface_create_for_pixmap_with_visual", (PyCFunction)surface_create_for_pixmap_with_visual,
-      METH_VARARGS },
-    { "surface_create_for_window_with_visual", (PyCFunction)surface_create_for_window_with_visual,
-      METH_VARARGS },
+    { "surface_create_for_drawable",  /* deprecated */
+      (PyCFunction)surface_create_for_drawable,           METH_VARARGS },
+    { "surface_create_for_pixbuf", 
+      (PyCFunction)surface_create_for_pixbuf,             METH_VARARGS },
+    { "surface_create_for_pixmap", 
+      (PyCFunction)surface_create_for_pixmap,             METH_VARARGS },
+    { "surface_create_for_pixmap_with_visual", 
+      (PyCFunction)surface_create_for_pixmap_with_visual, METH_VARARGS },
+    { "surface_create_for_window_with_visual", 
+      (PyCFunction)surface_create_for_window_with_visual, METH_VARARGS },
     { NULL, NULL, 0 }
 };
 




More information about the cairo-commit mailing list