[pango/regular-face] fontconfig: Try harder to return a default face




commit 4db6068b827e100664c931b4d4aff3a5a2d7f996
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, 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;
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]