[pango/pango2: 74/195] Drop redundant enumeration api
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango/pango2: 74/195] Drop redundant enumeration api
- Date: Mon, 6 Jun 2022 04:14:40 +0000 (UTC)
commit f6c2982017a1da334273d34b4eec19c6cae255e2
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Feb 12 14:22:13 2022 -0500
Drop redundant enumeration api
We have list models now.
pango/pango-font-family-private.h | 3 --
pango/pango-font-family.c | 94 +++++----------------------------------
pango/pango-font-family.h | 4 --
pango/pango-fontmap.c | 68 ++++------------------------
pango/pango-fontmap.h | 16 +++----
pango/pangofc-fontmap.c | 57 ------------------------
6 files changed, 27 insertions(+), 215 deletions(-)
---
diff --git a/pango/pango-font-family-private.h b/pango/pango-font-family-private.h
index 42ccdb9e..81fc41f4 100644
--- a/pango/pango-font-family-private.h
+++ b/pango/pango-font-family-private.h
@@ -35,9 +35,6 @@ struct _PangoFontFamilyClass
/*< public >*/
- void (*list_faces) (PangoFontFamily *family,
- PangoFontFace ***faces,
- int *n_faces);
const char * (*get_name) (PangoFontFamily *family);
gboolean (*is_monospace) (PangoFontFamily *family);
gboolean (*is_variable) (PangoFontFamily *family);
diff --git a/pango/pango-font-family.c b/pango/pango-font-family.c
index e77efa2d..072cc1af 100644
--- a/pango/pango-font-family.c
+++ b/pango/pango-font-family.c
@@ -34,33 +34,16 @@ pango_font_family_get_item_type (GListModel *list)
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;
+ g_assert_not_reached ();
+ return 0;
}
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;
+ g_assert_not_reached ();
+ return NULL;
}
static void
@@ -89,25 +72,12 @@ pango_font_family_default_is_variable (PangoFontFamily *family)
return FALSE;
}
-static void
-pango_font_family_default_list_faces (PangoFontFamily *family,
- PangoFontFace ***faces,
- int *n_faces)
-{
- if (faces)
- *faces = NULL;
-
- if (n_faces)
- *n_faces = 0;
-}
-
static void
pango_font_family_class_init (PangoFontFamilyClass *class G_GNUC_UNUSED)
{
class->is_monospace = pango_font_family_default_is_monospace;
class->is_variable = pango_font_family_default_is_variable;
class->get_face = pango_font_family_real_get_face;
- class->list_faces = pango_font_family_default_list_faces;
}
static void
@@ -136,66 +106,26 @@ pango_font_family_get_name (PangoFontFamily *family)
return PANGO_FONT_FAMILY_GET_CLASS (family)->get_name (family);
}
-/**
- * pango_font_family_list_faces:
- * @family: a `PangoFontFamily`
- * @faces: (out) (optional) (array length=n_faces) (transfer container):
- * location to store an array of pointers to `PangoFontFace` objects,
- * or %NULL. This array should be freed with g_free() when it is no
- * longer needed.
- * @n_faces: (out): location to store number of elements in @faces.
- *
- * Lists the different font faces that make up @family.
- *
- * The faces in a family share a common design, but differ in slant, weight,
- * width and other aspects.
- *
- * Note that the returned faces are not in any particular order, and
- * multiple faces may have the same name or characteristics.
- *
- * `PangoFontFamily` also implemented the [iface@Gio.ListModel] interface
- * for enumerating faces.
- */
-void
-pango_font_family_list_faces (PangoFontFamily *family,
- PangoFontFace ***faces,
- int *n_faces)
-{
- g_return_if_fail (PANGO_IS_FONT_FAMILY (family));
-
- PANGO_FONT_FAMILY_GET_CLASS (family)->list_faces (family, faces, n_faces);
-}
-
static PangoFontFace *
pango_font_family_real_get_face (PangoFontFamily *family,
const char *name)
{
- PangoFontFace **faces;
- int n_faces;
PangoFontFace *face;
- int i;
-
- pango_font_family_list_faces (family, &faces, &n_faces);
face = NULL;
- if (name == NULL && n_faces > 0)
- {
- face = faces[0];
- }
- else
+
+ for (int i = 0; i < g_list_model_get_n_items (G_LIST_MODEL (family)); i++)
{
- for (i = 0; i < n_faces; i++)
+ PangoFontFace *f = g_list_model_get_item (G_LIST_MODEL (family), i);
+ g_object_unref (f);
+ if (name == NULL ||
+ strcmp (name, pango_font_face_get_face_name (f)) == 0)
{
- if (strcmp (name, pango_font_face_get_face_name (faces[i])) == 0)
- {
- face = faces[i];
- break;
- }
+ face = f;
+ break;
}
}
- g_free (faces);
-
return face;
}
diff --git a/pango/pango-font-family.h b/pango/pango-font-family.h
index 5a605a22..927352eb 100644
--- a/pango/pango-font-family.h
+++ b/pango/pango-font-family.h
@@ -32,10 +32,6 @@ G_BEGIN_DECLS
PANGO_AVAILABLE_IN_ALL
PANGO_DECLARE_INTERNAL_TYPE (PangoFontFamily, pango_font_family, PANGO, FONT_FAMILY, GObject)
-PANGO_AVAILABLE_IN_ALL
-void pango_font_family_list_faces (PangoFontFamily *family,
- PangoFontFace ***faces,
- int *n_faces);
PANGO_AVAILABLE_IN_ALL
const char * pango_font_family_get_name (PangoFontFamily *family) G_GNUC_PURE;
PANGO_AVAILABLE_IN_1_4
diff --git a/pango/pango-fontmap.c b/pango/pango-fontmap.c
index 2cb1b175..fa7cfdc8 100644
--- a/pango/pango-fontmap.c
+++ b/pango/pango-fontmap.c
@@ -115,35 +115,6 @@ pango_font_map_load_font (PangoFontMap *fontmap,
return PANGO_FONT_MAP_GET_CLASS (fontmap)->load_font (fontmap, context, desc);
}
-/**
- * pango_font_map_list_families:
- * @fontmap: a `PangoFontMap`
- * @families: (out) (array length=n_families) (transfer container): location to
- * store a pointer to an array of `PangoFontFamily` *.
- * This array should be freed with g_free().
- * @n_families: (out): location to store the number of elements in @families
- *
- * List all families for a fontmap.
- *
- * Note that the returned families are not in any particular order.
- *
- * `PangoFontMap` also implemented the [iface@Gio.ListModel] interface
- * for enumerating families.
- */
-void
-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;
-}
-
/**
* pango_font_map_load_fontset:
* @fontmap: a `PangoFontMap`
@@ -363,26 +334,22 @@ static PangoFontFamily *
pango_font_map_real_get_family (PangoFontMap *fontmap,
const char *name)
{
- PangoFontFamily **families;
- int n_families;
PangoFontFamily *family;
int i;
- pango_font_map_list_families (fontmap, &families, &n_families);
-
family = NULL;
- for (i = 0; i < n_families; i++)
+ for (i = 0; i < g_list_model_get_n_items (G_LIST_MODEL (fontmap)); i++)
{
- if (strcmp (name, pango_font_family_get_name (families[i])) == 0)
+ PangoFontFamily *fam = g_list_model_get_item (G_LIST_MODEL (fontmap), i);
+ g_object_unref (fam);
+ if (strcmp (name, pango_font_family_get_name (fam)) == 0)
{
- family = families[i];
+ family = fam;
break;
}
}
- g_free (families);
-
return family;
}
@@ -415,33 +382,16 @@ pango_font_map_get_item_type (GListModel *list)
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;
+ g_assert_not_reached ();
+ return 0;
}
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;
+ g_assert_not_reached ();
+ return NULL;
}
static void
diff --git a/pango/pango-fontmap.h b/pango/pango-fontmap.h
index 0c0cb817..d9c0ac25 100644
--- a/pango/pango-fontmap.h
+++ b/pango/pango-fontmap.h
@@ -10,7 +10,7 @@
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
@@ -37,17 +37,13 @@ PANGO_AVAILABLE_IN_1_22
PangoContext * pango_font_map_create_context (PangoFontMap *fontmap);
PANGO_AVAILABLE_IN_ALL
PangoFont * pango_font_map_load_font (PangoFontMap *fontmap,
- PangoContext *context,
- const PangoFontDescription *desc);
+ PangoContext *context,
+ const PangoFontDescription *desc);
PANGO_AVAILABLE_IN_ALL
PangoFontset *pango_font_map_load_fontset (PangoFontMap *fontmap,
- PangoContext *context,
- const PangoFontDescription *desc,
- PangoLanguage *language);
-PANGO_AVAILABLE_IN_ALL
-void pango_font_map_list_families (PangoFontMap *fontmap,
- PangoFontFamily ***families,
- int *n_families);
+ PangoContext *context,
+ const PangoFontDescription *desc,
+ PangoLanguage *language);
PANGO_AVAILABLE_IN_1_32
guint pango_font_map_get_serial (PangoFontMap *fontmap);
PANGO_AVAILABLE_IN_1_34
diff --git a/pango/pangofc-fontmap.c b/pango/pangofc-fontmap.c
index ba1e81f5..8904c362 100644
--- a/pango/pangofc-fontmap.c
+++ b/pango/pangofc-fontmap.c
@@ -234,9 +234,6 @@ static PangoFontset *pango_fc_font_map_load_fontset (PangoFontMap
PangoContext *context,
const PangoFontDescription *desc,
PangoLanguage *language);
-static void pango_fc_font_map_list_families (PangoFontMap *fontmap,
- PangoFontFamily ***families,
- int *n_families);
static PangoFontFamily *pango_fc_font_map_get_family (PangoFontMap *fontmap,
const char *name);
@@ -1494,7 +1491,6 @@ pango_fc_font_map_class_init (PangoFcFontMapClass *class)
object_class->finalize = pango_fc_font_map_finalize;
fontmap_class->load_font = pango_fc_font_map_load_font;
fontmap_class->load_fontset = pango_fc_font_map_load_fontset;
- fontmap_class->list_families = pango_fc_font_map_list_families;
fontmap_class->get_family = pango_fc_font_map_get_family;
fontmap_class->get_face = pango_fc_font_map_get_face;
fontmap_class->changed = pango_fc_font_map_changed;
@@ -1748,33 +1744,6 @@ ensure_families (PangoFcFontMap *fcfontmap)
}
}
-static void
-pango_fc_font_map_list_families (PangoFontMap *fontmap,
- PangoFontFamily ***families,
- int *n_families)
-{
- PangoFcFontMap *fcfontmap = PANGO_FC_FONT_MAP (fontmap);
- PangoFcFontMapPrivate *priv = fcfontmap->priv;
-
- if (priv->closed)
- {
- if (families)
- *families = NULL;
- if (n_families)
- *n_families = 0;
-
- return;
- }
-
- ensure_families (fcfontmap);
-
- if (n_families)
- *n_families = priv->n_families;
-
- if (families)
- *families = g_memdup2 (priv->families, priv->n_families * sizeof (PangoFontFamily *));
-}
-
static PangoFontFamily *
pango_fc_font_map_get_family (PangoFontMap *fontmap,
const char *name)
@@ -3318,31 +3287,6 @@ ensure_faces (PangoFcFamily *fcfamily)
}
}
-static void
-pango_fc_family_list_faces (PangoFontFamily *family,
- PangoFontFace ***faces,
- int *n_faces)
-{
- PangoFcFamily *fcfamily = PANGO_FC_FAMILY (family);
-
- if (faces)
- *faces = NULL;
-
- if (n_faces)
- *n_faces = 0;
-
- if (G_UNLIKELY (!fcfamily->fontmap))
- return;
-
- ensure_faces (fcfamily);
-
- if (n_faces)
- *n_faces = fcfamily->n_faces;
-
- if (faces)
- *faces = g_memdup2 (fcfamily->faces, fcfamily->n_faces * sizeof (PangoFontFace *));
-}
-
static PangoFontFace *
pango_fc_family_get_face (PangoFontFamily *family,
const char *name)
@@ -3416,7 +3360,6 @@ pango_fc_family_class_init (PangoFcFamilyClass *class)
object_class->finalize = pango_fc_family_finalize;
- class->list_faces = pango_fc_family_list_faces;
class->get_face = pango_fc_family_get_face;
class->get_name = pango_fc_family_get_name;
class->is_monospace = pango_fc_family_is_monospace;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]