Add FcPatternHash, clean up a few valgrind issues
This commit is contained in:
parent
8a39040e2a
commit
d0f07b8d58
|
@ -603,6 +603,9 @@ FcPatternEqual (const FcPattern *pa, const FcPattern *pb);
|
||||||
FcBool
|
FcBool
|
||||||
FcPatternEqualSubset (const FcPattern *pa, const FcPattern *pb, const FcObjectSet *os);
|
FcPatternEqualSubset (const FcPattern *pa, const FcPattern *pb, const FcObjectSet *os);
|
||||||
|
|
||||||
|
FcChar32
|
||||||
|
FcPatternHash (const FcPattern *p);
|
||||||
|
|
||||||
FcBool
|
FcBool
|
||||||
FcPatternAdd (FcPattern *p, const char *object, FcValue value, FcBool append);
|
FcPatternAdd (FcPattern *p, const char *object, FcValue value, FcBool append);
|
||||||
|
|
||||||
|
|
|
@ -901,8 +901,8 @@ FcConfigMatchValueList (FcPattern *p,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
FcValueDestroy (value);
|
||||||
}
|
}
|
||||||
FcValueDestroy (value);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -250,7 +250,8 @@ FcCompareValueList (const char *object,
|
||||||
FcValueListPrint (v2orig);
|
FcValueListPrint (v2orig);
|
||||||
printf ("\n");
|
printf ("\n");
|
||||||
}
|
}
|
||||||
value[i] += best;
|
if (value)
|
||||||
|
value[i] += best;
|
||||||
return FcTrue;
|
return FcTrue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -317,7 +318,6 @@ FcFontRenderPrepare (FcConfig *config,
|
||||||
int i;
|
int i;
|
||||||
FcPatternElt *fe, *pe;
|
FcPatternElt *fe, *pe;
|
||||||
FcValue v;
|
FcValue v;
|
||||||
double score[NUM_MATCHER];
|
|
||||||
FcResult result;
|
FcResult result;
|
||||||
|
|
||||||
new = FcPatternCreate ();
|
new = FcPatternCreate ();
|
||||||
|
@ -330,7 +330,7 @@ FcFontRenderPrepare (FcConfig *config,
|
||||||
if (pe)
|
if (pe)
|
||||||
{
|
{
|
||||||
if (!FcCompareValueList (pe->object, pe->values,
|
if (!FcCompareValueList (pe->object, pe->values,
|
||||||
fe->values, &v, score, &result))
|
fe->values, &v, 0, &result))
|
||||||
{
|
{
|
||||||
FcPatternDestroy (new);
|
FcPatternDestroy (new);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -598,7 +598,10 @@ FcFontSetSort (FcConfig *config,
|
||||||
if (!FcSortWalk (nodeps, nnodes, ret, &cs, trim))
|
if (!FcSortWalk (nodeps, nnodes, ret, &cs, trim))
|
||||||
goto bail2;
|
goto bail2;
|
||||||
|
|
||||||
*csp = cs;
|
if (csp)
|
||||||
|
*csp = cs;
|
||||||
|
else
|
||||||
|
FcCharSetDestroy (cs);
|
||||||
|
|
||||||
free (nodes);
|
free (nodes);
|
||||||
|
|
||||||
|
|
78
src/fcpat.c
78
src/fcpat.c
|
@ -148,6 +148,56 @@ FcValueEqual (FcValue va, FcValue vb)
|
||||||
return FcFalse;
|
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
|
static FcBool
|
||||||
FcValueListEqual (FcValueList *la, FcValueList *lb)
|
FcValueListEqual (FcValueList *la, FcValueList *lb)
|
||||||
{
|
{
|
||||||
|
@ -163,6 +213,19 @@ FcValueListEqual (FcValueList *la, FcValueList *lb)
|
||||||
return FcTrue;
|
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
|
void
|
||||||
FcPatternDestroy (FcPattern *p)
|
FcPatternDestroy (FcPattern *p)
|
||||||
{
|
{
|
||||||
|
@ -283,6 +346,21 @@ FcPatternEqual (const FcPattern *pa, const FcPattern *pb)
|
||||||
return FcTrue;
|
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
|
FcBool
|
||||||
FcPatternEqualSubset (const FcPattern *pa, const FcPattern *pb, const FcObjectSet *os)
|
FcPatternEqualSubset (const FcPattern *pa, const FcPattern *pb, const FcObjectSet *os)
|
||||||
{
|
{
|
||||||
|
|
13
src/fcxml.c
13
src/fcxml.c
|
@ -25,7 +25,18 @@
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include "fcint.h"
|
#include "fcint.h"
|
||||||
|
|
||||||
|
#ifndef HAVE_EXPAT
|
||||||
|
#define HAVE_EXPAT 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HAVE_XML2
|
||||||
|
#define HAVE_XML2 0
|
||||||
|
#endif
|
||||||
|
|
||||||
#if HAVE_EXPAT
|
#if HAVE_EXPAT
|
||||||
|
#ifndef HAVE_XMLPARSE_H
|
||||||
|
#define HAVE_XMLPARSE_H 0
|
||||||
|
#endif
|
||||||
#if HAVE_XMLPARSE_H
|
#if HAVE_XMLPARSE_H
|
||||||
#include <xmlparse.h>
|
#include <xmlparse.h>
|
||||||
#else
|
#else
|
||||||
|
@ -1135,7 +1146,7 @@ FcParseAlias (FcConfigParse *parse)
|
||||||
if (edit)
|
if (edit)
|
||||||
{
|
{
|
||||||
test = FcTestCreate (FcQualAny,
|
test = FcTestCreate (FcQualAny,
|
||||||
FcStrCopy ((FcChar8 *) "family"),
|
FC_FAMILY,
|
||||||
FcOpEqual,
|
FcOpEqual,
|
||||||
family);
|
family);
|
||||||
if (test)
|
if (test)
|
||||||
|
|
Loading…
Reference in New Issue