[pango/regular-face] fontconfig: Try harder to return a default face
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango/regular-face] fontconfig: Try harder to return a default face
- Date: Thu, 5 Nov 2020 20:57:57 +0000 (UTC)
commit 74f2c5764b393d1219d0743a0c743498f86169ee
Author: Matthias Clasen <mclasen redhat com>
Date: Thu Nov 5 14:23:29 2020 -0500
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".
pango/pangofc-fontmap.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
---
diff --git a/pango/pangofc-fontmap.c b/pango/pangofc-fontmap.c
index 0f211c46..2caa9759 100644
--- a/pango/pangofc-fontmap.c
+++ b/pango/pangofc-fontmap.c
@@ -182,6 +182,7 @@ struct _PangoFcFace
FcPattern *pattern;
guint fake : 1;
+ guint is_default: 1;
};
struct _PangoFcFamily
@@ -2792,7 +2793,8 @@ static PangoFcFace *
create_face (PangoFcFamily *fcfamily,
const char *style,
FcPattern *pattern,
- gboolean fake)
+ gboolean fake,
+ gboolean is_default)
{
PangoFcFace *face = g_object_new (PANGO_FC_TYPE_FACE, NULL);
face->style = g_strdup (style);
@@ -2801,6 +2803,7 @@ create_face (PangoFcFamily *fcfamily,
face->pattern = pattern;
face->family = fcfamily;
face->fake = fake;
+ face->is_default = is_default;
return face;
}
@@ -2983,7 +2986,7 @@ pango_fc_family_get_face (PangoFontFamily *family,
ensure_faces (fcfamily);
if (name == NULL)
- name = "Regular"; /* This name always exists in fontconfig */
+ name = "Regular";
for (i = 0; i < fcfamily->n_faces; i++)
{
@@ -2993,6 +2996,9 @@ pango_fc_family_get_face (PangoFontFamily *family,
return face;
}
+ if (fcfamily->n_faces > 0)
+ return PANGO_FONT_FACE (fcfamily->faces[0]);
+
return NULL;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]