From: Patrick Lam Date: Sun, 5 Mar 2006 06:05:50 +0000 (+0000) Subject: Ok, so some people (wine!) use FcPatternGet to fetch FC_FILE. Make that X-Git-Tag: fc-2_3_95~45 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=618adbaf7bbad8441efb589417d7144476f828c7;p=fontconfig.git Ok, so some people (wine!) use FcPatternGet to fetch FC_FILE. Make that work. Reported by Bernhard Rosenkraenzer. --- diff --git a/ChangeLog b/ChangeLog index 0678fe6..ba86c68 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2006-03-05 Patrick Lam + * src/fcpat.c (FcPatternGetString, FcPatternGet): + + Ok, so some people (wine!) use FcPatternGet to fetch FC_FILE. + Make that work. Reported by Bernhard Rosenkraenzer. + 2006-03-03 Patrick Lam * src/fcint.h: diff --git a/src/fcpat.c b/src/fcpat.c index 2fc77bc..980b16e 100644 --- a/src/fcpat.c +++ b/src/fcpat.c @@ -1098,6 +1098,39 @@ FcPatternAddLangSet (FcPattern *p, const char *object, const FcLangSet *ls) return FcPatternAdd (p, object, v, FcTrue); } +static FcResult +FcPatternGetFile (const FcPattern *p, const char *object, int id, FcChar8 ** s) +{ + const char *fn, *fpath; + FcChar8 *fname; + int size; + + fn = FcPatternFindFullFname(p); + if (fn) + { + *s = (FcChar8 *) fn; + return FcResultMatch; + } + + if (!p->bank) + return FcResultMatch; + + fpath = FcCacheFindBankDir (p->bank); + size = strlen((char *)fpath) + 1 + strlen ((char *)*s) + 1; + fname = malloc (size); + if (!fname) + return FcResultOutOfMemory; + + FcMemAlloc (FC_MEM_STRING, size); + strcpy ((char *)fname, (char *)fpath); + strcat ((char *)fname, "/"); + strcat ((char *)fname, (char *)*s); + + FcPatternAddFullFname (p, (const char *)fname); + *s = (FcChar8 *)fname; + return FcResultMatch; +} + FcResult FcPatternGet (const FcPattern *p, const char *object, int id, FcValue *v) { @@ -1112,6 +1145,12 @@ FcPatternGet (const FcPattern *p, const char *object, int id, FcValue *v) if (!id) { *v = FcValueCanonicalize(&FcValueListPtrU(l)->value); + + /* Pull the FC_FILE trick here too. */ + if (v->type == FcTypeString && + FcObjectToPtr(object) == FcObjectToPtr(FC_FILE)) + return FcPatternGetFile (p, object, id, (FcChar8 **)&(v->u.s)); + return FcResultMatch; } id--; @@ -1176,39 +1215,7 @@ FcPatternGetString (const FcPattern *p, const char *object, int id, FcChar8 ** s return FcResultTypeMismatch; if (FcObjectToPtr(object) == FcObjectToPtr(FC_FILE)) - { - const char *fn, *fpath; - FcChar8 *fname; - int size; - - fn = FcPatternFindFullFname(p); - if (fn) - { - *s = (FcChar8 *) fn; - return FcResultMatch; - } - - if (!p->bank) - { - *s = (FcChar8 *) v.u.s; - return FcResultMatch; - } - - fpath = FcCacheFindBankDir (p->bank); - size = strlen((char*)fpath) + 1 + strlen ((char *)v.u.s) + 1; - fname = malloc (size); - if (!fname) - return FcResultOutOfMemory; - - FcMemAlloc (FC_MEM_STRING, size); - strcpy ((char *)fname, (char *)fpath); - strcat ((char *)fname, "/"); - strcat ((char *)fname, (char *)v.u.s); - - FcPatternAddFullFname (p, (const char *)fname); - *s = (FcChar8 *)fname; - return FcResultMatch; - } + return FcPatternGetFile (p, object, id, s); *s = (FcChar8 *) v.u.s; return FcResultMatch;