diff --git a/gtk/gtkfontchooserwidget.c b/gtk/gtkfontchooserwidget.c index e16de437c4..7faa68ba59 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) || @@ -1130,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) { @@ -1141,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); @@ -1521,13 +1582,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; @@ -1597,7 +1651,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); 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); *