From 3c3df8f0f19f6fb87931bd68b8dbb61bc3af0de0 Mon Sep 17 00:00:00 2001 From: Tor Lillqvist Date: Mon, 26 May 2008 21:30:59 +0000 Subject: [PATCH] Prune duplicated face names. Makes the GTK+ font selector look a bit saner 2008-05-27 Tor Lillqvist * pango/pangowin32-fontmap.c (pango_win32_family_list_faces): Prune duplicated face names. Makes the GTK+ font selector look a bit saner for the "sans", "serif" and "monospace" standard pseudo font families with just one instance of each style. That we get duplicated styles in the first place is because of the magic code snippet in pango_win32_insert_font() that sets up the list of faces for the standard pseudo font families. I don't like that code but without it these families wouldn't currently show up in the font selector at all. A problem is still that the magic code blindly adds all random fonts that claim to be FF_ROMAN to the list of faces for the "serif" family, etc. I think it would be preferrable to do it only for well-known sensible fonts. That would be those that are listed in builtin_aliases in pango-utils.c, I guess. svn path=/trunk/; revision=2638 --- ChangeLog | 19 +++++++++++++++++++ pango/pangowin32-fontmap.c | 45 +++++++++++++++++++++++++++++++++++++-------- 2 files changed, 56 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index efdc331..264cbcc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,22 @@ +2008-05-27 Tor Lillqvist + + * pango/pangowin32-fontmap.c (pango_win32_family_list_faces): + Prune duplicated face names. Makes the GTK+ font selector look a + bit saner for the "sans", "serif" and "monospace" standard pseudo + font families with just one instance of each style. + + That we get duplicated styles in the first place is because of the + magic code snippet in pango_win32_insert_font() that sets up the + list of faces for the standard pseudo font families. I don't like + that code but without it these families wouldn't currently show up + in the font selector at all. + + A problem is still that the magic code blindly adds all random + fonts that claim to be FF_ROMAN to the list of faces for the + "serif" family, etc. I think it would be preferrable to do it only + for well-known sensible fonts. That would be those that are listed + in builtin_aliases in pango-utils.c, I guess. + 2008-05-26 Tor Lillqvist * pango/pangowin32-private.h diff --git a/pango/pangowin32-fontmap.c b/pango/pangowin32-fontmap.c index cff4312..3ee1d1d 100644 --- a/pango/pangowin32-fontmap.c +++ b/pango/pangowin32-fontmap.c @@ -357,22 +357,51 @@ pango_win32_family_list_faces (PangoFontFamily *family, int *n_faces) { PangoWin32Family *win32family = PANGO_WIN32_FAMILY (family); + GSList *p; + int n; + + p = win32family->faces; + n = 0; + while (p) + { + GSList *q; + q = win32family->faces; + while (q != p) + { + if (strcmp (pango_win32_face_get_face_name ((PangoFontFace *) q->data), + pango_win32_face_get_face_name ((PangoFontFace *) p->data)) == 0) + break; + q = q->next; + } + if (q == p) + n++; + p = p->next; + } - *n_faces = g_slist_length (win32family->faces); if (faces) { - GSList *tmp_list; - int i = 0; + int i; - *faces = g_new (PangoFontFace *, *n_faces); + *faces = g_new (PangoFontFace *, n); - tmp_list = win32family->faces; - while (tmp_list) + p = win32family->faces; + i = 0; + while (p) { - (*faces)[i++] = tmp_list->data; - tmp_list = tmp_list->next; + int j; + for (j = 0; j < i; j++) + { + if (strcmp (pango_win32_face_get_face_name ((*faces)[j]), + pango_win32_face_get_face_name ((PangoFontFace *) p->data)) == 0) + break; + } + if (j == i) + (*faces)[i++] = p->data; + p = p->next; } } + if (n_faces) + *n_faces = n; } static const char * -- 2.7.4