changeset 28598:401012968fea

Fix apply_font to use a PangoFontDescription to get the requested font family name rather than just stripping any trailing digits from the full font string. This seemed to do the right thing for me for all fonts I tried, but it would be good if people who actually use custom fonts would give this a whirl. Fixes #5030
author Etan Reisner <pidgin@unreliablesource.net>
date Sat, 15 Aug 2009 05:45:58 +0000
parents 329d665c78b2
children 618c41ef0ab8
files pidgin/gtkimhtmltoolbar.c
diffstat 1 files changed, 18 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/pidgin/gtkimhtmltoolbar.c	Sat Aug 15 05:11:36 2009 +0000
+++ b/pidgin/gtkimhtmltoolbar.c	Sat Aug 15 05:45:58 2009 +0000
@@ -133,22 +133,30 @@
 	destroy_toolbar_font(widget, NULL, toolbar);
 }
 
-static void apply_font(GtkWidget *widget, GtkFontSelection *fontsel)
+static void
+apply_font(GtkWidget *widget, GtkFontSelectionDialog *fontsel)
 {
 	/* this could be expanded to include font size, weight, etc.
 	   but for now only works with font face */
-	char *fontname;
-	char *space;
-	GtkIMHtmlToolbar *toolbar =  g_object_get_data(G_OBJECT(fontsel), "purple_toolbar");
+	gchar *fontname = gtk_font_selection_dialog_get_font_name(fontsel);
+	GtkIMHtmlToolbar *toolbar = g_object_get_data(G_OBJECT(fontsel),
+	                                              "purple_toolbar");
 
-	fontname = gtk_font_selection_dialog_get_font_name(GTK_FONT_SELECTION_DIALOG(fontsel));
+	if (fontname) {
+		const gchar *family_name = NULL;
+		PangoFontDescription *desc = NULL;
 
-	space = strrchr(fontname, ' ');
-	if(space && isdigit(*(space+1)))
-		*space = '\0';
+		desc = pango_font_description_from_string(fontname);
+		family_name = pango_font_description_get_family(desc);
 
-	gtk_imhtml_toggle_fontface(GTK_IMHTML(toolbar->imhtml), fontname);
-	g_free(fontname);
+		if (family_name) {
+			gtk_imhtml_toggle_fontface(GTK_IMHTML(toolbar->imhtml),
+			                           family_name);
+		}
+
+		pango_font_description_free(desc);
+		g_free(fontname);
+	}
 
 	cancel_toolbar_font(NULL, toolbar);
 }