From d0f07b8d582499fdc6fa0ca6c5e2ef3727baddae Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 8 Jun 2002 17:32:05 +0000 Subject: [PATCH] Add FcPatternHash, clean up a few valgrind issues --- fontconfig/fontconfig.h | 3 ++ src/fccfg.c | 2 +- src/fcmatch.c | 11 +++--- src/fcpat.c | 78 +++++++++++++++++++++++++++++++++++++++++ src/fcxml.c | 13 ++++++- 5 files changed, 101 insertions(+), 6 deletions(-) diff --git a/fontconfig/fontconfig.h b/fontconfig/fontconfig.h index 3d00ec0..d7e1023 100644 --- a/fontconfig/fontconfig.h +++ b/fontconfig/fontconfig.h @@ -603,6 +603,9 @@ FcPatternEqual (const FcPattern *pa, const FcPattern *pb); FcBool FcPatternEqualSubset (const FcPattern *pa, const FcPattern *pb, const FcObjectSet *os); +FcChar32 +FcPatternHash (const FcPattern *p); + FcBool FcPatternAdd (FcPattern *p, const char *object, FcValue value, FcBool append); diff --git a/src/fccfg.c b/src/fccfg.c index 0cee6de..baa1cbc 100644 --- a/src/fccfg.c +++ b/src/fccfg.c @@ -901,8 +901,8 @@ FcConfigMatchValueList (FcPattern *p, } } } + FcValueDestroy (value); } - FcValueDestroy (value); return ret; } diff --git a/src/fcmatch.c b/src/fcmatch.c index c616c63..a95e5f6 100644 --- a/src/fcmatch.c +++ b/src/fcmatch.c @@ -250,7 +250,8 @@ FcCompareValueList (const char *object, FcValueListPrint (v2orig); printf ("\n"); } - value[i] += best; + if (value) + value[i] += best; return FcTrue; } @@ -317,7 +318,6 @@ FcFontRenderPrepare (FcConfig *config, int i; FcPatternElt *fe, *pe; FcValue v; - double score[NUM_MATCHER]; FcResult result; new = FcPatternCreate (); @@ -330,7 +330,7 @@ FcFontRenderPrepare (FcConfig *config, if (pe) { if (!FcCompareValueList (pe->object, pe->values, - fe->values, &v, score, &result)) + fe->values, &v, 0, &result)) { FcPatternDestroy (new); return 0; @@ -598,7 +598,10 @@ FcFontSetSort (FcConfig *config, if (!FcSortWalk (nodeps, nnodes, ret, &cs, trim)) goto bail2; - *csp = cs; + if (csp) + *csp = cs; + else + FcCharSetDestroy (cs); free (nodes); diff --git a/src/fcpat.c b/src/fcpat.c index 68ded72..e212fa0 100644 --- a/src/fcpat.c +++ b/src/fcpat.c @@ -148,6 +148,56 @@ FcValueEqual (FcValue va, FcValue vb) return FcFalse; } +static FcChar32 +FcDoubleHash (double d) +{ + if (d < 0) + d = -d; + if (d > 0xffffffff) + d = 0xffffffff; + return (FcChar32) d; +} + +static FcChar32 +FcStringHash (const FcChar8 *s) +{ + FcChar8 c; + FcChar32 h = 0; + + if (s) + while ((c = *s++)) + h = ((h << 1) | (h >> 31)) ^ c; + return h; +} + +static FcChar32 +FcValueHash (FcValue v) +{ + switch (v.type) { + case FcTypeVoid: + return 0; + case FcTypeInteger: + return (FcChar32) v.u.i; + case FcTypeDouble: + return FcDoubleHash (v.u.d); + case FcTypeString: + return FcStringHash (v.u.s); + case FcTypeBool: + return (FcChar32) v.u.b; + case FcTypeMatrix: + return (FcDoubleHash (v.u.m->xx) ^ + FcDoubleHash (v.u.m->xy) ^ + FcDoubleHash (v.u.m->yx) ^ + FcDoubleHash (v.u.m->yy)); + case FcTypeCharSet: + return (FcChar32) v.u.c->num; + case FcTypeFTFace: + return FcStringHash ((const FcChar8 *) ((FT_Face) v.u.f)->family_name) ^ + FcStringHash ((const FcChar8 *) ((FT_Face) v.u.f)->style_name); + } + return FcFalse; +} + static FcBool FcValueListEqual (FcValueList *la, FcValueList *lb) { @@ -163,6 +213,19 @@ FcValueListEqual (FcValueList *la, FcValueList *lb) return FcTrue; } +static FcChar32 +FcValueListHash (FcValueList *l) +{ + FcChar32 hash = 0; + + while (l) + { + hash = ((hash << 1) | (hash >> 31)) ^ FcValueHash (l->value); + l = l->next; + } + return hash; +} + void FcPatternDestroy (FcPattern *p) { @@ -283,6 +346,21 @@ FcPatternEqual (const FcPattern *pa, const FcPattern *pb) return FcTrue; } +FcChar32 +FcPatternHash (const FcPattern *p) +{ + int i; + FcChar32 h = 0; + + for (i = 0; i < p->num; i++) + { + h = (((h << 1) | (h >> 31)) ^ + FcStringHash ((const FcChar8 *) p->elts[i].object) ^ + FcValueListHash (p->elts[i].values)); + } + return h; +} + FcBool FcPatternEqualSubset (const FcPattern *pa, const FcPattern *pb, const FcObjectSet *os) { diff --git a/src/fcxml.c b/src/fcxml.c index 09aa79e..ef116d0 100644 --- a/src/fcxml.c +++ b/src/fcxml.c @@ -25,7 +25,18 @@ #include #include "fcint.h" +#ifndef HAVE_EXPAT +#define HAVE_EXPAT 1 +#endif + +#ifndef HAVE_XML2 +#define HAVE_XML2 0 +#endif + #if HAVE_EXPAT +#ifndef HAVE_XMLPARSE_H +#define HAVE_XMLPARSE_H 0 +#endif #if HAVE_XMLPARSE_H #include #else @@ -1135,7 +1146,7 @@ FcParseAlias (FcConfigParse *parse) if (edit) { test = FcTestCreate (FcQualAny, - FcStrCopy ((FcChar8 *) "family"), + FC_FAMILY, FcOpEqual, family); if (test) -- 2.39.2