summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2020-11-05 14:23:29 -0500
committerMatthias Clasen <mclasen@redhat.com>2020-11-05 16:03:38 -0500
commit4db6068b827e100664c931b4d4aff3a5a2d7f996 (patch)
tree30672449dd2e025b4f3c89253e6cfd4be43f639a
parent48875108896b34233cdb727ccfe8a25cbc16e311 (diff)
downloadpango-4db6068b827e100664c931b4d4aff3a5a2d7f996.tar.gz
fontconfig: Try harder to return a default face
pango_font_family_get_face() is documented as nullable, so we are technically within our rights to return NULL, but that is unexpected when passing NULL to get the default face, and the family has faces. So, try a little harder by returning the first face if we don't find a face with the name "Regular".
-rw-r--r--pango/pangofc-fontmap.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/pango/pangofc-fontmap.c b/pango/pangofc-fontmap.c
index 0f211c46..3b7f1915 100644
--- a/pango/pangofc-fontmap.c
+++ b/pango/pangofc-fontmap.c
@@ -2979,20 +2979,24 @@ pango_fc_family_get_face (PangoFontFamily *family,
{
PangoFcFamily *fcfamily = PANGO_FC_FAMILY (family);
int i;
+ const char *style = name;
ensure_faces (fcfamily);
- if (name == NULL)
- name = "Regular"; /* This name always exists in fontconfig */
+ if (style == NULL)
+ style = "Regular";
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)
+ if (strcmp (style, pango_font_face_get_face_name (face)) == 0)
return face;
}
+ if (name == NULL && fcfamily->n_faces > 0)
+ return PANGO_FONT_FACE (fcfamily->faces[0]);
+
return NULL;
}