Package: pango1.0 / 1.46.2-3

fontconfig_Try-harder-to-return-a-default-face.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
From: Matthias Clasen <mclasen@redhat.com>
Date: Fri, 6 Nov 2020 11:24:47 -0500
Subject: [PATCH] fontconfig: Try harder to find a default face
Bug-Ubuntu: https://launchpad.net/bugs/1900729
Bug-GNOME: https://gitlab.gnome.org/GNOME/pango/-/issues/483
Origin: Concatenated commits from upstream master:
 * https://gitlab.gnome.org/GNOME/pango/-/commit/4db6068b
 * https://gitlab.gnome.org/GNOME/pango/-/commit/3c995c93

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".
---
Fonts are amazing, and not in a good way. My system has
fonts with 0, 1, 2 "Regular" faces. It also has fonts
where the "Regular" face is, in fact, bold.

So, we need to work even harder to return a reasonable
face when asked about the default. We already make
a determination of faces that we consider 'regular'
when we create the faces initially. Just keep that
information for later reuse.
---
 pango/pangofc-fontmap.c | 27 +++++++++++++++++++++++----
 1 file changed, 23 insertions(+), 4 deletions(-)

diff --git a/pango/pangofc-fontmap.c b/pango/pangofc-fontmap.c
index 341b2d6..c7dcc86 100644
--- a/pango/pangofc-fontmap.c
+++ b/pango/pangofc-fontmap.c
@@ -181,6 +181,7 @@ struct _PangoFcFace
   FcPattern *pattern;
 
   guint fake : 1;
+  guint regular : 1;
 };
 
 struct _PangoFcFamily
@@ -2773,6 +2774,7 @@ ensure_faces (PangoFcFamily *fcfamily)
 	  fcfamily->faces[i++] = create_face (fcfamily, "Bold", NULL, TRUE);
 	  fcfamily->faces[i++] = create_face (fcfamily, "Italic", NULL, TRUE);
 	  fcfamily->faces[i++] = create_face (fcfamily, "Bold Italic", NULL, TRUE);
+          fcfamily->faces[0]->regular = 1;
 	}
       else
 	{
@@ -2786,12 +2788,17 @@ ensure_faces (PangoFcFamily *fcfamily)
 	  gboolean has_face [4] = { FALSE, FALSE, FALSE, FALSE };
 	  PangoFcFace **faces;
 	  gint num = 0;
+          int regular_weight;
+          int regular_idx;
 
 	  fontset = fcfamily->patterns;
 
 	  /* at most we have 3 additional artifical faces */
 	  faces = g_new (PangoFcFace *, fontset->nfont + 3);
 
+          regular_weight = 0;
+          regular_idx = -1;
+
 	  for (i = 0; i < fontset->nfont; i++)
 	    {
 	      const char *style, *font_style = NULL;
@@ -2816,12 +2823,23 @@ ensure_faces (PangoFcFamily *fcfamily)
 	      if (FcPatternGetString (fontset->fonts[i], FC_STYLE, 0, (FcChar8 **)(void*)&font_style) != FcResultMatch)
 		font_style = NULL;
 
+              if (font_style && strcmp (font_style, "Regular") == 0)
+                {
+                  regular_weight = FC_WEIGHT_MEDIUM;
+                  regular_idx = num;
+                }
+
 	      if (weight <= FC_WEIGHT_MEDIUM)
 		{
 		  if (slant == FC_SLANT_ROMAN)
 		    {
 		      has_face[REGULAR] = TRUE;
 		      style = "Regular";
+                      if (weight > regular_weight)
+                        {
+                          regular_weight = weight;
+                          regular_idx = num;
+                        }
 		    }
 		  else
 		    {
@@ -2859,6 +2877,9 @@ ensure_faces (PangoFcFamily *fcfamily)
 	  if ((has_face[REGULAR] || has_face[ITALIC] || has_face[BOLD]) && !has_face[BOLD_ITALIC])
 	    faces[num++] = create_face (fcfamily, "Bold Italic", NULL, TRUE);
 
+          if (regular_idx != -1)
+            faces[regular_idx]->regular = 1;
+
 	  faces = g_renew (PangoFcFace *, faces, num);
 
           qsort (faces, num, sizeof (PangoFcFace *), compare_face);
@@ -2903,14 +2924,12 @@ pango_fc_family_get_face (PangoFontFamily *family,
 
   ensure_faces (fcfamily);
 
-  if (name == NULL)
-    name = "Regular"; /* This name always exists in fontconfig */
-
   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 ((name != NULL && strcmp (name, pango_font_face_get_face_name (face)) == 0) ||
+          (name == NULL && PANGO_FC_FACE (face)->regular))
         return face;
     }