diff options
author | Matthias Clasen <mclasen@redhat.com> | 2019-12-04 22:20:21 -0500 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2019-12-04 22:20:21 -0500 |
commit | 0f195bf167ed98ce8e78bb2b269a3ab8e033215f (patch) | |
tree | f60100b4593f8952c0fb9c7d76120f80401ca74d /pango | |
parent | 4d3a0a504fe924a0f293db8b679b1ae124cb7c75 (diff) | |
download | pango-0f195bf167ed98ce8e78bb2b269a3ab8e033215f.tar.gz |
family: Implement GListModel
Make a PangoFontFamily a list model which
contains the faces of the family.
The current implementation is not optimized.
Diffstat (limited to 'pango')
-rw-r--r-- | pango/fonts.c | 51 |
1 files changed, 50 insertions, 1 deletions
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 <math.h> #include <string.h> +#include <gio/gio.h> + #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); |