[Github-comments] [geany/geany] choose font: classify families into monospace/proportional (#1928)
VictorelPetrovich
notifications at xxxxx
Sun Aug 26 05:01:55 UTC 2018
```
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#GtkFontFilterFunc)
// it will be called by gtk-font-chooser-set-filter-func,
// https://developer.gnome.org/gtk3/stable/GtkFontChooser.html#gtk-font-chooser-set-filter-func ,
// 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-is-monospace
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-set-filter-func
// 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
```
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/geany/geany/issues/1928#issuecomment-416014264
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.geany.org/pipermail/github-comments/attachments/20180825/9a894614/attachment.html>
More information about the Github-comments
mailing list