changeset 1148:439f276042cc

Implemented dw_pixmap_set_font() on GTK3. Better fix for missing font during dw_draw_text() on GTK3... Don't clobber fontname variable.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sun, 11 Sep 2011 22:09:10 +0000
parents 091ed7c20b3f
children cf934fd39d03
files dw.h gtk3/dw.c
diffstat 2 files changed, 37 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/dw.h	Sun Sep 11 21:56:55 2011 +0000
+++ b/dw.h	Sun Sep 11 22:09:10 2011 +0000
@@ -1259,7 +1259,7 @@
 typedef struct _hpixmap {
    unsigned long width, height;
    HWND handle;
-   void *font;
+   char *font;
 #if GTK_MAJOR_VERSION > 2
    GdkPixbuf *pixbuf;  /* the actual image */
    cairo_surface_t *image; /* Going to have dual storage for now */
--- a/gtk3/dw.c	Sun Sep 11 21:56:55 2011 +0000
+++ b/gtk3/dw.c	Sun Sep 11 22:09:10 2011 +0000
@@ -6832,7 +6832,7 @@
    int _locked_by_me = FALSE;
    cairo_t *cr = NULL;
    PangoFontDescription *font;
-   char *fontname = "fixed";
+   char *tmpname, *fontname = "fixed";
 
    if(!text)
       return;
@@ -6848,16 +6848,22 @@
          return;
       }
       cr = gdk_cairo_create(window);
-      fontname = (char *)g_object_get_data(G_OBJECT(handle), "_dw_fontname");
+      if((tmpname = (char *)g_object_get_data(G_OBJECT(handle), "_dw_fontname")))
+         fontname = tmpname;
    }
    else if(pixmap)
    {
-      fontname = (char *)g_object_get_data(G_OBJECT(pixmap->handle), "_dw_fontname");
+      char *tmpname;
+      
+      if(pixmap->font)
+         fontname = pixmap->font;
+      else if(pixmap->handle && (tmpname = (char *)g_object_get_data(G_OBJECT(pixmap->handle), "_dw_fontname")))
+         fontname = tmpname;
       cr = cairo_create(pixmap->image);
    }
    if(cr)
    {
-      font = pango_font_description_from_string(fontname ? fontname : "Sans");
+      font = pango_font_description_from_string(fontname);
       if(font)
       {
          PangoContext *context = pango_cairo_create_context(cr);
@@ -7153,6 +7159,30 @@
 }
 
 /*
+ * Sets the font used by a specified pixmap.
+ * Normally the pixmap font is obtained from the associated window handle.
+ * However this can be used to override that, or for pixmaps with no window.
+ * Parameters:
+ *          pixmap: Handle to a pixmap returned by dw_pixmap_new() or
+ *                  passed to the application via a callback.
+ *          fontname: Name and size of the font in the form "size.fontname"
+ * Returns:
+ *       DW_ERROR_NONE on success and DW_ERROR_GENERAL on failure.
+ */
+int API dw_pixmap_set_font(HPIXMAP pixmap, char *fontname)
+{
+    if(pixmap && fontname && *fontname)
+    {
+         char *oldfont = pixmap->font;
+         pixmap->font = strdup(fontname);
+         if(oldfont)
+             free(oldfont);
+         return DW_ERROR_NONE;
+    }
+    return DW_ERROR_GENERAL;
+}
+
+/*
  * Destroys an allocated pixmap.
  * Parameters:
  *       pixmap: Handle to a pixmap returned by
@@ -7165,6 +7195,8 @@
    DW_MUTEX_LOCK;
    g_object_unref(G_OBJECT(pixmap->pixbuf));
    cairo_surface_destroy(pixmap->image);
+   if(pixmap->font)
+      free(pixmap->font);
    free(pixmap);
    DW_MUTEX_UNLOCK;
 }