summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/pango-sections.txt1
-rw-r--r--pango/fonts.c50
-rw-r--r--pango/pango-font.h9
-rw-r--r--pango/pangofc-fontmap.c51
4 files changed, 98 insertions, 13 deletions
diff --git a/docs/pango-sections.txt b/docs/pango-sections.txt
index 3abcf7c3..cb165610 100644
--- a/docs/pango-sections.txt
+++ b/docs/pango-sections.txt
@@ -264,6 +264,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_font_face_get_face_name
diff --git a/pango/fonts.c b/pango/fonts.c
index 4ffa0378..eaff2378 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.46
+ */
+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.h b/pango/pango-font.h
index 70c24d20..d84847a5 100644
--- a/pango/pango-font.h
+++ b/pango/pango-font.h
@@ -428,11 +428,14 @@ 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);
};
#endif /* PANGO_DISABLE_DEPRECATED */
@@ -451,6 +454,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_46
+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 8b49bdce..aa8012f8 100644
--- a/pango/pangofc-fontmap.c
+++ b/pango/pangofc-fontmap.c
@@ -2583,20 +2583,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)
{
@@ -2705,6 +2695,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;
@@ -2713,6 +2719,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)
{
@@ -2766,6 +2792,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;