diff -uNrp pango-1.4.0.org/pango/pangofc-fontmap.c pango-1.4.0/pango/pangofc-fontmap.c --- pango-1.4.0.org/pango/pangofc-fontmap.c 2004-03-16 21:51:46.000000000 +0800 +++ pango-1.4.0/pango/pangofc-fontmap.c 2004-05-24 09:48:13.000000000 +0800 @@ -75,6 +75,11 @@ struct _PangoFcFace PangoFcFamily *family; char *style; + /* Add by firefly@firefly.idv.tw + * 這個式樣名稱是模擬的嗎 ? + * This style name is alias? (TRUE:yes, FALSE:no) + */ + int is_alias_style; }; struct _PangoFcFamily @@ -1194,8 +1199,13 @@ pango_fc_face_describe (PangoFontFace *f FcResult res; FcPattern *match_pattern; FcPattern *result_pattern; - - if (is_alias_family (fcfamily->family_name)) + /* + * Add by firefly@firefly.idv.tw + * 如果這個字型名稱或式樣是虛擬的, 就模擬該式樣的斜體、粗體 + * If this family name or style name is alias name. + * Makeup this style's "weight & slant". + */ + if (is_alias_family (fcfamily->family_name) || fcface->is_alias_style) { if (strcmp (fcface->style, "Regular") == 0) return make_alias_description (fcfamily, FALSE, FALSE); @@ -1384,11 +1394,13 @@ pango_fc_face_get_type (void) */ static PangoFcFace * create_face (PangoFcFamily *fcfamily, - const char *style) + const char *style, + int is_alias_style) { PangoFcFace *face = g_object_new (PANGO_FC_TYPE_FACE, NULL); face->style = g_strdup (style); face->family = fcfamily; + face->is_alias_style = is_alias_style; return face; } @@ -1413,24 +1425,67 @@ pango_fc_family_list_faces (PangoFontFam fcfamily->faces = g_new (PangoFcFace *, fcfamily->n_faces); i = 0; - fcfamily->faces[i++] = create_face (fcfamily, "Regular"); - fcfamily->faces[i++] = create_face (fcfamily, "Bold"); - fcfamily->faces[i++] = create_face (fcfamily, "Italic"); - fcfamily->faces[i++] = create_face (fcfamily, "Bold Italic"); + fcfamily->faces[i++] = create_face (fcfamily, "Regular", TRUE); + fcfamily->faces[i++] = create_face (fcfamily, "Bold", TRUE); + fcfamily->faces[i++] = create_face (fcfamily, "Italic", TRUE); + fcfamily->faces[i++] = create_face (fcfamily, "Bold Italic", TRUE); } else { - FcObjectSet *os = FcObjectSetBuild (FC_STYLE, NULL); + FcObjectSet *os = FcObjectSetBuild (FC_STYLE, FC_WEIGHT, FC_SLANT, NULL); FcPattern *pat = FcPatternBuild (NULL, FC_FAMILY, FcTypeString, fcfamily->family_name, NULL); + /*---------------------------------------------------------- + * Add by firefly@firefly.idv.tw + *---------------------------------------------------------*/ + #define ST_REGULAR 0 + #define ST_ITALIC 1 + #define ST_BOLD 2 + #define ST_BOLD_ITALIC 3 + int style_table[] = { FcFalse, FcFalse, FcFalse, FcFalse }; + int nstyle_alias = 0; + /*----------------------------------------------------------*/ fontset = FcFontList (NULL, pat, os); FcPatternDestroy (pat); FcObjectSetDestroy (os); - fcfamily->n_faces = fontset->nfont; + /*---------------------------------------------------------- + * Add by firefly@firefly.idv.tw + * 檢查這個 family 的 styles 是否有四種式樣 + * Check this family's styles. + *---------------------------------------------------------*/ + for (i = 0; i < fontset->nfont; i++) + { + int weight, slant; + + if (FcPatternGetInteger(fontset->fonts[i], FC_WEIGHT, 0, &weight) != FcResultMatch) + weight = 0; + + if (FcPatternGetInteger(fontset->fonts[i], FC_SLANT, 0, &slant) != FcResultMatch) + slant = 0; + + if (weight <= FC_WEIGHT_MEDIUM && slant < FC_SLANT_ITALIC) + style_table[ST_REGULAR] = FcTrue; + else if (weight <= FC_WEIGHT_MEDIUM && slant >= FC_SLANT_ITALIC) + style_table[ST_ITALIC] = FcTrue; + else if (weight > FC_WEIGHT_MEDIUM && slant < FC_SLANT_ITALIC) + style_table[ST_BOLD] = FcTrue; + else if (weight > FC_WEIGHT_MEDIUM && slant >= FC_SLANT_ITALIC) + style_table[ST_BOLD_ITALIC] = FcTrue; + } + /* 計算缺少的 Styles 數目*/ + for (i = 1 ; i < 4 ; i++) + { + if (!style_table[i]) + nstyle_alias++; + } + /*----------------------------------------------------------*/ + + /* 真正的 style 數再加上缺少的 style 數 */ + fcfamily->n_faces = fontset->nfont + nstyle_alias; fcfamily->faces = g_new (PangoFcFace *, fcfamily->n_faces); for (i = 0; i < fontset->nfont; i++) @@ -1442,8 +1497,16 @@ pango_fc_family_list_faces (PangoFontFam if (res != FcResultMatch) s = "Regular"; - fcfamily->faces[i] = create_face (fcfamily, s); + fcfamily->faces[i] = create_face (fcfamily, s, FALSE); } + /* 加入缺少的 style */ + int k = fontset->nfont; + if (!style_table[ST_BOLD]) + fcfamily->faces[k++] = create_face (fcfamily, "Bold", TRUE); + if (!style_table[ST_ITALIC]) + fcfamily->faces[k++] = create_face (fcfamily, "Italic", TRUE); + if (!style_table[ST_BOLD_ITALIC]) + fcfamily->faces[k++] = create_face (fcfamily, "Bold Italic", TRUE); FcFontSetDestroy (fontset); }