[gtk+/wip/matthiasc/font-variations: 44/58] font chooser: Add language/script filtering
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/matthiasc/font-variations: 44/58] font chooser: Add language/script filtering
- Date: Sat, 30 Dec 2017 05:23:09 +0000 (UTC)
commit a13eddbf9779523a5134f8cfe3580ca420e79747
Author: Matthias Clasen <mclasen redhat com>
Date: Thu Dec 21 13:40:41 2017 -0500
font chooser: Add language/script filtering
Allow filtering the list script or language.
This relies on pango api that is not on master
yet.
gtk/gtkfontchooserdialog.c | 2 +
gtk/gtkfontchooserwidget.c | 685 +++++++++++++++++++++++++++++++++++++++-
gtk/language-names.c | 233 ++++++++++++++
gtk/language-names.h | 13 +
gtk/meson.build | 2 +
gtk/script-names.c | 184 +++++++++++
gtk/script-names.h | 13 +
gtk/ui/gtkfontchooserwidget.ui | 188 ++++++++++-
8 files changed, 1303 insertions(+), 17 deletions(-)
---
diff --git a/gtk/gtkfontchooserdialog.c b/gtk/gtkfontchooserdialog.c
index 83bc307..db1a383 100644
--- a/gtk/gtkfontchooserdialog.c
+++ b/gtk/gtkfontchooserdialog.c
@@ -149,6 +149,8 @@ gtk_font_chooser_dialog_class_init (GtkFontChooserDialogClass *klass)
_gtk_font_chooser_install_properties (gobject_class);
+ widget_class->key_press_event = gtk_font_chooser_dialog_key_press_event;
+
/* Bind class to template
*/
gtk_widget_class_set_template_from_resource (widget_class,
diff --git a/gtk/gtkfontchooserwidget.c b/gtk/gtkfontchooserwidget.c
index 8a14777..46380ef 100644
--- a/gtk/gtkfontchooserwidget.c
+++ b/gtk/gtkfontchooserwidget.c
@@ -22,6 +22,7 @@
#include <string.h>
#include <atk/atk.h>
+#include <pango/pango.h>
#include "gtkfontchooserwidget.h"
#include "gtkfontchooserwidgetprivate.h"
@@ -51,11 +52,19 @@
#include "gtkwidget.h"
#include "gtksettings.h"
#include "gtkdialog.h"
+#include "gtkcombobox.h"
+#include "gtkcelllayout.h"
+#include "gtkbutton.h"
+#include "gtkrevealer.h"
+#include "gtklistbox.h"
+#include "gtkpopover.h"
#if defined(HAVE_HARFBUZZ) && defined(HAVE_PANGOFT)
#include <pango/pangofc-font.h>
#include <freetype/freetype.h>
#include <freetype/ftmm.h>
+#include "language-names.h"
+#include "script-names.h"
#endif
/**
@@ -89,6 +98,7 @@ struct _GtkFontChooserWidgetPrivate
{
GtkWidget *grid;
GtkWidget *search_entry;
+
GtkWidget *family_face_list;
GtkTreeViewColumn *family_face_column;
GtkCellRenderer *family_face_cell;
@@ -97,6 +107,21 @@ struct _GtkFontChooserWidgetPrivate
GtkTreeModel *model;
GtkTreeModel *filter_model;
+ GtkWidget *filter_popover;
+ GtkWidget *script_filter_revealer;
+ GtkWidget *script_filter_button;
+ GtkWidget *script_filter_button_label;
+ GtkWidget *script_list;
+ GtkWidget *script_filter_entry;
+ char *script_term;
+
+ GtkWidget *language_filter_revealer;
+ GtkWidget *language_filter_button;
+ GtkWidget *language_filter_button_label;
+ GtkWidget *language_list;
+ GtkWidget *language_filter_entry;
+ char *language_term;
+
GtkWidget *preview;
gchar *preview_text;
gboolean show_preview_entry;
@@ -116,6 +141,9 @@ struct _GtkFontChooserWidgetPrivate
gpointer filter_data;
GDestroyNotify filter_data_destroy;
+ PangoScript script;
+ PangoLanguage *language;
+
guint last_fontconfig_timestamp;
GHashTable *axes;
@@ -173,6 +201,7 @@ static void gtk_font_chooser_widget_set_show_preview_entry (GtkFontChooserWi
static void gtk_font_chooser_widget_set_cell_size (GtkFontChooserWidget *fontchooser);
static void gtk_font_chooser_widget_load_fonts (GtkFontChooserWidget *fontchooser,
gboolean force);
+static void gtk_font_chooser_widget_populate_filters (GtkFontChooserWidget *fontchooser);
static gboolean visible_func (GtkTreeModel *model,
GtkTreeIter *iter,
gpointer user_data);
@@ -185,6 +214,31 @@ static void gtk_font_chooser_widget_set_level (GtkFontChooserWidg
GtkFontChooserLevel level);
static GtkFontChooserLevel gtk_font_chooser_widget_get_level (GtkFontChooserWidget *fontchooser);
+static void script_filter_button_clicked (GtkButton *button,
+ GtkFontChooserWidget *fontchooser);
+static void script_row_activated (GtkListBox *list,
+ GtkListBoxRow *row,
+ GtkFontChooserWidget *fontchooser);
+static void show_script_list (GtkFontChooserWidget *fontchooser);
+static void hide_script_list (GtkFontChooserWidget *fontchooser,
+ gboolean animate);
+static void script_filter_changed (GtkFontChooserWidget *fontchooser);
+static void script_filter_stop (GtkFontChooserWidget *fontchooser);
+static void script_filter_activated (GtkFontChooserWidget *fontchooser);
+static void language_filter_button_clicked (GtkButton *button,
+ GtkFontChooserWidget *fontchooser);
+static void language_row_activated (GtkListBox *list,
+ GtkListBoxRow *row,
+ GtkFontChooserWidget *fontchooser);
+static void show_language_list (GtkFontChooserWidget *fontchooser);
+static void hide_language_list (GtkFontChooserWidget *fontchooser,
+ gboolean animate);
+static void language_filter_changed (GtkFontChooserWidget *fontchooser);
+static void language_filter_stop (GtkFontChooserWidget *fontchooser);
+static void language_filter_activated (GtkFontChooserWidget *fontchooser);
+static void popover_notify (GObject *object,
+ GParamSpec *pspec,
+ GtkFontChooserWidget *fontchooser);
static void gtk_font_chooser_widget_iface_init (GtkFontChooserIface *iface);
@@ -197,6 +251,8 @@ typedef struct _GtkDelayedFontDescription GtkDelayedFontDescription;
struct _GtkDelayedFontDescription {
PangoFontFace *face;
PangoFontDescription *desc;
+ PangoScript *scripts;
+ int n_scripts;
guint ref_count;
};
@@ -209,6 +265,8 @@ gtk_delayed_font_description_new (PangoFontFace *face)
result->face = g_object_ref (face);
result->desc = NULL;
+ result->scripts = NULL;
+ result->n_scripts = -1;
result->ref_count = 1;
return result;
@@ -234,6 +292,8 @@ gtk_delayed_font_description_unref (GtkDelayedFontDescription *desc)
if (desc->desc)
pango_font_description_free (desc->desc);
+ g_free (desc->scripts);
+
g_slice_free (GtkDelayedFontDescription, desc);
}
@@ -679,6 +739,18 @@ gtk_font_chooser_widget_class_init (GtkFontChooserWidgetClass *klass)
gtk_widget_class_bind_template_child_private (widget_class, GtkFontChooserWidget, grid);
gtk_widget_class_bind_template_child_private (widget_class, GtkFontChooserWidget, font_grid);
+ gtk_widget_class_bind_template_child_private (widget_class, GtkFontChooserWidget, filter_popover);
+ gtk_widget_class_bind_template_child_private (widget_class, GtkFontChooserWidget, script_filter_revealer);
+ gtk_widget_class_bind_template_child_private (widget_class, GtkFontChooserWidget, script_filter_button);
+ gtk_widget_class_bind_template_child_private (widget_class, GtkFontChooserWidget,
script_filter_button_label);
+ gtk_widget_class_bind_template_child_private (widget_class, GtkFontChooserWidget, script_list);
+ gtk_widget_class_bind_template_child_private (widget_class, GtkFontChooserWidget, script_filter_entry);
+ gtk_widget_class_bind_template_child_private (widget_class, GtkFontChooserWidget,
language_filter_revealer);
+ gtk_widget_class_bind_template_child_private (widget_class, GtkFontChooserWidget, language_filter_button);
+ gtk_widget_class_bind_template_child_private (widget_class, GtkFontChooserWidget,
language_filter_button_label);
+ gtk_widget_class_bind_template_child_private (widget_class, GtkFontChooserWidget, language_list);
+ gtk_widget_class_bind_template_child_private (widget_class, GtkFontChooserWidget, language_filter_entry);
+
gtk_widget_class_bind_template_callback (widget_class, text_changed_cb);
gtk_widget_class_bind_template_callback (widget_class, stop_search_cb);
gtk_widget_class_bind_template_callback (widget_class, cursor_changed_cb);
@@ -688,6 +760,17 @@ gtk_font_chooser_widget_class_init (GtkFontChooserWidgetClass *klass)
gtk_widget_class_bind_template_callback (widget_class, rows_changed_cb);
gtk_widget_class_bind_template_callback (widget_class, size_change_cb);
gtk_widget_class_bind_template_callback (widget_class, output_cb);
+ gtk_widget_class_bind_template_callback (widget_class, script_filter_button_clicked);
+ gtk_widget_class_bind_template_callback (widget_class, script_row_activated);
+ gtk_widget_class_bind_template_callback (widget_class, script_filter_changed);
+ gtk_widget_class_bind_template_callback (widget_class, script_filter_stop);
+ gtk_widget_class_bind_template_callback (widget_class, script_filter_activated);
+ gtk_widget_class_bind_template_callback (widget_class, language_filter_button_clicked);
+ gtk_widget_class_bind_template_callback (widget_class, language_row_activated);
+ gtk_widget_class_bind_template_callback (widget_class, language_filter_changed);
+ gtk_widget_class_bind_template_callback (widget_class, language_filter_stop);
+ gtk_widget_class_bind_template_callback (widget_class, language_filter_activated);
+ gtk_widget_class_bind_template_callback (widget_class, popover_notify);
gtk_widget_class_set_css_name (widget_class, I_("fontchooser"));
}
@@ -775,7 +858,7 @@ gtk_font_chooser_widget_init (GtkFontChooserWidget *fontchooser)
/* Setup treeview/model auxilary functions */
gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (priv->filter_model),
- visible_func, (gpointer)priv, NULL);
+ visible_func, fontchooser, NULL);
gtk_tree_view_column_set_cell_data_func (priv->family_face_column,
priv->family_face_cell,
@@ -785,6 +868,7 @@ gtk_font_chooser_widget_init (GtkFontChooserWidget *fontchooser)
/* Load data and set initial style-dependent parameters */
gtk_font_chooser_widget_load_fonts (fontchooser, TRUE);
+ gtk_font_chooser_widget_populate_filters (fontchooser);
gtk_font_chooser_widget_set_cell_size (fontchooser);
gtk_font_chooser_widget_take_font_desc (fontchooser, NULL);
}
@@ -912,18 +996,572 @@ gtk_font_chooser_widget_load_fonts (GtkFontChooserWidget *fontchooser,
gtk_font_chooser_widget_ensure_selection (fontchooser);
}
+static GtkWidget *
+script_row_new (const char *title,
+ PangoScript script,
+ gboolean active)
+{
+ GtkWidget *label;
+ GtkWidget *image;
+ GtkWidget *box;
+ GtkWidget *row;
+ char *term;
+ char *key;
+
+ label = gtk_label_new (title);
+ g_object_set (label, "margin", 10, NULL);
+ gtk_label_set_xalign (GTK_LABEL (label), 0);
+ gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
+ gtk_widget_set_hexpand (label, TRUE);
+ image = gtk_image_new_from_icon_name ("object-select-symbolic");
+ g_object_set (image,
+ "margin-top", 10,
+ "margin-bottom", 10,
+ "margin-end", 10,
+ NULL);
+ gtk_style_context_add_class (gtk_widget_get_style_context (image), "dim-label");
+ gtk_widget_set_opacity (image, active ? 1 : 0);
+ box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
+ gtk_container_add (GTK_CONTAINER (box), label);
+ gtk_container_add (GTK_CONTAINER (box), image);
+ row = gtk_list_box_row_new ();
+ gtk_container_add (GTK_CONTAINER (row), box);
+ g_object_set_data (G_OBJECT (row), "script", GINT_TO_POINTER (script));
+ term = g_utf8_casefold (title, -1);
+ g_object_set_data_full (G_OBJECT (row), "term", term, g_free);
+ key = g_utf8_collate_key (term, -1);
+ g_object_set_data_full (G_OBJECT (row), "key", key, g_free);
+ g_object_set_data (G_OBJECT (row), "label", label);
+ g_object_set_data (G_OBJECT (row), "image", image);
+
+ return row;
+}
+
+static void
+script_row_activated (GtkListBox *list,
+ GtkListBoxRow *row,
+ GtkFontChooserWidget *fontchooser)
+{
+ GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
+ GtkWidget *label;
+ const char *title;
+ GtkWidget *child;
+ GtkWidget *image;
+
+ priv->script = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (row), "script"));
+
+ label = GTK_WIDGET (g_object_get_data (G_OBJECT (row), "label"));
+ title = gtk_label_get_label (GTK_LABEL (label));
+ gtk_label_set_label (GTK_LABEL (priv->script_filter_button_label), title);
+
+ gtk_font_chooser_widget_refilter_font_list (fontchooser);
+
+ for (child = gtk_widget_get_first_child (GTK_WIDGET (list));
+ child != NULL;
+ child = gtk_widget_get_next_sibling (child))
+ {
+ image = GTK_WIDGET (g_object_get_data (G_OBJECT (child), "image"));
+ if (image)
+ gtk_widget_set_opacity (image, 0);
+ }
+
+ image = GTK_WIDGET (g_object_get_data (G_OBJECT (row), "image"));
+ gtk_widget_set_opacity (image, 1);
+
+ hide_script_list (fontchooser, TRUE);
+}
+
+static gboolean
+script_filter_func (GtkListBoxRow *row,
+ gpointer data)
+{
+ GtkFontChooserWidget *fontchooser = data;
+ GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
+ PangoScript script;
+ const char *term;
+
+ if (priv->script_term == NULL)
+ return TRUE;
+
+ term = (const char *)g_object_get_data (G_OBJECT (row), "term");
+
+ return g_str_has_prefix (term, priv->script_term);
+}
+
+static int
+script_sort_func (GtkListBoxRow *row1,
+ GtkListBoxRow *row2,
+ gpointer data)
+{
+ const char *key1, *key2;
+
+ key1 = (const char *)g_object_get_data (G_OBJECT (row1), "key");
+ key2 = (const char *)g_object_get_data (G_OBJECT (row2), "key");
+
+ if (key1 == NULL)
+ return -1;
+ else if (key2 == NULL)
+ return 1;
+ else
+ return strcmp (key1, key2);
+}
+
+static void
+show_script_list (GtkFontChooserWidget *fontchooser)
+{
+ GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
+
+ gtk_widget_hide (priv->script_filter_button);
+ gtk_widget_show (priv->script_filter_revealer);
+ gtk_revealer_set_reveal_child (GTK_REVEALER (priv->script_filter_revealer), TRUE);
+}
+
+static void
+hide_script_list (GtkFontChooserWidget *fontchooser,
+ gboolean animate)
+{
+ GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
+
+ gtk_entry_set_text (GTK_ENTRY (priv->script_filter_entry), "");
+ gtk_widget_show (priv->script_filter_button);
+ if (!animate)
+ gtk_revealer_set_transition_type (GTK_REVEALER (priv->script_filter_revealer),
+ GTK_REVEALER_TRANSITION_TYPE_NONE);
+ gtk_revealer_set_reveal_child (GTK_REVEALER (priv->script_filter_revealer), FALSE);
+ if (!animate)
+ gtk_revealer_set_transition_type (GTK_REVEALER (priv->script_filter_revealer),
+ GTK_REVEALER_TRANSITION_TYPE_SLIDE_DOWN);
+}
+
+static void
+script_filter_button_clicked (GtkButton *button,
+ GtkFontChooserWidget *fontchooser)
+{
+ hide_language_list (fontchooser, TRUE);
+ show_script_list (fontchooser);
+}
+
+static void
+script_filter_changed (GtkFontChooserWidget *fontchooser)
+{
+ GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
+ const char *term;
+
+ term = gtk_entry_get_text (GTK_ENTRY (priv->script_filter_entry));
+ g_free (priv->script_term);
+ priv->script_term = g_utf8_casefold (term, -1);
+ gtk_list_box_invalidate_filter (GTK_LIST_BOX (priv->script_list));
+}
+
+static void
+script_filter_stop (GtkFontChooserWidget *fontchooser)
+{
+ GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
+
+ gtk_entry_set_text (GTK_ENTRY (priv->script_filter_entry), "");
+}
+
+static void
+script_filter_activated (GtkFontChooserWidget *fontchooser)
+{
+ GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
+ GList *children, *l;
+ GtkWidget *row;
+
+ row = NULL;
+ children = gtk_container_get_children (GTK_CONTAINER (priv->script_list));
+ for (l = children; l; l = l->next)
+ {
+ GtkWidget *r = l->data;
+
+ if (!script_filter_func (GTK_LIST_BOX_ROW (r), fontchooser))
+ continue;
+
+ if (row != NULL)
+ {
+ /* more than one match, don't activate */
+ g_list_free (children);
+ return;
+ }
+
+ row = r;
+ }
+ g_list_free (children);
+
+ gtk_widget_activate (row);
+}
+
+static GtkWidget *
+language_row_new (const char *title,
+ PangoLanguage *language,
+ gboolean active)
+{
+ GtkWidget *label;
+ GtkWidget *image;
+ GtkWidget *box;
+ GtkWidget *row;
+ char *term;
+ char *key;
+
+ label = gtk_label_new (title);
+ g_object_set (label, "margin", 10, NULL);
+ gtk_label_set_xalign (GTK_LABEL (label), 0);
+ gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
+ gtk_widget_set_hexpand (label, TRUE);
+ image = gtk_image_new_from_icon_name ("object-select-symbolic");
+ g_object_set (image,
+ "margin-top", 10,
+ "margin-bottom", 10,
+ "margin-end", 10,
+ NULL);
+ gtk_style_context_add_class (gtk_widget_get_style_context (image), "dim-label");
+ gtk_widget_set_opacity (image, active ? 1 : 0);
+ box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
+ gtk_container_add (GTK_CONTAINER (box), label);
+ gtk_container_add (GTK_CONTAINER (box), image);
+ row = gtk_list_box_row_new ();
+ gtk_container_add (GTK_CONTAINER (row), box);
+ g_object_set_data (G_OBJECT (row), "language", language);
+ term = g_utf8_casefold (title, -1);
+ g_object_set_data_full (G_OBJECT (row), "term", term, g_free);
+ key = g_utf8_collate_key (term, -1);
+ g_object_set_data_full (G_OBJECT (row), "key", key, g_free);
+ g_object_set_data (G_OBJECT (row), "label", label);
+ g_object_set_data (G_OBJECT (row), "image", image);
+
+ return row;
+}
+
+static void
+language_row_activated (GtkListBox *list,
+ GtkListBoxRow *row,
+ GtkFontChooserWidget *fontchooser)
+{
+ GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
+ const char *title;
+ GtkWidget *child;
+ GtkWidget *image;
+
+ priv->language = (PangoLanguage *) g_object_get_data (G_OBJECT (row), "language");
+
+ title = gtk_label_get_label (GTK_LABEL (g_object_get_data (G_OBJECT (row), "label")));
+ gtk_label_set_label (GTK_LABEL (priv->language_filter_button_label), title);
+
+ gtk_font_chooser_widget_refilter_font_list (fontchooser);
+
+ for (child = gtk_widget_get_first_child (GTK_WIDGET (list));
+ child != NULL;
+ child = gtk_widget_get_next_sibling (child))
+ {
+ image = GTK_WIDGET (g_object_get_data (G_OBJECT (child), "image"));
+ if (image)
+ gtk_widget_set_opacity (image, 0);
+ }
+
+ image = GTK_WIDGET (g_object_get_data (G_OBJECT (row), "image"));
+ gtk_widget_set_opacity (image, 1);
+
+ hide_language_list (fontchooser, TRUE);
+}
+
+static gboolean
+language_filter_func (GtkListBoxRow *row,
+ gpointer data)
+{
+ GtkFontChooserWidget *fontchooser = data;
+ GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
+ const char *term;
+
+ if (priv->language_term == NULL)
+ return TRUE;
+
+ term = (const char *)g_object_get_data (G_OBJECT (row), "term");
+
+ return g_str_has_prefix (term, priv->language_term);
+}
+
+static int
+language_sort_func (GtkListBoxRow *row1,
+ GtkListBoxRow *row2,
+ gpointer data)
+{
+ const char *key1, *key2;
+
+ key1 = (const char *)g_object_get_data (G_OBJECT (row1), "key");
+ key2 = (const char *)g_object_get_data (G_OBJECT (row2), "key");
+
+ if (key1 == NULL)
+ return -1;
+ else if (key2 == NULL)
+ return 1;
+ else
+ return strcmp (key1, key2);
+}
+
+static void
+gtk_font_chooser_widget_populate_filters (GtkFontChooserWidget *fontchooser)
+{
+ GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
+#if defined(HAVE_HARFBUZZ) && defined(HAVE_PANGOFT)
+
+ FcPattern *pat;
+ FcObjectSet *os;
+ FcFontSet *fs;
+ FcLangSet *ls;
+ FcStrSet *ss;
+ FcStrList *sl;
+ int i;
+ GHashTable *all_langs;
+ GHashTable *all_scripts;
+ GHashTableIter iter;
+ char *s;
+
+ pat = FcPatternCreate ();
+ os = FcObjectSetCreate ();
+ FcObjectSetAdd (os, FC_LANG);
+ fs = FcFontList (0, pat, os);
+ FcObjectSetDestroy (os);
+ FcPatternDestroy (pat);
+ all_langs = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
+ for (i = 0; i < fs->nfont; i++)
+ {
+ FcPatternGetLangSet (fs->fonts[i], FC_LANG, 0, (FcLangSet **)&ls);
+ ss = FcLangSetGetLangs (ls);
+ sl = FcStrListCreate (ss);
+ FcStrListFirst (sl);
+ while ((s = (char *)FcStrListNext (sl)))
+ {
+ if (!g_hash_table_contains (all_langs, s))
+ g_hash_table_add (all_langs, g_strdup (s));
+ }
+ FcStrListDone (sl);
+ FcStrSetDestroy (ss);
+ }
+
+ gtk_container_add (GTK_CONTAINER (priv->script_list), script_row_new (_("All Scripts"), 0, TRUE));
+ gtk_container_add (GTK_CONTAINER (priv->language_list), language_row_new (_("All Languages"), NULL, TRUE));
+
+ all_scripts = g_hash_table_new (NULL, NULL);
+
+ g_hash_table_iter_init (&iter, all_langs);
+ while (g_hash_table_iter_next (&iter, (gpointer *)&s, NULL))
+ {
+ PangoLanguage *lang = pango_language_from_string (s);
+
+ if (lang)
+ {
+ const char *name = get_language_name (lang);
+ if (name)
+ gtk_container_add (GTK_CONTAINER (priv->language_list), language_row_new (name, lang, FALSE));
+ }
+
+ if (lang)
+ {
+ const PangoScript *scripts;
+ int num_scripts;
+
+ scripts = pango_language_get_scripts (lang, &num_scripts);
+ for (i = 0; i < num_scripts; i++)
+ {
+ const char *name;
+
+ if (g_hash_table_contains (all_scripts, GINT_TO_POINTER (scripts[i])))
+ continue;
+
+ g_hash_table_add (all_scripts, GINT_TO_POINTER (scripts[i]));
+ name = get_script_name ((GUnicodeScript)scripts[i]);
+ if (name)
+ gtk_container_add (GTK_CONTAINER (priv->script_list), script_row_new (name, scripts[i],
FALSE));
+ }
+ }
+ }
+
+ g_hash_table_unref (all_scripts);
+ g_hash_table_unref (all_langs);
+
+ gtk_list_box_set_filter_func (GTK_LIST_BOX (priv->language_list), language_filter_func, fontchooser, NULL);
+ gtk_list_box_set_sort_func (GTK_LIST_BOX (priv->language_list), language_sort_func, fontchooser, NULL);
+
+ gtk_list_box_set_filter_func (GTK_LIST_BOX (priv->script_list), script_filter_func, fontchooser, NULL);
+ gtk_list_box_set_sort_func (GTK_LIST_BOX (priv->script_list), script_sort_func, fontchooser, NULL);
+#endif
+}
+
+static void
+show_language_list (GtkFontChooserWidget *fontchooser)
+{
+ GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
+
+ gtk_widget_hide (priv->language_filter_button);
+ gtk_widget_show (priv->language_filter_revealer);
+ gtk_revealer_set_reveal_child (GTK_REVEALER (priv->language_filter_revealer), TRUE);
+}
+
+static void
+hide_language_list (GtkFontChooserWidget *fontchooser,
+ gboolean animate)
+{
+ GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
+
+ gtk_entry_set_text (GTK_ENTRY (priv->language_filter_entry), "");
+ gtk_widget_show (priv->language_filter_button);
+ if (!animate)
+ gtk_revealer_set_transition_type (GTK_REVEALER (priv->language_filter_revealer),
+ GTK_REVEALER_TRANSITION_TYPE_NONE);
+ gtk_revealer_set_reveal_child (GTK_REVEALER (priv->language_filter_revealer), FALSE);
+ if (!animate)
+ gtk_revealer_set_transition_type (GTK_REVEALER (priv->language_filter_revealer),
+ GTK_REVEALER_TRANSITION_TYPE_SLIDE_DOWN);
+}
+
+static void
+language_filter_button_clicked (GtkButton *button,
+ GtkFontChooserWidget *fontchooser)
+{
+ hide_script_list (fontchooser, TRUE);
+ show_language_list (fontchooser);
+}
+
+static void
+language_filter_changed (GtkFontChooserWidget *fontchooser)
+{
+ GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
+ const char *term;
+
+ term = gtk_entry_get_text (GTK_ENTRY (priv->language_filter_entry));
+ g_free (priv->language_term);
+ priv->language_term = g_utf8_casefold (term, -1);
+ gtk_list_box_invalidate_filter (GTK_LIST_BOX (priv->language_list));
+}
+
+static void
+language_filter_stop (GtkFontChooserWidget *fontchooser)
+{
+ GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
+
+ gtk_entry_set_text (GTK_ENTRY (priv->language_filter_entry), "");
+}
+
+static void
+language_filter_activated (GtkFontChooserWidget *fontchooser)
+{
+ GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
+ GList *children, *l;
+ GtkWidget *row;
+
+ row = NULL;
+ children = gtk_container_get_children (GTK_CONTAINER (priv->language_list));
+ for (l = children; l; l = l->next)
+ {
+ GtkWidget *r = l->data;
+
+ if (!language_filter_func (GTK_LIST_BOX_ROW (r), fontchooser))
+ continue;
+
+ if (row != NULL)
+ {
+ /* more than one match, don't activate */
+ g_list_free (children);
+ return;
+ }
+
+ row = r;
+ }
+ g_list_free (children);
+
+ gtk_widget_activate (row);
+}
+
+static void
+popover_notify (GObject *object,
+ GParamSpec *pspec,
+ GtkFontChooserWidget *fontchooser)
+{
+ hide_script_list (fontchooser, FALSE);
+ hide_language_list (fontchooser, FALSE);
+}
+
+static gboolean
+is_alias_family (PangoFontFamily *family)
+{
+ const char *family_name;
+
+ family_name = pango_font_family_get_name (family);
+
+ switch (family_name[0])
+ {
+ case 'm':
+ case 'M':
+ return (g_ascii_strcasecmp (family_name, "monospace") == 0);
+ case 's':
+ case 'S':
+ return (g_ascii_strcasecmp (family_name, "sans") == 0 ||
+ g_ascii_strcasecmp (family_name, "serif") == 0);
+ default:
+ return FALSE;
+ }
+
+ return FALSE;
+}
+
static gboolean
visible_func (GtkTreeModel *model,
GtkTreeIter *iter,
gpointer user_data)
{
- GtkFontChooserWidgetPrivate *priv = user_data;
+ GtkFontChooserWidget *fontchooser = user_data;
+ GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
gboolean result = TRUE;
const gchar *search_text;
gchar **split_terms;
gchar *font_name, *font_name_casefold;
guint i;
+ if (priv->script != 0 || priv->language != NULL)
+ {
+ PangoFontFamily *family;
+ PangoFontFace *face;
+ PangoLanguage **languages;
+ int n_languages;
+ int i;
+ gboolean is_alias;
+
+ gtk_tree_model_get (priv->model, iter,
+ FAMILY_COLUMN, &family,
+ FACE_COLUMN, &face,
+ -1);
+
+ pango_font_face_get_languages (face, &languages, &n_languages);
+ is_alias = is_alias_family (family);
+
+ g_object_unref (face);
+ g_object_unref (family);
+
+ if (!is_alias)
+ {
+ gboolean script_found;
+ gboolean language_found;
+
+ if (n_languages == 0)
+ return FALSE;
+
+ script_found = priv->script == 0;
+ language_found = priv->language == NULL;
+
+ for (i = 0; i < n_languages; i++)
+ {
+ if (priv->script != 0 &&
+ pango_language_includes_script (languages[i], priv->script))
+ script_found = TRUE;
+ if (priv->language != NULL && priv->language == languages[i])
+ language_found = TRUE;
+ }
+
+ if (!script_found || !language_found)
+ return FALSE;
+ }
+ }
+
if (priv->filter_func != NULL)
{
PangoFontFamily *family;
@@ -938,7 +1576,7 @@ visible_func (GtkTreeModel *model,
g_object_unref (family);
g_object_unref (face);
-
+
if (!result)
return FALSE;
}
@@ -1093,6 +1731,9 @@ gtk_font_chooser_widget_finalize (GObject *object)
if (priv->axes)
g_hash_table_unref (priv->axes);
+ g_free (priv->script_term);
+ g_free (priv->language_term);
+
G_OBJECT_CLASS (gtk_font_chooser_widget_parent_class)->finalize (object);
}
@@ -1713,5 +2354,43 @@ gtk_font_chooser_widget_handle_event (GtkWidget *widget,
GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
GdkEvent *event = (GdkEvent *)key_event;
+ if (gdk_event_get_event_type (event) == GDK_KEY_PRESS)
+ {
+ GdkModifierType state;
+ guint keyval;
+
+ gdk_event_get_state (event, &state);
+ gdk_event_get_keyval (event, &keyval);
+
+ if (gtk_widget_is_visible (priv->filter_popover))
+ {
+ if (gtk_revealer_get_child_revealed (GTK_REVEALER (priv->script_filter_revealer)))
+ {
+ gtk_widget_grab_focus (priv->script_filter_entry);
+ return gtk_widget_event (priv->script_filter_entry, event);
+ }
+
+ if (gtk_revealer_get_child_revealed (GTK_REVEALER (priv->language_filter_revealer)))
+ {
+ gtk_widget_grab_focus (priv->language_filter_entry);
+ return gtk_widget_event (priv->language_filter_entry, event);
+ }
+
+ if (keyval == GDK_KEY_Escape)
+ {
+ gtk_popover_popdown (GTK_POPOVER (priv->filter_popover));
+ return GDK_EVENT_STOP;
+ }
+ }
+ else
+ {
+ if ((state & GDK_MOD1_MASK) > 0 && keyval == GDK_KEY_Down)
+ {
+ gtk_popover_popup (GTK_POPOVER (priv->filter_popover));
+ return GDK_EVENT_STOP;
+ }
+ }
+ }
+
return gtk_search_entry_handle_event (GTK_SEARCH_ENTRY (priv->search_entry), event);
}
diff --git a/gtk/language-names.c b/gtk/language-names.c
new file mode 100644
index 0000000..2d433cf
--- /dev/null
+++ b/gtk/language-names.c
@@ -0,0 +1,233 @@
+#include "config.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <dirent.h>
+#include <locale.h>
+#include <langinfo.h>
+#include <sys/stat.h>
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <glib/gstdio.h>
+#include <hb-ot.h>
+
+#include "language-names.h"
+
+#define ISO_CODES_PREFIX "/usr"
+#define ISO_CODES_DATADIR ISO_CODES_PREFIX "/share/xml/iso-codes"
+#define ISO_CODES_LOCALESDIR ISO_CODES_PREFIX "/share/locale"
+
+static GHashTable *language_map;
+
+static char *
+get_first_item_in_semicolon_list (const char *list)
+{
+ char **items;
+ char *item;
+
+ items = g_strsplit (list, "; ", 2);
+
+ item = g_strdup (items[0]);
+ g_strfreev (items);
+
+ return item;
+}
+
+static char *
+capitalize_utf8_string (const char *str)
+{
+ char first[8] = { 0 };
+
+ if (!str)
+ return NULL;
+
+ g_unichar_to_utf8 (g_unichar_totitle (g_utf8_get_char (str)), first);
+
+ return g_strconcat (first, g_utf8_offset_to_pointer (str, 1), NULL);
+}
+
+static char *
+get_display_name (const char *language)
+{
+ const char *translated;
+ char *tmp;
+ char *name;
+
+ translated = dgettext ("iso_639", language);
+
+ tmp = get_first_item_in_semicolon_list (translated);
+ name = capitalize_utf8_string (tmp);
+ g_free (tmp);
+
+ return name;
+}
+
+static void
+languages_parse_start_tag (GMarkupParseContext *ctx,
+ const char *element_name,
+ const char **attr_names,
+ const char **attr_values,
+ gpointer user_data,
+ GError **error)
+{
+ const char *ccode_longB;
+ const char *ccode_longT;
+ const char *ccode;
+ const char *ccode_id;
+ const char *lang_name;
+ char *display_name;
+
+ if (!(g_str_equal (element_name, "iso_639_entry") ||
+ g_str_equal (element_name, "iso_639_3_entry")) ||
+ attr_names == NULL ||
+ attr_values == NULL)
+ return;
+
+ ccode = NULL;
+ ccode_longB = NULL;
+ ccode_longT = NULL;
+ ccode_id = NULL;
+ lang_name = NULL;
+
+ while (*attr_names && *attr_values)
+ {
+ if (g_str_equal (*attr_names, "iso_639_1_code"))
+ {
+ if (**attr_values)
+ {
+ if (strlen (*attr_values) != 2)
+ return;
+ ccode = *attr_values;
+ }
+ }
+ else if (g_str_equal (*attr_names, "iso_639_2B_code"))
+ {
+ if (**attr_values)
+ {
+ if (strlen (*attr_values) != 3)
+ return;
+ ccode_longB = *attr_values;
+ }
+ }
+ else if (g_str_equal (*attr_names, "iso_639_2T_code"))
+ {
+ if (**attr_values)
+ {
+ if (strlen (*attr_values) != 3)
+ return;
+ ccode_longT = *attr_values;
+ }
+ }
+ else if (g_str_equal (*attr_names, "id"))
+ {
+ if (**attr_values)
+ {
+ if (strlen (*attr_values) != 2 &&
+ strlen (*attr_values) != 3)
+ return;
+ ccode_id = *attr_values;
+ }
+ }
+ else if (g_str_equal (*attr_names, "name"))
+ {
+ lang_name = *attr_values;
+ }
+
+ ++attr_names;
+ ++attr_values;
+ }
+
+ if (lang_name == NULL)
+ return;
+
+ display_name = get_display_name (lang_name);
+
+ if (ccode != NULL)
+ g_hash_table_insert (language_map,
+ pango_language_from_string (ccode),
+ g_strdup (display_name));
+
+ if (ccode_longB != NULL)
+ g_hash_table_insert (language_map,
+ pango_language_from_string (ccode_longB),
+ g_strdup (display_name));
+
+ if (ccode_longT != NULL)
+ g_hash_table_insert (language_map,
+ pango_language_from_string (ccode_longT),
+ g_strdup (display_name));
+
+ if (ccode_id != NULL)
+ g_hash_table_insert (language_map,
+ pango_language_from_string (ccode_id),
+ g_strdup (display_name));
+
+ g_free (display_name);
+}
+
+static void
+languages_variant_init (const char *variant)
+{
+ gboolean res;
+ gsize buf_len;
+ g_autofree char *buf = NULL;
+ g_autofree char *filename = NULL;
+ g_autoptr (GError) error = NULL;
+
+ bindtextdomain (variant, ISO_CODES_LOCALESDIR);
+ bind_textdomain_codeset (variant, "UTF-8");
+
+ error = NULL;
+ filename = g_strconcat (ISO_CODES_DATADIR, "/", variant, ".xml", NULL);
+ res = g_file_get_contents (filename, &buf, &buf_len, &error);
+ if (res)
+ {
+ g_autoptr (GMarkupParseContext) ctx = NULL;
+ GMarkupParser parser = { languages_parse_start_tag, NULL, NULL, NULL, NULL };
+
+ ctx = g_markup_parse_context_new (&parser, 0, NULL, NULL);
+
+ error = NULL;
+ res = g_markup_parse_context_parse (ctx, buf, buf_len, &error);
+
+ if (!res)
+ g_warning ("Failed to parse '%s': %s\n", filename, error->message);
+ }
+ else
+ g_warning ("Failed to load '%s': %s\n", filename, error->message);
+}
+
+static void
+languages_init (void)
+{
+ if (language_map)
+ return;
+
+ language_map = g_hash_table_new_full (NULL, NULL, NULL, g_free);
+ languages_variant_init ("iso_639");
+ languages_variant_init ("iso_639_3");
+}
+
+const char *
+get_language_name (PangoLanguage *language)
+{
+ languages_init ();
+
+ return (const char *) g_hash_table_lookup (language_map, language);
+}
+
+const char *
+get_language_name_for_tag (guint32 tag)
+{
+ hb_language_t lang;
+ const char *s;
+
+ lang = hb_ot_tag_to_language (tag);
+ s = hb_language_to_string (lang);
+
+ return get_language_name (pango_language_from_string (s));
+}
diff --git a/gtk/language-names.h b/gtk/language-names.h
new file mode 100644
index 0000000..562f7ae
--- /dev/null
+++ b/gtk/language-names.h
@@ -0,0 +1,13 @@
+#ifndef LANGUAGE_NAMES_H
+#define LANGUAGE_NAMES_H
+
+#include <pango/pango.h>
+
+G_BEGIN_DECLS
+
+const char * get_language_name (PangoLanguage *language);
+const char * get_language_name_for_tag (guint32 tag);
+
+G_END_DECLS
+
+#endif
diff --git a/gtk/meson.build b/gtk/meson.build
index 49f8f9f..0a95643 100644
--- a/gtk/meson.build
+++ b/gtk/meson.build
@@ -5,6 +5,8 @@ subdir('inspector')
gtk_public_sources = files([
'fallback-c89.c',
'fnmatch.c',
+ 'language-names.c',
+ 'script-names.c',
'gdkpixbufutils.c',
'gtkaboutdialog.c',
'gtkaccelgroup.c',
diff --git a/gtk/script-names.c b/gtk/script-names.c
new file mode 100644
index 0000000..5049c34
--- /dev/null
+++ b/gtk/script-names.c
@@ -0,0 +1,184 @@
+#include "config.h"
+#include <glib.h>
+#include <glib/gi18n-lib.h>
+#include <hb-ot.h>
+
+#include "script-names.h"
+
+static struct {
+ GUnicodeScript script;
+ hb_script_t hb_script;
+ const char *name;
+} scripts[] =
+{
+ { G_UNICODE_SCRIPT_COMMON, HB_SCRIPT_COMMON, NULL },
+ { G_UNICODE_SCRIPT_INHERITED, HB_SCRIPT_INHERITED, NULL },
+ { G_UNICODE_SCRIPT_ARABIC, HB_SCRIPT_ARABIC, NC_("Script", "Arabic") },
+ { G_UNICODE_SCRIPT_ARMENIAN, HB_SCRIPT_ARMENIAN, NC_("Script", "Armenian") },
+ { G_UNICODE_SCRIPT_BENGALI, HB_SCRIPT_BENGALI, NC_("Script", "Bengali") },
+ { G_UNICODE_SCRIPT_BOPOMOFO, HB_SCRIPT_BOPOMOFO, NC_("Script", "Bopomofo") },
+ { G_UNICODE_SCRIPT_CHEROKEE, HB_SCRIPT_CHEROKEE, NC_("Script", "Cherokee") },
+ { G_UNICODE_SCRIPT_COPTIC, HB_SCRIPT_COPTIC, NC_("Script", "Coptic") },
+ { G_UNICODE_SCRIPT_CYRILLIC, HB_SCRIPT_CYRILLIC, NC_("Script", "Cyrillic") },
+ { G_UNICODE_SCRIPT_DESERET, HB_SCRIPT_DESERET, NC_("Script", "Deseret") },
+ { G_UNICODE_SCRIPT_DEVANAGARI, HB_SCRIPT_DEVANAGARI, NC_("Script", "Devanagari") },
+ { G_UNICODE_SCRIPT_ETHIOPIC, HB_SCRIPT_ETHIOPIC, NC_("Script", "Ethiopic") },
+ { G_UNICODE_SCRIPT_GEORGIAN, HB_SCRIPT_GEORGIAN, NC_("Script", "Georgian") },
+ { G_UNICODE_SCRIPT_GOTHIC, HB_SCRIPT_GOTHIC, NC_("Script", "Gothic") },
+ { G_UNICODE_SCRIPT_GREEK, HB_SCRIPT_GREEK, NC_("Script", "Greek") },
+ { G_UNICODE_SCRIPT_GUJARATI, HB_SCRIPT_GUJARATI, NC_("Script", "Gujarati") },
+ { G_UNICODE_SCRIPT_GURMUKHI, HB_SCRIPT_GURMUKHI, NC_("Script", "Gurmukhi") },
+ { G_UNICODE_SCRIPT_HAN, HB_SCRIPT_HAN, NC_("Script", "Han") },
+ { G_UNICODE_SCRIPT_HANGUL, HB_SCRIPT_HANGUL, NC_("Script", "Hangul") },
+ { G_UNICODE_SCRIPT_HEBREW, HB_SCRIPT_HEBREW, NC_("Script", "Hebrew") },
+ { G_UNICODE_SCRIPT_HIRAGANA, HB_SCRIPT_HIRAGANA, NC_("Script", "Hiragana") },
+ { G_UNICODE_SCRIPT_KANNADA, HB_SCRIPT_KANNADA, NC_("Script", "Kannada") },
+ { G_UNICODE_SCRIPT_KATAKANA, HB_SCRIPT_KATAKANA, NC_("Script", "Katakana") },
+ { G_UNICODE_SCRIPT_KHMER, HB_SCRIPT_KHMER, NC_("Script", "Khmer") },
+ { G_UNICODE_SCRIPT_LAO, HB_SCRIPT_LAO, NC_("Script", "Lao") },
+ { G_UNICODE_SCRIPT_LATIN, HB_SCRIPT_LATIN, NC_("Script", "Latin") },
+ { G_UNICODE_SCRIPT_MALAYALAM, HB_SCRIPT_MALAYALAM, NC_("Script", "Malayalam") },
+ { G_UNICODE_SCRIPT_MONGOLIAN, HB_SCRIPT_MONGOLIAN, NC_("Script", "Mongolian") },
+ { G_UNICODE_SCRIPT_MYANMAR, HB_SCRIPT_MYANMAR, NC_("Script", "Myanmar") },
+ { G_UNICODE_SCRIPT_OGHAM, HB_SCRIPT_OGHAM, NC_("Script", "Ogham") },
+ { G_UNICODE_SCRIPT_OLD_ITALIC, HB_SCRIPT_OLD_ITALIC, NC_("Script", "Old Italic") },
+ { G_UNICODE_SCRIPT_ORIYA, HB_SCRIPT_ORIYA, NC_("Script", "Oriya") },
+ { G_UNICODE_SCRIPT_RUNIC, HB_SCRIPT_RUNIC, NC_("Script", "Runic") },
+ { G_UNICODE_SCRIPT_SINHALA, HB_SCRIPT_SINHALA, NC_("Script", "Sinhala") },
+ { G_UNICODE_SCRIPT_SYRIAC, HB_SCRIPT_SYRIAC, NC_("Script", "Syriac") },
+ { G_UNICODE_SCRIPT_TAMIL, HB_SCRIPT_TAMIL, NC_("Script", "Tamil") },
+ { G_UNICODE_SCRIPT_TELUGU, HB_SCRIPT_TELUGU, NC_("Script", "Telugu") },
+ { G_UNICODE_SCRIPT_THAANA, HB_SCRIPT_THAANA, NC_("Script", "Thaana") },
+ { G_UNICODE_SCRIPT_THAI, HB_SCRIPT_THAI, NC_("Script", "Thai") },
+ { G_UNICODE_SCRIPT_TIBETAN, HB_SCRIPT_TIBETAN, NC_("Script", "Tibetan") },
+ { G_UNICODE_SCRIPT_CANADIAN_ABORIGINAL, HB_SCRIPT_CANADIAN_ABORIGINAL, NC_("Script", "Canadian
Aboriginal") },
+ { G_UNICODE_SCRIPT_YI, HB_SCRIPT_YI, NC_("Script", "Yi") },
+ { G_UNICODE_SCRIPT_TAGALOG, HB_SCRIPT_TAGALOG, NC_("Script", "Tagalog") },
+ { G_UNICODE_SCRIPT_HANUNOO, HB_SCRIPT_HANUNOO, NC_("Script", "Hanunoo") },
+ { G_UNICODE_SCRIPT_BUHID, HB_SCRIPT_BUHID, NC_("Script", "Buhid") },
+ { G_UNICODE_SCRIPT_TAGBANWA, HB_SCRIPT_TAGBANWA, NC_("Script", "Tagbanwa") },
+ { G_UNICODE_SCRIPT_BRAILLE, HB_SCRIPT_BRAILLE, NC_("Script", "Braille") },
+ { G_UNICODE_SCRIPT_CYPRIOT, HB_SCRIPT_CYPRIOT, NC_("Script", "Cypriot") },
+ { G_UNICODE_SCRIPT_LIMBU, HB_SCRIPT_LIMBU, NC_("Script", "Limbu") },
+ { G_UNICODE_SCRIPT_OSMANYA, HB_SCRIPT_OSMANYA, NC_("Script", "Osmanya") },
+ { G_UNICODE_SCRIPT_SHAVIAN, HB_SCRIPT_SHAVIAN, NC_("Script", "Shavian") },
+ { G_UNICODE_SCRIPT_LINEAR_B, HB_SCRIPT_LINEAR_B, NC_("Script", "Linear B") },
+ { G_UNICODE_SCRIPT_TAI_LE, HB_SCRIPT_TAI_LE, NC_("Script", "Tai Le") },
+ { G_UNICODE_SCRIPT_UGARITIC, HB_SCRIPT_UGARITIC, NC_("Script", "Ugaritic") },
+ { G_UNICODE_SCRIPT_NEW_TAI_LUE, HB_SCRIPT_NEW_TAI_LUE, NC_("Script", "New Tai Lue") },
+ { G_UNICODE_SCRIPT_BUGINESE, HB_SCRIPT_BUGINESE, NC_("Script", "Buginese") },
+ { G_UNICODE_SCRIPT_GLAGOLITIC, HB_SCRIPT_GLAGOLITIC, NC_("Script", "Glagolitic") },
+ { G_UNICODE_SCRIPT_TIFINAGH, HB_SCRIPT_TIFINAGH, NC_("Script", "Tifinagh") },
+ { G_UNICODE_SCRIPT_SYLOTI_NAGRI, HB_SCRIPT_SYLOTI_NAGRI, NC_("Script", "Syloti Nagri") },
+ { G_UNICODE_SCRIPT_OLD_PERSIAN, HB_SCRIPT_OLD_PERSIAN, NC_("Script", "Old Persian") },
+ { G_UNICODE_SCRIPT_KHAROSHTHI, HB_SCRIPT_KHAROSHTHI, NC_("Script", "Kharoshthi") },
+ { G_UNICODE_SCRIPT_UNKNOWN, HB_SCRIPT_UNKNOWN, NC_("Script", "Unknown") },
+ { G_UNICODE_SCRIPT_BALINESE, HB_SCRIPT_BALINESE, NC_("Script", "Balinese") },
+ { G_UNICODE_SCRIPT_CUNEIFORM, HB_SCRIPT_CUNEIFORM, NC_("Script", "Cuneiform") },
+ { G_UNICODE_SCRIPT_PHOENICIAN, HB_SCRIPT_PHOENICIAN, NC_("Script", "Phoenician") },
+ { G_UNICODE_SCRIPT_PHAGS_PA, HB_SCRIPT_PHAGS_PA, NC_("Script", "Phags-pa") },
+ { G_UNICODE_SCRIPT_NKO, HB_SCRIPT_NKO, NC_("Script", "N'Ko") },
+ { G_UNICODE_SCRIPT_KAYAH_LI, HB_SCRIPT_KAYAH_LI, NC_("Script", "Kayah Li") },
+ { G_UNICODE_SCRIPT_LEPCHA, HB_SCRIPT_LEPCHA, NC_("Script", "Lepcha") },
+ { G_UNICODE_SCRIPT_REJANG, HB_SCRIPT_REJANG, NC_("Script", "Rejang") },
+ { G_UNICODE_SCRIPT_SUNDANESE, HB_SCRIPT_SUNDANESE, NC_("Script", "Sundanese") },
+ { G_UNICODE_SCRIPT_SAURASHTRA, HB_SCRIPT_SAURASHTRA, NC_("Script", "Saurashtra") },
+ { G_UNICODE_SCRIPT_CHAM, HB_SCRIPT_CHAM, NC_("Script", "Cham") },
+ { G_UNICODE_SCRIPT_OL_CHIKI, HB_SCRIPT_OL_CHIKI, NC_("Script", "Ol Chiki") },
+ { G_UNICODE_SCRIPT_VAI, HB_SCRIPT_VAI, NC_("Script", "Vai") },
+ { G_UNICODE_SCRIPT_CARIAN, HB_SCRIPT_CARIAN, NC_("Script", "Carian") },
+ { G_UNICODE_SCRIPT_LYCIAN, HB_SCRIPT_LYCIAN, NC_("Script", "Lycian") },
+ { G_UNICODE_SCRIPT_LYDIAN, HB_SCRIPT_LYDIAN, NC_("Script", "Lydian") },
+ { G_UNICODE_SCRIPT_AVESTAN, HB_SCRIPT_AVESTAN, NC_("Script", "Avestan") },
+ { G_UNICODE_SCRIPT_BAMUM, HB_SCRIPT_BAMUM, NC_("Script", "Bamum") },
+ { G_UNICODE_SCRIPT_EGYPTIAN_HIEROGLYPHS, HB_SCRIPT_EGYPTIAN_HIEROGLYPHS, NC_("Script", "Egyptian
Hieroglpyhs") },
+ { G_UNICODE_SCRIPT_IMPERIAL_ARAMAIC, HB_SCRIPT_IMPERIAL_ARAMAIC, NC_("Script", "Imperial Aramaic") },
+ { G_UNICODE_SCRIPT_INSCRIPTIONAL_PAHLAVI, HB_SCRIPT_INSCRIPTIONAL_PAHLAVI, NC_("Script", "Inscriptional
Pahlavi") },
+ { G_UNICODE_SCRIPT_INSCRIPTIONAL_PARTHIAN, HB_SCRIPT_INSCRIPTIONAL_PARTHIAN, NC_("Script", "Inscriptional
Parthian") },
+ { G_UNICODE_SCRIPT_JAVANESE, HB_SCRIPT_JAVANESE, NC_("Script", "Javanese") },
+ { G_UNICODE_SCRIPT_KAITHI, HB_SCRIPT_KAITHI, NC_("Script", "Kaithi") },
+ { G_UNICODE_SCRIPT_LISU, HB_SCRIPT_LISU, NC_("Script", "Lisu") },
+ { G_UNICODE_SCRIPT_MEETEI_MAYEK, HB_SCRIPT_MEETEI_MAYEK, NC_("Script", "Meetei Mayek") },
+ { G_UNICODE_SCRIPT_OLD_SOUTH_ARABIAN, HB_SCRIPT_OLD_SOUTH_ARABIAN, NC_("Script", "Old South Arabian") },
+ { G_UNICODE_SCRIPT_OLD_TURKIC, HB_SCRIPT_OLD_TURKIC, NC_("Script", "Old Turkic") },
+ { G_UNICODE_SCRIPT_SAMARITAN, HB_SCRIPT_SAMARITAN, NC_("Script", "Samaritan") },
+ { G_UNICODE_SCRIPT_TAI_THAM, HB_SCRIPT_TAI_THAM, NC_("Script", "Tai Tham") },
+ { G_UNICODE_SCRIPT_TAI_VIET, HB_SCRIPT_TAI_VIET, NC_("Script", "Tai Viet") },
+ { G_UNICODE_SCRIPT_BATAK, HB_SCRIPT_BATAK, NC_("Script", "Batak") },
+ { G_UNICODE_SCRIPT_BRAHMI, HB_SCRIPT_BRAHMI, NC_("Script", "Brahmi") },
+ { G_UNICODE_SCRIPT_MANDAIC, HB_SCRIPT_MANDAIC, NC_("Script", "Mandaic") },
+ { G_UNICODE_SCRIPT_CHAKMA, HB_SCRIPT_CHAKMA, NC_("Script", "Chakma") },
+ { G_UNICODE_SCRIPT_MEROITIC_CURSIVE, HB_SCRIPT_MEROITIC_CURSIVE, NC_("Script", "Meroitic Cursive") },
+ { G_UNICODE_SCRIPT_MEROITIC_HIEROGLYPHS, HB_SCRIPT_MEROITIC_HIEROGLYPHS, NC_("Script", "Meroitic
Hieroglyphs") },
+ { G_UNICODE_SCRIPT_MIAO, HB_SCRIPT_MIAO, NC_("Script", "Miao") },
+ { G_UNICODE_SCRIPT_SHARADA, HB_SCRIPT_SHARADA, NC_("Script", "Sharada") },
+ { G_UNICODE_SCRIPT_SORA_SOMPENG, HB_SCRIPT_SORA_SOMPENG, NC_("Script", "Sora Sompeng") },
+ { G_UNICODE_SCRIPT_TAKRI, HB_SCRIPT_TAKRI, NC_("Script", "Takri") },
+ { G_UNICODE_SCRIPT_BASSA_VAH, HB_SCRIPT_BASSA_VAH, NC_("Script", "Bassa") },
+ { G_UNICODE_SCRIPT_CAUCASIAN_ALBANIAN, HB_SCRIPT_CAUCASIAN_ALBANIAN, NC_("Script", "Caucasian Albanian")
},
+ { G_UNICODE_SCRIPT_DUPLOYAN, HB_SCRIPT_DUPLOYAN, NC_("Script", "Duployan") },
+ { G_UNICODE_SCRIPT_ELBASAN, HB_SCRIPT_ELBASAN, NC_("Script", "Elbasan") },
+ { G_UNICODE_SCRIPT_GRANTHA, HB_SCRIPT_GRANTHA, NC_("Script", "Grantha") },
+ { G_UNICODE_SCRIPT_KHOJKI, HB_SCRIPT_KHOJKI, NC_("Script", "Kjohki") },
+ { G_UNICODE_SCRIPT_KHUDAWADI, HB_SCRIPT_KHUDAWADI, NC_("Script", "Khudawadi, Sindhi") },
+ { G_UNICODE_SCRIPT_LINEAR_A, HB_SCRIPT_LINEAR_A, NC_("Script", "Linear A") },
+ { G_UNICODE_SCRIPT_MAHAJANI, HB_SCRIPT_MAHAJANI, NC_("Script", "Mahajani") },
+ { G_UNICODE_SCRIPT_MANICHAEAN, HB_SCRIPT_MANICHAEAN, NC_("Script", "Manichaean") },
+ { G_UNICODE_SCRIPT_MENDE_KIKAKUI, HB_SCRIPT_MENDE_KIKAKUI, NC_("Script", "Mende Kikakui") },
+ { G_UNICODE_SCRIPT_MODI, HB_SCRIPT_MODI, NC_("Script", "Modi") },
+ { G_UNICODE_SCRIPT_MRO, HB_SCRIPT_MRO, NC_("Script", "Mro") },
+ { G_UNICODE_SCRIPT_NABATAEAN, HB_SCRIPT_NABATAEAN, NC_("Script", "Nabataean") },
+ { G_UNICODE_SCRIPT_OLD_NORTH_ARABIAN, HB_SCRIPT_OLD_NORTH_ARABIAN, NC_("Script", "Old North Arabian") },
+ { G_UNICODE_SCRIPT_OLD_PERMIC, HB_SCRIPT_OLD_PERMIC, NC_("Script", "Old Permic") },
+ { G_UNICODE_SCRIPT_PAHAWH_HMONG, HB_SCRIPT_PAHAWH_HMONG, NC_("Script", "Pahawh Hmong") },
+ { G_UNICODE_SCRIPT_PALMYRENE, HB_SCRIPT_PALMYRENE, NC_("Script", "Palmyrene") },
+ { G_UNICODE_SCRIPT_PAU_CIN_HAU, HB_SCRIPT_PAU_CIN_HAU, NC_("Script", "Pau Cin Hau") },
+ { G_UNICODE_SCRIPT_PSALTER_PAHLAVI, HB_SCRIPT_PSALTER_PAHLAVI, NC_("Script", "Psalter Pahlavi") },
+ { G_UNICODE_SCRIPT_SIDDHAM, HB_SCRIPT_SIDDHAM, NC_("Script", "Siddham") },
+ { G_UNICODE_SCRIPT_TIRHUTA, HB_SCRIPT_TIRHUTA, NC_("Script", "Tirhuta") },
+ { G_UNICODE_SCRIPT_WARANG_CITI, HB_SCRIPT_WARANG_CITI, NC_("Script", "Warang Citi") },
+ { G_UNICODE_SCRIPT_AHOM, HB_SCRIPT_AHOM, NC_("Script", "Ahom") },
+ { G_UNICODE_SCRIPT_ANATOLIAN_HIEROGLYPHS, HB_SCRIPT_ANATOLIAN_HIEROGLYPHS, NC_("Script", "Anatolian
Hieroglyphs") },
+ { G_UNICODE_SCRIPT_HATRAN, HB_SCRIPT_HATRAN, NC_("Script", "Hatran") },
+ { G_UNICODE_SCRIPT_MULTANI, HB_SCRIPT_MULTANI, NC_("Script", "Multani") },
+ { G_UNICODE_SCRIPT_OLD_HUNGARIAN, HB_SCRIPT_OLD_HUNGARIAN, NC_("Script", "Old Hungarian") },
+ { G_UNICODE_SCRIPT_SIGNWRITING, HB_SCRIPT_SIGNWRITING, NC_("Script", "Signwriting") },
+ { G_UNICODE_SCRIPT_ADLAM, HB_SCRIPT_ADLAM, NC_("Script", "Adlam") },
+ { G_UNICODE_SCRIPT_BHAIKSUKI, HB_SCRIPT_BHAIKSUKI, NC_("Script", "Bhaiksuki") },
+ { G_UNICODE_SCRIPT_MARCHEN, HB_SCRIPT_MARCHEN, NC_("Script", "Marchen") },
+ { G_UNICODE_SCRIPT_NEWA, HB_SCRIPT_NEWA, NC_("Script", "Newa") },
+ { G_UNICODE_SCRIPT_OSAGE, HB_SCRIPT_OSAGE, NC_("Script", "Osage") },
+ { G_UNICODE_SCRIPT_TANGUT, HB_SCRIPT_TANGUT, NC_("Script", "Tangut") },
+ { G_UNICODE_SCRIPT_MASARAM_GONDI, HB_SCRIPT_INVALID, NC_("Script", "Masaram Gondi") },
+ { G_UNICODE_SCRIPT_NUSHU, HB_SCRIPT_INVALID, NC_("Script", "Nushu") },
+ { G_UNICODE_SCRIPT_SOYOMBO, HB_SCRIPT_INVALID, NC_("Script", "Soyombo") },
+ { G_UNICODE_SCRIPT_ZANABAZAR_SQUARE, HB_SCRIPT_INVALID, NC_("Script", "Zanabazar Square") },
+};
+
+const char *
+get_script_name (GUnicodeScript script)
+{
+ int i;
+
+ for (i = 0; i < G_N_ELEMENTS (scripts); i++)
+ {
+ if (scripts[i].script == script)
+ return g_dpgettext2 (GETTEXT_PACKAGE, "Script", scripts[i].name);
+ }
+
+ return NULL;
+}
+
+const char *
+get_script_name_for_tag (guint32 tag)
+{
+ int i;
+
+ for (i = 0; i < G_N_ELEMENTS (scripts); i++)
+ {
+ if (scripts[i].hb_script == hb_script_from_iso15924_tag (tag))
+ return g_dpgettext2 (GETTEXT_PACKAGE, "Script", scripts[i].name);
+ }
+
+ return NULL;
+}
diff --git a/gtk/script-names.h b/gtk/script-names.h
new file mode 100644
index 0000000..3036c05
--- /dev/null
+++ b/gtk/script-names.h
@@ -0,0 +1,13 @@
+#ifndef SCRIPT_NAMES_H
+#define SCRIPT_NAMES_H
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+const char * get_script_name (GUnicodeScript script);
+const char * get_script_name_for_tag (guint32 tag);
+
+G_END_DECLS
+
+#endif
diff --git a/gtk/ui/gtkfontchooserwidget.ui b/gtk/ui/gtkfontchooserwidget.ui
index d74962b..ad5c78c 100644
--- a/gtk/ui/gtkfontchooserwidget.ui
+++ b/gtk/ui/gtkfontchooserwidget.ui
@@ -36,23 +36,34 @@
<property name="row-spacing">6</property>
<property name="column-spacing">6</property>
<child>
- <object class="GtkSearchEntry" id="search_entry">
- <property name="can-focus">1</property>
- <property name="hexpand">1</property>
- <property name="activates-default">1</property>
- <property name="primary-icon-name">edit-find-symbolic</property>
- <property name="primary-icon-activatable">0</property>
- <property name="secondary-icon-activatable">0</property>
- <property name="primary-icon-sensitive">0</property>
- <property name="secondary-icon-sensitive">0</property>
- <property name="placeholder-text" translatable="yes">Search font name</property>
- <signal name="search-changed" handler="text_changed_cb" swapped="no"/>
- <signal name="stop-search" handler="stop_search_cb" swapped="no"/>
+ <object class="GtkBox">
+ <style>
+ <class name="linked"/>
+ </style>
+ <child>
+ <object class="GtkSearchEntry" id="search_entry">
+ <property name="can-focus">1</property>
+ <property name="hexpand">1</property>
+ <property name="activates-default">1</property>
+ <property name="primary-icon-name">edit-find-symbolic</property>
+ <property name="primary-icon-activatable">0</property>
+ <property name="secondary-icon-activatable">0</property>
+ <property name="primary-icon-sensitive">0</property>
+ <property name="secondary-icon-sensitive">0</property>
+ <property name="placeholder-text" translatable="yes">Search font name</property>
+ <signal name="search-changed" handler="text_changed_cb" swapped="no"/>
+ <signal name="stop-search" handler="stop_search_cb" swapped="no"/>
+ </object>
+ </child>
+ <child>
+ <object class="GtkMenuButton" id="filter_button">
+ <property name="popover">filter_popover</property>
+ </object>
+ </child>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">0</property>
- <property name="width">2</property>
</packing>
</child>
<child>
@@ -201,7 +212,6 @@
<packing>
<property name="left-attach">0</property>
<property name="top-attach">1</property>
- <property name="width">2</property>
</packing>
</child>
</object>
@@ -211,4 +221,154 @@
<property name="names">font-x-generic-symbolic
emblem-documents-symbolic</property>
</object>
+ <object class="GtkPopover" id="filter_popover">
+ <property name="width-request">300</property>
+ <signal name="notify::visible" handler="popover_notify"/>
+ <child>
+ <object class="GtkBox">
+ <property name="orientation">vertical</property>
+ <property name="margin">20</property>
+ <child>
+ <object class="GtkLabel">
+ <property name="label" translatable="yes">Script</property>
+ <property name="xalign">0</property>
+ <property name="margin-bottom">10</property>
+ <style>
+ <class name="dim-label"/>
+ </style>
+ </object>
+ </child>
+ <child>
+ <object class="GtkButton" id="script_filter_button">
+ <signal name="clicked" handler="script_filter_button_clicked"/>
+ <child>
+ <object class="GtkBox">
+ <property name="spacing">10</property>
+ <child>
+ <object class="GtkLabel" id="script_filter_button_label">
+ <property name="xalign">0</property>
+ <property name="max-width-chars">25</property>
+ <property name="label" translatable="yes">Any script</property>
+ <property name="hexpand">1</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkImage">
+ <property name="visible">1</property>
+ <property name="icon-name">pan-down-symbolic</property>
+ <property name="icon-size">1</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkRevealer" id="script_filter_revealer">
+ <property name="margin-bottom">20</property>
+ <child>
+ <object class="GtkBox">
+ <property name="orientation">vertical</property>
+ <property name="spacing">10</property>
+ <child>
+ <object class="GtkSearchEntry" id="script_filter_entry">
+ <property name="placeholder-text" translatable="yes">Search…</property>
+ <signal name="search-changed" handler="script_filter_changed" swapped="yes"/>
+ <signal name="stop-search" handler="script_filter_stop" swapped="yes"/>
+ <signal name="activate" handler="script_filter_activated" swapped="yes"/>
+ </object>
+ </child>
+ <child>
+ <object class="GtkScrolledWindow">
+ <property name="shadow-type">in</property>
+ <property name="hscrollbar-policy">never</property>
+ <property name="vscrollbar-policy">automatic</property>
+ <property name="propagate-natural-height">1</property>
+ <property name="max-content-height">200</property>
+ <child>
+ <object class="GtkListBox" id="script_list">
+ <property name="visible">1</property>
+ <property name="selection-mode">none</property>
+ <signal name="row-activated" handler="script_row_activated"/>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkLabel">
+ <property name="label" translatable="yes">Language</property>
+ <property name="xalign">0</property>
+ <property name="margin-bottom">10</property>
+ <style>
+ <class name="dim-label"/>
+ </style>
+ </object>
+ </child>
+ <child>
+ <object class="GtkButton" id="language_filter_button">
+ <signal name="clicked" handler="language_filter_button_clicked"/>
+ <child>
+ <object class="GtkBox">
+ <property name="spacing">10</property>
+ <child>
+ <object class="GtkLabel" id="language_filter_button_label">
+ <property name="xalign">0</property>
+ <property name="max-width-chars">25</property>
+ <property name="label" translatable="yes">Any language</property>
+ <property name="hexpand">1</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkImage">
+ <property name="visible">1</property>
+ <property name="icon-name">pan-down-symbolic</property>
+ <property name="icon-size">1</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkRevealer" id="language_filter_revealer">
+ <property name="margin-bottom">20</property>
+ <child>
+ <object class="GtkBox">
+ <property name="orientation">vertical</property>
+ <property name="spacing">10</property>
+ <child>
+ <object class="GtkSearchEntry" id="language_filter_entry">
+ <property name="placeholder-text" translatable="yes">Search…</property>
+ <signal name="search-changed" handler="language_filter_changed" swapped="yes"/>
+ <signal name="stop-search" handler="language_filter_stop" swapped="yes"/>
+ <signal name="activate" handler="language_filter_activated" swapped="yes"/>
+ </object>
+ </child>
+ <child>
+ <object class="GtkScrolledWindow">
+ <property name="shadow-type">in</property>
+ <property name="hscrollbar-policy">never</property>
+ <property name="vscrollbar-policy">automatic</property>
+ <property name="propagate-natural-height">1</property>
+ <property name="max-content-height">200</property>
+ <child>
+ <object class="GtkListBox" id="language_list">
+ <property name="visible">1</property>
+ <property name="selection-mode">none</property>
+ <signal name="row-activated" handler="language_row_activated"/>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
</interface>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]