summaryrefslogtreecommitdiff
path: root/pango/pangofc-fontmap.c
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2019-12-04 23:04:09 -0500
committerMatthias Clasen <mclasen@redhat.com>2019-12-04 23:04:09 -0500
commitc40f0f530671a6682091e91b443a519b041af041 (patch)
tree786e19883759744290216551bdc09aaec73eb635 /pango/pangofc-fontmap.c
parent12b2db7af917ebbadcc74f2248c6986c78e157e9 (diff)
downloadpango-c40f0f530671a6682091e91b443a519b041af041.tar.gz
pangofc: Add list model implementations
Reimplement GListModel in the fontconfig backend. This implementation avoids memory copies.
Diffstat (limited to 'pango/pangofc-fontmap.c')
-rw-r--r--pango/pangofc-fontmap.c91
1 files changed, 86 insertions, 5 deletions
diff --git a/pango/pangofc-fontmap.c b/pango/pangofc-fontmap.c
index 03d508dd..626fd1eb 100644
--- a/pango/pangofc-fontmap.c
+++ b/pango/pangofc-fontmap.c
@@ -45,6 +45,8 @@
#include "config.h"
#include <math.h>
+#include <gio/gio.h>
+
#include "pango-context.h"
#include "pango-font-private.h"
#include "pangofc-fontmap-private.h"
@@ -1119,8 +1121,49 @@ pango_fc_fontset_foreach (PangoFontset *fontset,
* PangoFcFontMap
*/
+static GType
+pango_fc_font_map_get_item_type (GListModel *list)
+{
+ return PANGO_TYPE_FONT_FAMILY;
+}
+
+static void ensure_families (PangoFcFontMap *fcfontmap);
+
+static guint
+pango_fc_font_map_get_n_items (GListModel *list)
+{
+ PangoFcFontMap *fcfontmap = PANGO_FC_FONT_MAP (list);
+
+ ensure_families (fcfontmap);
+
+ return fcfontmap->priv->n_families;
+}
+
+static gpointer
+pango_fc_font_map_get_item (GListModel *list,
+ guint position)
+{
+ PangoFcFontMap *fcfontmap = PANGO_FC_FONT_MAP (list);
+
+ ensure_families (fcfontmap);
+
+ if (position < fcfontmap->priv->n_families)
+ return g_object_ref (fcfontmap->priv->families[position]);
+
+ return NULL;
+}
+
+static void
+pango_fc_font_map_list_model_init (GListModelInterface *iface)
+{
+ iface->get_item_type = pango_fc_font_map_get_item_type;
+ iface->get_n_items = pango_fc_font_map_get_n_items;
+ iface->get_item = pango_fc_font_map_get_item;
+}
+
G_DEFINE_ABSTRACT_TYPE_WITH_CODE (PangoFcFontMap, pango_fc_font_map, PANGO_TYPE_FONT_MAP,
- G_ADD_PRIVATE (PangoFcFontMap))
+ G_ADD_PRIVATE (PangoFcFontMap)
+ G_IMPLEMENT_INTERFACE (G_TYPE_LIST_MODEL, pango_fc_font_map_list_model_init))
static void
pango_fc_font_map_init (PangoFcFontMap *fcfontmap)
@@ -2596,7 +2639,48 @@ pango_fc_face_class_init (PangoFcFaceClass *class)
typedef PangoFontFamilyClass PangoFcFamilyClass;
-G_DEFINE_TYPE (PangoFcFamily, pango_fc_family, PANGO_TYPE_FONT_FAMILY)
+static GType
+pango_fc_family_get_item_type (GListModel *list)
+{
+ return PANGO_TYPE_FONT_FACE;
+}
+
+static void ensure_faces (PangoFcFamily *family);
+
+static guint
+pango_fc_family_get_n_items (GListModel *list)
+{
+ PangoFcFamily *fcfamily = PANGO_FC_FAMILY (list);
+
+ ensure_faces (fcfamily);
+
+ return (guint)fcfamily->n_faces;
+}
+
+static gpointer
+pango_fc_family_get_item (GListModel *list,
+ guint position)
+{
+ PangoFcFamily *fcfamily = PANGO_FC_FAMILY (list);
+
+ ensure_faces (fcfamily);
+
+ if (position < fcfamily->n_faces)
+ return g_object_ref (fcfamily->faces[position]);
+
+ return NULL;
+}
+
+static void
+pango_fc_family_list_model_init (GListModelInterface *iface)
+{
+ iface->get_item_type = pango_fc_family_get_item_type;
+ iface->get_n_items = pango_fc_family_get_n_items;
+ iface->get_item = pango_fc_family_get_item;
+}
+
+G_DEFINE_TYPE_WITH_CODE (PangoFcFamily, pango_fc_family, PANGO_TYPE_FONT_FAMILY,
+ G_IMPLEMENT_INTERFACE (G_TYPE_LIST_MODEL, pango_fc_family_list_model_init))
static PangoFcFace *
create_face (PangoFcFamily *fcfamily,
@@ -2737,9 +2821,6 @@ pango_fc_family_list_faces (PangoFontFamily *family,
{
PangoFcFamily *fcfamily = PANGO_FC_FAMILY (family);
- *faces = NULL;
- *n_faces = 0;
-
if (G_UNLIKELY (!fcfamily->fontmap))
return;