From 0f195bf167ed98ce8e78bb2b269a3ab8e033215f Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Wed, 4 Dec 2019 22:20:21 -0500 Subject: family: Implement GListModel Make a PangoFontFamily a list model which contains the faces of the family. The current implementation is not optimized. --- pango/fonts.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) (limited to 'pango/fonts.c') diff --git a/pango/fonts.c b/pango/fonts.c index 9e6325b7..736c9c20 100644 --- a/pango/fonts.c +++ b/pango/fonts.c @@ -37,6 +37,8 @@ #include #include +#include + #include "pango-types.h" #include "pango-font-private.h" #include "pango-fontmap.h" @@ -2176,7 +2178,54 @@ pango_font_metrics_get_strikethrough_thickness (PangoFontMetrics *metrics) * PangoFontFamily */ -G_DEFINE_ABSTRACT_TYPE (PangoFontFamily, pango_font_family, G_TYPE_OBJECT) +static GType +pango_font_family_get_item_type (GListModel *list) +{ + return PANGO_TYPE_FONT_FACE; +} + +static guint +pango_font_family_get_n_items (GListModel *list) +{ + PangoFontFamily *family = PANGO_FONT_FAMILY (list); + int n_faces; + + pango_font_family_list_faces (family, NULL, &n_faces); + + return (guint)n_faces; +} + +static gpointer +pango_font_family_get_item (GListModel *list, + guint position) +{ + PangoFontFamily *family = PANGO_FONT_FAMILY (list); + PangoFontFace **faces; + int n_faces; + PangoFontFace *face; + + pango_font_family_list_faces (family, &faces, &n_faces); + + if (position < n_faces) + face = g_object_ref (faces[position]); + else + face = NULL; + + g_free (faces); + + return face; +} + +static void +pango_font_family_list_model_init (GListModelInterface *iface) +{ + iface->get_item_type = pango_font_family_get_item_type; + iface->get_n_items = pango_font_family_get_n_items; + iface->get_item = pango_font_family_get_item; +} + +G_DEFINE_ABSTRACT_TYPE_WITH_CODE (PangoFontFamily, pango_font_family, G_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE (G_TYPE_LIST_MODEL, pango_font_family_list_model_init)) static PangoFontFace *pango_font_family_real_get_face (PangoFontFamily *family, const char *name); -- cgit v1.2.1