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
|
2010-11-10 22:45:42 +01:00
|
|
|
* documentation, and that the name of the author(s) not be used in
|
2002-02-15 00:34:13 +01:00
|
|
|
* advertising or publicity pertaining to distribution of the software without
|
2010-11-10 22:45:42 +01:00
|
|
|
* specific, written prior permission. The authors make no
|
2002-02-15 00:34:13 +01:00
|
|
|
* representations about the suitability of this software for any purpose. It
|
|
|
|
* is provided "as is" without express or implied warranty.
|
|
|
|
*
|
2009-03-12 21:00:08 +01:00
|
|
|
* THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
2002-02-15 00:34:13 +01:00
|
|
|
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
2009-03-12 21:00:08 +01:00
|
|
|
* EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR
|
2002-02-15 00:34:13 +01:00
|
|
|
* 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"
|
2008-01-02 17:47:14 +01:00
|
|
|
#include "fcftint.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
|
|
|
|
|
|
|
FcPattern *
|
|
|
|
FcPatternCreate (void)
|
|
|
|
{
|
|
|
|
FcPattern *p;
|
|
|
|
|
|
|
|
p = (FcPattern *) malloc (sizeof (FcPattern));
|
|
|
|
if (!p)
|
|
|
|
return 0;
|
|
|
|
p->num = 0;
|
|
|
|
p->size = 0;
|
2006-08-30 13:16:22 +02:00
|
|
|
p->elts_offset = FcPtrToOffset (p, NULL);
|
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)
|
|
|
|
{
|
2012-12-30 04:11:09 +01:00
|
|
|
switch ((int) v.type) {
|
2002-02-15 00:34:13 +01:00
|
|
|
case FcTypeString:
|
2012-03-28 06:37:15 +02:00
|
|
|
if (!FcSharedStrFree (v.u.s))
|
2005-12-05 17:08:01 +01:00
|
|
|
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)
|
|
|
|
{
|
2006-08-30 13:16:22 +02:00
|
|
|
FcValue new;
|
2005-08-24 08:21:30 +02:00
|
|
|
|
2012-12-30 04:11:09 +01:00
|
|
|
switch ((int) v->type)
|
2006-08-30 13:16:22 +02:00
|
|
|
{
|
|
|
|
case FcTypeString:
|
2009-11-16 21:46:46 +01:00
|
|
|
new.u.s = FcValueString(v);
|
2006-08-30 13:16:22 +02:00
|
|
|
new.type = FcTypeString;
|
|
|
|
break;
|
|
|
|
case FcTypeCharSet:
|
2009-11-16 21:46:46 +01:00
|
|
|
new.u.c = FcValueCharSet(v);
|
2006-08-30 13:16:22 +02:00
|
|
|
new.type = FcTypeCharSet;
|
|
|
|
break;
|
|
|
|
case FcTypeLangSet:
|
2009-11-16 21:46:46 +01:00
|
|
|
new.u.l = FcValueLangSet(v);
|
2006-08-30 13:16:22 +02:00
|
|
|
new.type = FcTypeLangSet;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
new = *v;
|
|
|
|
break;
|
2005-08-24 08:21:30 +02:00
|
|
|
}
|
2006-08-30 13:16:22 +02:00
|
|
|
return new;
|
2005-08-24 08:21:30 +02:00
|
|
|
}
|
|
|
|
|
2002-02-15 00:34:13 +01:00
|
|
|
FcValue
|
|
|
|
FcValueSave (FcValue v)
|
|
|
|
{
|
2012-12-30 04:11:09 +01:00
|
|
|
switch ((int) v.type) {
|
2002-02-15 00:34:13 +01:00
|
|
|
case FcTypeString:
|
2012-03-28 06:37:15 +02:00
|
|
|
v.u.s = FcSharedStr (v.u.s);
|
2005-08-24 08:21:30 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-11-15 08:37:01 +01:00
|
|
|
FcValueListPtr
|
|
|
|
FcValueListCreate (void)
|
|
|
|
{
|
2012-12-30 05:12:07 +01:00
|
|
|
return calloc (1, sizeof (FcValueList));
|
2012-11-15 08:37:01 +01:00
|
|
|
}
|
|
|
|
|
2002-02-15 00:34:13 +01:00
|
|
|
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;
|
2006-08-30 13:16:22 +02:00
|
|
|
for (; l; l = next)
|
2002-02-15 00:34:13 +01:00
|
|
|
{
|
2012-12-30 04:11:09 +01:00
|
|
|
switch ((int) l->value.type) {
|
2002-02-15 00:34:13 +01:00
|
|
|
case FcTypeString:
|
2012-03-28 06:37:15 +02:00
|
|
|
if (!FcSharedStrFree ((FcChar8 *)l->value.u.s))
|
2006-08-30 13:16:22 +02:00
|
|
|
FcStrFree ((FcChar8 *)l->value.u.s);
|
2002-02-15 00:34:13 +01:00
|
|
|
break;
|
|
|
|
case FcTypeMatrix:
|
2006-08-30 13:16:22 +02:00
|
|
|
FcMatrixFree ((FcMatrix *)l->value.u.m);
|
2002-02-15 00:34:13 +01:00
|
|
|
break;
|
|
|
|
case FcTypeCharSet:
|
2010-04-12 18:18:50 +02:00
|
|
|
FcCharSetDestroy
|
2006-08-30 13:16:22 +02:00
|
|
|
((FcCharSet *) (l->value.u.c));
|
2002-02-15 00:34:13 +01:00
|
|
|
break;
|
2002-08-22 09:36:45 +02:00
|
|
|
case FcTypeLangSet:
|
2010-04-12 18:18:50 +02:00
|
|
|
FcLangSetDestroy
|
2006-08-30 13:16:22 +02:00
|
|
|
((FcLangSet *) (l->value.u.l));
|
2002-08-22 09:36:45 +02:00
|
|
|
break;
|
2002-02-15 00:34:13 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2006-08-30 13:16:22 +02:00
|
|
|
next = FcValueListNext(l);
|
|
|
|
free(l);
|
2002-02-15 00:34:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-15 08:37:01 +01:00
|
|
|
FcValueListPtr
|
|
|
|
FcValueListPrepend (FcValueListPtr vallist,
|
|
|
|
FcValue value,
|
|
|
|
FcValueBinding binding)
|
|
|
|
{
|
|
|
|
FcValueListPtr new;
|
|
|
|
|
|
|
|
if (value.type == FcTypeVoid)
|
|
|
|
return vallist;
|
|
|
|
new = FcValueListCreate ();
|
|
|
|
if (!new)
|
|
|
|
return vallist;
|
|
|
|
|
|
|
|
new->value = FcValueSave (value);
|
|
|
|
new->binding = binding;
|
|
|
|
new->next = vallist;
|
|
|
|
|
|
|
|
return new;
|
|
|
|
}
|
|
|
|
|
|
|
|
FcValueListPtr
|
|
|
|
FcValueListAppend (FcValueListPtr vallist,
|
|
|
|
FcValue value,
|
|
|
|
FcValueBinding binding)
|
|
|
|
{
|
|
|
|
FcValueListPtr new, last;
|
|
|
|
|
|
|
|
if (value.type == FcTypeVoid)
|
|
|
|
return vallist;
|
|
|
|
new = FcValueListCreate ();
|
|
|
|
if (!new)
|
|
|
|
return vallist;
|
|
|
|
|
|
|
|
new->value = FcValueSave (value);
|
|
|
|
new->binding = binding;
|
|
|
|
new->next = NULL;
|
|
|
|
|
|
|
|
if (vallist)
|
|
|
|
{
|
|
|
|
for (last = vallist; FcValueListNext (last); last = FcValueListNext (last));
|
|
|
|
|
|
|
|
last->next = new;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
vallist = new;
|
|
|
|
|
|
|
|
return vallist;
|
|
|
|
}
|
|
|
|
|
|
|
|
FcValueListPtr
|
|
|
|
FcValueListDuplicate(FcValueListPtr orig)
|
|
|
|
{
|
|
|
|
FcValueListPtr new = NULL, l, t = NULL;
|
|
|
|
FcValue v;
|
|
|
|
|
|
|
|
for (l = orig; l != NULL; l = FcValueListNext (l))
|
|
|
|
{
|
|
|
|
if (!new)
|
|
|
|
{
|
|
|
|
t = new = FcValueListCreate();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
t->next = FcValueListCreate();
|
|
|
|
t = FcValueListNext (t);
|
|
|
|
}
|
|
|
|
v = FcValueCanonicalize (&l->value);
|
|
|
|
t->value = FcValueSave (v);
|
|
|
|
t->binding = l->binding;
|
|
|
|
t->next = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return new;
|
|
|
|
}
|
|
|
|
|
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;
|
2010-04-12 18:18:50 +02:00
|
|
|
|
2002-06-08 19:32:05 +02:00
|
|
|
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
|
|
|
{
|
2009-11-16 21:43:08 +01:00
|
|
|
switch (v->type) {
|
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:
|
2009-11-16 21:46:46 +01:00
|
|
|
return FcStringHash (FcValueString(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:
|
2010-04-12 18:18:50 +02:00
|
|
|
return (FcDoubleHash (v->u.m->xx) ^
|
|
|
|
FcDoubleHash (v->u.m->xy) ^
|
|
|
|
FcDoubleHash (v->u.m->yx) ^
|
2006-02-07 22:15:33 +01:00
|
|
|
FcDoubleHash (v->u.m->yy));
|
2002-06-08 19:32:05 +02:00
|
|
|
case FcTypeCharSet:
|
2009-11-16 21:46:46 +01:00
|
|
|
return (FcChar32) FcValueCharSet(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:
|
2009-11-16 21:46:46 +01:00
|
|
|
return FcLangSetHash (FcValueLangSet(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
|
|
|
{
|
2006-08-30 13:16:22 +02:00
|
|
|
if (la == lb)
|
2002-08-22 09:36:45 +02:00
|
|
|
return FcTrue;
|
|
|
|
|
2006-08-30 13:16:22 +02:00
|
|
|
while (la && lb)
|
2002-05-22 06:37:07 +02:00
|
|
|
{
|
2006-08-30 13:16:22 +02:00
|
|
|
if (!FcValueEqual (la->value, lb->value))
|
2002-05-22 06:37:07 +02:00
|
|
|
return FcFalse;
|
2006-08-30 13:16:22 +02:00
|
|
|
la = FcValueListNext(la);
|
|
|
|
lb = FcValueListNext(lb);
|
2002-05-22 06:37:07 +02:00
|
|
|
}
|
2006-08-30 13:16:22 +02:00
|
|
|
if (la || 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;
|
2010-04-12 18:18:50 +02:00
|
|
|
|
2006-08-30 13:16:22 +02:00
|
|
|
for (; l; l = FcValueListNext(l))
|
2002-06-08 19:32:05 +02:00
|
|
|
{
|
2006-08-30 13:16:22 +02:00
|
|
|
hash = ((hash << 1) | (hash >> 31)) ^ FcValueHash (&l->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;
|
2006-08-30 13:16:22 +02:00
|
|
|
FcPatternElt *elts;
|
2010-04-12 18:18:50 +02:00
|
|
|
|
2006-09-05 07:20:25 +02:00
|
|
|
if (p->ref == FC_REF_CONSTANT)
|
|
|
|
{
|
|
|
|
FcCacheObjectDereference (p);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (--p->ref > 0)
|
2002-06-19 22:08:22 +02:00
|
|
|
return;
|
|
|
|
|
2006-08-30 13:16:22 +02:00
|
|
|
elts = FcPatternElts (p);
|
2002-02-15 00:34:13 +01:00
|
|
|
for (i = 0; i < p->num; i++)
|
2006-08-30 13:16:22 +02:00
|
|
|
FcValueListDestroy (FcPatternEltValues(&elts[i]));
|
2002-02-15 00:34:13 +01:00
|
|
|
|
2006-08-30 13:16:22 +02:00
|
|
|
free (elts);
|
2002-02-15 00:34:13 +01:00
|
|
|
free (p);
|
|
|
|
}
|
|
|
|
|
2002-06-03 10:31:15 +02:00
|
|
|
static int
|
2006-08-30 13:16:22 +02:00
|
|
|
FcPatternObjectPosition (const FcPattern *p, FcObject object)
|
2002-02-15 00:34:13 +01:00
|
|
|
{
|
2002-06-03 10:31:15 +02:00
|
|
|
int low, high, mid, c;
|
2006-08-30 13:16:22 +02:00
|
|
|
FcPatternElt *elts = FcPatternElts(p);
|
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;
|
2006-08-30 13:16:22 +02:00
|
|
|
c = elts[mid].object - object;
|
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 *
|
2006-08-30 13:16:22 +02:00
|
|
|
FcPatternObjectFindElt (const FcPattern *p, FcObject object)
|
2002-06-03 10:31:15 +02:00
|
|
|
{
|
2006-08-30 13:16:22 +02:00
|
|
|
int i = FcPatternObjectPosition (p, object);
|
2002-06-03 10:31:15 +02:00
|
|
|
if (i < 0)
|
2002-05-22 06:37:07 +02:00
|
|
|
return 0;
|
2006-08-30 13:16:22 +02:00
|
|
|
return &FcPatternElts(p)[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 *
|
2006-08-30 13:16:22 +02:00
|
|
|
FcPatternObjectInsertElt (FcPattern *p, FcObject object)
|
2002-06-03 10:31:15 +02:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
FcPatternElt *e;
|
2010-04-12 18:18:50 +02:00
|
|
|
|
2006-08-30 13:16:22 +02:00
|
|
|
i = FcPatternObjectPosition (p, object);
|
2002-06-03 10:31:15 +02:00
|
|
|
if (i < 0)
|
2002-02-15 00:34:13 +01:00
|
|
|
{
|
2002-06-03 10:31:15 +02:00
|
|
|
i = -i - 1;
|
2010-04-12 18:18:50 +02:00
|
|
|
|
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;
|
2006-08-30 13:16:22 +02:00
|
|
|
if (p->size)
|
2005-06-28 05:41:02 +02:00
|
|
|
{
|
2006-08-30 13:16:22 +02:00
|
|
|
FcPatternElt *e0 = FcPatternElts(p);
|
2005-06-28 05:41:02 +02:00
|
|
|
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;
|
2006-08-30 13:16:22 +02:00
|
|
|
p->elts_offset = FcPtrToOffset (p, e);
|
2002-06-03 10:31:15 +02:00
|
|
|
while (p->size < s)
|
|
|
|
{
|
2006-08-30 13:16:22 +02:00
|
|
|
e[p->size].object = 0;
|
|
|
|
e[p->size].values = NULL;
|
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
|
|
|
|
2006-08-30 13:16:22 +02:00
|
|
|
e = FcPatternElts(p);
|
2002-06-03 10:31:15 +02:00
|
|
|
/* move elts up */
|
2006-08-30 13:16:22 +02:00
|
|
|
memmove (e + i + 1,
|
|
|
|
e + i,
|
2002-06-03 10:31:15 +02:00
|
|
|
sizeof (FcPatternElt) *
|
|
|
|
(p->num - i));
|
2010-04-12 18:18:50 +02:00
|
|
|
|
2002-06-03 10:31:15 +02:00
|
|
|
/* bump count */
|
|
|
|
p->num++;
|
|
|
|
|
2006-08-30 13:16:22 +02:00
|
|
|
e[i].object = object;
|
|
|
|
e[i].values = NULL;
|
2002-02-15 00:34:13 +01:00
|
|
|
}
|
2010-04-12 18:18:50 +02:00
|
|
|
|
2006-08-30 13:16:22 +02:00
|
|
|
return FcPatternElts(p) + 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;
|
2006-08-30 13:16:22 +02:00
|
|
|
FcPatternElt *pae, *pbe;
|
2002-05-22 06:37:07 +02:00
|
|
|
|
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;
|
2006-08-30 13:16:22 +02:00
|
|
|
pae = FcPatternElts(pa);
|
|
|
|
pbe = FcPatternElts(pb);
|
2002-05-22 06:37:07 +02:00
|
|
|
for (i = 0; i < pa->num; i++)
|
|
|
|
{
|
2006-08-30 13:16:22 +02:00
|
|
|
if (pae[i].object != pbe[i].object)
|
2002-05-22 06:37:07 +02:00
|
|
|
return FcFalse;
|
2006-08-30 13:16:22 +02:00
|
|
|
if (!FcValueListEqual (FcPatternEltValues(&pae[i]),
|
|
|
|
FcPatternEltValues(&pbe[i])))
|
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;
|
2006-08-30 13:16:22 +02:00
|
|
|
FcPatternElt *pe = FcPatternElts(p);
|
2002-06-08 19:32:05 +02:00
|
|
|
|
|
|
|
for (i = 0; i < p->num; i++)
|
|
|
|
{
|
2010-04-12 18:18:50 +02:00
|
|
|
h = (((h << 1) | (h >> 31)) ^
|
2006-08-30 13:16:22 +02:00
|
|
|
pe[i].object ^
|
|
|
|
FcValueListHash (FcPatternEltValues(&pe[i])));
|
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;
|
2010-04-12 18:18:50 +02:00
|
|
|
|
2002-06-03 10:31:15 +02:00
|
|
|
for (i = 0; i < os->nobject; i++)
|
|
|
|
{
|
2006-08-30 13:16:22 +02:00
|
|
|
FcObject object = FcObjectFromName (os->objects[i]);
|
|
|
|
ea = FcPatternObjectFindElt (pai, object);
|
|
|
|
eb = FcPatternObjectFindElt (pbi, object);
|
2002-06-03 10:31:15 +02:00
|
|
|
if (ea)
|
|
|
|
{
|
|
|
|
if (!eb)
|
|
|
|
return FcFalse;
|
2006-08-30 13:16:22 +02:00
|
|
|
if (!FcValueListEqual (FcPatternEltValues(ea), FcPatternEltValues(eb)))
|
2002-06-03 10:31:15 +02:00
|
|
|
return FcFalse;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (eb)
|
|
|
|
return FcFalse;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FcTrue;
|
|
|
|
}
|
|
|
|
|
2012-11-15 08:37:01 +01:00
|
|
|
FcBool
|
|
|
|
FcPatternObjectListAdd (FcPattern *p,
|
|
|
|
FcObject object,
|
|
|
|
FcValueListPtr list,
|
|
|
|
FcBool append)
|
|
|
|
{
|
|
|
|
FcPatternElt *e;
|
|
|
|
FcValueListPtr l, *prev;
|
|
|
|
|
|
|
|
if (p->ref == FC_REF_CONSTANT)
|
|
|
|
goto bail0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure the stored type is valid for built-in objects
|
|
|
|
*/
|
|
|
|
for (l = list; l != NULL; l = FcValueListNext (l))
|
|
|
|
{
|
|
|
|
if (!FcObjectValidType (object, l->value.type))
|
|
|
|
{
|
2013-01-02 02:52:14 +01:00
|
|
|
fprintf (stderr,
|
|
|
|
"Fontconfig warning: FcPattern object %s does not accept value", FcObjectName (object));
|
|
|
|
FcValuePrintFile (stderr, l->value);
|
|
|
|
fprintf (stderr, "\n");
|
2012-11-15 08:37:01 +01:00
|
|
|
goto bail0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
e = FcPatternObjectInsertElt (p, object);
|
|
|
|
if (!e)
|
|
|
|
goto bail0;
|
|
|
|
|
|
|
|
if (append)
|
|
|
|
{
|
|
|
|
for (prev = &e->values; *prev; prev = &(*prev)->next)
|
|
|
|
;
|
|
|
|
*prev = list;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (prev = &list; *prev; prev = &(*prev)->next)
|
|
|
|
;
|
|
|
|
*prev = e->values;
|
|
|
|
e->values = list;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FcTrue;
|
|
|
|
|
|
|
|
bail0:
|
|
|
|
return FcFalse;
|
|
|
|
}
|
|
|
|
|
2002-02-15 00:34:13 +01:00
|
|
|
FcBool
|
2006-08-30 13:16:22 +02:00
|
|
|
FcPatternObjectAddWithBinding (FcPattern *p,
|
|
|
|
FcObject 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;
|
2002-02-15 00:34:13 +01:00
|
|
|
|
2002-08-22 09:36:45 +02:00
|
|
|
if (p->ref == FC_REF_CONSTANT)
|
|
|
|
goto bail0;
|
|
|
|
|
2012-11-15 08:37:01 +01:00
|
|
|
new = FcValueListCreate ();
|
2006-08-30 13:16:22 +02:00
|
|
|
if (!new)
|
2002-02-15 00:34:13 +01:00
|
|
|
goto bail0;
|
|
|
|
|
2009-06-05 22:49:07 +02:00
|
|
|
value = FcValueSave (value);
|
2002-02-15 00:34:13 +01:00
|
|
|
if (value.type == FcTypeVoid)
|
|
|
|
goto bail1;
|
|
|
|
|
2006-08-30 13:16:22 +02:00
|
|
|
/*
|
|
|
|
* Make sure the stored type is valid for built-in objects
|
|
|
|
*/
|
|
|
|
if (!FcObjectValidType (object, value.type))
|
2006-09-01 10:15:14 +02:00
|
|
|
{
|
2013-01-02 02:52:14 +01:00
|
|
|
fprintf (stderr,
|
|
|
|
"Fontconfig warning: FcPattern object %s does not accept value",
|
|
|
|
FcObjectName (object));
|
|
|
|
FcValuePrintFile (stderr, value);
|
|
|
|
fprintf (stderr, "\n");
|
2006-08-30 13:16:22 +02:00
|
|
|
goto bail1;
|
2006-09-01 10:15:14 +02:00
|
|
|
}
|
2006-08-30 13:16:22 +02:00
|
|
|
|
|
|
|
new->value = value;
|
|
|
|
new->binding = binding;
|
|
|
|
new->next = NULL;
|
2010-04-12 18:18:50 +02:00
|
|
|
|
2006-08-30 13:16:22 +02:00
|
|
|
e = FcPatternObjectInsertElt (p, object);
|
2002-02-15 00:34:13 +01:00
|
|
|
if (!e)
|
|
|
|
goto bail2;
|
2010-04-12 18:18:50 +02:00
|
|
|
|
2002-02-15 00:34:13 +01:00
|
|
|
if (append)
|
|
|
|
{
|
2006-08-30 13:16:22 +02:00
|
|
|
for (prev = &e->values; *prev; prev = &(*prev)->next)
|
2005-06-28 05:41:02 +02:00
|
|
|
;
|
2002-02-15 00:34:13 +01:00
|
|
|
*prev = new;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-08-30 13:16:22 +02:00
|
|
|
new->next = e->values;
|
2002-02-15 00:34:13 +01:00
|
|
|
e->values = new;
|
|
|
|
}
|
2010-04-12 18:18:50 +02:00
|
|
|
|
2002-02-15 00:34:13 +01:00
|
|
|
return FcTrue;
|
|
|
|
|
2010-04-12 18:18:50 +02:00
|
|
|
bail2:
|
2006-08-30 13:16:22 +02:00
|
|
|
FcValueDestroy (value);
|
2002-02-15 00:34:13 +01:00
|
|
|
bail1:
|
2006-08-30 13:16:22 +02:00
|
|
|
free (new);
|
2002-02-15 00:34:13 +01:00
|
|
|
bail0:
|
|
|
|
return FcFalse;
|
|
|
|
}
|
|
|
|
|
2006-08-30 13:16:22 +02:00
|
|
|
FcBool
|
|
|
|
FcPatternObjectAdd (FcPattern *p, FcObject object, FcValue value, FcBool append)
|
|
|
|
{
|
|
|
|
return FcPatternObjectAddWithBinding (p, object,
|
|
|
|
value, FcValueBindingStrong, append);
|
|
|
|
}
|
|
|
|
|
2002-07-07 01:47:44 +02:00
|
|
|
FcBool
|
|
|
|
FcPatternAdd (FcPattern *p, const char *object, FcValue value, FcBool append)
|
|
|
|
{
|
2006-08-30 13:16:22 +02:00
|
|
|
return FcPatternObjectAddWithBinding (p, FcObjectFromName (object),
|
|
|
|
value, FcValueBindingStrong, append);
|
2002-07-07 01:47:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
FcBool
|
|
|
|
FcPatternAddWeak (FcPattern *p, const char *object, FcValue value, FcBool append)
|
|
|
|
{
|
2006-08-30 13:16:22 +02:00
|
|
|
return FcPatternObjectAddWithBinding (p, FcObjectFromName (object),
|
|
|
|
value, FcValueBindingWeak, append);
|
2002-07-07 01:47:44 +02:00
|
|
|
}
|
|
|
|
|
2002-02-15 00:34:13 +01:00
|
|
|
FcBool
|
2006-08-30 13:16:22 +02:00
|
|
|
FcPatternObjectDel (FcPattern *p, FcObject object)
|
2002-02-15 00:34:13 +01:00
|
|
|
{
|
|
|
|
FcPatternElt *e;
|
|
|
|
|
2006-08-30 13:16:22 +02:00
|
|
|
e = FcPatternObjectFindElt (p, object);
|
2002-02-15 00:34:13 +01:00
|
|
|
if (!e)
|
|
|
|
return FcFalse;
|
|
|
|
|
|
|
|
/* destroy value */
|
|
|
|
FcValueListDestroy (e->values);
|
2010-04-12 18:18:50 +02:00
|
|
|
|
2002-02-15 00:34:13 +01:00
|
|
|
/* shuffle existing ones down */
|
2010-04-12 18:18:50 +02:00
|
|
|
memmove (e, e+1,
|
|
|
|
(FcPatternElts(p) + p->num - (e + 1)) *
|
2005-06-28 05:41:02 +02:00
|
|
|
sizeof (FcPatternElt));
|
2002-02-15 00:34:13 +01:00
|
|
|
p->num--;
|
2006-08-30 13:16:22 +02:00
|
|
|
e = FcPatternElts(p) + p->num;
|
|
|
|
e->object = 0;
|
|
|
|
e->values = NULL;
|
2002-02-15 00:34:13 +01:00
|
|
|
return FcTrue;
|
|
|
|
}
|
|
|
|
|
2006-08-30 13:16:22 +02:00
|
|
|
FcBool
|
|
|
|
FcPatternDel (FcPattern *p, const char *object)
|
|
|
|
{
|
|
|
|
return FcPatternObjectDel (p, FcObjectFromName (object));
|
|
|
|
}
|
2010-04-12 18:18:50 +02:00
|
|
|
|
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
|
|
|
|
2006-08-30 13:16:22 +02:00
|
|
|
e = FcPatternObjectFindElt (p, FcObjectFromName (object));
|
2004-12-04 20:41:10 +01:00
|
|
|
if (!e)
|
|
|
|
return FcFalse;
|
2006-08-30 13:16:22 +02:00
|
|
|
for (prev = &e->values; (l = *prev); prev = &l->next)
|
2004-12-04 20:41:10 +01:00
|
|
|
{
|
|
|
|
if (!id)
|
|
|
|
{
|
2006-08-30 13:16:22 +02:00
|
|
|
*prev = l->next;
|
|
|
|
l->next = NULL;
|
2004-12-04 20:41:10 +01:00
|
|
|
FcValueListDestroy (l);
|
2006-08-30 13:16:22 +02:00
|
|
|
if (!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
|
2006-08-30 13:16:22 +02:00
|
|
|
FcPatternObjectAddInteger (FcPattern *p, FcObject object, int i)
|
2002-02-15 00:34:13 +01:00
|
|
|
{
|
|
|
|
FcValue v;
|
|
|
|
|
|
|
|
v.type = FcTypeInteger;
|
|
|
|
v.u.i = i;
|
2006-08-30 13:16:22 +02:00
|
|
|
return FcPatternObjectAdd (p, object, v, FcTrue);
|
2002-02-15 00:34:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
FcBool
|
2006-08-30 13:16:22 +02:00
|
|
|
FcPatternAddInteger (FcPattern *p, const char *object, int i)
|
|
|
|
{
|
|
|
|
return FcPatternObjectAddInteger (p, FcObjectFromName (object), i);
|
|
|
|
}
|
|
|
|
|
|
|
|
FcBool
|
|
|
|
FcPatternObjectAddDouble (FcPattern *p, FcObject object, double d)
|
2002-02-15 00:34:13 +01:00
|
|
|
{
|
|
|
|
FcValue v;
|
|
|
|
|
|
|
|
v.type = FcTypeDouble;
|
|
|
|
v.u.d = d;
|
2006-08-30 13:16:22 +02:00
|
|
|
return FcPatternObjectAdd (p, object, v, FcTrue);
|
2002-02-15 00:34:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FcBool
|
2006-08-30 13:16:22 +02:00
|
|
|
FcPatternAddDouble (FcPattern *p, const char *object, double d)
|
|
|
|
{
|
|
|
|
return FcPatternObjectAddDouble (p, FcObjectFromName (object), d);
|
|
|
|
}
|
|
|
|
|
|
|
|
FcBool
|
|
|
|
FcPatternObjectAddString (FcPattern *p, FcObject 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;
|
2006-08-30 13:16:22 +02:00
|
|
|
return FcPatternObjectAdd (p, object, v, FcTrue);
|
2005-12-08 06:54:27 +01:00
|
|
|
}
|
|
|
|
|
2002-02-15 00:34:13 +01:00
|
|
|
v.type = FcTypeString;
|
2012-03-28 06:37:15 +02:00
|
|
|
v.u.s = s;
|
2006-08-30 13:16:22 +02:00
|
|
|
return FcPatternObjectAdd (p, object, v, FcTrue);
|
|
|
|
}
|
|
|
|
|
|
|
|
FcBool
|
|
|
|
FcPatternAddString (FcPattern *p, const char *object, const FcChar8 *s)
|
|
|
|
{
|
|
|
|
return FcPatternObjectAddString (p, FcObjectFromName (object), s);
|
2002-02-15 00:34:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2006-08-30 13:16:22 +02:00
|
|
|
FcPatternObjectAddBool (FcPattern *p, FcObject object, FcBool b)
|
2002-02-15 00:34:13 +01:00
|
|
|
{
|
|
|
|
FcValue v;
|
|
|
|
|
|
|
|
v.type = FcTypeBool;
|
|
|
|
v.u.b = b;
|
2006-08-30 13:16:22 +02:00
|
|
|
return FcPatternObjectAdd (p, object, v, FcTrue);
|
|
|
|
}
|
|
|
|
|
|
|
|
FcBool
|
|
|
|
FcPatternAddBool (FcPattern *p, const char *object, FcBool b)
|
|
|
|
{
|
|
|
|
return FcPatternObjectAddBool (p, FcObjectFromName (object), b);
|
2002-02-15 00:34:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2006-08-30 13:16:22 +02:00
|
|
|
FcPatternObjectGet (const FcPattern *p, FcObject 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
|
|
|
|
2006-08-30 13:16:22 +02:00
|
|
|
e = FcPatternObjectFindElt (p, object);
|
2002-02-15 00:34:13 +01:00
|
|
|
if (!e)
|
|
|
|
return FcResultNoMatch;
|
2006-08-30 13:16:22 +02:00
|
|
|
for (l = FcPatternEltValues(e); l; l = FcValueListNext(l))
|
2002-02-15 00:34:13 +01:00
|
|
|
{
|
|
|
|
if (!id)
|
|
|
|
{
|
2006-08-30 13:16:22 +02:00
|
|
|
*v = FcValueCanonicalize(&l->value);
|
2002-02-15 00:34:13 +01:00
|
|
|
return FcResultMatch;
|
|
|
|
}
|
|
|
|
id--;
|
|
|
|
}
|
|
|
|
return FcResultNoId;
|
|
|
|
}
|
|
|
|
|
|
|
|
FcResult
|
2006-08-30 13:16:22 +02:00
|
|
|
FcPatternGet (const FcPattern *p, const char *object, int id, FcValue *v)
|
|
|
|
{
|
|
|
|
return FcPatternObjectGet (p, FcObjectFromName (object), id, v);
|
|
|
|
}
|
|
|
|
|
|
|
|
FcResult
|
|
|
|
FcPatternObjectGetInteger (const FcPattern *p, FcObject object, int id, int *i)
|
2002-02-15 00:34:13 +01:00
|
|
|
{
|
|
|
|
FcValue v;
|
|
|
|
FcResult r;
|
|
|
|
|
2006-08-30 13:16:22 +02:00
|
|
|
r = FcPatternObjectGet (p, object, id, &v);
|
2002-02-15 00:34:13 +01:00
|
|
|
if (r != FcResultMatch)
|
|
|
|
return r;
|
2012-12-30 04:11:09 +01:00
|
|
|
switch ((int) v.type) {
|
2002-02-15 00:34:13 +01:00
|
|
|
case FcTypeDouble:
|
|
|
|
*i = (int) v.u.d;
|
|
|
|
break;
|
|
|
|
case FcTypeInteger:
|
|
|
|
*i = v.u.i;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return FcResultTypeMismatch;
|
|
|
|
}
|
|
|
|
return FcResultMatch;
|
|
|
|
}
|
|
|
|
|
|
|
|
FcResult
|
2006-08-30 13:16:22 +02:00
|
|
|
FcPatternGetInteger (const FcPattern *p, const char *object, int id, int *i)
|
|
|
|
{
|
|
|
|
return FcPatternObjectGetInteger (p, FcObjectFromName (object), id, i);
|
|
|
|
}
|
2010-04-12 18:18:50 +02:00
|
|
|
|
|
|
|
|
2006-08-30 13:16:22 +02:00
|
|
|
FcResult
|
|
|
|
FcPatternObjectGetDouble (const FcPattern *p, FcObject object, int id, double *d)
|
2002-02-15 00:34:13 +01:00
|
|
|
{
|
|
|
|
FcValue v;
|
|
|
|
FcResult r;
|
|
|
|
|
2006-08-30 13:16:22 +02:00
|
|
|
r = FcPatternObjectGet (p, object, id, &v);
|
2002-02-15 00:34:13 +01:00
|
|
|
if (r != FcResultMatch)
|
|
|
|
return r;
|
2012-12-30 04:11:09 +01:00
|
|
|
switch ((int) v.type) {
|
2002-02-15 00:34:13 +01:00
|
|
|
case FcTypeDouble:
|
|
|
|
*d = v.u.d;
|
|
|
|
break;
|
|
|
|
case FcTypeInteger:
|
|
|
|
*d = (double) v.u.i;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return FcResultTypeMismatch;
|
|
|
|
}
|
|
|
|
return FcResultMatch;
|
|
|
|
}
|
|
|
|
|
|
|
|
FcResult
|
2006-08-30 13:16:22 +02:00
|
|
|
FcPatternGetDouble (const FcPattern *p, const char *object, int id, double *d)
|
|
|
|
{
|
|
|
|
return FcPatternObjectGetDouble (p, FcObjectFromName (object), id, d);
|
|
|
|
}
|
|
|
|
|
|
|
|
FcResult
|
|
|
|
FcPatternObjectGetString (const FcPattern *p, FcObject object, int id, FcChar8 ** s)
|
2002-02-15 00:34:13 +01:00
|
|
|
{
|
|
|
|
FcValue v;
|
|
|
|
FcResult r;
|
|
|
|
|
2006-08-30 13:16:22 +02:00
|
|
|
r = FcPatternObjectGet (p, object, id, &v);
|
2002-02-15 00:34:13 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2006-08-30 13:16:22 +02:00
|
|
|
FcResult
|
|
|
|
FcPatternGetString (const FcPattern *p, const char *object, int id, FcChar8 ** s)
|
|
|
|
{
|
|
|
|
return FcPatternObjectGetString (p, FcObjectFromName (object), id, s);
|
|
|
|
}
|
2010-04-12 18:18:50 +02:00
|
|
|
|
2002-02-15 00:34:13 +01:00
|
|
|
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;
|
|
|
|
|
2006-08-30 13:16:22 +02:00
|
|
|
e = FcPatternElts(orig);
|
2005-06-28 05:41:02 +02:00
|
|
|
|
2002-02-15 00:34:13 +01:00
|
|
|
for (i = 0; i < orig->num; i++)
|
|
|
|
{
|
2006-08-30 13:16:22 +02:00
|
|
|
for (l = FcPatternEltValues(e + i); l; l = FcValueListNext(l))
|
2007-03-12 18:21:35 +01:00
|
|
|
{
|
|
|
|
if (!FcPatternObjectAddWithBinding (new, e[i].object,
|
|
|
|
FcValueCanonicalize(&l->value),
|
|
|
|
l->binding,
|
|
|
|
FcTrue))
|
2002-02-15 00:34:13 +01:00
|
|
|
goto bail1;
|
2010-04-12 18:18:50 +02:00
|
|
|
|
2007-03-12 18:21:35 +01:00
|
|
|
}
|
2002-02-15 00:34:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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++;
|
2006-09-05 07:20:25 +02:00
|
|
|
else
|
|
|
|
FcCacheObjectReference (p);
|
2002-06-19 22:08:22 +02:00
|
|
|
}
|
|
|
|
|
2002-02-15 00:34:13 +01:00
|
|
|
FcPattern *
|
2008-08-14 21:27:16 +02:00
|
|
|
FcPatternVaBuild (FcPattern *p, va_list va)
|
2002-02-15 00:34:13 +01:00
|
|
|
{
|
|
|
|
FcPattern *ret;
|
2010-04-12 18:18:50 +02:00
|
|
|
|
2008-08-14 21:27:16 +02:00
|
|
|
FcPatternVapBuild (ret, p, va);
|
2002-02-15 00:34:13 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
FcPattern *
|
2008-08-14 21:27:16 +02:00
|
|
|
FcPatternBuild (FcPattern *p, ...)
|
2002-02-15 00:34:13 +01:00
|
|
|
{
|
|
|
|
va_list va;
|
2010-04-12 18:18:50 +02:00
|
|
|
|
2008-08-14 21:27:16 +02:00
|
|
|
va_start (va, p);
|
|
|
|
FcPatternVapBuild (p, p, va);
|
2002-02-15 00:34:13 +01:00
|
|
|
va_end (va);
|
2008-08-14 21:27:16 +02:00
|
|
|
return p;
|
2002-02-15 00:34:13 +01:00
|
|
|
}
|
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;
|
2010-04-12 18:18:50 +02:00
|
|
|
|
2004-12-04 20:41:10 +01:00
|
|
|
for (i = 0; i < s->num; i++)
|
|
|
|
{
|
2006-08-30 13:16:22 +02:00
|
|
|
e = FcPatternElts(s)+i;
|
|
|
|
for (v = FcPatternEltValues(e); v; v = FcValueListNext(v))
|
2004-12-04 20:41:10 +01:00
|
|
|
{
|
2006-08-30 13:16:22 +02:00
|
|
|
if (!FcPatternObjectAddWithBinding (p, e->object,
|
2010-04-12 18:18:50 +02:00
|
|
|
FcValueCanonicalize(&v->value),
|
2006-08-30 13:16:22 +02:00
|
|
|
v->binding, FcTrue))
|
2004-12-04 20:41:10 +01:00
|
|
|
return FcFalse;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FcTrue;
|
|
|
|
}
|
|
|
|
|
2008-08-13 08:50:35 +02:00
|
|
|
FcPattern *
|
|
|
|
FcPatternFilter (FcPattern *p, const FcObjectSet *os)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
FcPattern *ret;
|
|
|
|
FcPatternElt *e;
|
|
|
|
FcValueListPtr v;
|
|
|
|
|
|
|
|
if (!os)
|
|
|
|
return FcPatternDuplicate (p);
|
|
|
|
|
|
|
|
ret = FcPatternCreate ();
|
|
|
|
if (!ret)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
for (i = 0; i < os->nobject; i++)
|
|
|
|
{
|
|
|
|
FcObject object = FcObjectFromName (os->objects[i]);
|
|
|
|
e = FcPatternObjectFindElt (p, object);
|
|
|
|
if (e)
|
|
|
|
{
|
|
|
|
for (v = FcPatternEltValues(e); v; v = FcValueListNext(v))
|
|
|
|
{
|
|
|
|
if (!FcPatternObjectAddWithBinding (ret, e->object,
|
|
|
|
FcValueCanonicalize(&v->value),
|
|
|
|
v->binding, FcTrue))
|
|
|
|
goto bail0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-01-16 01:12:27 +01:00
|
|
|
return ret;
|
2008-08-13 08:50:35 +02:00
|
|
|
|
|
|
|
bail0:
|
|
|
|
FcPatternDestroy (ret);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-03-28 06:38:53 +02:00
|
|
|
#define OBJECT_HASH_SIZE 251
|
2005-09-11 04:16:09 +02:00
|
|
|
static struct objectBucket {
|
2005-08-24 08:21:30 +02:00
|
|
|
struct objectBucket *next;
|
|
|
|
FcChar32 hash;
|
2012-03-28 06:37:15 +02:00
|
|
|
int ref_count;
|
2005-09-11 04:16:09 +02:00
|
|
|
} *FcObjectBuckets[OBJECT_HASH_SIZE];
|
2005-08-24 08:21:30 +02:00
|
|
|
|
2012-03-28 06:37:15 +02:00
|
|
|
FcBool
|
|
|
|
FcSharedStrFree (const FcChar8 *name)
|
2005-12-05 17:08:01 +01:00
|
|
|
{
|
|
|
|
FcChar32 hash = FcStringHash (name);
|
|
|
|
struct objectBucket **p;
|
|
|
|
struct objectBucket *b;
|
2012-03-28 06:37:15 +02:00
|
|
|
int size;
|
2005-12-05 17:08:01 +01:00
|
|
|
|
|
|
|
for (p = &FcObjectBuckets[hash % OBJECT_HASH_SIZE]; (b = *p); p = &(b->next))
|
2008-09-23 00:16:30 +02:00
|
|
|
if (b->hash == hash && ((char *)name == (char *) (b + 1)))
|
2012-03-28 06:37:15 +02:00
|
|
|
{
|
|
|
|
b->ref_count--;
|
|
|
|
if (!b->ref_count)
|
|
|
|
{
|
|
|
|
*p = b->next;
|
|
|
|
size = sizeof (struct objectBucket) + strlen ((char *)name) + 1;
|
2012-06-01 12:06:17 +02:00
|
|
|
size = (size + 3) & ~3;
|
2012-03-28 06:37:15 +02:00
|
|
|
free (b);
|
|
|
|
}
|
2005-12-05 17:08:01 +01:00
|
|
|
return FcTrue;
|
2012-03-28 06:37:15 +02:00
|
|
|
}
|
2005-12-05 17:08:01 +01:00
|
|
|
return FcFalse;
|
|
|
|
}
|
|
|
|
|
2005-09-11 04:16:09 +02:00
|
|
|
const FcChar8 *
|
2012-03-28 06:37:15 +02:00
|
|
|
FcSharedStr (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)))
|
2012-03-28 06:37:15 +02:00
|
|
|
{
|
|
|
|
b->ref_count++;
|
2005-09-11 04:16:09 +02:00
|
|
|
return (FcChar8 *) (b + 1);
|
2012-03-28 06:37:15 +02:00
|
|
|
}
|
2005-09-11 04:16:09 +02:00
|
|
|
size = sizeof (struct objectBucket) + strlen ((char *)name) + 1;
|
2011-03-28 22:33:12 +02:00
|
|
|
/*
|
|
|
|
* workaround valgrind warning because glibc takes advantage of how it knows memory is
|
|
|
|
* allocated to implement strlen by reading in groups of 4
|
|
|
|
*/
|
|
|
|
size = (size + 3) & ~3;
|
|
|
|
b = malloc (size);
|
2005-08-24 08:21:30 +02:00
|
|
|
if (!b)
|
|
|
|
return NULL;
|
|
|
|
b->next = 0;
|
|
|
|
b->hash = hash;
|
2012-03-28 06:37:15 +02:00
|
|
|
b->ref_count = 1;
|
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
|
|
|
}
|
|
|
|
|
2006-08-30 13:16:22 +02:00
|
|
|
FcBool
|
|
|
|
FcPatternSerializeAlloc (FcSerialize *serialize, const FcPattern *pat)
|
2005-08-24 08:21:30 +02:00
|
|
|
{
|
2006-08-30 13:16:22 +02:00
|
|
|
int i;
|
|
|
|
FcPatternElt *elts = FcPatternElts(pat);
|
2010-04-12 18:18:50 +02:00
|
|
|
|
2006-08-30 13:16:22 +02:00
|
|
|
if (!FcSerializeAlloc (serialize, pat, sizeof (FcPattern)))
|
|
|
|
return FcFalse;
|
|
|
|
if (!FcSerializeAlloc (serialize, elts, pat->num * sizeof (FcPatternElt)))
|
|
|
|
return FcFalse;
|
|
|
|
for (i = 0; i < pat->num; i++)
|
|
|
|
if (!FcValueListSerializeAlloc (serialize, FcPatternEltValues(elts+i)))
|
|
|
|
return FcFalse;
|
|
|
|
return FcTrue;
|
2005-08-24 08:21:30 +02:00
|
|
|
}
|
|
|
|
|
2005-06-28 05:41:02 +02:00
|
|
|
FcPattern *
|
2006-08-30 13:16:22 +02:00
|
|
|
FcPatternSerialize (FcSerialize *serialize, const FcPattern *pat)
|
2005-06-28 05:41:02 +02:00
|
|
|
{
|
2006-08-30 13:16:22 +02:00
|
|
|
FcPattern *pat_serialized;
|
|
|
|
FcPatternElt *elts = FcPatternElts (pat);
|
|
|
|
FcPatternElt *elts_serialized;
|
|
|
|
FcValueList *values_serialized;
|
|
|
|
int i;
|
2005-07-25 06:10:09 +02:00
|
|
|
|
2006-08-30 13:16:22 +02:00
|
|
|
pat_serialized = FcSerializePtr (serialize, pat);
|
|
|
|
if (!pat_serialized)
|
|
|
|
return NULL;
|
|
|
|
*pat_serialized = *pat;
|
|
|
|
pat_serialized->size = pat->num;
|
|
|
|
pat_serialized->ref = FC_REF_CONSTANT;
|
2010-04-12 18:18:50 +02:00
|
|
|
|
2006-08-30 13:16:22 +02:00
|
|
|
elts_serialized = FcSerializePtr (serialize, elts);
|
|
|
|
if (!elts_serialized)
|
|
|
|
return NULL;
|
2010-04-12 18:18:50 +02:00
|
|
|
|
2006-08-30 13:16:22 +02:00
|
|
|
pat_serialized->elts_offset = FcPtrToOffset (pat_serialized,
|
|
|
|
elts_serialized);
|
2005-07-25 06:10:09 +02:00
|
|
|
|
2006-08-30 13:16:22 +02:00
|
|
|
for (i = 0; i < pat->num; i++)
|
2005-06-28 05:41:02 +02:00
|
|
|
{
|
2006-08-30 13:16:22 +02:00
|
|
|
values_serialized = FcValueListSerialize (serialize, FcPatternEltValues (elts+i));
|
|
|
|
if (!values_serialized)
|
|
|
|
return NULL;
|
|
|
|
elts_serialized[i].object = elts[i].object;
|
2010-04-12 18:18:50 +02:00
|
|
|
elts_serialized[i].values = FcPtrToEncodedOffset (&elts_serialized[i],
|
2006-08-30 13:16:22 +02:00
|
|
|
values_serialized,
|
|
|
|
FcValueList);
|
2005-06-28 05:41:02 +02:00
|
|
|
}
|
2006-08-30 22:51:03 +02:00
|
|
|
if (FcDebug() & FC_DBG_CACHEV) {
|
|
|
|
printf ("Raw pattern:\n");
|
|
|
|
FcPatternPrint (pat);
|
|
|
|
printf ("Serialized pattern:\n");
|
|
|
|
FcPatternPrint (pat_serialized);
|
|
|
|
printf ("\n");
|
|
|
|
}
|
2006-08-30 13:16:22 +02:00
|
|
|
return pat_serialized;
|
2005-08-24 08:21:30 +02:00
|
|
|
}
|
2005-07-25 06:10:09 +02:00
|
|
|
|
2006-08-30 13:16:22 +02:00
|
|
|
FcBool
|
|
|
|
FcValueListSerializeAlloc (FcSerialize *serialize, const FcValueList *vl)
|
2005-08-24 08:21:30 +02:00
|
|
|
{
|
2006-08-30 13:16:22 +02:00
|
|
|
while (vl)
|
2005-07-25 06:10:09 +02:00
|
|
|
{
|
2006-08-30 13:16:22 +02:00
|
|
|
if (!FcSerializeAlloc (serialize, vl, sizeof (FcValueList)))
|
|
|
|
return FcFalse;
|
2012-12-30 04:11:09 +01:00
|
|
|
switch ((int) vl->value.type) {
|
2006-08-30 13:16:22 +02:00
|
|
|
case FcTypeString:
|
|
|
|
if (!FcStrSerializeAlloc (serialize, vl->value.u.s))
|
|
|
|
return FcFalse;
|
|
|
|
break;
|
2005-08-24 08:21:30 +02:00
|
|
|
case FcTypeCharSet:
|
2006-08-30 13:16:22 +02:00
|
|
|
if (!FcCharSetSerializeAlloc (serialize, vl->value.u.c))
|
|
|
|
return FcFalse;
|
2005-08-24 08:21:30 +02:00
|
|
|
break;
|
|
|
|
case FcTypeLangSet:
|
2006-08-30 13:16:22 +02:00
|
|
|
if (!FcLangSetSerializeAlloc (serialize, vl->value.u.l))
|
|
|
|
return FcFalse;
|
2005-08-24 08:21:30 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2006-08-30 13:16:22 +02:00
|
|
|
vl = vl->next;
|
2005-08-24 08:21:30 +02:00
|
|
|
}
|
2005-07-25 06:10:09 +02:00
|
|
|
return FcTrue;
|
|
|
|
}
|
|
|
|
|
2006-08-30 13:16:22 +02:00
|
|
|
FcValueList *
|
|
|
|
FcValueListSerialize (FcSerialize *serialize, const FcValueList *vl)
|
2005-07-25 06:10:09 +02:00
|
|
|
{
|
2006-08-30 13:16:22 +02:00
|
|
|
FcValueList *vl_serialized;
|
|
|
|
FcChar8 *s_serialized;
|
|
|
|
FcCharSet *c_serialized;
|
|
|
|
FcLangSet *l_serialized;
|
|
|
|
FcValueList *head_serialized = NULL;
|
|
|
|
FcValueList *prev_serialized = NULL;
|
2005-08-24 08:21:30 +02:00
|
|
|
|
2006-08-30 13:16:22 +02:00
|
|
|
while (vl)
|
2005-07-07 14:09:10 +02:00
|
|
|
{
|
2006-08-30 13:16:22 +02:00
|
|
|
vl_serialized = FcSerializePtr (serialize, vl);
|
|
|
|
if (!vl_serialized)
|
|
|
|
return NULL;
|
2010-04-12 18:18:50 +02:00
|
|
|
|
2006-08-30 13:16:22 +02:00
|
|
|
if (prev_serialized)
|
|
|
|
prev_serialized->next = FcPtrToEncodedOffset (prev_serialized,
|
|
|
|
vl_serialized,
|
|
|
|
FcValueList);
|
|
|
|
else
|
|
|
|
head_serialized = vl_serialized;
|
|
|
|
|
|
|
|
vl_serialized->next = NULL;
|
2006-12-02 22:04:05 +01:00
|
|
|
vl_serialized->value.type = vl->value.type;
|
2012-12-30 04:11:09 +01:00
|
|
|
switch ((int) vl->value.type) {
|
2006-12-02 22:04:05 +01:00
|
|
|
case FcTypeInteger:
|
|
|
|
vl_serialized->value.u.i = vl->value.u.i;
|
|
|
|
break;
|
|
|
|
case FcTypeDouble:
|
|
|
|
vl_serialized->value.u.d = vl->value.u.d;
|
|
|
|
break;
|
2006-08-30 13:16:22 +02:00
|
|
|
case FcTypeString:
|
|
|
|
s_serialized = FcStrSerialize (serialize, vl->value.u.s);
|
|
|
|
if (!s_serialized)
|
|
|
|
return NULL;
|
|
|
|
vl_serialized->value.u.s = FcPtrToEncodedOffset (&vl_serialized->value,
|
|
|
|
s_serialized,
|
|
|
|
FcChar8);
|
|
|
|
break;
|
2006-12-02 22:04:05 +01:00
|
|
|
case FcTypeBool:
|
|
|
|
vl_serialized->value.u.b = vl->value.u.b;
|
|
|
|
break;
|
|
|
|
case FcTypeMatrix:
|
|
|
|
/* can't happen */
|
|
|
|
break;
|
2006-08-30 13:16:22 +02:00
|
|
|
case FcTypeCharSet:
|
|
|
|
c_serialized = FcCharSetSerialize (serialize, vl->value.u.c);
|
|
|
|
if (!c_serialized)
|
|
|
|
return NULL;
|
|
|
|
vl_serialized->value.u.c = FcPtrToEncodedOffset (&vl_serialized->value,
|
|
|
|
c_serialized,
|
|
|
|
FcCharSet);
|
|
|
|
break;
|
2006-12-02 22:04:05 +01:00
|
|
|
case FcTypeFTFace:
|
|
|
|
/* can't happen */
|
|
|
|
break;
|
2006-08-30 13:16:22 +02:00
|
|
|
case FcTypeLangSet:
|
|
|
|
l_serialized = FcLangSetSerialize (serialize, vl->value.u.l);
|
|
|
|
if (!l_serialized)
|
|
|
|
return NULL;
|
|
|
|
vl_serialized->value.u.l = FcPtrToEncodedOffset (&vl_serialized->value,
|
|
|
|
l_serialized,
|
|
|
|
FcLangSet);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2005-07-07 14:09:10 +02:00
|
|
|
}
|
2006-08-31 18:07:32 +02:00
|
|
|
prev_serialized = vl_serialized;
|
2006-08-30 13:16:22 +02:00
|
|
|
vl = vl->next;
|
2005-07-07 14:09:10 +02:00
|
|
|
}
|
2006-08-30 13:16:22 +02:00
|
|
|
return head_serialized;
|
2005-07-15 20:49:12 +02:00
|
|
|
}
|
2006-09-05 11:24:01 +02:00
|
|
|
#define __fcpat__
|
|
|
|
#include "fcaliastail.h"
|
2008-01-08 01:31:06 +01:00
|
|
|
#include "fcftaliastail.h"
|
2006-09-05 11:24:01 +02:00
|
|
|
#undef __fcpat__
|