At: menu/view/ change font...
It would be so much easier to choose a desired font family (most people only know a couple of fonts) if the families were classified. I believe a good classification is into monospace vs proportional fonts.
Thanks!
The font chooser is a standard GTK dialog, you could try asking them to add it.
It might be possible to add a checkbox/combobox to the dialog's action area, if anyone feels like working on this.
Nah, font chooser does not allow sorting of the dialog, only filtering.
Thanks for the replies.
Nah, font chooser does not allow sorting of the dialog, only filtering.
Maybe it's possible to simply replace there the `Family` box with 2 boxes, one containing monospace families, the other proportional?
I personally have no idea how GTK dialogs are programmed ( I only know a bit of programming) , but on my part, I could do the job of actually classifying all the fonts into those 2 categories.
Maybe it's possible to simply replace there the Family box with 2 boxes, one containing monospace families, the other proportional?
The dialog is a standard GTK dialog, ie its not programmed by the Geany project. As such changes are difficult.
I could do the job of actually classifying all the fonts into those 2 categories.
Not sure how you get the list of fonts? Remember Geany runs on Win and Lin and OSX and BSD.
Could you point me to the specific GTK project/ forum dealing with that dialog then? I will try to ask them. And then they probably have the entire list of fonts.
Could you point me to the specific GTK project/ forum dealing with that dialog then?
gtk.org should have all contact methods.
And then they probably have the entire list of fonts.
Fonts are something thats installed on your individual machine, there is no universal list of fonts.
[GtkDialog](https://developer.gnome.org/gtk3/stable/GtkDialog.html) allows you to [add "action widgets"](https://developer.gnome.org/gtk3/stable/GtkDialog.html#gtk-dialog-add-action...) so it would be relatively trivial to add a checkbox or combobox into it, specific to a particular application.
As for the fonts, you can use [Pango directly to get a list of all fonts](https://developer.gnome.org/pango/stable/pango-Fonts.html#pango-font-map-lis...), and it contains information about each font such as [whether they're fixed-width](https://developer.gnome.org/pango/stable/pango-Fonts.html#pango-font-family-...) or such.
There's no real technical hurdles here, the only blockers are 1) who's going to write the code, and 2) is this a feature people want in Geany.
@codebrainz sure you can add an action widget checkbox, but the GTK dialog doesn't allow access to control ordering of the list, so sorting it by some characteristic would need a total new dialog replacing the GTK one. Still as you say its just a MMOP, but somebody has to do it after its decided its needed, and for me its a waste of time and maintenance effort to have a non-standard font dialog.
GtkFontChooser allows you to [filter the list of fonts it shows](https://developer.gnome.org/gtk3/stable/GtkFontChooser.html#gtk-font-chooser...), so it shouldn't be tough.
AFAICT the filter just allows a boolean return to show or not show a font, not sure how that can sort the list, still if Pango is being accessed directly the extra effort a a custom dialog is simply GTKtreeview manipulation which is really the simplest widget of the lot :).
You could just have a combobox with "Fixed-pitch", "Proportional" and "Both (default)", and filter the list accordingly. IIUC that's basically what @VictorelPetrovich is after.
@codebrainz @elextr Yes indeed filtering will do, and it's probably better than having the entire list sorted: if the list starts with say monospace fonts, one will have to scroll alot till gets to the proportional ones. Whether it's specifically [combobox ](https://developer.gnome.org/gtk3/stable/GtkComboBox.html) to select one of the 3 options ( mono., prop., both), or just 2 [checkbuttons](https://developer.gnome.org/gtk3/stable/GtkCheckButton.html) to select one or both of (mono. , prop.) -- both do the job.
It's just a little convenient feature; I can only speak for myself, and I seldom need to pick fonts, but when I do it's tedious to scroll such a long list. It's the same "problem" in any other editor I remember, so it's not something to blame Geany at all. Perhaps if one editor does it, then others will follow too :) But by all means, I'm not trying to distract you from more serious problems.
Just needs somebody to make the pull request.
I change fonts quite a bit and GTK+ 3 font chooser dialog is by far my least favourite thing about GTK+ 3. It's horrible how it lists every single variant/style of every single font in huge text that doesn't even follow the size control at the bottom. I have to scroll for like 20 minutes to get from the top to the bottom of the list (I have a lot of fonts and some have many variants). It's absolute rubbish. /rant
I've considered doing some work on filtering out all the redundant variants/styles/etc which Geany can't even use anyway, if I do, I will evaluate how hard this request would be and perhaps implement it.
Yeah, only needs to show the basic font, different font styles (bold italic etc) are chosen by the colour scheme so no point of choosing one of those.
It's horrible how it lists every single variant/style of every single font in huge text that doesn't even follow the size control at the bottom.
I guess you see [this](https://www.google.ca/search?q=GtkFontSelectionDialog&rlz=1C1CHBD_enCA80...). I'm a bit luckier, as on my installation of Geany in Windows 7, I get [that](https://www.google.ca/search?q=GtkFontChooserDialog&rlz=1C1CHBD_enCA809C...), so it at least keeps the sub-variants of every family in a separate box. My guess is, that's because in my installation: `15:54:44: Geany INFO : GTK 2.24.32, GLib 2.54.3` , and so my Geany uses [GtkFontSelectionDialog](https://developer.gnome.org/gtk3/stable/GtkFontSelectionDialog.html), which is said to be "deprecated", while your Geany uses newer Gtk with [GtkFontChooserDialog](https://developer.gnome.org/gtk3/stable/GtkFontChooserDialog.html). So maybe Geany should stick to GtkFontSelectionDialog ? Just saying...
So maybe Geany should stick to GtkFontSelectionDialog ? Just saying...
That would mean staying with GTK2, that will die at some point (probably with little warning) and distros are already pushing for all apps to be GTK3, so no choice.
Actually thinking about it a bit, the GTK2 dialog is worse in this application, as I said above, only the font family is selected, the style, like bold or italic is set by the colour scheme. So the GTK2 dialog having the second selection for style is advertising something that, in this use, is going to be ignored, select a bold font and the display is still the same.
@codebrainz suggestion to filter out the extraneous styles and only display normal fonts is the best way, and of course then the GTK3 single list will be good.
@VictorelPetrovich yeah, my rant was aimed squarely at the newer GtkFontChooser. GtkFontSelection is decent enough.
@elextr GtkFontSelection is available in GTK+3 as well, IIRC it's still used in some parts of Geany even in GTK+ 3 (prefs dialog font buttons). It also provides access to the individual widgets so they could trivially be disabled to solve the issue with Geany not supporting font properties normally. Both possibilities suck, using a deprecated dialog or using a supported one with a user-hostile UI.
GtkFontSelection is available in GTK+3
Oh, ok, deprecated in 3.2
IIRC it's still used in some parts of Geany even in GTK+ 3 (prefs dialog font buttons)
Not here, maybe in some plugins I don't use (and therefore don't care).
Well, showing only the sensible fonts in either dialog is the least suckiest way to go, and then as I said the GTK2 one is downgraded to the GTK3 one anyway so it doesn't matter. As always just needs somebody to do it.
Closed #1928.
So that is why I was never able to specify in Geany, in the font dialog, the style (bold/italic etc) for a font family. Makes sense.
Yesterday I decided to adventure in the world of programming :) , and after 2 days of staring on GTK documentation, put together some `coding ideas` for all this filtering. _Disclaimer: I'm not a programmer, I only have rudimentary C knowledge, and never ever before had to deal with Gtk or anything like that... So most likely much of the "code" below is simply wrong, but maybe somehow it will still help a tiny bit the person who will actually implement this filtering._
Any feedback welcome!
So, I just assumed a 2 check-buttons style for selecting monospace vs proportional, without bothering with further styling, or correct placing within the Geany overall code (for which I don't have a clue).
On terminology and labels choice: Different pages disagree on whether "duospaced" fonts are monospace or not; so perhaps "fixed-width" vs "variable-width" is a better option... But that's not so relevant for now. //https://developer.gnome.org/pango/stable/pango-Fonts.html#pango-font-family-... // https://en.wikipedia.org/wiki/Monospaced_font // https://en.wikipedia.org/wiki/Typeface#Proportion //https://en.wikipedia.org/wiki/Duospaced_font
To filter out unused faces ("styles" in my Geany font chooser) for a family: a tricky part may be that some font families don't contain "normal" faces, but say only Bold faces ; (selecting such font actually makes the text bold in Geany; example in my installation: `Adobe Caslo Pro Bold` only has 2 named styles: Bold and Bold Italic ; or `Aharoni` and many others ). So they cannot be filtered out by asking the style and weight of a face to be specifically "normal". (see below [this](https://developer.gnome.org/pango/stable/pango-Fonts.html#PangoFontDescripti...)
Maybe one can instead make the filter allow a font only if it is the first encountered face of a family. This assumes that the [gtk_font_chooser_set_filter_func] (https://developer.gnome.org/gtk3/stable/GtkFontChooser.html#gtk-font-chooser...) runs over some list of all fonts (all faces of all families, for a given platform), and that list is sorted by family, and also all fonts of a family are sorted so that a font with "normal" style/weight (IF any present for the particular family) appears before fonts with bold/slanted etc style/weight.
Maybe it's a naive assumption, but seems plausible. Anyway, that is what I have assumed bellow...
I have included the filtering out of the unneeded faces/styles in the same function that filters based on checking-state of the buttons. I'm aware this is very inefficient, because this filtering will be done everytime the fontChooser dialog is launched and the checkbuttons activated -- instead of a single filtering of the uneeded styles once and for all, for a given Geany installation, and save the info in a local file, and to be consulted when Fontchooser dialog starts. But I've no idea, for now, how to do that . (Maybe related to [PangoFontMap or PangoFontSet](https://developer.gnome.org/pango/stable/pango-Fonts.html) ) And anyway, this is just some ideas...
Low and behold, `coding horror` follows :)
Reopened #1928.
```
GtkWidget *mono_chbn, *prop_chbn; //check_buttons pointers gint mono_response, prop_response; //response_id for the checkbuttons
//will be needed by filter function struct Data { gboolean mono_checked; // checked/active state of Ist check_button gboolean prop_checked; char previous_family[50]; // stores the family name of the font // encountered by gtk_font_chooser_set_filter_func() }filter_data;
//the filter function //(https://developer.gnome.org/gtk3/stable/GtkFontChooser.html#GtkFontFilterFun...)
// it will be called by gtk-font-chooser-set-filter-func, // https://developer.gnome.org/gtk3/stable/GtkFontChooser.html#gtk-font-chooser... , // so should probabably keep the same number and kind of arguments as // described there. gboolean check_filter (const PangoFontFamily *family, // family=related group of faces, of varying slant, weight, width // and other aspects const PangoFontFace *face, // within a face only size varies; NOT USED here; // but probably should not remove this parameter in any case. struct Data *filter_data); // gpointer user_data char current_family[]=pango_font_family_get_name (family);
if (strcmp(current_family, filter_data->previous_family){ //strings not equal returns 1, so consider admiting the font strcpy( filter_data->previous_family, current_family); // https://developer.gnome.org/pango/stable/pango-Fonts.html#pango-font-family-... if(pango_font_family_is_monospace (family);){ return (filter_data -> mono_checked) }else{ return (filter_data -> mono_checked) } }else{ return FALSE //current font is of same family as previous } }
//creating the buttons
mono_chbn=gtk_check_button_new_with_label ("Monospaced"); // returns GtkWidget *; makes label to right of check button gtk_toggle_button_set_mode (mono_chbn, TRUE); // with indicator; Default value: FALSE mono_response=1;
prop_chbn=gtk_check_button_new_with_label ("Proportional"); //places a discrete GtkToggleButton next to a widget, (usually a GtkLabel). gtk_toggle_button_set_mode (mono_chbn, TRUE); prop_response=2;
// adding them to Geany gtkFontchooser dialog gtk_dialog_add_action_widget (FontChooserDG, mono_chbn, mono_response); //when mono_chbn clicked (checked), will make the dialog emit signal //"response" with response ID mono_response gtk_dialog_add_action_widget (FontChooserDG, prop_chbn, mono_response);
// AT OPENING FontChooserDG dialog: (by clicking GtkFontButton)
gboolean saved_mono_state="load from some saved Geany intersession file "; // don't know how it's done, but I guess should be done gboolean saved_prop_state="load from some saved Geany intersession file ";
gtk_toggle_button_set_active (mono_chbn, saved_mono_state); gtk_toggle_button_set_active (prop_chbn, saved_prop_state);
// Filtering of the fonts before user starts clicking inside the // opened font Chooser dialog
strcpy( filter_data.previous_family, ""); // or some other string that's not going to be any valid family font name filter_data.mono_checked = gtk_toggle_button_get_active (mono_chbn); filter_data.prop_checked = gtk_toggle_button_get_active (prop_chbn);
// QUESTION: here // https://developer.gnome.org/gtk3/stable/GtkFontChooser.html#gtk-font-chooser... // says "Adds a filter function that decides which fonts to display // in the font chooser." -- is it meant it only adds/sets/connects the //filter, or actually applies the filter (and does the filtering) //when called? I interpreted in IInd way..
if(filter_data.mono_checked || filter_data.prop_checked){ gtk_font_chooser_set_filter_func (fontchooserInterface, @check_filter, @filter_data, NULL); //GDestroyNotify destroy; // It seemed not needed that's why I set NULL }else{ // when both buttons unchecked, //don't waste time running the filter in vain "display empty list of fonts;" // don't know how it's done }
gtk_widget_show_all (FontChooserDG);
// REACTING to activation of checkbuttons in the dialog
//// QUESTION: // should the program react by "connecting" signals from buttons with //some functions (as I see in such examples // https://python-gtk-3-tutorial.readthedocs.io/en/latest/button_widgets.html), //or by using gtk_dialog_run() with emmitted response signal with // response_ID, as //https://developer.gnome.org/gtk3/stable/GtkDialog.html#gtk-dialog-run // ? Or is it that the latter is only good if one wants a "modal dialog" //(i.e, that is, one which freezes the rest of the application from // user input)? // Anyway, I did it in the IIn way...
while (FontChooserDG != NULL){ //i.e while FontChooserDG still exists gint responseID = gtk_dialog_run (FontChooserDG); //runs a recursive main loop until the dialog either emits // the “response” signal, or is destroyed. if (responseID==mono_response || responseID==prop_response ) { // if any of mono/prop checkbuttons activated strcpy( filter_data.previous_family, ""); filter_data.mono_checked = gtk_toggle_button_get_active (mono_chbn); filter_data.prop_checked = gtk_toggle_button_get_active (prop_chbn); if(filter_data.mono_checked || filter_data.prop_checked){ gtk_font_chooser_set_filter_func (fontchooserInterface, //GtkFontChooser *fontchooser, @check_filter @filter_data, NULL); }else{ // when both buttons unchecked, //don't waste time running the filter in vain "display empty list of fonts;" // I don't know how } }else if ("some other widgets within FontChooserDG were activated"){ //do_widget_specific_something (); }else { // assuming_dialog_was_cancelled (); "save the check-state of both checkbuttons in some Geany intersession file" // however it is done gtk_widget_destroy (FontChooserDG); }
}//while
```
"fixed-width" vs "variable-width" is a better option...
Well, even so called monospaced fonts are not fixed width if [wide Unicode characters](https://en.wikipedia.org/wiki/Halfwidth_and_fullwidth_forms) are present.
some font families don't contain "normal" faces,
Maybe just skip them, any syntactic entity identified by bolding or italics will not be distinguishable with those fonts, only show them when "all" is selected.
"normal" style/weight (IF any present for the particular family) appears before fonts with bold/slanted etc style/weight.
The ordering of fonts in my chooser generally follows that rule, but not always, eg Freeserif goes Bold Italic, Italic, Regular, Bold. Since I suspect the ordering in the chooser is the same as the enumeration from Pango this would indicate that may not be a good assumption. If its not documented to be in that order you can't assume it.
I have included the filtering out of the unneeded faces/styles in the same function that filters based on checking-state of the buttons.
Thats the way to do it, the cost of filtering will be insignificant compared to the cost of the chooser loading and rendering its sample text in every font available.
There is no way to make the standard dialogs use a list of fonts you have compiled, they will always consult the platforms font machinery, which can vary between platforms (win, lin, osx) and sometimes on the platform for different font types, eg True Type vs Open Type vs Adobe fonts. This is the correct method since your list will not reflect fonts installed later. Just forget about trying to optimise it, first get it right, then optimise if needed.
Havn't looked at your code in detail since you need to adjust your algorithm on the basis that regular won't always be first. However the basic idea of the filter function passed the button state via the user data is correct. A note on the user data, don't use fixed lengths for strings, someone will always overflow it, use dynamic strings.
Maybe just skip them, any syntactic entity identified by bolding or italics will not be distinguishable with those fonts, only show them when "all" is selected.
... Thats the way to do it, the cost of filtering will be insignificant compared to the cost of the chooser loading and rendering its sample text in every font available.
I see; when i wrote above ideas and code, somehow I assumed that unneeded fonts need to be filtered out once and for all. But this is bad idea, because some users may still want to see/use them (for instance, text/code editors are not used for programming only...).
So it should simply offer options for filtering that list. One way is with 3 check-buttons: - Fixed-width - Variable-width - Normal (regular): for fonts that are not slanted or bold (more options could be added later if people want)
They would represent constraints combined with "AND" logics: - if no buttons checked, then means no constraints, so all fonts will show up - some buttons checked, then only show those langs that each of them satisfy all the corresponding constrains Thus, checking "normal" and "fixed-width" will show most fonts suitable for programming needs.
I tend to favor check-buttons over a combobox, as the latter will have to include a list for all possible combinations from (fixed-w, variable-w, normal); and checkbuttons are faster to see access by the user.
I could continue playing with this (as free time allows); but, for windows I use, GTK included in binaries is 2.24; because it uses the older fontSelectiionDialog, that means I may not even get to use the results of this work?...
I tend to favor check-buttons over a combobox, as the latter will have to include a list for all possible combinations from (fixed-w, variable-w, normal); and checkbuttons are faster to see & access by the user.
Yeah, in the case where multiple options can be selected then checkboxes is a better UI.
GTK included in binaries is 2.24; because it uses the older fontSelectiionDialog, that means I may not even get to use the results of this work?
It should be possible to do it to both versions, but possibly not the same code. There are CERTAIN people `</troll>` who say you should `#ifdef ` different code for GTK2 and GTK3, but I think its entirely up to the PR writer, so long as they don't break the other GTK version, extra functionality should be acceptable even if its for only one GTK version.
github-comments@lists.geany.org