[pango/family-face-api: 3/5] Add pango_font_family_get_face
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango/family-face-api: 3/5] Add pango_font_family_get_face
- Date: Wed, 14 Aug 2019 03:44:18 +0000 (UTC)
commit 6c79e73a3d47afae811326370c63b5f6613d40ed
Author: Matthias Clasen <mclasen redhat com>
Date: Tue Aug 13 22:36:01 2019 -0400
Add pango_font_family_get_face
This lets us get a face by name.
docs/pango-sections.txt | 1 +
pango/fonts.c | 50 +++++++++++++++++++++++++++++++++++++++++++++
pango/pango-font-private.h | 3 ++-
pango/pango-font.h | 4 ++++
pango/pangofc-fontmap.c | 51 +++++++++++++++++++++++++++++++++++-----------
5 files changed, 96 insertions(+), 13 deletions(-)
---
diff --git a/docs/pango-sections.txt b/docs/pango-sections.txt
index ecbdcbe9..f2bb1af7 100644
--- a/docs/pango-sections.txt
+++ b/docs/pango-sections.txt
@@ -277,6 +277,7 @@ pango_font_family_get_name
pango_font_family_is_monospace
pango_font_family_is_variable
pango_font_family_list_faces
+pango_font_family_get_face
<SUBSECTION>
PangoFontFace
PANGO_TYPE_FONT_FACE
diff --git a/pango/fonts.c b/pango/fonts.c
index 4ffa0378..99ff1b80 100644
--- a/pango/fonts.c
+++ b/pango/fonts.c
@@ -2160,9 +2160,13 @@ pango_font_metrics_get_strikethrough_thickness (PangoFontMetrics *metrics)
G_DEFINE_ABSTRACT_TYPE (PangoFontFamily, pango_font_family, G_TYPE_OBJECT)
+static PangoFontFace *pango_font_family_real_get_face (PangoFontFamily *family,
+ const char *name);
+
static void
pango_font_family_class_init (PangoFontFamilyClass *class G_GNUC_UNUSED)
{
+ class->get_face = pango_font_family_real_get_face;
}
static void
@@ -2212,6 +2216,52 @@ pango_font_family_list_faces (PangoFontFamily *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;
+ for (i = 0; i < n_faces; i++)
+ {
+ if (strcmp (name, pango_font_face_get_face_name (faces[i])) == 0)
+ {
+ face = faces[i];
+ break;
+ }
+ }
+
+ g_free (faces);
+
+ return face;
+}
+
+/**
+ * pango_font_family_get_face:
+ * @family: a #PangoFontFamily
+ * @name: the name of a face
+ *
+ * Gets the #PangoFontFace of @family with the given name.
+ *
+ * Returns: (transfer none): the #PangoFontFace
+ *
+ * Since: 1.44
+ */
+PangoFontFace *
+pango_font_family_get_face (PangoFontFamily *family,
+ const char *name)
+{
+ g_return_val_if_fail (PANGO_IS_FONT_FAMILY (family), NULL);
+
+ return PANGO_FONT_FAMILY_GET_CLASS (family)->get_face (family, name);
+}
+
/**
* pango_font_family_is_monospace:
* @family: a #PangoFontFamily
diff --git a/pango/pango-font-private.h b/pango/pango-font-private.h
index d43440b4..ed569873 100644
--- a/pango/pango-font-private.h
+++ b/pango/pango-font-private.h
@@ -82,11 +82,12 @@ struct _PangoFontFamilyClass
gboolean (*is_monospace) (PangoFontFamily *family);
gboolean (*is_variable) (PangoFontFamily *family);
+ PangoFontFace * (*get_face) (PangoFontFamily *family,
+ const char *name);
/*< private >*/
/* Padding for future expansion */
void (*_pango_reserved2) (void);
- void (*_pango_reserved3) (void);
};
diff --git a/pango/pango-font.h b/pango/pango-font.h
index 18d16b37..a8490f56 100644
--- a/pango/pango-font.h
+++ b/pango/pango-font.h
@@ -394,6 +394,10 @@ gboolean pango_font_family_is_monospace (PangoFontFamily *family) G_G
PANGO_AVAILABLE_IN_1_44
gboolean pango_font_family_is_variable (PangoFontFamily *family) G_GNUC_PURE;
+PANGO_AVAILABLE_IN_1_44
+PangoFontFace *pango_font_family_get_face (PangoFontFamily *family,
+ const char *name);
+
/*
* PangoFontFace
diff --git a/pango/pangofc-fontmap.c b/pango/pangofc-fontmap.c
index e3b88e66..11350041 100644
--- a/pango/pangofc-fontmap.c
+++ b/pango/pangofc-fontmap.c
@@ -2585,20 +2585,10 @@ create_face (PangoFcFamily *fcfamily,
}
static void
-pango_fc_family_list_faces (PangoFontFamily *family,
- PangoFontFace ***faces,
- int *n_faces)
+ensure_faces (PangoFcFamily *fcfamily)
{
- PangoFcFamily *fcfamily = PANGO_FC_FAMILY (family);
PangoFcFontMap *fcfontmap = fcfamily->fontmap;
- PangoFcFontMapPrivate *priv;
-
- *faces = NULL;
- *n_faces = 0;
- if (G_UNLIKELY (!fcfontmap))
- return;
-
- priv = fcfontmap->priv;
+ PangoFcFontMapPrivate *priv = fcfontmap->priv;
if (fcfamily->n_faces < 0)
{
@@ -2707,6 +2697,22 @@ pango_fc_family_list_faces (PangoFontFamily *family,
fcfamily->faces = faces;
}
}
+}
+
+static void
+pango_fc_family_list_faces (PangoFontFamily *family,
+ PangoFontFace ***faces,
+ int *n_faces)
+{
+ PangoFcFamily *fcfamily = PANGO_FC_FAMILY (family);
+
+ *faces = NULL;
+ *n_faces = 0;
+
+ if (G_UNLIKELY (!fcfamily->fontmap))
+ return;
+
+ ensure_faces (fcfamily);
if (n_faces)
*n_faces = fcfamily->n_faces;
@@ -2715,6 +2721,26 @@ pango_fc_family_list_faces (PangoFontFamily *family,
*faces = g_memdup (fcfamily->faces, fcfamily->n_faces * sizeof (PangoFontFace *));
}
+static PangoFontFace *
+pango_fc_family_get_face (PangoFontFamily *family,
+ const char *name)
+{
+ PangoFcFamily *fcfamily = PANGO_FC_FAMILY (family);
+ int i;
+
+ ensure_faces (fcfamily);
+
+ for (i = 0; i < fcfamily->n_faces; i++)
+ {
+ PangoFontFace *face = PANGO_FONT_FACE (fcfamily->faces[i]);
+
+ if (strcmp (name, pango_font_face_get_face_name (face)) == 0)
+ return face;
+ }
+
+ return NULL;
+}
+
static const char *
pango_fc_family_get_name (PangoFontFamily *family)
{
@@ -2768,6 +2794,7 @@ 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;
class->is_variable = pango_fc_family_is_variable;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]