diff options
author | Matthias Clasen <mclasen@redhat.com> | 2020-09-21 12:52:42 -0400 |
---|---|---|
committer | Marco Trevisan (TreviƱo) <mail@3v1n0.net> | 2021-05-05 17:22:10 +0200 |
commit | f56697daed7a5d5255fe24a27102bc8c420c46cf (patch) | |
tree | 7ea1d75af96806cadec669a2613db8bba2d3abcd /pango/pangofc-fontmap.c | |
parent | 8e26d43f6713d52b1e5b93c0c38157b4d36d5fb3 (diff) | |
download | pango-f56697daed7a5d5255fe24a27102bc8c420c46cf.tar.gz |
fc: Sort faces of a family
Make pango_font_family_list_faces() return faces
sorted by slant and weight. This makes the font
chooser look much less random.
(cherry-picked from commit 99f4661a)
Diffstat (limited to 'pango/pangofc-fontmap.c')
-rw-r--r-- | pango/pangofc-fontmap.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/pango/pangofc-fontmap.c b/pango/pangofc-fontmap.c index cbe9f07e..e85cf54c 100644 --- a/pango/pangofc-fontmap.c +++ b/pango/pangofc-fontmap.c @@ -2572,6 +2572,32 @@ create_face (PangoFcFamily *fcfamily, return face; } +static int +compare_face (const void *p1, const void *p2) +{ + const PangoFcFace *f1 = *(const void **)p1; + const PangoFcFace *f2 = *(const void **)p2; + int w1, w2; + int s1, s2; + + if (FcPatternGetInteger (f1->pattern, FC_WEIGHT, 0, &w1) != FcResultMatch) + w1 = FC_WEIGHT_MEDIUM; + + if (FcPatternGetInteger (f1->pattern, FC_SLANT, 0, &s1) != FcResultMatch) + s1 = FC_SLANT_ROMAN; + + if (FcPatternGetInteger (f2->pattern, FC_WEIGHT, 0, &w2) != FcResultMatch) + w2 = FC_WEIGHT_MEDIUM; + + if (FcPatternGetInteger (f2->pattern, FC_SLANT, 0, &s2) != FcResultMatch) + s2 = FC_SLANT_ROMAN; + + if (s1 != s2) + return s1 - s2; /* roman < italic < oblique */ + + return w1 - w2; /* from light to heavy */ +} + static void pango_fc_family_list_faces (PangoFontFamily *family, PangoFontFace ***faces, @@ -2691,6 +2717,8 @@ pango_fc_family_list_faces (PangoFontFamily *family, faces = g_renew (PangoFcFace *, faces, num); + qsort (faces, num, sizeof (PangoFcFace *), compare_face); + fcfamily->n_faces = num; fcfamily->faces = faces; } |