From 536b05e35be73502c3e92069b009934f9aad1bd9 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Fri, 31 Dec 2021 09:48:34 -0500 Subject: [PATCH 1/4] maplistmodel: Cosmetics --- gtk/gtkmaplistmodel.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/gtk/gtkmaplistmodel.c b/gtk/gtkmaplistmodel.c index 72dea55616..0de6b7c7d8 100644 --- a/gtk/gtkmaplistmodel.c +++ b/gtk/gtkmaplistmodel.c @@ -45,8 +45,7 @@ * * widgets = gtk_widget_observe_children (widget); * - * controllers = gtk_map_list_model_new (G_TYPE_LIST_MODEL, - * widgets, + * controllers = gtk_map_list_model_new (widgets, * map_to_controllers, * NULL, NULL); * From e12ef76de532d4cf652fe50383bc5bb378866295 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Fri, 31 Dec 2021 09:49:40 -0500 Subject: [PATCH 2/4] fontchooserwidget: Avoid a crash languages may be NULL, we need to be more careful here. --- gtk/gtkfontchooserwidget.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/gtk/gtkfontchooserwidget.c b/gtk/gtkfontchooserwidget.c index e16de437c4..27608eb16f 100644 --- a/gtk/gtkfontchooserwidget.c +++ b/gtk/gtkfontchooserwidget.c @@ -603,19 +603,20 @@ maybe_update_preview_text (GtkFontChooserWidget *self, /* Otherwise, we make a list of representative languages */ langs = g_hash_table_new (NULL, NULL); - for (i = 0; languages[i]; i++) - { - const PangoScript *scripts; - int num, j; + if (languages) + for (i = 0; languages[i]; i++) + { + const PangoScript *scripts; + int num, j; - scripts = pango_language_get_scripts (languages[i], &num); - for (j = 0; j < num; j++) - { - lang = pango_script_get_sample_language (scripts[j]); - if (lang) - g_hash_table_add (langs, lang); - } - } + scripts = pango_language_get_scripts (languages[i], &num); + for (j = 0; j < num; j++) + { + lang = pango_script_get_sample_language (scripts[j]); + if (lang) + g_hash_table_add (langs, lang); + } + } /* ... and compare it to the users default and preferred languages */ if (g_hash_table_contains (langs, default_lang) || From 2dc56a6e9ba9ec6fb430e9181968fea08367f9ff Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Fri, 31 Dec 2021 09:50:47 -0500 Subject: [PATCH 3/4] fontchooserwidget: Revise handling of named instances Allowing to tweak the axes of named instances does not do any harm. If we don't, we have to worry that we need at least one non-named-instance in the face list, and make it more obvious how to pick it out. --- gtk/gtkfontchooserwidget.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/gtk/gtkfontchooserwidget.c b/gtk/gtkfontchooserwidget.c index 27608eb16f..674349f418 100644 --- a/gtk/gtkfontchooserwidget.c +++ b/gtk/gtkfontchooserwidget.c @@ -1522,13 +1522,6 @@ should_show_axis (hb_ot_var_axis_info_t *ax) return TRUE; } -static gboolean -is_named_instance (hb_font_t *font) -{ - /* FIXME */ - return FALSE; -} - static struct { guint32 tag; const char *name; @@ -1598,7 +1591,7 @@ add_axis (GtkFontChooserWidget *fontchooser, adjustment_changed (axis->adjustment, axis); g_signal_connect (axis->adjustment, "value-changed", G_CALLBACK (adjustment_changed), axis); - if (is_named_instance (hb_font) || !should_show_axis (ax)) + if (!should_show_axis (ax)) { gtk_widget_hide (axis->label); gtk_widget_hide (axis->scale); From b7b6c147f9aba32047ac157e825d5517ac92a4ed Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Fri, 31 Dec 2021 09:52:48 -0500 Subject: [PATCH 4/4] fontchoserwidget: Do our own face filtering Pango may not do this for us, so don't rely on it. We only show one face with a given name, and we prefer a variable face over a non-variable one. The check for variable faces requires new Pango API that will be in Pango 1.52. --- gtk/gtkfontchooserwidget.c | 64 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 62 insertions(+), 2 deletions(-) diff --git a/gtk/gtkfontchooserwidget.c b/gtk/gtkfontchooserwidget.c index 674349f418..7faa68ba59 100644 --- a/gtk/gtkfontchooserwidget.c +++ b/gtk/gtkfontchooserwidget.c @@ -1131,6 +1131,66 @@ add_to_fontlist (GtkWidget *widget, return G_SOURCE_CONTINUE; } +/* Only show one face with a given face name. + * Prefer a variable face over a non-variable one. + */ +static gboolean +filter_face_func (gpointer item, + gpointer user_data) +{ + PangoFontFace *face = item; + PangoFontFamily *family; + int val; + + val = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (face), "gtk-font-chooser-show")); + if (val) + return val > 0; + + family = pango_font_face_get_family (face); + for (int i = 0; i < g_list_model_get_n_items (G_LIST_MODEL (family)); i++) + { + PangoFontFace *face2 = g_list_model_get_item (G_LIST_MODEL (family), i); + + g_object_unref (face2); + + if (face2 == face || + strcmp (pango_font_face_get_face_name (face), + pango_font_face_get_face_name (face2)) != 0) + continue; + + val = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (face2), "gtk-font-chooser-show")); + if (val < 0) + continue; + + if (val > 0) + { + g_object_set_data (G_OBJECT (face), "gtk-font-chooser-show", GINT_TO_POINTER (-1)); + return FALSE; + } + +#if PANGO_VERSION_CHECK (1,52,0) + if (pango_font_face_is_variable (face2)) + { + g_object_set_data (G_OBJECT (face2), "gtk-font-chooser-show", GINT_TO_POINTER (1)); + g_object_set_data (G_OBJECT (face), "gtk-font-chooser-show", GINT_TO_POINTER (-1)); + return FALSE; + } + else +#endif + g_object_set_data (G_OBJECT (face2), "gtk-font-chooser-show", GINT_TO_POINTER (-1)); + } + + g_object_set_data (G_OBJECT (face), "gtk-font-chooser-show", GINT_TO_POINTER (1)); + return TRUE; +} + +static gpointer +map_family_list (gpointer item, + gpointer user_data) +{ + return G_LIST_MODEL (gtk_filter_list_model_new (g_object_ref (G_LIST_MODEL (item)), GTK_FILTER (gtk_custom_filter_new (filter_face_func, NULL, NULL)))); +} + static void update_fontlist (GtkFontChooserWidget *self) { @@ -1142,9 +1202,9 @@ update_fontlist (GtkFontChooserWidget *self) fontmap = pango_cairo_font_map_get_default (); if ((self->level & GTK_FONT_CHOOSER_LEVEL_STYLE) == 0) - model = g_object_ref (G_LIST_MODEL (fontmap)); + model = G_LIST_MODEL (fontmap); else - model = G_LIST_MODEL (gtk_flatten_list_model_new (G_LIST_MODEL (g_object_ref (fontmap)))); + model = G_LIST_MODEL (gtk_flatten_list_model_new (G_LIST_MODEL (gtk_map_list_model_new (g_object_ref (G_LIST_MODEL (fontmap)), map_family_list, NULL, NULL)))); model = G_LIST_MODEL (gtk_slice_list_model_new (model, 0, 20)); gtk_widget_add_tick_callback (GTK_WIDGET (self), add_to_fontlist, g_object_ref (model), g_object_unref);