[gtk/font-list] Add a font list example
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/font-list] Add a font list example
- Date: Thu, 5 Dec 2019 03:45:31 +0000 (UTC)
commit 3c3ec9c5c4b5549042c6b0699617a13dfe0f3e24
Author: Matthias Clasen <mclasen redhat com>
Date: Wed Dec 4 22:43:18 2019 -0500
Add a font list example
This shows how to use the new pango list models.
tests/fontlist.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
tests/meson.build | 1 +
2 files changed, 70 insertions(+)
---
diff --git a/tests/fontlist.c b/tests/fontlist.c
new file mode 100644
index 0000000000..8818b7af94
--- /dev/null
+++ b/tests/fontlist.c
@@ -0,0 +1,69 @@
+#include <gtk/gtk.h>
+
+static gpointer
+pick_one_face (gpointer item, gpointer user_data)
+{
+ PangoFontFamily *family = PANGO_FONT_FAMILY (item);
+ PangoFontFace *face;
+
+ face = pango_font_family_get_face (family, "Regular");
+
+ g_object_unref (family);
+
+ return g_object_ref (face);
+}
+
+int
+main (int argc, char *argv[])
+{
+ PangoFontMap *fontmap;
+ int i;
+ GListModel *model;
+
+ fontmap = pango_cairo_font_map_get_default ();
+ model = G_LIST_MODEL (fontmap);
+ g_print ("Families\n--------\n");
+ for (i = 0; i < g_list_model_get_n_items (model); i++)
+ {
+ PangoFontFamily *family = PANGO_FONT_FAMILY (g_list_model_get_item (model, i));
+
+ g_print ("%s\n", pango_font_family_get_name (family));
+
+ g_object_unref (family);
+ }
+
+ g_print ("All faces\n-----\n");
+ model = G_LIST_MODEL (gtk_flatten_list_model_new (PANGO_TYPE_FONT_FACE, model));
+ for (i = 0; i < g_list_model_get_n_items (model); i++)
+ {
+ PangoFontFace *face = PANGO_FONT_FACE (g_list_model_get_item (model, i));
+
+ g_print ("%s %s\n",
+ pango_font_family_get_name (pango_font_face_get_family (face)),
+ pango_font_face_get_face_name (face));
+
+ g_object_unref (face);
+ }
+ g_object_unref (model);
+
+ g_print ("One face per family\n-------------------\n");
+ model = G_LIST_MODEL (gtk_map_list_model_new (PANGO_TYPE_FONT_FACE,
+ G_LIST_MODEL (fontmap),
+ pick_one_face,
+ NULL, NULL));
+ for (i = 0; i < g_list_model_get_n_items (model); i++)
+ {
+ PangoFontFace *face = PANGO_FONT_FACE (g_list_model_get_item (model, i));
+
+ g_print ("%s %s\n",
+ pango_font_family_get_name (pango_font_face_get_family (face)),
+ pango_font_face_get_face_name (face));
+
+ g_object_unref (face);
+ }
+ g_object_unref (model);
+
+ g_object_unref (fontmap);
+
+ return 0;
+}
diff --git a/tests/meson.build b/tests/meson.build
index 7b28428102..894ab1b35a 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -1,5 +1,6 @@
gtk_tests = [
# testname, optional extra sources
+ ['fontlist'],
['rendernode'],
['rendernode-create-tests'],
['overlayscroll'],
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]