diff gtk/dw.c @ 2249:14a1e07e8f4e

GTK2: Fix crash when calling dw_window_set_font() with NULL font name. Also there seemed to be some logic errors in the existing code, it did not seem to use the pango style font name after converting to it.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sun, 24 Jan 2021 19:38:54 +0000
parents 3e9c5bff0a57
children 3361ce6070ce
line wrap: on
line diff
--- a/gtk/dw.c	Sun Jan 24 19:27:16 2021 +0000
+++ b/gtk/dw.c	Sun Jan 24 19:38:54 2021 +0000
@@ -3167,7 +3167,7 @@
    GdkFont *gdkfont;
 #endif
    GtkWidget *handle2 = handle;
-   char *font = strdup(fontname);
+   char *font = fontname ? strdup(fontname) : NULL;
    int _locked_by_me = FALSE;
    gpointer data;
 
@@ -3203,13 +3203,18 @@
    /* Free old font if it exists */
    gdkfont = (GdkFont *)gtk_object_get_data(GTK_OBJECT(handle2), "_dw_gdkfont");
    if(gdkfont)
+   {
       gdk_font_unref(gdkfont);
-   gdkfont = gdk_font_load(fontname);
+      gdkfont = NULL;
+   }
+   if(fontname)
+      gdkfont = gdk_font_load(fontname);
    if(!gdkfont)
       gdkfont = gdk_font_load("fixed");
    gtk_object_set_data(GTK_OBJECT(handle2), "_dw_gdkfont", (gpointer)gdkfont);
 #else
-   _convert_font(font);
+   if(font)
+      _convert_font(font);
 #endif
 
    /* Free old font name if one is allocated */
@@ -3219,13 +3224,13 @@
       free(data);
 
 #if GTK_MAJOR_VERSION > 1
-   pfont = pango_font_description_from_string(fontname);
-
-   if(pfont)
+   if(font && (pfont = pango_font_description_from_string(font)))
    {
       gtk_widget_modify_font(handle2, pfont);
       pango_font_description_free(pfont);
    }
+   else
+      gtk_widget_modify_font(handle2, NULL);
 #endif
    DW_MUTEX_UNLOCK;
    return TRUE;