2002-02-15 00:34:13 +01:00
|
|
|
/*
|
2003-03-05 06:51:27 +01:00
|
|
|
* $RCSId: xc/lib/fontconfig/src/fcpat.c,v 1.18 2002/09/18 17:11:46 tsi Exp $
|
2002-02-15 00:34:13 +01:00
|
|
|
*
|
2004-12-07 02:14:46 +01:00
|
|
|
* Copyright © 2000 Keith Packard
|
2002-02-15 00:34:13 +01:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, distribute, and sell this software and its
|
|
|
|
* documentation for any purpose is hereby granted without fee, provided that
|
|
|
|
* the above copyright notice appear in all copies and that both that
|
|
|
|
* copyright notice and this permission notice appear in supporting
|
|
|
|
* documentation, and that the name of Keith Packard not be used in
|
|
|
|
* advertising or publicity pertaining to distribution of the software without
|
|
|
|
* specific, written prior permission. Keith Packard makes no
|
|
|
|
* representations about the suitability of this software for any purpose. It
|
|
|
|
* is provided "as is" without express or implied warranty.
|
|
|
|
*
|
|
|
|
* KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
|
|
|
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
|
|
|
* EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
|
|
|
|
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
|
|
|
|
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
|
|
|
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
|
|
* PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2006-04-25 07:57:41 +02:00
|
|
|
#include "fcint.h"
|
2002-02-15 00:34:13 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2002-08-22 09:36:45 +02:00
|
|
|
#include <assert.h>
|
2002-02-15 00:34:13 +01:00
|
|
|
|
2005-11-25 17:04:44 +01:00
|
|
|
static FcPattern ** _fcPatterns = 0;
|
2005-08-24 08:21:30 +02:00
|
|
|
static int fcpattern_bank_count = 0, fcpattern_ptr, fcpattern_count;
|
2005-11-25 17:04:44 +01:00
|
|
|
FcPatternElt ** _fcPatternElts = 0;
|
2005-06-28 05:41:02 +02:00
|
|
|
static int fcpatternelt_ptr, fcpatternelt_count;
|
2005-11-25 17:04:44 +01:00
|
|
|
FcValueList ** _fcValueLists = 0;
|
2005-08-24 08:21:30 +02:00
|
|
|
static int fcvaluelist_bank_count = 0, fcvaluelist_ptr, fcvaluelist_count;
|
2005-06-28 05:41:02 +02:00
|
|
|
|
|
|
|
static FcPatternEltPtr
|
|
|
|
FcPatternEltPtrCreateDynamic (FcPatternElt * e);
|
2005-12-05 17:08:01 +01:00
|
|
|
static FcBool
|
|
|
|
FcStrHashed (const FcChar8 *name);
|
2005-06-28 05:41:02 +02:00
|
|
|
|
2002-02-15 00:34:13 +01:00
|
|
|
FcPattern *
|
|
|
|
FcPatternCreate (void)
|
|
|
|
{
|
|
|
|
FcPattern *p;
|
|
|
|
|
|
|
|
p = (FcPattern *) malloc (sizeof (FcPattern));
|
|
|
|
if (!p)
|
|
|
|
return 0;
|
|
|
|
FcMemAlloc (FC_MEM_PATTERN, sizeof (FcPattern));
|
|
|
|
p->num = 0;
|
|
|
|
p->size = 0;
|
2005-06-28 05:41:02 +02:00
|
|
|
p->elts = FcPatternEltPtrCreateDynamic(0);
|
2005-08-24 08:21:30 +02:00
|
|
|
p->bank = FC_BANK_DYNAMIC;
|
2002-06-19 22:08:22 +02:00
|
|
|
p->ref = 1;
|
2002-02-15 00:34:13 +01:00
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FcValueDestroy (FcValue v)
|
|
|
|
{
|
|
|
|
switch (v.type) {
|
|
|
|
case FcTypeString:
|
2005-12-05 17:08:01 +01:00
|
|
|
if (!FcStrHashed (v.u.s))
|
|
|
|
FcStrFree ((FcChar8 *) v.u.s);
|
2002-02-15 00:34:13 +01:00
|
|
|
break;
|
|
|
|
case FcTypeMatrix:
|
2005-08-24 08:21:30 +02:00
|
|
|
FcMatrixFree ((FcMatrix *) v.u.m);
|
2002-02-15 00:34:13 +01:00
|
|
|
break;
|
|
|
|
case FcTypeCharSet:
|
2005-08-24 08:21:30 +02:00
|
|
|
FcCharSetDestroy ((FcCharSet *) v.u.c);
|
2002-02-15 00:34:13 +01:00
|
|
|
break;
|
2002-08-22 09:36:45 +02:00
|
|
|
case FcTypeLangSet:
|
2005-08-24 08:21:30 +02:00
|
|
|
FcLangSetDestroy ((FcLangSet *) v.u.l);
|
2002-08-22 09:36:45 +02:00
|
|
|
break;
|
2002-02-15 00:34:13 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-08-24 08:21:30 +02:00
|
|
|
FcValue
|
|
|
|
FcValueCanonicalize (const FcValue *v)
|
|
|
|
{
|
|
|
|
if (v->type & FC_STORAGE_STATIC)
|
|
|
|
{
|
|
|
|
FcValue new = *v;
|
|
|
|
|
|
|
|
switch (v->type & ~FC_STORAGE_STATIC)
|
|
|
|
{
|
|
|
|
case FcTypeString:
|
|
|
|
new.u.s = fc_value_string(v);
|
|
|
|
new.type = FcTypeString;
|
|
|
|
break;
|
|
|
|
case FcTypeCharSet:
|
|
|
|
new.u.c = fc_value_charset(v);
|
|
|
|
new.type = FcTypeCharSet;
|
|
|
|
break;
|
|
|
|
case FcTypeLangSet:
|
|
|
|
new.u.l = fc_value_langset(v);
|
|
|
|
new.type = FcTypeLangSet;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return new;
|
|
|
|
}
|
|
|
|
return *v;
|
|
|
|
}
|
|
|
|
|
2002-02-15 00:34:13 +01:00
|
|
|
FcValue
|
|
|
|
FcValueSave (FcValue v)
|
|
|
|
{
|
|
|
|
switch (v.type) {
|
|
|
|
case FcTypeString:
|
2005-08-24 08:21:30 +02:00
|
|
|
v.u.s = FcStrCopy (v.u.s);
|
|
|
|
if (!v.u.s)
|
2002-02-15 00:34:13 +01:00
|
|
|
v.type = FcTypeVoid;
|
|
|
|
break;
|
|
|
|
case FcTypeMatrix:
|
2005-08-24 08:21:30 +02:00
|
|
|
v.u.m = FcMatrixCopy (v.u.m);
|
|
|
|
if (!v.u.m)
|
2002-02-15 00:34:13 +01:00
|
|
|
v.type = FcTypeVoid;
|
|
|
|
break;
|
|
|
|
case FcTypeCharSet:
|
2005-08-24 08:21:30 +02:00
|
|
|
v.u.c = FcCharSetCopy ((FcCharSet *) v.u.c);
|
|
|
|
if (!v.u.c)
|
2002-02-15 00:34:13 +01:00
|
|
|
v.type = FcTypeVoid;
|
|
|
|
break;
|
2002-08-22 09:36:45 +02:00
|
|
|
case FcTypeLangSet:
|
2005-08-24 08:21:30 +02:00
|
|
|
v.u.l = FcLangSetCopy (v.u.l);
|
|
|
|
if (!v.u.l)
|
2002-08-22 09:36:45 +02:00
|
|
|
v.type = FcTypeVoid;
|
|
|
|
break;
|
2002-02-15 00:34:13 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2005-06-28 05:41:02 +02:00
|
|
|
FcValueListDestroy (FcValueListPtr l)
|
2002-02-15 00:34:13 +01:00
|
|
|
{
|
2005-06-28 05:41:02 +02:00
|
|
|
FcValueListPtr next;
|
|
|
|
for (; FcValueListPtrU(l); l = next)
|
2002-02-15 00:34:13 +01:00
|
|
|
{
|
2005-06-28 05:41:02 +02:00
|
|
|
switch (FcValueListPtrU(l)->value.type) {
|
2002-02-15 00:34:13 +01:00
|
|
|
case FcTypeString:
|
2005-12-05 17:08:01 +01:00
|
|
|
if (!FcStrHashed ((FcChar8 *)FcValueListPtrU(l)->value.u.s))
|
|
|
|
FcStrFree ((FcChar8 *)FcValueListPtrU(l)->value.u.s);
|
2002-02-15 00:34:13 +01:00
|
|
|
break;
|
|
|
|
case FcTypeMatrix:
|
2005-08-24 08:21:30 +02:00
|
|
|
FcMatrixFree ((FcMatrix *)FcValueListPtrU(l)->value.u.m);
|
2002-02-15 00:34:13 +01:00
|
|
|
break;
|
|
|
|
case FcTypeCharSet:
|
2005-06-28 05:41:02 +02:00
|
|
|
FcCharSetDestroy
|
2005-08-24 08:21:30 +02:00
|
|
|
((FcCharSet *) (FcValueListPtrU(l)->value.u.c));
|
2002-02-15 00:34:13 +01:00
|
|
|
break;
|
2002-08-22 09:36:45 +02:00
|
|
|
case FcTypeLangSet:
|
2005-06-28 05:41:02 +02:00
|
|
|
FcLangSetDestroy
|
2005-08-24 08:21:30 +02:00
|
|
|
((FcLangSet *) (FcValueListPtrU(l)->value.u.l));
|
2002-08-22 09:36:45 +02:00
|
|
|
break;
|
2002-02-15 00:34:13 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2005-06-28 05:41:02 +02:00
|
|
|
next = FcValueListPtrU(l)->next;
|
2002-02-15 00:34:13 +01:00
|
|
|
FcMemFree (FC_MEM_VALLIST, sizeof (FcValueList));
|
2005-08-24 08:21:30 +02:00
|
|
|
if (l.bank == FC_BANK_DYNAMIC)
|
2005-06-28 05:41:02 +02:00
|
|
|
free(l.u.dyn);
|
2002-02-15 00:34:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-05-22 06:37:07 +02:00
|
|
|
FcBool
|
|
|
|
FcValueEqual (FcValue va, FcValue vb)
|
|
|
|
{
|
|
|
|
if (va.type != vb.type)
|
|
|
|
{
|
|
|
|
if (va.type == FcTypeInteger)
|
|
|
|
{
|
|
|
|
va.type = FcTypeDouble;
|
|
|
|
va.u.d = va.u.i;
|
|
|
|
}
|
|
|
|
if (vb.type == FcTypeInteger)
|
|
|
|
{
|
|
|
|
vb.type = FcTypeDouble;
|
|
|
|
vb.u.d = vb.u.i;
|
|
|
|
}
|
|
|
|
if (va.type != vb.type)
|
|
|
|
return FcFalse;
|
|
|
|
}
|
|
|
|
switch (va.type) {
|
|
|
|
case FcTypeVoid:
|
|
|
|
return FcTrue;
|
|
|
|
case FcTypeInteger:
|
|
|
|
return va.u.i == vb.u.i;
|
|
|
|
case FcTypeDouble:
|
|
|
|
return va.u.d == vb.u.d;
|
|
|
|
case FcTypeString:
|
2005-08-24 08:21:30 +02:00
|
|
|
return FcStrCmpIgnoreCase (va.u.s, vb.u.s) == 0;
|
2002-05-22 06:37:07 +02:00
|
|
|
case FcTypeBool:
|
|
|
|
return va.u.b == vb.u.b;
|
|
|
|
case FcTypeMatrix:
|
2005-08-24 08:21:30 +02:00
|
|
|
return FcMatrixEqual (va.u.m, vb.u.m);
|
2002-05-22 06:37:07 +02:00
|
|
|
case FcTypeCharSet:
|
2005-08-24 08:21:30 +02:00
|
|
|
return FcCharSetEqual (va.u.c, vb.u.c);
|
2002-06-01 01:21:25 +02:00
|
|
|
case FcTypeFTFace:
|
|
|
|
return va.u.f == vb.u.f;
|
2002-08-22 09:36:45 +02:00
|
|
|
case FcTypeLangSet:
|
2005-08-24 08:21:30 +02:00
|
|
|
return FcLangSetEqual (va.u.l, vb.u.l);
|
2002-05-22 06:37:07 +02:00
|
|
|
}
|
|
|
|
return FcFalse;
|
|
|
|
}
|
|
|
|
|
2002-06-08 19:32:05 +02:00
|
|
|
static FcChar32
|
|
|
|
FcDoubleHash (double d)
|
|
|
|
{
|
|
|
|
if (d < 0)
|
|
|
|
d = -d;
|
|
|
|
if (d > 0xffffffff)
|
|
|
|
d = 0xffffffff;
|
|
|
|
return (FcChar32) d;
|
|
|
|
}
|
|
|
|
|
2005-08-27 04:34:24 +02:00
|
|
|
FcChar32
|
2002-06-08 19:32:05 +02:00
|
|
|
FcStringHash (const FcChar8 *s)
|
|
|
|
{
|
|
|
|
FcChar8 c;
|
|
|
|
FcChar32 h = 0;
|
|
|
|
|
|
|
|
if (s)
|
|
|
|
while ((c = *s++))
|
|
|
|
h = ((h << 1) | (h >> 31)) ^ c;
|
|
|
|
return h;
|
|
|
|
}
|
|
|
|
|
|
|
|
static FcChar32
|
2006-02-07 22:15:33 +01:00
|
|
|
FcValueHash (const FcValue *v)
|
2002-06-08 19:32:05 +02:00
|
|
|
{
|
2006-02-07 22:15:33 +01:00
|
|
|
switch (fc_storage_type(v)) {
|
2002-06-08 19:32:05 +02:00
|
|
|
case FcTypeVoid:
|
|
|
|
return 0;
|
|
|
|
case FcTypeInteger:
|
2006-02-07 22:15:33 +01:00
|
|
|
return (FcChar32) v->u.i;
|
2002-06-08 19:32:05 +02:00
|
|
|
case FcTypeDouble:
|
2006-02-07 22:15:33 +01:00
|
|
|
return FcDoubleHash (v->u.d);
|
2002-06-08 19:32:05 +02:00
|
|
|
case FcTypeString:
|
2006-02-07 22:15:33 +01:00
|
|
|
return FcStringHash (fc_value_string(v));
|
2002-06-08 19:32:05 +02:00
|
|
|
case FcTypeBool:
|
2006-02-07 22:15:33 +01:00
|
|
|
return (FcChar32) v->u.b;
|
2002-06-08 19:32:05 +02:00
|
|
|
case FcTypeMatrix:
|
2006-02-07 22:15:33 +01:00
|
|
|
return (FcDoubleHash (v->u.m->xx) ^
|
|
|
|
FcDoubleHash (v->u.m->xy) ^
|
|
|
|
FcDoubleHash (v->u.m->yx) ^
|
|
|
|
FcDoubleHash (v->u.m->yy));
|
2002-06-08 19:32:05 +02:00
|
|
|
case FcTypeCharSet:
|
2006-02-07 22:15:33 +01:00
|
|
|
return (FcChar32) fc_value_charset(v)->num;
|
2002-06-08 19:32:05 +02:00
|
|
|
case FcTypeFTFace:
|
2006-02-07 22:15:33 +01:00
|
|
|
return FcStringHash ((const FcChar8 *) ((FT_Face) v->u.f)->family_name) ^
|
|
|
|
FcStringHash ((const FcChar8 *) ((FT_Face) v->u.f)->style_name);
|
2002-08-22 09:36:45 +02:00
|
|
|
case FcTypeLangSet:
|
2006-02-07 22:15:33 +01:00
|
|
|
return FcLangSetHash (fc_value_langset(v));
|
2002-06-08 19:32:05 +02:00
|
|
|
}
|
|
|
|
return FcFalse;
|
|
|
|
}
|
|
|
|
|
2002-05-22 06:37:07 +02:00
|
|
|
static FcBool
|
2005-06-28 05:41:02 +02:00
|
|
|
FcValueListEqual (FcValueListPtr la, FcValueListPtr lb)
|
2002-05-22 06:37:07 +02:00
|
|
|
{
|
2005-06-28 05:41:02 +02:00
|
|
|
if (FcValueListPtrU(la) == FcValueListPtrU(lb))
|
2002-08-22 09:36:45 +02:00
|
|
|
return FcTrue;
|
|
|
|
|
2005-06-28 05:41:02 +02:00
|
|
|
while (FcValueListPtrU(la) && FcValueListPtrU(lb))
|
2002-05-22 06:37:07 +02:00
|
|
|
{
|
2005-06-28 05:41:02 +02:00
|
|
|
if (!FcValueEqual (FcValueListPtrU(la)->value,
|
|
|
|
FcValueListPtrU(lb)->value))
|
2002-05-22 06:37:07 +02:00
|
|
|
return FcFalse;
|
2005-06-28 05:41:02 +02:00
|
|
|
la = FcValueListPtrU(la)->next;
|
|
|
|
lb = FcValueListPtrU(lb)->next;
|
2002-05-22 06:37:07 +02:00
|
|
|
}
|
2005-06-28 05:41:02 +02:00
|
|
|
if (FcValueListPtrU(la) || FcValueListPtrU(lb))
|
2002-05-22 06:37:07 +02:00
|
|
|
return FcFalse;
|
|
|
|
return FcTrue;
|
|
|
|
}
|
|
|
|
|
2002-06-08 19:32:05 +02:00
|
|
|
static FcChar32
|
2005-06-28 05:41:02 +02:00
|
|
|
FcValueListHash (FcValueListPtr l)
|
2002-06-08 19:32:05 +02:00
|
|
|
{
|
|
|
|
FcChar32 hash = 0;
|
2006-02-07 22:15:33 +01:00
|
|
|
FcValueList *l_ptrU;
|
2002-06-08 19:32:05 +02:00
|
|
|
|
2006-02-07 22:15:33 +01:00
|
|
|
for (l_ptrU = FcValueListPtrU(l); l_ptrU;
|
|
|
|
l_ptrU = FcValueListPtrU(l_ptrU->next))
|
2002-06-08 19:32:05 +02:00
|
|
|
{
|
2006-02-07 22:15:33 +01:00
|
|
|
hash = ((hash << 1) | (hash >> 31)) ^ FcValueHash (&l_ptrU->value);
|
2002-06-08 19:32:05 +02:00
|
|
|
}
|
|
|
|
return hash;
|
|
|
|
}
|
|
|
|
|
2002-02-15 00:34:13 +01:00
|
|
|
void
|
|
|
|
FcPatternDestroy (FcPattern *p)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2002-08-22 09:36:45 +02:00
|
|
|
if (p->ref == FC_REF_CONSTANT || --p->ref > 0)
|
2002-06-19 22:08:22 +02:00
|
|
|
return;
|
|
|
|
|
2002-02-15 00:34:13 +01:00
|
|
|
for (i = 0; i < p->num; i++)
|
2005-06-28 05:41:02 +02:00
|
|
|
FcValueListDestroy ((FcPatternEltU(p->elts)+i)->values);
|
2002-02-15 00:34:13 +01:00
|
|
|
|
|
|
|
p->num = 0;
|
2005-08-24 08:21:30 +02:00
|
|
|
if (FcPatternEltU(p->elts) && p->elts.bank == FC_BANK_DYNAMIC)
|
2002-02-15 00:34:13 +01:00
|
|
|
{
|
|
|
|
FcMemFree (FC_MEM_PATELT, p->size * sizeof (FcPatternElt));
|
2005-06-28 05:41:02 +02:00
|
|
|
free (FcPatternEltU(p->elts));
|
|
|
|
p->elts = FcPatternEltPtrCreateDynamic(0);
|
2002-02-15 00:34:13 +01:00
|
|
|
}
|
|
|
|
p->size = 0;
|
|
|
|
FcMemFree (FC_MEM_PATTERN, sizeof (FcPattern));
|
|
|
|
free (p);
|
|
|
|
}
|
|
|
|
|
2002-06-03 10:31:15 +02:00
|
|
|
static int
|
|
|
|
FcPatternPosition (const FcPattern *p, const char *object)
|
2002-02-15 00:34:13 +01:00
|
|
|
{
|
2002-06-03 10:31:15 +02:00
|
|
|
int low, high, mid, c;
|
2005-06-28 05:41:02 +02:00
|
|
|
FcObjectPtr obj;
|
2002-05-22 06:37:07 +02:00
|
|
|
|
2005-08-24 08:21:30 +02:00
|
|
|
obj = FcObjectToPtr(object);
|
2002-05-22 06:37:07 +02:00
|
|
|
low = 0;
|
2002-06-03 10:31:15 +02:00
|
|
|
high = p->num - 1;
|
|
|
|
c = 1;
|
|
|
|
mid = 0;
|
|
|
|
while (low <= high)
|
2002-02-15 00:34:13 +01:00
|
|
|
{
|
2002-06-03 10:31:15 +02:00
|
|
|
mid = (low + high) >> 1;
|
2005-06-28 05:41:02 +02:00
|
|
|
c = FcObjectPtrCompare((FcPatternEltU(p->elts)+mid)->object, obj);
|
2002-06-03 10:31:15 +02:00
|
|
|
if (c == 0)
|
|
|
|
return mid;
|
|
|
|
if (c < 0)
|
|
|
|
low = mid + 1;
|
2002-05-22 06:37:07 +02:00
|
|
|
else
|
2002-06-03 10:31:15 +02:00
|
|
|
high = mid - 1;
|
2002-02-15 00:34:13 +01:00
|
|
|
}
|
2002-06-03 10:31:15 +02:00
|
|
|
if (c < 0)
|
|
|
|
mid++;
|
|
|
|
return -(mid + 1);
|
|
|
|
}
|
2002-02-15 00:34:13 +01:00
|
|
|
|
2002-06-03 10:31:15 +02:00
|
|
|
FcPatternElt *
|
|
|
|
FcPatternFindElt (const FcPattern *p, const char *object)
|
|
|
|
{
|
|
|
|
int i = FcPatternPosition (p, object);
|
|
|
|
if (i < 0)
|
2002-05-22 06:37:07 +02:00
|
|
|
return 0;
|
2005-06-28 05:41:02 +02:00
|
|
|
return FcPatternEltU(p->elts)+i;
|
2002-06-03 10:31:15 +02:00
|
|
|
}
|
2002-02-15 00:34:13 +01:00
|
|
|
|
2002-06-03 10:31:15 +02:00
|
|
|
FcPatternElt *
|
|
|
|
FcPatternInsertElt (FcPattern *p, const char *object)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
FcPatternElt *e;
|
|
|
|
|
|
|
|
i = FcPatternPosition (p, object);
|
|
|
|
if (i < 0)
|
2002-02-15 00:34:13 +01:00
|
|
|
{
|
2002-06-03 10:31:15 +02:00
|
|
|
i = -i - 1;
|
|
|
|
|
2005-06-28 05:41:02 +02:00
|
|
|
/* reallocate array */
|
2002-06-03 10:31:15 +02:00
|
|
|
if (p->num + 1 >= p->size)
|
2002-02-15 00:34:13 +01:00
|
|
|
{
|
2002-06-03 10:31:15 +02:00
|
|
|
int s = p->size + 16;
|
2005-06-28 05:41:02 +02:00
|
|
|
if (FcPatternEltU(p->elts))
|
|
|
|
{
|
|
|
|
FcPatternElt *e0 = FcPatternEltU(p->elts);
|
|
|
|
e = (FcPatternElt *) realloc (e0, s * sizeof (FcPatternElt));
|
|
|
|
if (!e) /* maybe it was mmapped */
|
|
|
|
{
|
|
|
|
e = malloc(s * sizeof (FcPatternElt));
|
|
|
|
if (e)
|
|
|
|
memcpy(e, e0, p->num * sizeof (FcPatternElt));
|
|
|
|
}
|
|
|
|
}
|
2002-06-03 10:31:15 +02:00
|
|
|
else
|
|
|
|
e = (FcPatternElt *) malloc (s * sizeof (FcPatternElt));
|
|
|
|
if (!e)
|
|
|
|
return FcFalse;
|
2005-06-28 05:41:02 +02:00
|
|
|
p->elts = FcPatternEltPtrCreateDynamic(e);
|
2002-06-03 10:31:15 +02:00
|
|
|
if (p->size)
|
|
|
|
FcMemFree (FC_MEM_PATELT, p->size * sizeof (FcPatternElt));
|
|
|
|
FcMemAlloc (FC_MEM_PATELT, s * sizeof (FcPatternElt));
|
|
|
|
while (p->size < s)
|
|
|
|
{
|
2005-07-07 14:09:10 +02:00
|
|
|
(FcPatternEltU(p->elts)+p->size)->object = 0;
|
2005-06-28 05:41:02 +02:00
|
|
|
(FcPatternEltU(p->elts)+p->size)->values =
|
|
|
|
FcValueListPtrCreateDynamic(0);
|
2002-06-03 10:31:15 +02:00
|
|
|
p->size++;
|
|
|
|
}
|
2002-02-15 00:34:13 +01:00
|
|
|
}
|
2002-06-03 10:31:15 +02:00
|
|
|
|
|
|
|
/* move elts up */
|
2005-06-28 05:41:02 +02:00
|
|
|
memmove (FcPatternEltU(p->elts) + i + 1,
|
|
|
|
FcPatternEltU(p->elts) + i,
|
2002-06-03 10:31:15 +02:00
|
|
|
sizeof (FcPatternElt) *
|
|
|
|
(p->num - i));
|
|
|
|
|
|
|
|
/* bump count */
|
|
|
|
p->num++;
|
|
|
|
|
2005-08-24 08:21:30 +02:00
|
|
|
(FcPatternEltU(p->elts)+i)->object = FcObjectToPtr (object);
|
2005-06-28 05:41:02 +02:00
|
|
|
(FcPatternEltU(p->elts)+i)->values = FcValueListPtrCreateDynamic(0);
|
2002-02-15 00:34:13 +01:00
|
|
|
}
|
|
|
|
|
2005-06-28 05:41:02 +02:00
|
|
|
return FcPatternEltU(p->elts)+i;
|
2002-02-15 00:34:13 +01:00
|
|
|
}
|
|
|
|
|
2002-05-22 06:37:07 +02:00
|
|
|
FcBool
|
2002-06-03 10:31:15 +02:00
|
|
|
FcPatternEqual (const FcPattern *pa, const FcPattern *pb)
|
2002-05-22 06:37:07 +02:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2002-08-07 03:45:59 +02:00
|
|
|
if (pa == pb)
|
|
|
|
return FcTrue;
|
|
|
|
|
2002-05-22 06:37:07 +02:00
|
|
|
if (pa->num != pb->num)
|
|
|
|
return FcFalse;
|
|
|
|
for (i = 0; i < pa->num; i++)
|
|
|
|
{
|
2005-06-28 05:41:02 +02:00
|
|
|
if (FcObjectPtrCompare((FcPatternEltU(pa->elts)+i)->object,
|
|
|
|
(FcPatternEltU(pb->elts)+i)->object) != 0)
|
2002-05-22 06:37:07 +02:00
|
|
|
return FcFalse;
|
2005-06-28 05:41:02 +02:00
|
|
|
if (!FcValueListEqual ((FcPatternEltU(pa->elts)+i)->values,
|
|
|
|
(FcPatternEltU(pb->elts)+i)->values))
|
2002-05-22 06:37:07 +02:00
|
|
|
return FcFalse;
|
|
|
|
}
|
|
|
|
return FcTrue;
|
|
|
|
}
|
|
|
|
|
2002-06-08 19:32:05 +02:00
|
|
|
FcChar32
|
|
|
|
FcPatternHash (const FcPattern *p)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
FcChar32 h = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < p->num; i++)
|
|
|
|
{
|
|
|
|
h = (((h << 1) | (h >> 31)) ^
|
2005-09-11 04:16:09 +02:00
|
|
|
FcStringHash ((FcChar8 *)FcObjectPtrU ((FcPatternEltU(p->elts)+i)->object)) ^
|
2005-06-28 05:41:02 +02:00
|
|
|
FcValueListHash ((FcPatternEltU(p->elts)+i)->values));
|
2002-06-08 19:32:05 +02:00
|
|
|
}
|
|
|
|
return h;
|
|
|
|
}
|
|
|
|
|
2002-06-03 10:31:15 +02:00
|
|
|
FcBool
|
2005-06-28 05:41:02 +02:00
|
|
|
FcPatternEqualSubset (const FcPattern *pai, const FcPattern *pbi, const FcObjectSet *os)
|
2002-06-03 10:31:15 +02:00
|
|
|
{
|
|
|
|
FcPatternElt *ea, *eb;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < os->nobject; i++)
|
|
|
|
{
|
2005-08-24 08:21:30 +02:00
|
|
|
ea = FcPatternFindElt (pai, os->objects[i]);
|
|
|
|
eb = FcPatternFindElt (pbi, os->objects[i]);
|
2002-06-03 10:31:15 +02:00
|
|
|
if (ea)
|
|
|
|
{
|
|
|
|
if (!eb)
|
|
|
|
return FcFalse;
|
|
|
|
if (!FcValueListEqual (ea->values, eb->values))
|
|
|
|
return FcFalse;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (eb)
|
|
|
|
return FcFalse;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FcTrue;
|
|
|
|
}
|
|
|
|
|
2002-02-15 00:34:13 +01:00
|
|
|
FcBool
|
2002-07-07 01:47:44 +02:00
|
|
|
FcPatternAddWithBinding (FcPattern *p,
|
|
|
|
const char *object,
|
|
|
|
FcValue value,
|
|
|
|
FcValueBinding binding,
|
|
|
|
FcBool append)
|
2002-02-15 00:34:13 +01:00
|
|
|
{
|
|
|
|
FcPatternElt *e;
|
2005-06-28 05:41:02 +02:00
|
|
|
FcValueListPtr new, *prev;
|
2005-11-24 22:40:20 +01:00
|
|
|
FcValueList *newp;
|
|
|
|
FcObjectPtr objectPtr;
|
2002-02-15 00:34:13 +01:00
|
|
|
|
2002-08-22 09:36:45 +02:00
|
|
|
if (p->ref == FC_REF_CONSTANT)
|
|
|
|
goto bail0;
|
|
|
|
|
2005-06-28 05:41:02 +02:00
|
|
|
newp = malloc (sizeof (FcValueList));
|
|
|
|
if (!newp)
|
2002-02-15 00:34:13 +01:00
|
|
|
goto bail0;
|
|
|
|
|
2005-06-28 05:41:02 +02:00
|
|
|
memset(newp, 0, sizeof (FcValueList));
|
|
|
|
new = FcValueListPtrCreateDynamic(newp);
|
2002-02-15 00:34:13 +01:00
|
|
|
FcMemAlloc (FC_MEM_VALLIST, sizeof (FcValueList));
|
|
|
|
/* dup string */
|
2006-01-25 15:52:49 +01:00
|
|
|
if (value.type == FcTypeString)
|
|
|
|
{
|
|
|
|
value.u.s = FcStrStaticName (value.u.s);
|
|
|
|
if (!value.u.s)
|
|
|
|
value.type = FcTypeVoid;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
value = FcValueSave (value);
|
2002-02-15 00:34:13 +01:00
|
|
|
if (value.type == FcTypeVoid)
|
|
|
|
goto bail1;
|
|
|
|
|
2005-11-24 22:40:20 +01:00
|
|
|
/* quick and dirty hack to enable FcCompareFamily/FcCompareString
|
|
|
|
* speedup: only allow strings to be added under the FC_FAMILY,
|
|
|
|
* FC_FOUNDRY, FC_STYLE, FC_RASTERIZER keys.
|
|
|
|
* and charsets under FC_CHARSET key.
|
|
|
|
* This is slightly semantically different from the old behaviour,
|
|
|
|
* but fonts shouldn't be getting non-strings here anyway.
|
2005-11-24 21:20:26 +01:00
|
|
|
* a better hack would use FcBaseObjectTypes to check all objects. */
|
2005-11-24 22:40:20 +01:00
|
|
|
objectPtr = FcObjectToPtr(object);
|
|
|
|
if ((objectPtr == FcObjectToPtr(FC_FAMILY)
|
|
|
|
|| objectPtr == FcObjectToPtr(FC_FOUNDRY)
|
|
|
|
|| objectPtr == FcObjectToPtr(FC_STYLE)
|
|
|
|
|| objectPtr == FcObjectToPtr(FC_RASTERIZER))
|
|
|
|
&& value.type != FcTypeString)
|
|
|
|
goto bail1;
|
|
|
|
if (objectPtr == FcObjectToPtr(FC_CHARSET)
|
|
|
|
&& value.type != FcTypeCharSet)
|
2005-11-24 21:20:26 +01:00
|
|
|
goto bail1;
|
|
|
|
|
2005-06-28 05:41:02 +02:00
|
|
|
FcValueListPtrU(new)->value = value;
|
|
|
|
FcValueListPtrU(new)->binding = binding;
|
|
|
|
FcValueListPtrU(new)->next = FcValueListPtrCreateDynamic(0);
|
2002-02-15 00:34:13 +01:00
|
|
|
|
2002-06-03 10:31:15 +02:00
|
|
|
e = FcPatternInsertElt (p, object);
|
2002-02-15 00:34:13 +01:00
|
|
|
if (!e)
|
|
|
|
goto bail2;
|
|
|
|
|
|
|
|
if (append)
|
|
|
|
{
|
2005-06-28 05:41:02 +02:00
|
|
|
for (prev = &e->values; FcValueListPtrU(*prev); prev = &FcValueListPtrU(*prev)->next)
|
|
|
|
;
|
2002-02-15 00:34:13 +01:00
|
|
|
*prev = new;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-06-28 05:41:02 +02:00
|
|
|
FcValueListPtrU(new)->next = e->values;
|
2002-02-15 00:34:13 +01:00
|
|
|
e->values = new;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FcTrue;
|
|
|
|
|
|
|
|
bail2:
|
|
|
|
switch (value.type) {
|
|
|
|
case FcTypeString:
|
2005-08-24 08:21:30 +02:00
|
|
|
FcStrFree ((FcChar8 *) value.u.s);
|
2002-02-15 00:34:13 +01:00
|
|
|
break;
|
|
|
|
case FcTypeMatrix:
|
2005-08-24 08:21:30 +02:00
|
|
|
FcMatrixFree ((FcMatrix *) value.u.m);
|
2002-02-15 00:34:13 +01:00
|
|
|
break;
|
|
|
|
case FcTypeCharSet:
|
2005-08-24 08:21:30 +02:00
|
|
|
FcCharSetDestroy ((FcCharSet *) value.u.c);
|
2002-02-15 00:34:13 +01:00
|
|
|
break;
|
2002-08-22 09:36:45 +02:00
|
|
|
case FcTypeLangSet:
|
2005-08-24 08:21:30 +02:00
|
|
|
FcLangSetDestroy ((FcLangSet *) value.u.l);
|
2002-08-22 09:36:45 +02:00
|
|
|
break;
|
2002-02-15 00:34:13 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
bail1:
|
|
|
|
FcMemFree (FC_MEM_VALLIST, sizeof (FcValueList));
|
2005-06-28 05:41:02 +02:00
|
|
|
free (FcValueListPtrU(new));
|
2002-02-15 00:34:13 +01:00
|
|
|
bail0:
|
|
|
|
return FcFalse;
|
|
|
|
}
|
|
|
|
|
2002-07-07 01:47:44 +02:00
|
|
|
FcBool
|
|
|
|
FcPatternAdd (FcPattern *p, const char *object, FcValue value, FcBool append)
|
|
|
|
{
|
|
|
|
return FcPatternAddWithBinding (p, object, value, FcValueBindingStrong, append);
|
|
|
|
}
|
|
|
|
|
|
|
|
FcBool
|
|
|
|
FcPatternAddWeak (FcPattern *p, const char *object, FcValue value, FcBool append)
|
|
|
|
{
|
|
|
|
return FcPatternAddWithBinding (p, object, value, FcValueBindingWeak, append);
|
|
|
|
}
|
|
|
|
|
2002-02-15 00:34:13 +01:00
|
|
|
FcBool
|
|
|
|
FcPatternDel (FcPattern *p, const char *object)
|
|
|
|
{
|
|
|
|
FcPatternElt *e;
|
|
|
|
|
2002-06-03 10:31:15 +02:00
|
|
|
e = FcPatternFindElt (p, object);
|
2002-02-15 00:34:13 +01:00
|
|
|
if (!e)
|
|
|
|
return FcFalse;
|
|
|
|
|
|
|
|
/* destroy value */
|
|
|
|
FcValueListDestroy (e->values);
|
|
|
|
|
|
|
|
/* shuffle existing ones down */
|
2005-06-28 05:41:02 +02:00
|
|
|
memmove (e, e+1,
|
|
|
|
(FcPatternEltU(p->elts) + p->num - (e + 1)) *
|
|
|
|
sizeof (FcPatternElt));
|
2002-02-15 00:34:13 +01:00
|
|
|
p->num--;
|
2005-07-07 14:09:10 +02:00
|
|
|
(FcPatternEltU(p->elts)+p->num)->object = 0;
|
2005-06-28 05:41:02 +02:00
|
|
|
(FcPatternEltU(p->elts)+p->num)->values = FcValueListPtrCreateDynamic(0);
|
2002-02-15 00:34:13 +01:00
|
|
|
return FcTrue;
|
|
|
|
}
|
|
|
|
|
2004-12-04 20:41:10 +01:00
|
|
|
FcBool
|
|
|
|
FcPatternRemove (FcPattern *p, const char *object, int id)
|
|
|
|
{
|
2005-06-28 05:41:02 +02:00
|
|
|
FcPatternElt *e;
|
|
|
|
FcValueListPtr *prev, l;
|
2004-12-04 20:41:10 +01:00
|
|
|
|
|
|
|
e = FcPatternFindElt (p, object);
|
|
|
|
if (!e)
|
|
|
|
return FcFalse;
|
2005-06-28 05:41:02 +02:00
|
|
|
for (prev = &e->values;
|
|
|
|
FcValueListPtrU(l = *prev);
|
|
|
|
prev = &FcValueListPtrU(l)->next)
|
2004-12-04 20:41:10 +01:00
|
|
|
{
|
|
|
|
if (!id)
|
|
|
|
{
|
2005-06-28 05:41:02 +02:00
|
|
|
*prev = FcValueListPtrU(l)->next;
|
|
|
|
FcValueListPtrU(l)->next = FcValueListPtrCreateDynamic(0);
|
2004-12-04 20:41:10 +01:00
|
|
|
FcValueListDestroy (l);
|
2005-06-28 05:41:02 +02:00
|
|
|
if (!FcValueListPtrU(e->values))
|
2004-12-04 20:41:10 +01:00
|
|
|
FcPatternDel (p, object);
|
|
|
|
return FcTrue;
|
|
|
|
}
|
|
|
|
id--;
|
|
|
|
}
|
|
|
|
return FcFalse;
|
|
|
|
}
|
|
|
|
|
2002-02-15 00:34:13 +01:00
|
|
|
FcBool
|
|
|
|
FcPatternAddInteger (FcPattern *p, const char *object, int i)
|
|
|
|
{
|
|
|
|
FcValue v;
|
|
|
|
|
|
|
|
v.type = FcTypeInteger;
|
|
|
|
v.u.i = i;
|
|
|
|
return FcPatternAdd (p, object, v, FcTrue);
|
|
|
|
}
|
|
|
|
|
|
|
|
FcBool
|
|
|
|
FcPatternAddDouble (FcPattern *p, const char *object, double d)
|
|
|
|
{
|
|
|
|
FcValue v;
|
|
|
|
|
|
|
|
v.type = FcTypeDouble;
|
|
|
|
v.u.d = d;
|
|
|
|
return FcPatternAdd (p, object, v, FcTrue);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FcBool
|
2002-02-15 07:01:28 +01:00
|
|
|
FcPatternAddString (FcPattern *p, const char *object, const FcChar8 *s)
|
2002-02-15 00:34:13 +01:00
|
|
|
{
|
|
|
|
FcValue v;
|
|
|
|
|
2005-12-08 06:54:27 +01:00
|
|
|
if (!s)
|
|
|
|
{
|
|
|
|
v.type = FcTypeVoid;
|
|
|
|
v.u.s = 0;
|
|
|
|
return FcPatternAdd (p, object, v, FcTrue);
|
|
|
|
}
|
|
|
|
|
2002-02-15 00:34:13 +01:00
|
|
|
v.type = FcTypeString;
|
2005-08-27 04:34:24 +02:00
|
|
|
v.u.s = FcStrStaticName(s);
|
2002-02-15 00:34:13 +01:00
|
|
|
return FcPatternAdd (p, object, v, FcTrue);
|
|
|
|
}
|
|
|
|
|
|
|
|
FcBool
|
|
|
|
FcPatternAddMatrix (FcPattern *p, const char *object, const FcMatrix *s)
|
|
|
|
{
|
|
|
|
FcValue v;
|
|
|
|
|
|
|
|
v.type = FcTypeMatrix;
|
2005-08-24 08:21:30 +02:00
|
|
|
v.u.m = s;
|
2002-02-15 00:34:13 +01:00
|
|
|
return FcPatternAdd (p, object, v, FcTrue);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FcBool
|
|
|
|
FcPatternAddBool (FcPattern *p, const char *object, FcBool b)
|
|
|
|
{
|
|
|
|
FcValue v;
|
|
|
|
|
|
|
|
v.type = FcTypeBool;
|
|
|
|
v.u.b = b;
|
|
|
|
return FcPatternAdd (p, object, v, FcTrue);
|
|
|
|
}
|
|
|
|
|
|
|
|
FcBool
|
|
|
|
FcPatternAddCharSet (FcPattern *p, const char *object, const FcCharSet *c)
|
|
|
|
{
|
|
|
|
FcValue v;
|
|
|
|
|
|
|
|
v.type = FcTypeCharSet;
|
2005-08-24 08:21:30 +02:00
|
|
|
v.u.c = (FcCharSet *)c;
|
2002-02-15 00:34:13 +01:00
|
|
|
return FcPatternAdd (p, object, v, FcTrue);
|
|
|
|
}
|
|
|
|
|
2002-06-01 01:21:25 +02:00
|
|
|
FcBool
|
|
|
|
FcPatternAddFTFace (FcPattern *p, const char *object, const FT_Face f)
|
|
|
|
{
|
|
|
|
FcValue v;
|
|
|
|
|
|
|
|
v.type = FcTypeFTFace;
|
|
|
|
v.u.f = (void *) f;
|
|
|
|
return FcPatternAdd (p, object, v, FcTrue);
|
|
|
|
}
|
|
|
|
|
2002-08-22 09:36:45 +02:00
|
|
|
FcBool
|
|
|
|
FcPatternAddLangSet (FcPattern *p, const char *object, const FcLangSet *ls)
|
|
|
|
{
|
|
|
|
FcValue v;
|
|
|
|
|
|
|
|
v.type = FcTypeLangSet;
|
2005-08-24 08:21:30 +02:00
|
|
|
v.u.l = (FcLangSet *)ls;
|
2002-08-22 09:36:45 +02:00
|
|
|
return FcPatternAdd (p, object, v, FcTrue);
|
|
|
|
}
|
|
|
|
|
2002-02-15 00:34:13 +01:00
|
|
|
FcResult
|
2002-10-11 19:53:03 +02:00
|
|
|
FcPatternGet (const FcPattern *p, const char *object, int id, FcValue *v)
|
2002-02-15 00:34:13 +01:00
|
|
|
{
|
|
|
|
FcPatternElt *e;
|
2005-06-28 05:41:02 +02:00
|
|
|
FcValueListPtr l;
|
2002-02-15 00:34:13 +01:00
|
|
|
|
2002-06-03 10:31:15 +02:00
|
|
|
e = FcPatternFindElt (p, object);
|
2002-02-15 00:34:13 +01:00
|
|
|
if (!e)
|
|
|
|
return FcResultNoMatch;
|
2005-06-28 05:41:02 +02:00
|
|
|
for (l = e->values; FcValueListPtrU(l); l = FcValueListPtrU(l)->next)
|
2002-02-15 00:34:13 +01:00
|
|
|
{
|
|
|
|
if (!id)
|
|
|
|
{
|
2005-08-24 08:21:30 +02:00
|
|
|
*v = FcValueCanonicalize(&FcValueListPtrU(l)->value);
|
2002-02-15 00:34:13 +01:00
|
|
|
return FcResultMatch;
|
|
|
|
}
|
|
|
|
id--;
|
|
|
|
}
|
|
|
|
return FcResultNoId;
|
|
|
|
}
|
|
|
|
|
|
|
|
FcResult
|
2002-10-11 19:53:03 +02:00
|
|
|
FcPatternGetInteger (const FcPattern *p, const char *object, int id, int *i)
|
2002-02-15 00:34:13 +01:00
|
|
|
{
|
|
|
|
FcValue v;
|
|
|
|
FcResult r;
|
|
|
|
|
|
|
|
r = FcPatternGet (p, object, id, &v);
|
|
|
|
if (r != FcResultMatch)
|
|
|
|
return r;
|
|
|
|
switch (v.type) {
|
|
|
|
case FcTypeDouble:
|
|
|
|
*i = (int) v.u.d;
|
|
|
|
break;
|
|
|
|
case FcTypeInteger:
|
|
|
|
*i = v.u.i;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return FcResultTypeMismatch;
|
|
|
|
}
|
|
|
|
return FcResultMatch;
|
|
|
|
}
|
|
|
|
|
|
|
|
FcResult
|
2002-10-11 19:53:03 +02:00
|
|
|
FcPatternGetDouble (const FcPattern *p, const char *object, int id, double *d)
|
2002-02-15 00:34:13 +01:00
|
|
|
{
|
|
|
|
FcValue v;
|
|
|
|
FcResult r;
|
|
|
|
|
|
|
|
r = FcPatternGet (p, object, id, &v);
|
|
|
|
if (r != FcResultMatch)
|
|
|
|
return r;
|
|
|
|
switch (v.type) {
|
|
|
|
case FcTypeDouble:
|
|
|
|
*d = v.u.d;
|
|
|
|
break;
|
|
|
|
case FcTypeInteger:
|
|
|
|
*d = (double) v.u.i;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return FcResultTypeMismatch;
|
|
|
|
}
|
|
|
|
return FcResultMatch;
|
|
|
|
}
|
|
|
|
|
|
|
|
FcResult
|
2002-10-11 19:53:03 +02:00
|
|
|
FcPatternGetString (const FcPattern *p, const char *object, int id, FcChar8 ** s)
|
2002-02-15 00:34:13 +01:00
|
|
|
{
|
|
|
|
FcValue v;
|
|
|
|
FcResult r;
|
|
|
|
|
|
|
|
r = FcPatternGet (p, object, id, &v);
|
|
|
|
if (r != FcResultMatch)
|
|
|
|
return r;
|
|
|
|
if (v.type != FcTypeString)
|
|
|
|
return FcResultTypeMismatch;
|
2005-11-01 06:26:27 +01:00
|
|
|
|
2005-08-24 08:21:30 +02:00
|
|
|
*s = (FcChar8 *) v.u.s;
|
2002-02-15 00:34:13 +01:00
|
|
|
return FcResultMatch;
|
|
|
|
}
|
|
|
|
|
|
|
|
FcResult
|
2002-10-11 19:53:03 +02:00
|
|
|
FcPatternGetMatrix(const FcPattern *p, const char *object, int id, FcMatrix **m)
|
2002-02-15 00:34:13 +01:00
|
|
|
{
|
|
|
|
FcValue v;
|
|
|
|
FcResult r;
|
|
|
|
|
|
|
|
r = FcPatternGet (p, object, id, &v);
|
|
|
|
if (r != FcResultMatch)
|
|
|
|
return r;
|
|
|
|
if (v.type != FcTypeMatrix)
|
|
|
|
return FcResultTypeMismatch;
|
2005-08-24 08:21:30 +02:00
|
|
|
*m = (FcMatrix *)v.u.m;
|
2002-02-15 00:34:13 +01:00
|
|
|
return FcResultMatch;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FcResult
|
2002-10-11 19:53:03 +02:00
|
|
|
FcPatternGetBool(const FcPattern *p, const char *object, int id, FcBool *b)
|
2002-02-15 00:34:13 +01:00
|
|
|
{
|
|
|
|
FcValue v;
|
|
|
|
FcResult r;
|
|
|
|
|
|
|
|
r = FcPatternGet (p, object, id, &v);
|
|
|
|
if (r != FcResultMatch)
|
|
|
|
return r;
|
|
|
|
if (v.type != FcTypeBool)
|
|
|
|
return FcResultTypeMismatch;
|
|
|
|
*b = v.u.b;
|
|
|
|
return FcResultMatch;
|
|
|
|
}
|
|
|
|
|
|
|
|
FcResult
|
2002-10-11 19:53:03 +02:00
|
|
|
FcPatternGetCharSet(const FcPattern *p, const char *object, int id, FcCharSet **c)
|
2002-02-15 00:34:13 +01:00
|
|
|
{
|
|
|
|
FcValue v;
|
|
|
|
FcResult r;
|
|
|
|
|
|
|
|
r = FcPatternGet (p, object, id, &v);
|
|
|
|
if (r != FcResultMatch)
|
|
|
|
return r;
|
|
|
|
if (v.type != FcTypeCharSet)
|
|
|
|
return FcResultTypeMismatch;
|
2005-08-24 08:21:30 +02:00
|
|
|
*c = (FcCharSet *)v.u.c;
|
2002-02-15 00:34:13 +01:00
|
|
|
return FcResultMatch;
|
|
|
|
}
|
|
|
|
|
2002-06-01 01:21:25 +02:00
|
|
|
FcResult
|
2002-10-11 19:53:03 +02:00
|
|
|
FcPatternGetFTFace(const FcPattern *p, const char *object, int id, FT_Face *f)
|
2002-06-01 01:21:25 +02:00
|
|
|
{
|
|
|
|
FcValue v;
|
|
|
|
FcResult r;
|
|
|
|
|
|
|
|
r = FcPatternGet (p, object, id, &v);
|
|
|
|
if (r != FcResultMatch)
|
|
|
|
return r;
|
|
|
|
if (v.type != FcTypeFTFace)
|
|
|
|
return FcResultTypeMismatch;
|
|
|
|
*f = (FT_Face) v.u.f;
|
|
|
|
return FcResultMatch;
|
|
|
|
}
|
|
|
|
|
2002-08-22 09:36:45 +02:00
|
|
|
FcResult
|
2002-10-11 19:53:03 +02:00
|
|
|
FcPatternGetLangSet(const FcPattern *p, const char *object, int id, FcLangSet **ls)
|
2002-08-22 09:36:45 +02:00
|
|
|
{
|
|
|
|
FcValue v;
|
|
|
|
FcResult r;
|
|
|
|
|
|
|
|
r = FcPatternGet (p, object, id, &v);
|
|
|
|
if (r != FcResultMatch)
|
|
|
|
return r;
|
|
|
|
if (v.type != FcTypeLangSet)
|
|
|
|
return FcResultTypeMismatch;
|
2005-08-24 08:21:30 +02:00
|
|
|
*ls = (FcLangSet *)v.u.l;
|
2002-08-22 09:36:45 +02:00
|
|
|
return FcResultMatch;
|
|
|
|
}
|
|
|
|
|
2002-02-15 00:34:13 +01:00
|
|
|
FcPattern *
|
2002-10-11 19:53:03 +02:00
|
|
|
FcPatternDuplicate (const FcPattern *orig)
|
2002-02-15 00:34:13 +01:00
|
|
|
{
|
|
|
|
FcPattern *new;
|
2005-06-28 05:41:02 +02:00
|
|
|
FcPatternElt *e;
|
2002-02-15 00:34:13 +01:00
|
|
|
int i;
|
2005-06-28 05:41:02 +02:00
|
|
|
FcValueListPtr l;
|
2002-02-15 00:34:13 +01:00
|
|
|
|
|
|
|
new = FcPatternCreate ();
|
|
|
|
if (!new)
|
|
|
|
goto bail0;
|
|
|
|
|
2005-06-28 05:41:02 +02:00
|
|
|
e = FcPatternEltU(orig->elts);
|
|
|
|
|
2002-02-15 00:34:13 +01:00
|
|
|
for (i = 0; i < orig->num; i++)
|
|
|
|
{
|
2005-06-28 05:41:02 +02:00
|
|
|
for (l = (e + i)->values;
|
|
|
|
FcValueListPtrU(l);
|
|
|
|
l = FcValueListPtrU(l)->next)
|
|
|
|
if (!FcPatternAdd (new, FcObjectPtrU((e + i)->object),
|
2005-09-16 06:57:18 +02:00
|
|
|
FcValueCanonicalize(&FcValueListPtrU(l)->value),
|
|
|
|
FcTrue))
|
2002-02-15 00:34:13 +01:00
|
|
|
goto bail1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return new;
|
|
|
|
|
|
|
|
bail1:
|
|
|
|
FcPatternDestroy (new);
|
|
|
|
bail0:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-06-19 22:08:22 +02:00
|
|
|
void
|
|
|
|
FcPatternReference (FcPattern *p)
|
|
|
|
{
|
2002-08-22 09:36:45 +02:00
|
|
|
if (p->ref != FC_REF_CONSTANT)
|
|
|
|
p->ref++;
|
2002-06-19 22:08:22 +02:00
|
|
|
}
|
|
|
|
|
2002-02-15 00:34:13 +01:00
|
|
|
FcPattern *
|
|
|
|
FcPatternVaBuild (FcPattern *orig, va_list va)
|
|
|
|
{
|
|
|
|
FcPattern *ret;
|
|
|
|
|
|
|
|
FcPatternVapBuild (ret, orig, va);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
FcPattern *
|
|
|
|
FcPatternBuild (FcPattern *orig, ...)
|
|
|
|
{
|
|
|
|
va_list va;
|
|
|
|
|
|
|
|
va_start (va, orig);
|
|
|
|
FcPatternVapBuild (orig, orig, va);
|
|
|
|
va_end (va);
|
|
|
|
return orig;
|
|
|
|
}
|
2004-12-04 20:41:10 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Add all of the elements in 's' to 'p'
|
|
|
|
*/
|
|
|
|
FcBool
|
|
|
|
FcPatternAppend (FcPattern *p, FcPattern *s)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
FcPatternElt *e;
|
2005-06-28 05:41:02 +02:00
|
|
|
FcValueListPtr v;
|
2004-12-04 20:41:10 +01:00
|
|
|
|
|
|
|
for (i = 0; i < s->num; i++)
|
|
|
|
{
|
2005-06-28 05:41:02 +02:00
|
|
|
e = FcPatternEltU(s->elts)+i;
|
|
|
|
for (v = e->values; FcValueListPtrU(v);
|
|
|
|
v = FcValueListPtrU(v)->next)
|
2004-12-04 20:41:10 +01:00
|
|
|
{
|
2005-06-28 05:41:02 +02:00
|
|
|
if (!FcPatternAddWithBinding (p, FcObjectPtrU(e->object),
|
2005-08-24 08:21:30 +02:00
|
|
|
FcValueCanonicalize(&FcValueListPtrU(v)->value),
|
2005-06-28 05:41:02 +02:00
|
|
|
FcValueListPtrU(v)->binding, FcTrue))
|
2004-12-04 20:41:10 +01:00
|
|
|
return FcFalse;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FcTrue;
|
|
|
|
}
|
|
|
|
|
2005-08-24 08:21:30 +02:00
|
|
|
#define OBJECT_HASH_SIZE 31
|
2005-09-11 04:16:09 +02:00
|
|
|
static struct objectBucket {
|
2005-08-24 08:21:30 +02:00
|
|
|
struct objectBucket *next;
|
|
|
|
FcChar32 hash;
|
2005-09-11 04:16:09 +02:00
|
|
|
} *FcObjectBuckets[OBJECT_HASH_SIZE];
|
2005-08-24 08:21:30 +02:00
|
|
|
|
2005-12-05 17:08:01 +01:00
|
|
|
static FcBool
|
|
|
|
FcStrHashed (const FcChar8 *name)
|
|
|
|
{
|
|
|
|
FcChar32 hash = FcStringHash (name);
|
|
|
|
struct objectBucket **p;
|
|
|
|
struct objectBucket *b;
|
|
|
|
|
|
|
|
for (p = &FcObjectBuckets[hash % OBJECT_HASH_SIZE]; (b = *p); p = &(b->next))
|
|
|
|
if (b->hash == hash && !strcmp ((char *)name, (char *) (b + 1)))
|
|
|
|
return FcTrue;
|
|
|
|
return FcFalse;
|
|
|
|
}
|
|
|
|
|
2005-09-11 04:16:09 +02:00
|
|
|
const FcChar8 *
|
|
|
|
FcStrStaticName (const FcChar8 *name)
|
2005-08-24 08:21:30 +02:00
|
|
|
{
|
2005-09-11 04:16:09 +02:00
|
|
|
FcChar32 hash = FcStringHash (name);
|
|
|
|
struct objectBucket **p;
|
|
|
|
struct objectBucket *b;
|
|
|
|
int size;
|
2005-08-24 08:21:30 +02:00
|
|
|
|
2005-09-11 04:16:09 +02:00
|
|
|
for (p = &FcObjectBuckets[hash % OBJECT_HASH_SIZE]; (b = *p); p = &(b->next))
|
|
|
|
if (b->hash == hash && !strcmp ((char *)name, (char *) (b + 1)))
|
|
|
|
return (FcChar8 *) (b + 1);
|
|
|
|
size = sizeof (struct objectBucket) + strlen ((char *)name) + 1;
|
2005-10-06 22:45:25 +02:00
|
|
|
b = malloc (size + sizeof (int));
|
|
|
|
/* workaround glibc bug which reads strlen in groups of 4 */
|
|
|
|
FcMemAlloc (FC_MEM_STATICSTR, size + sizeof (int));
|
2005-08-24 08:21:30 +02:00
|
|
|
if (!b)
|
|
|
|
return NULL;
|
|
|
|
b->next = 0;
|
|
|
|
b->hash = hash;
|
2005-09-11 04:16:09 +02:00
|
|
|
strcpy ((char *) (b + 1), (char *)name);
|
2005-08-24 08:21:30 +02:00
|
|
|
*p = b;
|
2005-09-11 04:16:09 +02:00
|
|
|
return (FcChar8 *) (b + 1);
|
2005-08-24 08:21:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2005-08-27 04:34:24 +02:00
|
|
|
FcStrStaticNameFini (void)
|
2005-06-28 05:41:02 +02:00
|
|
|
{
|
2005-08-24 08:21:30 +02:00
|
|
|
int i, size;
|
|
|
|
struct objectBucket *b, *next;
|
|
|
|
char *name;
|
|
|
|
|
|
|
|
for (i = 0; i < OBJECT_HASH_SIZE; i++)
|
2005-06-28 05:41:02 +02:00
|
|
|
{
|
2005-08-24 08:21:30 +02:00
|
|
|
for (b = FcObjectBuckets[i]; b; b = next)
|
|
|
|
{
|
|
|
|
next = b->next;
|
|
|
|
name = (char *) (b + 1);
|
|
|
|
size = sizeof (struct objectBucket) + strlen (name) + 1;
|
|
|
|
FcMemFree (FC_MEM_STATICSTR, size);
|
|
|
|
free (b);
|
|
|
|
}
|
|
|
|
FcObjectBuckets[i] = 0;
|
2005-06-28 05:41:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-08-24 08:21:30 +02:00
|
|
|
void
|
|
|
|
FcPatternFini (void)
|
|
|
|
{
|
2005-08-27 04:34:24 +02:00
|
|
|
FcStrStaticNameFini ();
|
2005-08-24 08:21:30 +02:00
|
|
|
FcObjectStaticNameFini ();
|
|
|
|
}
|
|
|
|
|
2005-06-28 05:41:02 +02:00
|
|
|
static FcPatternEltPtr
|
|
|
|
FcPatternEltPtrCreateDynamic (FcPatternElt * e)
|
|
|
|
{
|
|
|
|
FcPatternEltPtr new;
|
2005-08-24 08:21:30 +02:00
|
|
|
new.bank = FC_BANK_DYNAMIC;
|
2005-06-28 05:41:02 +02:00
|
|
|
new.u.dyn = e;
|
|
|
|
return new;
|
|
|
|
}
|
|
|
|
|
|
|
|
static FcPatternEltPtr
|
2005-08-24 08:21:30 +02:00
|
|
|
FcPatternEltPtrCreateStatic (int bank, int i)
|
2005-06-28 05:41:02 +02:00
|
|
|
{
|
|
|
|
FcPatternEltPtr new;
|
2005-08-24 08:21:30 +02:00
|
|
|
new.bank = bank;
|
2005-06-28 05:41:02 +02:00
|
|
|
new.u.stat = i;
|
|
|
|
return new;
|
|
|
|
}
|
|
|
|
|
2005-08-24 08:21:30 +02:00
|
|
|
static void
|
|
|
|
FcStrNewBank (void);
|
|
|
|
static int
|
2005-09-11 04:16:09 +02:00
|
|
|
FcStrNeededBytes (const FcChar8 * s);
|
2005-11-16 16:55:17 +01:00
|
|
|
static int
|
|
|
|
FcStrNeededBytesAlign (void);
|
2005-08-24 08:21:30 +02:00
|
|
|
static void *
|
|
|
|
FcStrDistributeBytes (FcCache * metadata, void * block_ptr);
|
2005-09-11 04:16:09 +02:00
|
|
|
static const FcChar8 *
|
|
|
|
FcStrSerialize (int bank, const FcChar8 * s);
|
2005-08-24 08:21:30 +02:00
|
|
|
static void *
|
2005-11-25 16:50:34 +01:00
|
|
|
FcStrUnserialize (FcCache * metadata, void *block_ptr);
|
2005-08-24 08:21:30 +02:00
|
|
|
|
|
|
|
static void
|
|
|
|
FcValueListNewBank (void);
|
|
|
|
static int
|
|
|
|
FcValueListNeededBytes (FcValueList * vl);
|
2005-11-16 16:55:17 +01:00
|
|
|
static int
|
|
|
|
FcValueListNeededBytesAlign (void);
|
2005-08-24 08:21:30 +02:00
|
|
|
static void *
|
|
|
|
FcValueListDistributeBytes (FcCache * metadata, void *block_ptr);
|
|
|
|
static FcValueListPtr
|
|
|
|
FcValueListSerialize(int bank, FcValueList *pi);
|
|
|
|
static void *
|
2005-11-25 16:50:34 +01:00
|
|
|
FcValueListUnserialize (FcCache * metadata, void *block_ptr);
|
2005-06-28 05:41:02 +02:00
|
|
|
|
|
|
|
|
|
|
|
void
|
2005-08-24 08:21:30 +02:00
|
|
|
FcPatternNewBank (void)
|
2005-06-28 05:41:02 +02:00
|
|
|
{
|
|
|
|
fcpattern_count = 0;
|
|
|
|
fcpatternelt_count = 0;
|
|
|
|
|
2005-08-24 08:21:30 +02:00
|
|
|
FcStrNewBank();
|
|
|
|
FcValueListNewBank();
|
2005-06-28 05:41:02 +02:00
|
|
|
}
|
|
|
|
|
2005-08-24 08:21:30 +02:00
|
|
|
int
|
|
|
|
FcPatternNeededBytes (FcPattern * p)
|
2005-06-28 05:41:02 +02:00
|
|
|
{
|
2005-08-24 08:21:30 +02:00
|
|
|
int i, cum = 0, c;
|
2005-06-28 05:41:02 +02:00
|
|
|
|
|
|
|
fcpattern_count++;
|
|
|
|
fcpatternelt_count += p->num;
|
|
|
|
|
|
|
|
for (i = 0; i < p->num; i++)
|
|
|
|
{
|
2005-08-24 08:21:30 +02:00
|
|
|
c = FcValueListNeededBytes (FcValueListPtrU
|
|
|
|
(((FcPatternEltU(p->elts)+i)->values)));
|
|
|
|
if (c < 0)
|
|
|
|
return c;
|
|
|
|
cum += c;
|
2005-06-28 05:41:02 +02:00
|
|
|
}
|
|
|
|
|
2005-08-24 08:21:30 +02:00
|
|
|
return cum + sizeof (FcPattern) + sizeof(FcPatternElt)*p->num;
|
2005-06-28 05:41:02 +02:00
|
|
|
}
|
|
|
|
|
2005-11-16 16:55:17 +01:00
|
|
|
int
|
|
|
|
FcPatternNeededBytesAlign (void)
|
|
|
|
{
|
2006-04-07 19:27:39 +02:00
|
|
|
return fc_alignof (FcPattern) + fc_alignof (FcPatternElt) +
|
2005-11-16 16:55:17 +01:00
|
|
|
FcValueListNeededBytesAlign ();
|
|
|
|
}
|
|
|
|
|
2005-08-24 08:21:30 +02:00
|
|
|
static FcBool
|
|
|
|
FcPatternEnsureBank (int bi)
|
2005-06-28 05:41:02 +02:00
|
|
|
{
|
2005-08-24 08:21:30 +02:00
|
|
|
FcPattern **pp;
|
|
|
|
FcPatternElt **ep;
|
|
|
|
int i;
|
2005-06-28 05:41:02 +02:00
|
|
|
|
2005-11-25 17:04:44 +01:00
|
|
|
if (!_fcPatterns || fcpattern_bank_count <= bi)
|
2005-06-28 05:41:02 +02:00
|
|
|
{
|
2005-08-24 08:21:30 +02:00
|
|
|
int new_count = bi + 4;
|
2005-11-25 17:04:44 +01:00
|
|
|
pp = realloc (_fcPatterns, sizeof (FcPattern *) * new_count);
|
2005-08-24 08:21:30 +02:00
|
|
|
if (!pp)
|
|
|
|
return 0;
|
2005-06-28 05:41:02 +02:00
|
|
|
|
2005-08-24 08:21:30 +02:00
|
|
|
FcMemAlloc (FC_MEM_PATTERN, sizeof (FcPattern *) * new_count);
|
2005-11-25 17:04:44 +01:00
|
|
|
_fcPatterns = pp;
|
2005-08-24 08:21:30 +02:00
|
|
|
|
2005-11-25 17:04:44 +01:00
|
|
|
ep = realloc (_fcPatternElts, sizeof (FcPatternElt *) * new_count);
|
2005-08-24 08:21:30 +02:00
|
|
|
if (!ep)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
FcMemAlloc (FC_MEM_PATELT, sizeof (FcPatternElt *) * new_count);
|
2005-11-25 17:04:44 +01:00
|
|
|
_fcPatternElts = ep;
|
2005-08-24 08:21:30 +02:00
|
|
|
|
|
|
|
for (i = fcpattern_bank_count; i < new_count; i++)
|
2005-06-28 05:41:02 +02:00
|
|
|
{
|
2005-11-25 17:04:44 +01:00
|
|
|
_fcPatterns[i] = 0;
|
|
|
|
_fcPatternElts[i] = 0;
|
2005-06-28 05:41:02 +02:00
|
|
|
}
|
2005-08-24 08:21:30 +02:00
|
|
|
|
|
|
|
fcpattern_bank_count = new_count;
|
2005-06-28 05:41:02 +02:00
|
|
|
}
|
2005-08-24 08:21:30 +02:00
|
|
|
|
|
|
|
FcMemAlloc (FC_MEM_PATTERN, sizeof (FcPattern) * fcpattern_count);
|
2005-06-28 05:41:02 +02:00
|
|
|
return FcTrue;
|
|
|
|
}
|
|
|
|
|
2005-08-24 08:21:30 +02:00
|
|
|
void *
|
|
|
|
FcPatternDistributeBytes (FcCache * metadata, void * block_ptr)
|
|
|
|
{
|
|
|
|
int bi = FcCacheBankToIndex(metadata->bank);
|
|
|
|
|
|
|
|
if (!FcPatternEnsureBank(bi))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fcpattern_ptr = 0;
|
2005-11-16 16:55:17 +01:00
|
|
|
block_ptr = ALIGN(block_ptr, FcPattern);
|
2005-11-25 17:04:44 +01:00
|
|
|
_fcPatterns[bi] = (FcPattern *)block_ptr;
|
2005-08-24 08:21:30 +02:00
|
|
|
block_ptr = (void *)((char *)block_ptr +
|
|
|
|
(sizeof (FcPattern) * fcpattern_count));
|
|
|
|
|
|
|
|
FcMemAlloc (FC_MEM_PATELT, sizeof (FcPatternElt) * fcpatternelt_count);
|
|
|
|
fcpatternelt_ptr = 0;
|
2005-11-16 16:55:17 +01:00
|
|
|
block_ptr = ALIGN(block_ptr, FcPatternElt);
|
2005-11-25 17:04:44 +01:00
|
|
|
_fcPatternElts[bi] = (FcPatternElt *)block_ptr;
|
2005-08-24 08:21:30 +02:00
|
|
|
block_ptr = (void *)((char *)block_ptr +
|
|
|
|
(sizeof (FcPatternElt) * fcpatternelt_count));
|
|
|
|
|
|
|
|
metadata->pattern_count = fcpattern_count;
|
|
|
|
metadata->patternelt_count = fcpatternelt_count;
|
|
|
|
|
|
|
|
block_ptr = FcStrDistributeBytes (metadata, block_ptr);
|
|
|
|
block_ptr = FcValueListDistributeBytes (metadata, block_ptr);
|
|
|
|
return block_ptr;
|
|
|
|
}
|
|
|
|
|
2005-06-28 05:41:02 +02:00
|
|
|
FcPattern *
|
2005-08-24 08:21:30 +02:00
|
|
|
FcPatternSerialize (int bank, FcPattern *old)
|
2005-06-28 05:41:02 +02:00
|
|
|
{
|
|
|
|
FcPattern *p;
|
|
|
|
FcPatternElt *e, *nep;
|
|
|
|
FcValueList * nv;
|
|
|
|
FcValueListPtr v, nv_head, nvp;
|
2005-08-24 08:21:30 +02:00
|
|
|
int i, elts, bi = FcCacheBankToIndex(bank);
|
2005-06-28 05:41:02 +02:00
|
|
|
|
2005-11-25 17:04:44 +01:00
|
|
|
p = &_fcPatterns[bi][fcpattern_ptr++];
|
2005-08-24 08:21:30 +02:00
|
|
|
p->bank = bank;
|
2005-06-28 05:41:02 +02:00
|
|
|
elts = fcpatternelt_ptr;
|
2005-11-25 17:04:44 +01:00
|
|
|
nep = &_fcPatternElts[bi][elts];
|
2005-06-28 05:41:02 +02:00
|
|
|
if (!nep)
|
|
|
|
return FcFalse;
|
2005-07-25 06:10:09 +02:00
|
|
|
|
2005-06-28 05:41:02 +02:00
|
|
|
fcpatternelt_ptr += old->num;
|
2005-07-25 06:10:09 +02:00
|
|
|
|
2005-06-28 05:41:02 +02:00
|
|
|
for (e = FcPatternEltU(old->elts), i=0; i < old->num; i++, e++)
|
|
|
|
{
|
|
|
|
v = e->values;
|
2005-08-24 08:21:30 +02:00
|
|
|
nvp = nv_head = FcValueListSerialize(bank, FcValueListPtrU(v));
|
2005-06-28 05:41:02 +02:00
|
|
|
if (!FcValueListPtrU(nv_head))
|
2005-08-24 08:21:30 +02:00
|
|
|
return 0;
|
2005-06-28 05:41:02 +02:00
|
|
|
nv = FcValueListPtrU(nvp);
|
|
|
|
|
|
|
|
for (;
|
|
|
|
FcValueListPtrU(v);
|
|
|
|
v = FcValueListPtrU(v)->next,
|
|
|
|
nv = FcValueListPtrU(nv->next))
|
|
|
|
{
|
|
|
|
|
|
|
|
if (FcValueListPtrU(FcValueListPtrU(v)->next))
|
|
|
|
{
|
|
|
|
nvp = FcValueListSerialize
|
2005-08-24 08:21:30 +02:00
|
|
|
(bank, FcValueListPtrU(FcValueListPtrU(v)->next));
|
2005-06-28 05:41:02 +02:00
|
|
|
nv->next = nvp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nep[i].values = nv_head;
|
2005-08-27 04:34:24 +02:00
|
|
|
nep[i].object = e->object;
|
2005-06-28 05:41:02 +02:00
|
|
|
}
|
2005-07-25 06:10:09 +02:00
|
|
|
|
|
|
|
p->elts = old->elts;
|
2005-08-24 08:21:30 +02:00
|
|
|
p->elts = FcPatternEltPtrCreateStatic(bank, elts);
|
2005-06-28 05:41:02 +02:00
|
|
|
p->size = old->num;
|
2005-07-25 06:10:09 +02:00
|
|
|
p->num = old->num;
|
2005-06-28 05:41:02 +02:00
|
|
|
p->ref = FC_REF_CONSTANT;
|
|
|
|
return p;
|
2005-07-25 06:10:09 +02:00
|
|
|
}
|
|
|
|
|
2005-08-27 04:34:24 +02:00
|
|
|
void *
|
2005-11-25 16:50:34 +01:00
|
|
|
FcPatternUnserialize (FcCache * metadata, void *block_ptr)
|
2005-07-25 06:10:09 +02:00
|
|
|
{
|
2005-11-25 16:50:34 +01:00
|
|
|
int bi = FcCacheBankToIndex(metadata->bank);
|
2005-08-24 08:21:30 +02:00
|
|
|
if (!FcPatternEnsureBank(bi))
|
2005-07-25 06:10:09 +02:00
|
|
|
return FcFalse;
|
|
|
|
|
2005-11-25 16:50:34 +01:00
|
|
|
FcMemAlloc (FC_MEM_PATTERN, sizeof (FcPattern) * metadata->pattern_count);
|
2005-11-16 16:55:17 +01:00
|
|
|
block_ptr = ALIGN(block_ptr, FcPattern);
|
2005-11-25 17:04:44 +01:00
|
|
|
_fcPatterns[bi] = (FcPattern *)block_ptr;
|
2005-08-24 08:21:30 +02:00
|
|
|
block_ptr = (void *)((char *)block_ptr +
|
2005-11-25 16:50:34 +01:00
|
|
|
(sizeof (FcPattern) * metadata->pattern_count));
|
2005-08-24 08:21:30 +02:00
|
|
|
|
|
|
|
FcMemAlloc (FC_MEM_PATELT,
|
2005-11-25 16:50:34 +01:00
|
|
|
sizeof (FcPatternElt) * metadata->patternelt_count);
|
2005-11-16 16:55:17 +01:00
|
|
|
block_ptr = ALIGN(block_ptr, FcPatternElt);
|
2005-11-25 17:04:44 +01:00
|
|
|
_fcPatternElts[bi] = (FcPatternElt *)block_ptr;
|
2005-08-24 08:21:30 +02:00
|
|
|
block_ptr = (void *)((char *)block_ptr +
|
2005-11-25 16:50:34 +01:00
|
|
|
(sizeof (FcPatternElt) * metadata->patternelt_count));
|
2005-08-24 08:21:30 +02:00
|
|
|
|
|
|
|
block_ptr = FcStrUnserialize (metadata, block_ptr);
|
|
|
|
block_ptr = FcValueListUnserialize (metadata, block_ptr);
|
|
|
|
|
2005-08-27 04:34:24 +02:00
|
|
|
return block_ptr;
|
2005-07-25 06:10:09 +02:00
|
|
|
}
|
|
|
|
|
2005-08-24 08:21:30 +02:00
|
|
|
static void
|
|
|
|
FcValueListNewBank (void)
|
2005-07-25 06:10:09 +02:00
|
|
|
{
|
2005-08-24 08:21:30 +02:00
|
|
|
fcvaluelist_count = 0;
|
|
|
|
|
|
|
|
FcCharSetNewBank();
|
|
|
|
FcLangSetNewBank();
|
|
|
|
}
|
2005-07-25 06:10:09 +02:00
|
|
|
|
2005-08-24 08:21:30 +02:00
|
|
|
static int
|
|
|
|
FcValueListNeededBytes (FcValueList *p)
|
|
|
|
{
|
|
|
|
FcValueList *vl;
|
|
|
|
int cum = 0;
|
2005-07-25 06:10:09 +02:00
|
|
|
|
2005-08-24 08:21:30 +02:00
|
|
|
for (vl = p;
|
|
|
|
vl;
|
|
|
|
vl = FcValueListPtrU(vl->next))
|
2005-07-25 06:10:09 +02:00
|
|
|
{
|
2006-03-03 07:35:53 +01:00
|
|
|
/* unserialize just in case */
|
|
|
|
FcValue v = FcValueCanonicalize(&vl->value);
|
2005-08-24 08:21:30 +02:00
|
|
|
|
|
|
|
switch (v.type)
|
|
|
|
{
|
|
|
|
case FcTypeCharSet:
|
|
|
|
cum += FcCharSetNeededBytes(v.u.c);
|
|
|
|
break;
|
|
|
|
case FcTypeLangSet:
|
|
|
|
cum += FcLangSetNeededBytes(v.u.l);
|
|
|
|
break;
|
|
|
|
case FcTypeString:
|
|
|
|
cum += FcStrNeededBytes(v.u.s);
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
fcvaluelist_count++;
|
|
|
|
cum += sizeof (FcValueList);
|
2005-07-25 06:10:09 +02:00
|
|
|
}
|
2005-08-24 08:21:30 +02:00
|
|
|
|
|
|
|
return cum;
|
2005-07-25 06:10:09 +02:00
|
|
|
}
|
|
|
|
|
2005-11-16 16:55:17 +01:00
|
|
|
static int
|
|
|
|
FcValueListNeededBytesAlign (void)
|
|
|
|
{
|
|
|
|
return FcCharSetNeededBytesAlign() + FcLangSetNeededBytesAlign() +
|
2006-04-07 19:27:39 +02:00
|
|
|
FcStrNeededBytesAlign() + fc_alignof (FcValueList);
|
2005-11-16 16:55:17 +01:00
|
|
|
}
|
|
|
|
|
2005-08-24 08:21:30 +02:00
|
|
|
static FcBool
|
|
|
|
FcValueListEnsureBank (int bi)
|
2005-07-25 06:10:09 +02:00
|
|
|
{
|
2005-08-24 08:21:30 +02:00
|
|
|
FcValueList **pvl;
|
|
|
|
|
2005-11-25 17:04:44 +01:00
|
|
|
if (!_fcValueLists || fcvaluelist_bank_count <= bi)
|
2005-08-24 08:21:30 +02:00
|
|
|
{
|
|
|
|
int new_count = bi + 2, i;
|
|
|
|
|
2005-11-25 17:04:44 +01:00
|
|
|
pvl = realloc (_fcValueLists, sizeof (FcValueList *) * new_count);
|
2005-08-24 08:21:30 +02:00
|
|
|
if (!pvl)
|
|
|
|
return FcFalse;
|
2005-07-25 06:10:09 +02:00
|
|
|
|
2005-08-24 08:21:30 +02:00
|
|
|
FcMemAlloc (FC_MEM_VALLIST, sizeof (FcValueList *) * new_count);
|
|
|
|
|
2005-11-25 17:04:44 +01:00
|
|
|
_fcValueLists = pvl;
|
2005-08-24 08:21:30 +02:00
|
|
|
for (i = fcvaluelist_bank_count; i < new_count; i++)
|
2005-11-25 17:04:44 +01:00
|
|
|
_fcValueLists[i] = 0;
|
2005-08-24 08:21:30 +02:00
|
|
|
|
|
|
|
fcvaluelist_bank_count = new_count;
|
|
|
|
}
|
2005-07-25 06:10:09 +02:00
|
|
|
return FcTrue;
|
|
|
|
}
|
|
|
|
|
2005-08-24 08:21:30 +02:00
|
|
|
static void *
|
|
|
|
FcValueListDistributeBytes (FcCache * metadata, void *block_ptr)
|
2005-07-25 06:10:09 +02:00
|
|
|
{
|
2005-08-24 08:21:30 +02:00
|
|
|
int bi = FcCacheBankToIndex(metadata->bank);
|
2005-07-25 06:10:09 +02:00
|
|
|
|
2005-08-24 08:21:30 +02:00
|
|
|
if (!FcValueListEnsureBank(bi))
|
|
|
|
return 0;
|
2005-07-25 06:10:09 +02:00
|
|
|
|
2005-08-24 08:21:30 +02:00
|
|
|
FcMemAlloc (FC_MEM_VALLIST, sizeof (FcValueList) * fcvaluelist_count);
|
|
|
|
fcvaluelist_ptr = 0;
|
2005-11-16 16:55:17 +01:00
|
|
|
block_ptr = ALIGN(block_ptr, FcValueList);
|
2005-11-25 17:04:44 +01:00
|
|
|
_fcValueLists[bi] = (FcValueList *)block_ptr;
|
2005-08-24 08:21:30 +02:00
|
|
|
block_ptr = (void *)((char *)block_ptr +
|
|
|
|
(sizeof (FcValueList) * fcvaluelist_count));
|
|
|
|
metadata->valuelist_count = fcvaluelist_count;
|
|
|
|
|
|
|
|
block_ptr = FcCharSetDistributeBytes(metadata, block_ptr);
|
|
|
|
block_ptr = FcLangSetDistributeBytes(metadata, block_ptr);
|
|
|
|
|
|
|
|
return block_ptr;
|
2005-07-25 06:10:09 +02:00
|
|
|
}
|
2005-06-28 05:41:02 +02:00
|
|
|
|
2005-08-24 08:21:30 +02:00
|
|
|
static FcValueListPtr
|
|
|
|
FcValueListSerialize(int bank, FcValueList *pi)
|
2005-06-28 05:41:02 +02:00
|
|
|
{
|
|
|
|
FcValueListPtr new;
|
|
|
|
FcValue * v;
|
2005-08-24 08:21:30 +02:00
|
|
|
int bi = FcCacheBankToIndex(bank);
|
2005-06-28 05:41:02 +02:00
|
|
|
|
2005-08-24 08:21:30 +02:00
|
|
|
if (!pi)
|
2005-06-28 05:41:02 +02:00
|
|
|
{
|
2005-08-24 08:21:30 +02:00
|
|
|
new.bank = FC_BANK_DYNAMIC;
|
|
|
|
new.u.dyn = 0;
|
|
|
|
return new;
|
2005-06-28 05:41:02 +02:00
|
|
|
}
|
|
|
|
|
2005-11-25 17:04:44 +01:00
|
|
|
_fcValueLists[bi][fcvaluelist_ptr] = *pi;
|
2005-08-24 08:21:30 +02:00
|
|
|
new.bank = bank;
|
2005-06-28 05:41:02 +02:00
|
|
|
new.u.stat = fcvaluelist_ptr++;
|
2005-11-25 17:04:44 +01:00
|
|
|
_fcValueLists[bi][new.u.stat].value = FcValueCanonicalize (&pi->value);
|
|
|
|
v = &_fcValueLists[bi][new.u.stat].value;
|
2005-06-28 05:41:02 +02:00
|
|
|
switch (v->type)
|
|
|
|
{
|
|
|
|
case FcTypeString:
|
2005-08-24 08:21:30 +02:00
|
|
|
if (v->u.s)
|
2005-06-28 05:41:02 +02:00
|
|
|
{
|
2005-09-11 04:16:09 +02:00
|
|
|
const FcChar8 * s = FcStrSerialize(bank, v->u.s);
|
2005-08-24 08:21:30 +02:00
|
|
|
if (!s)
|
2005-06-28 05:41:02 +02:00
|
|
|
return FcValueListPtrCreateDynamic(pi);
|
2005-09-11 04:16:09 +02:00
|
|
|
v->u.s_off = s - (const FcChar8 *)v;
|
2005-08-24 08:21:30 +02:00
|
|
|
v->type |= FC_STORAGE_STATIC;
|
2005-06-28 05:41:02 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FcTypeMatrix:
|
|
|
|
break;
|
|
|
|
case FcTypeCharSet:
|
2005-08-24 08:21:30 +02:00
|
|
|
if (v->u.c)
|
2005-06-28 05:41:02 +02:00
|
|
|
{
|
2005-08-24 08:21:30 +02:00
|
|
|
FcCharSet * c = FcCharSetSerialize(bank, (FcCharSet *)v->u.c);
|
|
|
|
if (!c)
|
2005-06-28 05:41:02 +02:00
|
|
|
return FcValueListPtrCreateDynamic(pi);
|
2005-08-24 08:21:30 +02:00
|
|
|
v->u.c_off = (char *)c - (char *)v;
|
|
|
|
v->type |= FC_STORAGE_STATIC;
|
2005-06-28 05:41:02 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FcTypeLangSet:
|
2005-08-24 08:21:30 +02:00
|
|
|
if (v->u.l)
|
2005-06-28 05:41:02 +02:00
|
|
|
{
|
2005-08-24 08:21:30 +02:00
|
|
|
FcLangSet * l = FcLangSetSerialize(bank, (FcLangSet *)v->u.l);
|
|
|
|
if (!l)
|
2005-06-28 05:41:02 +02:00
|
|
|
return FcValueListPtrCreateDynamic(pi);
|
2005-08-24 08:21:30 +02:00
|
|
|
v->u.l_off = (char *)l - (char *)v;
|
|
|
|
v->type |= FC_STORAGE_STATIC;
|
2005-06-28 05:41:02 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return new;
|
|
|
|
}
|
|
|
|
|
2005-08-24 08:21:30 +02:00
|
|
|
static void *
|
2005-11-25 16:50:34 +01:00
|
|
|
FcValueListUnserialize (FcCache * metadata, void *block_ptr)
|
2005-07-25 06:10:09 +02:00
|
|
|
{
|
2005-11-25 16:50:34 +01:00
|
|
|
int bi = FcCacheBankToIndex(metadata->bank);
|
2005-07-25 06:10:09 +02:00
|
|
|
|
2005-08-24 08:21:30 +02:00
|
|
|
if (!FcValueListEnsureBank(bi))
|
|
|
|
return 0;
|
2005-07-25 06:10:09 +02:00
|
|
|
|
2005-08-24 08:21:30 +02:00
|
|
|
FcMemAlloc (FC_MEM_VALLIST,
|
2005-11-25 16:50:34 +01:00
|
|
|
sizeof (FcValueList) * metadata->valuelist_count);
|
2005-11-16 16:55:17 +01:00
|
|
|
block_ptr = ALIGN(block_ptr, FcValueList);
|
2005-11-25 17:04:44 +01:00
|
|
|
_fcValueLists[bi] = (FcValueList *)block_ptr;
|
2005-08-24 08:21:30 +02:00
|
|
|
block_ptr = (void *)((char *)block_ptr +
|
2005-11-25 16:50:34 +01:00
|
|
|
(sizeof (FcValueList) * metadata->valuelist_count));
|
2005-07-25 06:10:09 +02:00
|
|
|
|
2005-08-24 08:21:30 +02:00
|
|
|
block_ptr = FcCharSetUnserialize(metadata, block_ptr);
|
|
|
|
block_ptr = FcLangSetUnserialize(metadata, block_ptr);
|
|
|
|
|
|
|
|
return block_ptr;
|
2005-07-25 06:10:09 +02:00
|
|
|
}
|
|
|
|
|
2005-06-28 05:41:02 +02:00
|
|
|
FcValueListPtr
|
|
|
|
FcValueListPtrCreateDynamic(FcValueList * p)
|
|
|
|
{
|
|
|
|
FcValueListPtr r;
|
|
|
|
|
2005-08-24 08:21:30 +02:00
|
|
|
r.bank = FC_BANK_DYNAMIC;
|
2005-06-28 05:41:02 +02:00
|
|
|
r.u.dyn = p;
|
|
|
|
return r;
|
2004-12-04 20:41:10 +01:00
|
|
|
}
|
2005-07-07 14:09:10 +02:00
|
|
|
|
2005-09-11 04:16:09 +02:00
|
|
|
static FcChar8 ** static_strs;
|
2005-08-24 08:21:30 +02:00
|
|
|
static int static_str_bank_count = 0, fcstr_ptr, fcstr_count;
|
2005-07-07 14:09:10 +02:00
|
|
|
|
2005-08-24 08:21:30 +02:00
|
|
|
static struct objectBucket *FcStrBuckets[OBJECT_HASH_SIZE];
|
2005-07-07 14:09:10 +02:00
|
|
|
|
2005-08-24 08:21:30 +02:00
|
|
|
static void
|
|
|
|
FcStrNewBank (void)
|
2005-07-07 14:09:10 +02:00
|
|
|
{
|
2005-08-24 08:21:30 +02:00
|
|
|
int i, size;
|
|
|
|
struct objectBucket *b, *next;
|
|
|
|
char *name;
|
2005-07-07 14:09:10 +02:00
|
|
|
|
2005-08-24 08:21:30 +02:00
|
|
|
for (i = 0; i < OBJECT_HASH_SIZE; i++)
|
2005-07-07 14:09:10 +02:00
|
|
|
{
|
2005-08-24 08:21:30 +02:00
|
|
|
for (b = FcStrBuckets[i]; b; b = next)
|
2005-07-07 14:09:10 +02:00
|
|
|
{
|
2005-08-24 08:21:30 +02:00
|
|
|
next = b->next;
|
|
|
|
name = (char *) (b + 1);
|
|
|
|
size = sizeof (struct objectBucket) + strlen (name) + 1;
|
|
|
|
FcMemFree (FC_MEM_STATICSTR, size);
|
|
|
|
free (b);
|
2005-07-07 14:09:10 +02:00
|
|
|
}
|
2005-08-24 08:21:30 +02:00
|
|
|
FcStrBuckets[i] = 0;
|
2005-07-07 14:09:10 +02:00
|
|
|
}
|
|
|
|
|
2005-08-24 08:21:30 +02:00
|
|
|
fcstr_count = 0;
|
|
|
|
}
|
2005-07-07 14:09:10 +02:00
|
|
|
|
2005-08-24 08:21:30 +02:00
|
|
|
static int
|
2005-09-11 04:16:09 +02:00
|
|
|
FcStrNeededBytes (const FcChar8 * s)
|
2005-08-24 08:21:30 +02:00
|
|
|
{
|
|
|
|
FcChar32 hash = FcStringHash ((const FcChar8 *) s);
|
|
|
|
struct objectBucket **p;
|
|
|
|
struct objectBucket *b;
|
|
|
|
int size;
|
2006-01-19 20:20:30 +01:00
|
|
|
FcChar8 *const null = 0;
|
2005-07-07 14:09:10 +02:00
|
|
|
|
2005-08-24 08:21:30 +02:00
|
|
|
for (p = &FcStrBuckets[hash % OBJECT_HASH_SIZE]; (b = *p); p = &(b->next))
|
2005-09-11 04:16:09 +02:00
|
|
|
if (b->hash == hash && !strcmp ((char *)s, (char *) (b + 1)))
|
2005-08-24 08:21:30 +02:00
|
|
|
return 0;
|
2005-09-11 04:16:09 +02:00
|
|
|
size = sizeof (struct objectBucket) + strlen ((char *)s) + 1 + sizeof(char *);
|
2005-07-07 14:09:10 +02:00
|
|
|
b = malloc (size);
|
|
|
|
FcMemAlloc (FC_MEM_STATICSTR, size);
|
2005-08-24 08:21:30 +02:00
|
|
|
if (!b)
|
|
|
|
return -1;
|
2005-07-07 14:09:10 +02:00
|
|
|
b->next = 0;
|
|
|
|
b->hash = hash;
|
2005-09-11 04:16:09 +02:00
|
|
|
strcpy ((char *) (b + 1), (char *)s);
|
2005-11-16 16:55:17 +01:00
|
|
|
|
|
|
|
/* Yes, the following line is convoluted. However, it is
|
|
|
|
* incorrect to replace the with a memset, because the C
|
|
|
|
* specification doesn't guarantee that the null pointer is
|
|
|
|
* the same as the zero bit pattern. */
|
2006-01-19 20:20:30 +01:00
|
|
|
/* Misaligned pointers are not guaranteed to work, either! */
|
|
|
|
memcpy (((char *) (b + 1) + strlen((char *)s) + 1), &null, sizeof (null));
|
2005-07-07 14:09:10 +02:00
|
|
|
*p = b;
|
|
|
|
|
2005-09-11 04:16:09 +02:00
|
|
|
fcstr_count += strlen((char *)s) + 1;
|
|
|
|
return strlen((char *)s) + 1;
|
2005-07-07 14:09:10 +02:00
|
|
|
}
|
|
|
|
|
2005-11-16 16:55:17 +01:00
|
|
|
static int
|
|
|
|
FcStrNeededBytesAlign (void)
|
|
|
|
{
|
2006-04-07 19:27:39 +02:00
|
|
|
return fc_alignof (char);
|
2005-11-16 16:55:17 +01:00
|
|
|
}
|
|
|
|
|
2005-07-07 14:09:10 +02:00
|
|
|
static FcBool
|
2005-08-24 08:21:30 +02:00
|
|
|
FcStrEnsureBank (int bi)
|
2005-07-07 14:09:10 +02:00
|
|
|
{
|
2005-09-11 04:16:09 +02:00
|
|
|
FcChar8 ** ss;
|
2005-07-07 14:09:10 +02:00
|
|
|
|
2005-08-24 08:21:30 +02:00
|
|
|
if (!static_strs || static_str_bank_count <= bi)
|
2005-07-07 14:09:10 +02:00
|
|
|
{
|
2005-08-24 08:21:30 +02:00
|
|
|
int new_count = bi + 4, i;
|
|
|
|
ss = realloc (static_strs, sizeof (const char *) * new_count);
|
|
|
|
if (!ss)
|
|
|
|
return FcFalse;
|
2005-07-07 14:09:10 +02:00
|
|
|
|
2005-08-24 08:21:30 +02:00
|
|
|
FcMemAlloc (FC_MEM_STRING, sizeof (const char *) * (new_count-static_str_bank_count));
|
|
|
|
static_strs = ss;
|
2005-07-07 14:09:10 +02:00
|
|
|
|
2005-08-24 08:21:30 +02:00
|
|
|
for (i = static_str_bank_count; i < new_count; i++)
|
|
|
|
static_strs[i] = 0;
|
|
|
|
static_str_bank_count = new_count;
|
2005-07-07 14:09:10 +02:00
|
|
|
}
|
|
|
|
return FcTrue;
|
|
|
|
}
|
|
|
|
|
2005-08-24 08:21:30 +02:00
|
|
|
static void *
|
|
|
|
FcStrDistributeBytes (FcCache * metadata, void * block_ptr)
|
2005-07-07 14:09:10 +02:00
|
|
|
{
|
2005-08-24 08:21:30 +02:00
|
|
|
int bi = FcCacheBankToIndex(metadata->bank);
|
|
|
|
if (!FcStrEnsureBank(bi))
|
|
|
|
return 0;
|
2005-07-07 14:09:10 +02:00
|
|
|
|
2005-08-24 08:21:30 +02:00
|
|
|
FcMemAlloc (FC_MEM_STRING, sizeof (char) * fcstr_count);
|
2005-11-16 16:55:17 +01:00
|
|
|
block_ptr = ALIGN (block_ptr, FcChar8);
|
2005-09-11 04:16:09 +02:00
|
|
|
static_strs[bi] = (FcChar8 *)block_ptr;
|
2005-08-24 08:21:30 +02:00
|
|
|
block_ptr = (void *)((char *)block_ptr + (sizeof (char) * fcstr_count));
|
|
|
|
metadata->str_count = fcstr_count;
|
|
|
|
fcstr_ptr = 0;
|
2005-07-07 14:09:10 +02:00
|
|
|
|
2005-08-24 08:21:30 +02:00
|
|
|
return block_ptr;
|
2005-07-07 14:09:10 +02:00
|
|
|
}
|
2005-07-15 20:49:12 +02:00
|
|
|
|
2005-09-11 04:16:09 +02:00
|
|
|
static const FcChar8 *
|
|
|
|
FcStrSerialize (int bank, const FcChar8 * s)
|
2005-07-25 06:10:09 +02:00
|
|
|
{
|
2005-08-24 08:21:30 +02:00
|
|
|
FcChar32 hash = FcStringHash ((const FcChar8 *) s);
|
|
|
|
struct objectBucket **p;
|
|
|
|
struct objectBucket *b;
|
|
|
|
int bi = FcCacheBankToIndex(bank);
|
2005-07-25 06:10:09 +02:00
|
|
|
|
2005-08-24 08:21:30 +02:00
|
|
|
for (p = &FcStrBuckets[hash % OBJECT_HASH_SIZE]; (b = *p); p = &(b->next))
|
2005-09-11 04:16:09 +02:00
|
|
|
if (b->hash == hash && !strcmp ((char *)s, (char *) (b + 1)))
|
2005-08-24 08:21:30 +02:00
|
|
|
{
|
2006-01-19 20:20:30 +01:00
|
|
|
FcChar8 * t;
|
|
|
|
memcpy (&t, ((FcChar8 *)(b + 1)) + strlen ((char *)s) + 1, sizeof (FcChar8 *));
|
2005-08-24 08:21:30 +02:00
|
|
|
if (!t)
|
|
|
|
{
|
2005-09-11 04:16:09 +02:00
|
|
|
strcpy((char *)(static_strs[bi] + fcstr_ptr), (char *)s);
|
2006-01-19 20:20:30 +01:00
|
|
|
t = static_strs[bi] + fcstr_ptr;
|
|
|
|
memcpy ((FcChar8 *) (b + 1) + strlen((char *)s) + 1, &t, sizeof (FcChar8 *));
|
2005-09-11 04:16:09 +02:00
|
|
|
fcstr_ptr += strlen((char *)s) + 1;
|
2006-01-19 20:20:30 +01:00
|
|
|
memcpy (&t, ((FcChar8 *)(b + 1)) + strlen ((char *)s) + 1, sizeof (FcChar8 *));
|
2005-08-24 08:21:30 +02:00
|
|
|
}
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
return 0;
|
2005-07-25 06:10:09 +02:00
|
|
|
}
|
|
|
|
|
2005-08-24 08:21:30 +02:00
|
|
|
static void *
|
2005-11-25 16:50:34 +01:00
|
|
|
FcStrUnserialize (FcCache * metadata, void *block_ptr)
|
2005-07-25 06:10:09 +02:00
|
|
|
{
|
2005-11-25 16:50:34 +01:00
|
|
|
int bi = FcCacheBankToIndex(metadata->bank);
|
2005-08-24 08:21:30 +02:00
|
|
|
if (!FcStrEnsureBank(bi))
|
|
|
|
return 0;
|
2005-07-25 06:10:09 +02:00
|
|
|
|
2005-11-25 16:50:34 +01:00
|
|
|
FcMemAlloc (FC_MEM_STRING, sizeof (char) * metadata->str_count);
|
2005-11-17 16:43:39 +01:00
|
|
|
block_ptr = ALIGN (block_ptr, FcChar8);
|
2005-09-11 04:16:09 +02:00
|
|
|
static_strs[bi] = (FcChar8 *)block_ptr;
|
2005-08-24 08:21:30 +02:00
|
|
|
block_ptr = (void *)((char *)block_ptr +
|
2005-11-25 16:50:34 +01:00
|
|
|
(sizeof (char) * metadata->str_count));
|
2005-07-15 20:49:12 +02:00
|
|
|
|
2005-08-24 08:21:30 +02:00
|
|
|
return block_ptr;
|
2005-07-15 20:49:12 +02:00
|
|
|
}
|