Hi, I'd like to be able to use full font names in match pattern. The first attached patch implements this. It is to be applied on top of Isaiah Beerbower's patch (the one with postscript names). There is a problem with it that also happens when matching fonts by postscript names. Not every font have a full name or a postscript name. Such fonts get a score of 0 (the best possible), while fonts that have a non-matching name get a score of 100. This results in fonts being selected based on other parameters (because both fonts with matching name and without a name get 0 for full name test). To fix this, the second patch gives the worst possible score to those match values that were not updated. Alternatively, the third patch makes sure that every font has a full name, making it up from it's family and style if needed. Either one of them is enough to make this feature work.
src/fcmatch.c | 14 +++++++++++++- 1 files changed, 13 insertions(+), 1 deletions(-) diff --git a/src/fcmatch.c b/src/fcmatch.c index a7c2878..98403b2 100644 --- a/src/fcmatch.c +++ b/src/fcmatch.c @@ -388,9 +388,12 @@ FcCompare (FcPattern *pat, FcResult *result) { int i, i1, i2; + int cnt[NUM_MATCH_VALUES]; - for (i = 0; i < NUM_MATCH_VALUES; i++) + for (i = 0; i < NUM_MATCH_VALUES; i++) { value[i] = 0.0; + cnt[i] = 0; + } i1 = 0; i2 = 0; @@ -411,10 +414,19 @@ FcCompare (FcPattern *pat, FcPatternEltValues(elt_i2), 0, value, result)) return FcFalse; + FcMatcher *match = FcObjectToMatcher(elt_i1->object); + if (match) { + ++ cnt[match->strong]; + if (match->strong != match->weak) + ++ cnt[match->weak]; + } i1++; i2++; } } + for (i = 0; i < NUM_MATCH_VALUES; i++) + if (cnt[i] == 0) + value[i] = 1e99; return FcTrue; }
src/fcmatch.c | 97 +++++++++++++++++++++++++++++++-------------------------- 1 files changed, 52 insertions(+), 45 deletions(-) diff --git a/src/fcmatch.c b/src/fcmatch.c index 98403b2..da8373d 100644 --- a/src/fcmatch.c +++ b/src/fcmatch.c @@ -192,65 +192,70 @@ static FcMatcher _FcMatchers [] = { #define MATCH_POSTSCRIPT_NAME 1 #define MATCH_POSTSCRIPT_NAME_INDEX 1 - { FC_CHARSET_OBJECT, FcCompareCharSet, 2, 2 }, -#define MATCH_CHARSET 2 -#define MATCH_CHARSET_INDEX 2 + { FC_FULLNAME_OBJECT, FcCompareString, 2, 2 }, +#define MATCH_FULLNAME 2 +#define MATCH_FULLNAME_INDEX 2 + + { FC_CHARSET_OBJECT, FcCompareCharSet, 3, 3 }, +#define MATCH_CHARSET 3 +#define MATCH_CHARSET_INDEX 3 + + { FC_FAMILY_OBJECT, FcCompareFamily, 4, 6 }, +#define MATCH_FAMILY 4 +#define MATCH_FAMILY_STRONG_INDEX 4 +#define MATCH_FAMILY_WEAK_INDEX 6 - { FC_FAMILY_OBJECT, FcCompareFamily, 3, 5 }, -#define MATCH_FAMILY 3 -#define MATCH_FAMILY_STRONG_INDEX 3 -#define MATCH_FAMILY_WEAK_INDEX 5 + { FC_LANG_OBJECT, FcCompareLang, 5, 5 }, +#define MATCH_LANG 5 +#define MATCH_LANG_INDEX 5 - { FC_LANG_OBJECT, FcCompareLang, 4, 4 }, -#define MATCH_LANG 4 -#define MATCH_LANG_INDEX 4 + { FC_SPACING_OBJECT, FcCompareNumber, 7, 7 }, +#define MATCH_SPACING 6 +#define MATCH_SPACING_INDEX 7 - { FC_SPACING_OBJECT, FcCompareNumber, 6, 6 }, -#define MATCH_SPACING 5 -#define MATCH_SPACING_INDEX 6 + { FC_PIXEL_SIZE_OBJECT, FcCompareSize, 8, 8 }, +#define MATCH_PIXEL_SIZE 7 +#define MATCH_PIXEL_SIZE_INDEX 8 - { FC_PIXEL_SIZE_OBJECT, FcCompareSize, 7, 7 }, -#define MATCH_PIXEL_SIZE 6 -#define MATCH_PIXEL_SIZE_INDEX 7 + { FC_STYLE_OBJECT, FcCompareString, 9, 9 }, +#define MATCH_STYLE 8 +#define MATCH_STYLE_INDEX 9 - { FC_STYLE_OBJECT, FcCompareString, 8, 8 }, -#define MATCH_STYLE 7 -#define MATCH_STYLE_INDEX 8 + { FC_SLANT_OBJECT, FcCompareNumber, 10, 10 }, +#define MATCH_SLANT 9 +#define MATCH_SLANT_INDEX 10 - { FC_SLANT_OBJECT, FcCompareNumber, 9, 9 }, -#define MATCH_SLANT 8 -#define MATCH_SLANT_INDEX 9 + { FC_WEIGHT_OBJECT, FcCompareNumber, 11, 11 }, +#define MATCH_WEIGHT 10 +#define MATCH_WEIGHT_INDEX 11 - { FC_WEIGHT_OBJECT, FcCompareNumber, 10, 10 }, -#define MATCH_WEIGHT 9 -#define MATCH_WEIGHT_INDEX 10 + { FC_WIDTH_OBJECT, FcCompareNumber, 12, 12 }, +#define MATCH_WIDTH 11 +#define MATCH_WIDTH_INDEX 12 - { FC_WIDTH_OBJECT, FcCompareNumber, 11, 11 }, -#define MATCH_WIDTH 10 -#define MATCH_WIDTH_INDEX 11 - - { FC_DECORATIVE_OBJECT, FcCompareBool, 12, 12 }, -#define MATCH_DECORATIVE 11 -#define MATCH_DECORATIVE_INDEX 12 + { FC_DECORATIVE_OBJECT, FcCompareBool, 13, 13 }, +#define MATCH_DECORATIVE 12 +#define MATCH_DECORATIVE_INDEX 13 - { FC_ANTIALIAS_OBJECT, FcCompareBool, 13, 13 }, -#define MATCH_ANTIALIAS 12 -#define MATCH_ANTIALIAS_INDEX 13 + { FC_ANTIALIAS_OBJECT, FcCompareBool, 14, 14 }, +#define MATCH_ANTIALIAS 13 +#define MATCH_ANTIALIAS_INDEX 14 - { FC_RASTERIZER_OBJECT, FcCompareString, 14, 14 }, -#define MATCH_RASTERIZER 13 -#define MATCH_RASTERIZER_INDEX 14 + { FC_RASTERIZER_OBJECT, FcCompareString, 15, 15 }, +#define MATCH_RASTERIZER 14 +#define MATCH_RASTERIZER_INDEX 15 + + { FC_OUTLINE_OBJECT, FcCompareBool, 16, 16 }, +#define MATCH_OUTLINE 15 +#define MATCH_OUTLINE_INDEX 16 - { FC_OUTLINE_OBJECT, FcCompareBool, 15, 15 }, -#define MATCH_OUTLINE 14 -#define MATCH_OUTLINE_INDEX 15 + { FC_FONTVERSION_OBJECT, FcCompareNumber, 17, 17 }, +#define MATCH_FONTVERSION 16 +#define MATCH_FONTVERSION_INDEX 17 - { FC_FONTVERSION_OBJECT, FcCompareNumber, 16, 16 }, -#define MATCH_FONTVERSION 15 -#define MATCH_FONTVERSION_INDEX 16 }; -#define NUM_MATCH_VALUES 17 +#define NUM_MATCH_VALUES 18 static FcMatcher* FcObjectToMatcher (FcObject object) @@ -263,6 +268,8 @@ FcObjectToMatcher (FcObject object) i = MATCH_FOUNDRY; break; case FC_POSTSCRIPT_NAME_OBJECT: i = MATCH_POSTSCRIPT_NAME; break; + case FC_FULLNAME_OBJECT: + i = MATCH_FULLNAME; break; case FC_FONTVERSION_OBJECT: i = MATCH_FONTVERSION; break; case FC_FAMILY_OBJECT:
src/fcfreetype.c | 18 ++++++++++++++++++ 1 files changed, 18 insertions(+), 0 deletions(-) diff --git a/src/fcfreetype.c b/src/fcfreetype.c index c041249..22e8f1c 100644 --- a/src/fcfreetype.c +++ b/src/fcfreetype.c @@ -1378,6 +1378,24 @@ FcFreeTypeQueryFace (const FT_Face face, goto bail1; } + if (!nfullname) { + char* family; + char* style; + char* s; + if (FcPatternGetString(pat, FC_FAMILY, 0, (FcChar8**)&family) != FcResultMatch) + goto bail1; + if (FcPatternGetString(pat, FC_STYLE, 0, (FcChar8**)&style) != FcResultMatch) + s = strdup(family); + else { + int len = strlen(family) + strlen(style) + 1 /* space */; + s = malloc(len + 1 /* \0 */); + snprintf(s, len + 1, "%s %s", family, style ? style : ""); + } + FcPatternAddString(pat, FC_FULLNAME, (FcChar8*)s); + free(s); + ++nfullname; + } + if (!FcPatternAddString (pat, FC_FILE, file)) goto bail1;
_______________________________________________ Fontconfig mailing list Fontconfig@xxxxxxxxxxxxxxxxxxxxx http://lists.freedesktop.org/mailman/listinfo/fontconfig