diff options
author | Matthias Clasen <mclasen@redhat.com> | 2019-12-04 22:21:29 -0500 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2019-12-04 22:21:29 -0500 |
commit | 12b2db7af917ebbadcc74f2248c6986c78e157e9 (patch) | |
tree | 2e90ea5ed8a879aa1237c87e43b2f64cacc422d5 | |
parent | 0f195bf167ed98ce8e78bb2b269a3ab8e033215f (diff) | |
download | pango-12b2db7af917ebbadcc74f2248c6986c78e157e9.tar.gz |
fontmap: Implement GListModel
Make PangoFontMap a list model which contains
the families.
The current implementation is not optimized.
-rw-r--r-- | pango/pango-fontmap.c | 54 |
1 files changed, 53 insertions, 1 deletions
diff --git a/pango/pango-fontmap.c b/pango/pango-fontmap.c index 54ac5d0d..a8b9f426 100644 --- a/pango/pango-fontmap.c +++ b/pango/pango-fontmap.c @@ -20,6 +20,9 @@ */ #include "config.h" + +#include <gio/gio.h> + #include "pango-fontmap-private.h" #include "pango-fontset-private.h" #include "pango-impl-utils.h" @@ -34,7 +37,10 @@ static PangoFontset *pango_font_map_real_load_fontset (PangoFontMap static PangoFontFamily *pango_font_map_real_get_family (PangoFontMap *fontmap, const char *name); -G_DEFINE_ABSTRACT_TYPE (PangoFontMap, pango_font_map, G_TYPE_OBJECT) +static void pango_font_map_list_model_init (GListModelInterface *iface); + +G_DEFINE_ABSTRACT_TYPE_WITH_CODE (PangoFontMap, pango_font_map, G_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE (G_TYPE_LIST_MODEL, pango_font_map_list_model_init)) static void pango_font_map_class_init (PangoFontMapClass *class) @@ -390,3 +396,49 @@ pango_font_map_get_family (PangoFontMap *fontmap, return PANGO_FONT_MAP_GET_CLASS (fontmap)->get_family (fontmap, name); } + +static GType +pango_font_map_get_item_type (GListModel *list) +{ + return PANGO_TYPE_FONT_FAMILY; +} + +static guint +pango_font_map_get_n_items (GListModel *list) +{ + PangoFontMap *fontmap = PANGO_FONT_MAP (list); + int n_families; + + pango_font_map_list_families (fontmap, NULL, &n_families); + + return (guint)n_families; +} + +static gpointer +pango_font_map_get_item (GListModel *list, + guint position) +{ + PangoFontMap *fontmap = PANGO_FONT_MAP (list); + PangoFontFamily **families; + guint n_families; + PangoFontFamily *family; + + pango_font_map_list_families (fontmap, &families, &n_families); + + if (position < n_families) + family = g_object_ref (families[position]); + else + family = NULL; + + g_free (families); + + return family; +} + +static void +pango_font_map_list_model_init (GListModelInterface *iface) +{ + iface->get_item_type = pango_font_map_get_item_type; + iface->get_n_items = pango_font_map_get_n_items; + iface->get_item = pango_font_map_get_item; +} |