summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2019-12-06 16:58:41 +0000
committerMatthias Clasen <mclasen@redhat.com>2019-12-06 16:58:41 +0000
commit5ab34cc4103de109ef4e4e54c435c5e4e41cfe96 (patch)
treede25138a2a38048e963122e2e7ef3fd2c383a250
parent53c2c907300f7a1b26a478ce0ed52cbfa76f6133 (diff)
parentca25302c53ae0c54c51d79bee5986b7a0bbb25d1 (diff)
downloadpango-5ab34cc4103de109ef4e4e54c435c5e4e41cfe96.tar.gz
Merge branch 'font-list' into 'master'
List models for pango See merge request GNOME/pango!163
-rw-r--r--meson.build4
-rw-r--r--pango/fonts.c51
-rw-r--r--pango/pango-fontmap.c78
-rw-r--r--pango/pangofc-fontmap.c110
4 files changed, 235 insertions, 8 deletions
diff --git a/meson.build b/meson.build
index 9c5f30ba..55f62974 100644
--- a/meson.build
+++ b/meson.build
@@ -205,7 +205,9 @@ glib_dep = dependency('glib-2.0', version: glib_req_version,
fallback: ['glib', 'libglib_dep'])
gobject_dep = dependency('gobject-2.0', version: glib_req_version,
fallback: ['glib', 'libgobject_dep'])
-pango_deps += [glib_dep, gobject_dep]
+gio_dep = dependency('gio-2.0', version: glib_req_version,
+ fallback: ['glib', 'libgio_dep'])
+pango_deps += [glib_dep, gobject_dep, gio_dep]
fribidi_dep = dependency('fribidi', version: fribidi_req_version,
fallback: ['fribidi', 'libfribidi_dep'],
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);
diff --git a/pango/pango-fontmap.c b/pango/pango-fontmap.c
index 54ac5d0d..8f4d7bc7 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,13 +37,24 @@ 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_real_changed (PangoFontMap *fontmap);
+
+static void pango_font_map_list_model_init (GListModelInterface *iface);
+
+typedef struct {
+ guint n_families;
+} PangoFontMapPrivate;
+
+G_DEFINE_ABSTRACT_TYPE_WITH_CODE (PangoFontMap, pango_font_map, G_TYPE_OBJECT,
+ G_ADD_PRIVATE (PangoFontMap)
+ G_IMPLEMENT_INTERFACE (G_TYPE_LIST_MODEL, pango_font_map_list_model_init))
static void
pango_font_map_class_init (PangoFontMapClass *class)
{
class->load_fontset = pango_font_map_real_load_fontset;
class->get_family = pango_font_map_real_get_family;
+ class->changed = pango_font_map_real_changed;
}
static void
@@ -114,9 +128,13 @@ pango_font_map_list_families (PangoFontMap *fontmap,
PangoFontFamily ***families,
int *n_families)
{
+ PangoFontMapPrivate *priv = pango_font_map_get_instance_private (fontmap);
g_return_if_fail (fontmap != NULL);
PANGO_FONT_MAP_GET_CLASS (fontmap)->list_families (fontmap, families, n_families);
+
+ /* keep this value for GListModel::changed */
+ priv->n_families = *n_families;
}
/**
@@ -321,6 +339,18 @@ pango_font_map_get_serial (PangoFontMap *fontmap)
return 1;
}
+static void
+pango_font_map_real_changed (PangoFontMap *fontmap)
+{
+ PangoFontMapPrivate *priv = pango_font_map_get_instance_private (fontmap);
+ guint removed, added;
+
+ removed = priv->n_families;
+ added = g_list_model_get_n_items (G_LIST_MODEL (fontmap));
+
+ g_list_model_items_changed (G_LIST_MODEL (fontmap), 0, removed, added);
+}
+
/**
* pango_font_map_changed:
* @fontmap: a #PangoFontMap
@@ -390,3 +420,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;
+ int 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;
+}
diff --git a/pango/pangofc-fontmap.c b/pango/pangofc-fontmap.c
index 03d508dd..49040b24 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"
@@ -231,6 +233,8 @@ static PangoFont *pango_fc_font_map_new_font (PangoFcFontMap *fontmap,
static PangoFontFace *pango_fc_font_map_get_face (PangoFontMap *fontmap,
PangoFont *font);
+static void pango_fc_font_map_changed (PangoFontMap *fontmap);
+
static guint pango_fc_font_face_data_hash (PangoFcFontFaceData *key);
static gboolean pango_fc_font_face_data_equal (PangoFcFontFaceData *key1,
PangoFcFontFaceData *key2);
@@ -1119,8 +1123,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)
@@ -1198,6 +1243,7 @@ pango_fc_font_map_class_init (PangoFcFontMapClass *class)
fontmap_class->get_family = pango_fc_font_map_get_family;
fontmap_class->get_face = pango_fc_font_map_get_face;
fontmap_class->shape_engine_type = PANGO_RENDER_TYPE_FC;
+ fontmap_class->changed = pango_fc_font_map_changed;
}
@@ -1932,15 +1978,31 @@ pango_fc_font_map_load_fontset (PangoFontMap *fontmap,
void
pango_fc_font_map_cache_clear (PangoFcFontMap *fcfontmap)
{
+ guint removed, added;
+
if (G_UNLIKELY (fcfontmap->priv->closed))
return;
+ removed = fcfontmap->priv->n_families;
+
pango_fc_font_map_fini (fcfontmap);
pango_fc_font_map_init (fcfontmap);
+
+ ensure_families (fcfontmap);
+
+ added = fcfontmap->priv->n_families;
+
+ g_list_model_items_changed (G_LIST_MODEL (fcfontmap), 0, removed, added);
pango_font_map_changed (PANGO_FONT_MAP (fcfontmap));
}
+static void
+pango_fc_font_map_changed (PangoFontMap *fontmap)
+{
+ /* we emit GListModel::changed in pango_fc_font_map_cache_clear() */
+}
+
/**
* pango_fc_font_map_config_changed:
* @fcfontmap: a #PangoFcFontMap
@@ -2596,7 +2658,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 +2840,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;