GNOME Bugzilla – Bug 54651
GtkFontSelection needs a filter feature
Last modified: 2011-09-05 04:17:41 UTC
Should be able to filter which fonts are offered for selection; e.g. a terminal might offer only monospace fonts.
For now terminal apps can just display an error if you choose a font that won't work well. Plus terminal apps probably want an X font selector not a Pango font selector anyhow.
The gvim GTK+ 2 port needs this feature too, and does use Pango. Currently it's just displaying an error message if you choose a proportional font (using a hack that compares the width of a few sample glyphs). But it's really tedious if the font selector shows say 200 fonts and about 5% of them can actually be used. I guess this could be implemented by an application by deriving a wrapper class from PangoFontMap, and applying filtering in the list_families() vfunc. Xft/FreeType seems to have API for this (the spacing property). But that would require including backend-related Pango headers, plus at least a fallback implementation for non-Xft platforms. I'm willing to implement the filtering feature; at least for the Xft backend (if noone else does :) But I'm not sure how much of this should go into Pango, and which filtering facilities other than monospace should be provided.
This bug causes problems for both the GNOME fixed width font selection in gnome-font-properties and for the Epiphany font preferences... Daniel, any plans to actually implement this? You will be my official Hero of the Week [tm].
Created attachment 62089 [details] [review] a patch This patch adds "monospace" property t GtkFontSelection and GtkFontButton. Is it needed to have custom filters? It's not hard to do something like: typedef void (*GtkFontFilterFunc) (PangoFontFamily *family, gpointer user_data); void gtk_font_selection_set_filter_func (GtkFontSelection *fontsel, GtkFontFilterFunc func, gpointer user_data); or even add something like GtkFileChooser api for filters. I personally only need monospace fonts, for a terminal.
Monospace, Serif and Sans-serif seem useful, eg. for web browsers or other html-related rendering applications (help applications, mail clients, ...)
Unfortunately, there is no way for Pango to tell whether a font is serif or not. So that filter can't be made.
We want to filter by font coverage too, so a filter is still required for Epiphany.
(In reply to comment #7) > We want to filter by font coverage too, so a filter is still required for > Epiphany. This font coverage thing, can it be done in font selector itself or you need a filter function? How about this: typedef enum { GTK_FONT_FILTER_NONE, GTK_FONT_FILTER_MONOSPACE /* something else? */ } GtkFontFilter; typedef gboolean (*GtkFontFilterFunc) (PangoFontFamily *family, gpointer data); void gtk_font_selection_set_filter (GtkFontSelection *fs, GtkFontFilter type); void gtk_font_selection_set_filter_func (GtkFontSelection *fs, GtkFontFilterFunc func, gpointer data, GDestroyNotify notify);
(In reply to comment #8) > typedef enum { > GTK_FONT_FILTER_NONE, > GTK_FONT_FILTER_MONOSPACE > /* something else? */ > } GtkFontFilter; GTK_FONT_FILTER_SERIF and GTK_FONT_FILTER_SANS_SERIF would make an aweful lot of sense as well, especially in a web context, since CSS font-family generic style include "sans-serif", "serif" and "monospace" (please ignore the "fantasy" stuff).
Also filtering by the font's coverage, so you could e.g. just show fonts with full Chinese coverage, fonts with Latin+Cyrillic coverage, etc.
(In reply to comment #9) > (In reply to comment #8) > > typedef enum { > > GTK_FONT_FILTER_NONE, > > GTK_FONT_FILTER_MONOSPACE > > /* something else? */ > > } GtkFontFilter; > > GTK_FONT_FILTER_SERIF and GTK_FONT_FILTER_SANS_SERIF would make an aweful lot > of sense as well, especially in a web context, since CSS font-family generic > style include "sans-serif", "serif" and "monospace" (please ignore the > "fantasy" stuff). I trusted comment #6 which said it's impossible :) (In reply to comment #10) > Also filtering by the font's coverage, so you could e.g. just show fonts with > full Chinese coverage, fonts with Latin+Cyrillic coverage, etc. How do you give language to the filter, do you give it a string "Chinese" or some pango stuff or something? Any pointers? I am willing to write the code but have only vague idea about what should be done; and I do want monospace filter! (I have a copy of GtkFontSelection here with added checkbox for that)
I've added filtering to GtkFontChooser