[pan2: 51/68] Replace deprecated gdk_pixmap_create_from_data.



commit efa630cd40541c88abe5f20b03a08eb9d3982b43
Author: K. Haley <haleykd users sf net>
Date:   Wed Aug 18 15:49:51 2010 -0600

    Replace deprecated gdk_pixmap_create_from_data.
    
    Replace with cairo to render x-face.  And don't invert the BW data.

 pan/gui/body-pane.cc |   10 ++++----
 pan/gui/xface.c      |   53 ++++++++++++++++++++++++-------------------------
 pan/gui/xface.h      |    3 +-
 3 files changed, 33 insertions(+), 33 deletions(-)
---
diff --git a/pan/gui/body-pane.cc b/pan/gui/body-pane.cc
index 7643e16..6090f3a 100644
--- a/pan/gui/body-pane.cc
+++ b/pan/gui/body-pane.cc
@@ -1062,13 +1062,13 @@ BodyPane :: set_text_from_message (GMimeMessage * message)
   gtk_label_set_width_chars (GTK_LABEL(_headers), (int)w);
 
   // set the x-face...
-  GdkPixbuf * pixbuf (0);
+  GdkPixmap *pixmap = NULL;
   const char * pch = message ? g_mime_object_get_header ((GMimeObject *) message, "X-Face") : 0;
   if (pch && _xface->window)
-    pixbuf = pan_gdk_pixbuf_create_from_x_face (gtk_widget_get_colormap(_xface), _xface->window, pch);
-  gtk_image_set_from_pixbuf (GTK_IMAGE(_xface), pixbuf);
-  if (pixbuf)
-    g_object_unref (pixbuf);
+    pixmap = pan_gdk_pixmap_create_from_x_face (_xface->window, pch);
+  gtk_image_set_from_pixmap (GTK_IMAGE(_xface), pixmap, NULL);
+  if (pixmap)
+    g_object_unref (pixmap);
 
   // set the terse headers...
   s.clear ();
diff --git a/pan/gui/xface.c b/pan/gui/xface.c
index 3914542..70583d5 100644
--- a/pan/gui/xface.c
+++ b/pan/gui/xface.c
@@ -1056,52 +1056,51 @@ uncompface(char * fbuf)
 
 /** end uncompface.c */
 
-GdkPixbuf*
-pan_gdk_pixbuf_create_from_x_face (GdkColormap* cmap, GdkDrawable *drawable, const char *text)
+GdkPixmap*
+pan_gdk_pixmap_create_from_x_face (GdkDrawable *widget, const char *text)
 {
   int status;
+  const int stride = cairo_format_stride_for_width( CAIRO_FORMAT_A1, WIDTH);
   char xface [2048];
-  GdkPixbuf * pixbuf = 0;
+  GdkPixmap * pixmap = NULL;
   
   g_strlcpy (xface, text, sizeof(xface));
   status = uncompface (xface);
   if (status >= 0)
   {
-    GdkPixmap * pixmap;
-    GdkColor black, white;
-    int i;
-    char *bits, *bp;
+    int i, l = stride * HEIGHT;
+    unsigned char *bits;
     const char *p;
 
     /* the compface library exports char F[], which uses a single
        byte per pixel to represent a 48x48 bitmap.  Yuck.
-       This loop written by Andy Piper. */
-    bp = bits = g_newa (char, PIXELS/8);
-    for (i=0, p=F; i<(PIXELS/8); ++i)
+       This loop written by Andy Piper.
+
+       modified to account for cairo stride.*/
+    bits = g_newa (char, l);
+    for (i=0, p=F; i<l; )
     {
       int n, b;
       /* reverse the bit order of each byte... */
       for (b=n=0; b<8; ++b)
         n |= ((*p++) << b);
-      n = ~n;
-      *bp++ = (char) n;
+      bits[i] = (unsigned char) n;
+      if( ++i % stride == WIDTH/8)
+        i = (i / stride + 1) * stride;
     }
 
-    if (!cmap)
-      cmap = gdk_colormap_get_system ();
-
-    gdk_color_parse ("black", &black);
-    gdk_colormap_alloc_color (cmap, &black, FALSE, TRUE);
-    gdk_color_parse ("white", &white);
-    gdk_colormap_alloc_color (cmap, &white, FALSE, TRUE);
-
-    pixmap = gdk_pixmap_create_from_data (drawable, bits, WIDTH, HEIGHT, -1, &white, &black);
-    pixbuf = gdk_pixbuf_get_from_drawable (NULL, pixmap, cmap, 0, 0, 0, 0, WIDTH, HEIGHT);
-    g_object_unref (pixmap);
-
-    gdk_colormap_free_colors (cmap, &white, 1 );
-    gdk_colormap_free_colors (cmap, &black, 1 );
+    cairo_surface_t *face = cairo_image_surface_create_for_data(bits, CAIRO_FORMAT_A1, WIDTH, HEIGHT, stride);
+    pixmap = gdk_pixmap_new(widget, WIDTH, HEIGHT, -1);
+    cairo_t *ct = gdk_cairo_create(pixmap);
+    cairo_set_source_rgb(ct, 1.0, 1.0, 1.0);
+    cairo_paint(ct);
+    cairo_set_source_surface(ct, face, 0, 0);
+    cairo_paint(ct);
+    cairo_surface_destroy(face);
+    cairo_destroy(ct);
+
+    g_free(bits);
   }
 
-  return pixbuf;
+  return pixmap;
 }
diff --git a/pan/gui/xface.h b/pan/gui/xface.h
index 4516622..efd44cc 100644
--- a/pan/gui/xface.h
+++ b/pan/gui/xface.h
@@ -1,12 +1,13 @@
 #ifndef __PAN_XFACE_H__
 #define __PAN_XFACE_H__
 
+#include <gdk/gdk.h>
 #include <gdk-pixbuf/gdk-pixbuf.h>
 
 G_BEGIN_DECLS
 
 /** @ingroup GUI */
-extern GdkPixbuf*   pan_gdk_pixbuf_create_from_x_face (GdkColormap*, GdkDrawable*, const char *);
+extern GdkPixmap*   pan_gdk_pixmap_create_from_x_face (GdkDrawable*, const char *);
 
 G_END_DECLS
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]