From 618adbaf7bbad8441efb589417d7144476f828c7 Mon Sep 17 00:00:00 2001 From: Patrick Lam Date: Sun, 5 Mar 2006 06:05:50 +0000 Subject: [PATCH] Ok, so some people (wine!) use FcPatternGet to fetch FC_FILE. Make that work. Reported by Bernhard Rosenkraenzer. --- ChangeLog | 6 +++++ src/fcpat.c | 73 +++++++++++++++++++++++++++++++++---------------------------- 2 files changed, 46 insertions(+), 33 deletions(-) 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; -- 2.7.4