Mercurial > dwindows
comparison 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 |
comparison
equal
deleted
inserted
replaced
2248:4fb54b9fcf78 | 2249:14a1e07e8f4e |
---|---|
3165 PangoFontDescription *pfont; | 3165 PangoFontDescription *pfont; |
3166 #else | 3166 #else |
3167 GdkFont *gdkfont; | 3167 GdkFont *gdkfont; |
3168 #endif | 3168 #endif |
3169 GtkWidget *handle2 = handle; | 3169 GtkWidget *handle2 = handle; |
3170 char *font = strdup(fontname); | 3170 char *font = fontname ? strdup(fontname) : NULL; |
3171 int _locked_by_me = FALSE; | 3171 int _locked_by_me = FALSE; |
3172 gpointer data; | 3172 gpointer data; |
3173 | 3173 |
3174 DW_MUTEX_LOCK; | 3174 DW_MUTEX_LOCK; |
3175 if(GTK_IS_SCROLLED_WINDOW(handle)) | 3175 if(GTK_IS_SCROLLED_WINDOW(handle)) |
3201 | 3201 |
3202 #if GTK_MAJOR_VERSION < 2 | 3202 #if GTK_MAJOR_VERSION < 2 |
3203 /* Free old font if it exists */ | 3203 /* Free old font if it exists */ |
3204 gdkfont = (GdkFont *)gtk_object_get_data(GTK_OBJECT(handle2), "_dw_gdkfont"); | 3204 gdkfont = (GdkFont *)gtk_object_get_data(GTK_OBJECT(handle2), "_dw_gdkfont"); |
3205 if(gdkfont) | 3205 if(gdkfont) |
3206 { | |
3206 gdk_font_unref(gdkfont); | 3207 gdk_font_unref(gdkfont); |
3207 gdkfont = gdk_font_load(fontname); | 3208 gdkfont = NULL; |
3209 } | |
3210 if(fontname) | |
3211 gdkfont = gdk_font_load(fontname); | |
3208 if(!gdkfont) | 3212 if(!gdkfont) |
3209 gdkfont = gdk_font_load("fixed"); | 3213 gdkfont = gdk_font_load("fixed"); |
3210 gtk_object_set_data(GTK_OBJECT(handle2), "_dw_gdkfont", (gpointer)gdkfont); | 3214 gtk_object_set_data(GTK_OBJECT(handle2), "_dw_gdkfont", (gpointer)gdkfont); |
3211 #else | 3215 #else |
3212 _convert_font(font); | 3216 if(font) |
3217 _convert_font(font); | |
3213 #endif | 3218 #endif |
3214 | 3219 |
3215 /* Free old font name if one is allocated */ | 3220 /* Free old font name if one is allocated */ |
3216 data = gtk_object_get_data(GTK_OBJECT(handle2), "_dw_fontname"); | 3221 data = gtk_object_get_data(GTK_OBJECT(handle2), "_dw_fontname"); |
3217 gtk_object_set_data(GTK_OBJECT(handle2), "_dw_fontname", (gpointer)font); | 3222 gtk_object_set_data(GTK_OBJECT(handle2), "_dw_fontname", (gpointer)font); |
3218 if(data) | 3223 if(data) |
3219 free(data); | 3224 free(data); |
3220 | 3225 |
3221 #if GTK_MAJOR_VERSION > 1 | 3226 #if GTK_MAJOR_VERSION > 1 |
3222 pfont = pango_font_description_from_string(fontname); | 3227 if(font && (pfont = pango_font_description_from_string(font))) |
3223 | |
3224 if(pfont) | |
3225 { | 3228 { |
3226 gtk_widget_modify_font(handle2, pfont); | 3229 gtk_widget_modify_font(handle2, pfont); |
3227 pango_font_description_free(pfont); | 3230 pango_font_description_free(pfont); |
3228 } | 3231 } |
3232 else | |
3233 gtk_widget_modify_font(handle2, NULL); | |
3229 #endif | 3234 #endif |
3230 DW_MUTEX_UNLOCK; | 3235 DW_MUTEX_UNLOCK; |
3231 return TRUE; | 3236 return TRUE; |
3232 } | 3237 } |
3233 | 3238 |