diff options
-rw-r--r-- | pango/pangofc-fontmap.c | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/pango/pangofc-fontmap.c b/pango/pangofc-fontmap.c index 3b7f1915..764336ae 100644 --- a/pango/pangofc-fontmap.c +++ b/pango/pangofc-fontmap.c @@ -182,6 +182,7 @@ struct _PangoFcFace FcPattern *pattern; guint fake : 1; + guint regular : 1; }; struct _PangoFcFamily @@ -2852,6 +2853,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 { @@ -2865,12 +2867,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; @@ -2895,12 +2902,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 { @@ -2938,6 +2956,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); @@ -2979,24 +3000,18 @@ pango_fc_family_get_face (PangoFontFamily *family, { PangoFcFamily *fcfamily = PANGO_FC_FAMILY (family); int i; - const char *style = name; ensure_faces (fcfamily); - if (style == NULL) - style = "Regular"; - for (i = 0; i < fcfamily->n_faces; i++) { PangoFontFace *face = PANGO_FONT_FACE (fcfamily->faces[i]); - if (strcmp (style, 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; } - if (name == NULL && fcfamily->n_faces > 0) - return PANGO_FONT_FACE (fcfamily->faces[0]); - return NULL; } |