Bug 43367 - RFE: iterator to peek objects in FcPattern
Add various APIs to obtain things in FcPattern through the iterator https://bugs.freedesktop.org/show_bug.cgi?id=43367
This commit is contained in:
parent
454923709a
commit
307639cff1
|
@ -57,6 +57,15 @@ Decrement the pattern reference count. If all references are gone, destroys
|
|||
the pattern, in the process destroying all related values.
|
||||
@@
|
||||
|
||||
@RET@ int
|
||||
@FUNC@ FcPatternObjectCount
|
||||
@TYPE1@ const FcPattern * @ARG1@ p
|
||||
@PURPOSE@ Returns the number of the object
|
||||
@DESC@
|
||||
Returns the number of the object <parameter>p</parameter> has.
|
||||
@SINCE@ 2.13.1
|
||||
@@
|
||||
|
||||
@RET@ FcBool
|
||||
@FUNC@ FcPatternEqual
|
||||
@TYPE1@ const FcPattern * @ARG1@ pa
|
||||
|
@ -383,7 +392,107 @@ whether the property existed or not.
|
|||
Removes the value associated with the property `object' at position `id', returning
|
||||
whether the property existed and had a value at that position or not.
|
||||
@@
|
||||
|
||||
|
||||
@RET@ void
|
||||
@FUNC@ FcPatternIterStart
|
||||
@TYPE1@ const FcPattern * @ARG1@ p
|
||||
@TYPE2@ FcPatternIter * @ARG2@ iter
|
||||
@PURPOSE@ Initialize the iterator with the first iterator in the pattern
|
||||
@DESC@
|
||||
Initialize <parameter>iter</parameter> with the first iterator in <parameter>p</parameter>.
|
||||
If there are no objects in <parameter>p</parameter>, <parameter>iter</parameter>
|
||||
will not have any valid data.
|
||||
@SINCE@ 2.13.1
|
||||
@@
|
||||
|
||||
@RET@ FcBool
|
||||
@FUNC@ FcPatternIterNext
|
||||
@TYPE1@ const FcPattern * @ARG1@ p
|
||||
@TYPE2@ FcPatternIter * @ARG2@ iter
|
||||
@PURPUSE@ Set the iterator to point to the next object in the pattern
|
||||
@DESC@
|
||||
Set <parameter>iter</parameter> to point to the next object in <parameter>p</parameter>
|
||||
and returns FcTrue if <parameter>iter</parameter> has been changed to the next object.
|
||||
returns FcFalse otherwise.
|
||||
@SINCE@ 2.13.1
|
||||
@@
|
||||
|
||||
@RET@ FcBool
|
||||
@FUNC@ FcPatternIterEqual
|
||||
@TYPE1@ const FcPattern * @ARG1@ p1
|
||||
@TYPE2@ FcPatternIter * @ARG2@ i1
|
||||
@TYPE3@ const FcPattern * @ARG3@ p2
|
||||
@TYPE4@ FcPatternIter * @ARG4@ i2
|
||||
@PURPOSE@ Compare iterators
|
||||
@DESC@
|
||||
Return FcTrue if both <parameter>i1</parameter> and <parameter>i2</parameter>
|
||||
point to same object and contains same values. return FcFalse otherwise.
|
||||
@SINCE@ 2.13.1
|
||||
@@
|
||||
|
||||
@RET@ FcBool
|
||||
@FUNC@ FcPatternFindIter
|
||||
@TYPE1@ const FcPattern * @ARG1@ p
|
||||
@TYPE2@ FcPatternIter * @ARG2@ iter
|
||||
@TYPE3@ const char * @ARG3@ object
|
||||
@PURPOSE@ Set the iterator to point to the object in the pattern
|
||||
@DESC@
|
||||
Set <parameter>iter</parameter> to point to <parameter>object</parameter> in
|
||||
<parameter>p</parameter> if any and returns FcTrue. returns FcFalse otherwise.
|
||||
@SINCE@ 2.13.1
|
||||
@@
|
||||
|
||||
@RET@ FcBool
|
||||
@FUNC@ FcPatternIterIsValid
|
||||
@TYPE1@ const FcPattern * @ARG1@ p
|
||||
@TYPE2@ FcPatternIter : @ARG2@ iter
|
||||
@PURPOSE@ Check whether the iterator is valid or not
|
||||
@DESC@
|
||||
Returns FcTrue if <parameter>iter</parameter> point to the valid entry
|
||||
in <parameter>p</parameter>. returns FcFalse otherwise.
|
||||
@SINCE@ 2.13.1
|
||||
@@
|
||||
|
||||
@RET@ const char *
|
||||
@FUNC@ FcPatternIterGetObject
|
||||
@TYPE1@ const FcPattern * @ARG1@ p
|
||||
@TYPE2@ FcPatternIter * @ARG2@ iter
|
||||
@PURPOSE@ Returns an object name which the iterator point to
|
||||
@DESC@
|
||||
Returns an object name in <parameter>p</parameter> which
|
||||
<parameter>iter</parameter> point to. returns NULL if
|
||||
<parameter>iter</parameter> isn't valid.
|
||||
@SINCE@ 2.13.1
|
||||
@@
|
||||
|
||||
@RET@ int
|
||||
@FUNC@ FcPatternIterValueCount
|
||||
@TYPE1@ const FcPattern * @ARG1@ p
|
||||
@TYPE2@ FcPatternIter * @ARG2@ iter
|
||||
@PURPOSE@ Returns the number of the values which the iterator point to
|
||||
@DESC@
|
||||
Returns the number of the values in the object which <parameter>iter</parameter>
|
||||
point to. if <parameter>iter</parameter> isn't valid, returns 0.
|
||||
@SINCE@ 2.13.1
|
||||
@@
|
||||
|
||||
@RET@ FcResult
|
||||
@FUNC@ FcPatternIterGetValue
|
||||
@TYPE1@ const FcPattern * @ARG1@ p
|
||||
@TYPE2@ FcPatternIter * @ARG2@ iter
|
||||
@TYPE3@ int @ARG3@ id
|
||||
@TYPE4@ FcValue * @ARG4@ v
|
||||
@TYPE5@ FcValueBinding * @ARG5@ b
|
||||
@PURPOSE@ Returns a value which the iterator point to
|
||||
@DESC@
|
||||
Returns in <parameter>v</parameter> the <parameter>id</parameter>'th value
|
||||
which <parameter>iter</parameter> point to. also binding to <parameter>b</parameter>
|
||||
if given.
|
||||
The value returned is not a copy, but rather refers to the data stored
|
||||
within the pattern directly. Applications must not free this value.
|
||||
@SINCE@ 2.13.1
|
||||
@@
|
||||
|
||||
@RET@ void
|
||||
@FUNC@ FcPatternPrint
|
||||
@TYPE1@ const FcPattern * @ARG1@ p
|
||||
|
|
|
@ -248,6 +248,11 @@ typedef enum _FcValueBinding {
|
|||
|
||||
typedef struct _FcPattern FcPattern;
|
||||
|
||||
typedef struct _FcPatternIter {
|
||||
void *dummy1;
|
||||
void *dummy2;
|
||||
} FcPatternIter;
|
||||
|
||||
typedef struct _FcLangSet FcLangSet;
|
||||
|
||||
typedef struct _FcRange FcRange;
|
||||
|
@ -861,6 +866,9 @@ FcValueSave (FcValue v);
|
|||
FcPublic void
|
||||
FcPatternDestroy (FcPattern *p);
|
||||
|
||||
int
|
||||
FcPatternObjectCount (const FcPattern *pat);
|
||||
|
||||
FcPublic FcBool
|
||||
FcPatternEqual (const FcPattern *pa, const FcPattern *pb);
|
||||
|
||||
|
@ -961,6 +969,31 @@ FcRangeCopy (const FcRange *r);
|
|||
FcPublic FcBool
|
||||
FcRangeGetDouble(const FcRange *range, double *begin, double *end);
|
||||
|
||||
FcPublic void
|
||||
FcPatternIterStart (const FcPattern *pat, FcPatternIter *iter);
|
||||
|
||||
FcPublic FcBool
|
||||
FcPatternIterNext (const FcPattern *pat, FcPatternIter *iter);
|
||||
|
||||
FcPublic FcBool
|
||||
FcPatternIterEqual (const FcPattern *p1, FcPatternIter *i1,
|
||||
const FcPattern *p2, FcPatternIter *i2);
|
||||
|
||||
FcPublic FcBool
|
||||
FcPatternFindIter (const FcPattern *pat, FcPatternIter *iter, const char *object);
|
||||
|
||||
FcPublic FcBool
|
||||
FcPatternIterIsValid (const FcPattern *pat, FcPatternIter *iter);
|
||||
|
||||
FcPublic const char *
|
||||
FcPatternIterGetObject (const FcPattern *pat, FcPatternIter *iter);
|
||||
|
||||
FcPublic int
|
||||
FcPatternIterValueCount (const FcPattern *pat, FcPatternIter *iter);
|
||||
|
||||
FcPublic FcResult
|
||||
FcPatternIterGetValue (const FcPattern *pat, FcPatternIter *iter, int id, FcValue *v, FcValueBinding *b);
|
||||
|
||||
/* fcweight.c */
|
||||
|
||||
FcPublic int
|
||||
|
|
15
src/fcdbg.c
15
src/fcdbg.c
|
@ -187,22 +187,21 @@ FcCharSetPrint (const FcCharSet *c)
|
|||
void
|
||||
FcPatternPrint (const FcPattern *p)
|
||||
{
|
||||
int i;
|
||||
FcPatternElt *e;
|
||||
FcPatternIter iter;
|
||||
|
||||
if (!p)
|
||||
{
|
||||
printf ("Null pattern\n");
|
||||
return;
|
||||
}
|
||||
printf ("Pattern has %d elts (size %d)\n", p->num, p->size);
|
||||
for (i = 0; i < p->num; i++)
|
||||
printf ("Pattern has %d elts (size %d)\n", FcPatternObjectCount (p), p->size);
|
||||
FcPatternIterStart (p, &iter);
|
||||
do
|
||||
{
|
||||
e = &FcPatternElts(p)[i];
|
||||
printf ("\t%s:", FcObjectName(e->object));
|
||||
FcValueListPrint (FcPatternEltValues(e));
|
||||
printf ("\t%s:", FcPatternIterGetObject (p, &iter));
|
||||
FcValueListPrint (FcPatternIterGetValues (p, &iter));
|
||||
printf ("\n");
|
||||
}
|
||||
} while (FcPatternIterNext (p, &iter));
|
||||
printf ("\n");
|
||||
}
|
||||
|
||||
|
|
|
@ -238,21 +238,22 @@ FcDefaultFini (void)
|
|||
void
|
||||
FcDefaultSubstitute (FcPattern *pattern)
|
||||
{
|
||||
FcPatternIter iter;
|
||||
FcValue v, namelang, v2;
|
||||
int i;
|
||||
double dpi, size, scale, pixelsize;
|
||||
|
||||
if (FcPatternObjectGet (pattern, FC_WEIGHT_OBJECT, 0, &v) == FcResultNoMatch )
|
||||
if (!FcPatternFindObjectIter (pattern, &iter, FC_WEIGHT_OBJECT))
|
||||
FcPatternObjectAddInteger (pattern, FC_WEIGHT_OBJECT, FC_WEIGHT_NORMAL);
|
||||
|
||||
if (FcPatternObjectGet (pattern, FC_SLANT_OBJECT, 0, &v) == FcResultNoMatch)
|
||||
if (!FcPatternFindObjectIter (pattern, &iter, FC_SLANT_OBJECT))
|
||||
FcPatternObjectAddInteger (pattern, FC_SLANT_OBJECT, FC_SLANT_ROMAN);
|
||||
|
||||
if (FcPatternObjectGet (pattern, FC_WIDTH_OBJECT, 0, &v) == FcResultNoMatch)
|
||||
if (!FcPatternFindObjectIter (pattern, &iter, FC_WIDTH_OBJECT))
|
||||
FcPatternObjectAddInteger (pattern, FC_WIDTH_OBJECT, FC_WIDTH_NORMAL);
|
||||
|
||||
for (i = 0; i < NUM_FC_BOOL_DEFAULTS; i++)
|
||||
if (FcPatternObjectGet (pattern, FcBoolDefaults[i].field, 0, &v) == FcResultNoMatch)
|
||||
if (!FcPatternFindObjectIter (pattern, &iter, FcBoolDefaults[i].field))
|
||||
FcPatternObjectAddBool (pattern, FcBoolDefaults[i].field, FcBoolDefaults[i].value);
|
||||
|
||||
if (FcPatternObjectGetDouble (pattern, FC_SIZE_OBJECT, 0, &size) != FcResultMatch)
|
||||
|
@ -269,7 +270,7 @@ FcDefaultSubstitute (FcPattern *pattern)
|
|||
if (FcPatternObjectGetDouble (pattern, FC_DPI_OBJECT, 0, &dpi) != FcResultMatch)
|
||||
dpi = 75.0;
|
||||
|
||||
if (FcPatternObjectGet (pattern, FC_PIXEL_SIZE_OBJECT, 0, &v) != FcResultMatch)
|
||||
if (!FcPatternFindObjectIter (pattern, &iter, FC_PIXEL_SIZE_OBJECT))
|
||||
{
|
||||
(void) FcPatternObjectDel (pattern, FC_SCALE_OBJECT);
|
||||
FcPatternObjectAddDouble (pattern, FC_SCALE_OBJECT, scale);
|
||||
|
@ -281,25 +282,22 @@ FcDefaultSubstitute (FcPattern *pattern)
|
|||
}
|
||||
else
|
||||
{
|
||||
FcPatternIterGetValue(pattern, &iter, 0, &v, NULL);
|
||||
size = v.u.d;
|
||||
size = size / dpi * 72.0 / scale;
|
||||
}
|
||||
(void) FcPatternObjectDel (pattern, FC_SIZE_OBJECT);
|
||||
FcPatternObjectAddDouble (pattern, FC_SIZE_OBJECT, size);
|
||||
|
||||
if (FcPatternObjectGet (pattern, FC_FONTVERSION_OBJECT, 0, &v) == FcResultNoMatch)
|
||||
{
|
||||
if (!FcPatternFindObjectIter (pattern, &iter, FC_FONTVERSION_OBJECT))
|
||||
FcPatternObjectAddInteger (pattern, FC_FONTVERSION_OBJECT, 0x7fffffff);
|
||||
}
|
||||
|
||||
if (FcPatternObjectGet (pattern, FC_HINT_STYLE_OBJECT, 0, &v) == FcResultNoMatch)
|
||||
{
|
||||
if (!FcPatternFindObjectIter (pattern, &iter, FC_HINT_STYLE_OBJECT))
|
||||
FcPatternObjectAddInteger (pattern, FC_HINT_STYLE_OBJECT, FC_HINT_FULL);
|
||||
}
|
||||
if (FcPatternObjectGet (pattern, FC_NAMELANG_OBJECT, 0, &v) == FcResultNoMatch)
|
||||
{
|
||||
|
||||
if (!FcPatternFindObjectIter (pattern, &iter, FC_NAMELANG_OBJECT))
|
||||
FcPatternObjectAddString (pattern, FC_NAMELANG_OBJECT, FcGetDefaultLang ());
|
||||
}
|
||||
|
||||
/* shouldn't be failed. */
|
||||
FcPatternObjectGet (pattern, FC_NAMELANG_OBJECT, 0, &namelang);
|
||||
/* Add a fallback to ensure the english name when the requested language
|
||||
|
@ -315,17 +313,17 @@ FcDefaultSubstitute (FcPattern *pattern)
|
|||
*/
|
||||
v2.type = FcTypeString;
|
||||
v2.u.s = (FcChar8 *) "en-us";
|
||||
if (FcPatternObjectGet (pattern, FC_FAMILYLANG_OBJECT, 0, &v) == FcResultNoMatch)
|
||||
if (!FcPatternFindObjectIter (pattern, &iter, FC_FAMILYLANG_OBJECT))
|
||||
{
|
||||
FcPatternObjectAdd (pattern, FC_FAMILYLANG_OBJECT, namelang, FcTrue);
|
||||
FcPatternObjectAddWithBinding (pattern, FC_FAMILYLANG_OBJECT, v2, FcValueBindingWeak, FcTrue);
|
||||
}
|
||||
if (FcPatternObjectGet (pattern, FC_STYLELANG_OBJECT, 0, &v) == FcResultNoMatch)
|
||||
if (!FcPatternFindObjectIter (pattern, &iter, FC_STYLELANG_OBJECT))
|
||||
{
|
||||
FcPatternObjectAdd (pattern, FC_STYLELANG_OBJECT, namelang, FcTrue);
|
||||
FcPatternObjectAddWithBinding (pattern, FC_STYLELANG_OBJECT, v2, FcValueBindingWeak, FcTrue);
|
||||
}
|
||||
if (FcPatternObjectGet (pattern, FC_FULLNAMELANG_OBJECT, 0, &v) == FcResultNoMatch)
|
||||
if (!FcPatternFindObjectIter (pattern, &iter, FC_FULLNAMELANG_OBJECT))
|
||||
{
|
||||
FcPatternObjectAdd (pattern, FC_FULLNAMELANG_OBJECT, namelang, FcTrue);
|
||||
FcPatternObjectAddWithBinding (pattern, FC_FULLNAMELANG_OBJECT, v2, FcValueBindingWeak, FcTrue);
|
||||
|
|
|
@ -544,7 +544,7 @@ interpret_count (FcFormatContext *c,
|
|||
FcStrBuf *buf)
|
||||
{
|
||||
int count;
|
||||
FcPatternElt *e;
|
||||
FcPatternIter iter;
|
||||
FcChar8 buf_static[64];
|
||||
|
||||
if (!expect_char (c, '#'))
|
||||
|
@ -554,16 +554,9 @@ interpret_count (FcFormatContext *c,
|
|||
return FcFalse;
|
||||
|
||||
count = 0;
|
||||
e = FcPatternObjectFindElt (pat,
|
||||
FcObjectFromName ((const char *) c->word));
|
||||
if (e)
|
||||
if (FcPatternFindIter (pat, &iter, (const char *) c->word))
|
||||
{
|
||||
FcValueListPtr l;
|
||||
count++;
|
||||
for (l = FcPatternEltValues(e);
|
||||
l->next;
|
||||
l = l->next)
|
||||
count++;
|
||||
count = FcPatternIterValueCount (pat, &iter);
|
||||
}
|
||||
|
||||
snprintf ((char *) buf_static, sizeof (buf_static), "%d", count);
|
||||
|
@ -695,7 +688,7 @@ interpret_simple (FcFormatContext *c,
|
|||
FcPattern *pat,
|
||||
FcStrBuf *buf)
|
||||
{
|
||||
FcPatternElt *e;
|
||||
FcPatternIter iter;
|
||||
FcBool add_colon = FcFalse;
|
||||
FcBool add_elt_name = FcFalse;
|
||||
int idx;
|
||||
|
@ -743,9 +736,7 @@ interpret_simple (FcFormatContext *c,
|
|||
c->word = orig;
|
||||
}
|
||||
|
||||
e = FcPatternObjectFindElt (pat,
|
||||
FcObjectFromName ((const char *) c->word));
|
||||
if (e || else_string)
|
||||
if (FcPatternFindIter (pat, &iter, (const char *) c->word) || else_string)
|
||||
{
|
||||
FcValueListPtr l = NULL;
|
||||
|
||||
|
@ -757,8 +748,7 @@ interpret_simple (FcFormatContext *c,
|
|||
FcStrBufChar (buf, '=');
|
||||
}
|
||||
|
||||
if (e)
|
||||
l = FcPatternEltValues(e);
|
||||
l = FcPatternIterGetValues (pat, &iter);
|
||||
|
||||
if (idx != -1)
|
||||
{
|
||||
|
|
|
@ -1150,6 +1150,15 @@ FcPatternAppend (FcPattern *p, FcPattern *s);
|
|||
FcPrivate int
|
||||
FcPatternPosition (const FcPattern *p, const char *object);
|
||||
|
||||
FcPrivate FcBool
|
||||
FcPatternFindObjectIter (const FcPattern *pat, FcPatternIter *iter, FcObject object);
|
||||
|
||||
FcPrivate FcObject
|
||||
FcPatternIterGetObjectId (const FcPattern *pat, FcPatternIter *iter);
|
||||
|
||||
FcPrivate FcValueListPtr
|
||||
FcPatternIterGetValues (const FcPattern *pat, FcPatternIter *iter);
|
||||
|
||||
FcPrivate FcChar32
|
||||
FcStringHash (const FcChar8 *s);
|
||||
|
||||
|
|
233
src/fcpat.c
233
src/fcpat.c
|
@ -392,13 +392,23 @@ FcPatternDestroy (FcPattern *p)
|
|||
return;
|
||||
|
||||
elts = FcPatternElts (p);
|
||||
for (i = 0; i < p->num; i++)
|
||||
for (i = 0; i < FcPatternObjectCount (p); i++)
|
||||
FcValueListDestroy (FcPatternEltValues(&elts[i]));
|
||||
|
||||
free (elts);
|
||||
free (p);
|
||||
}
|
||||
|
||||
int
|
||||
FcPatternObjectCount (const FcPattern *pat)
|
||||
{
|
||||
if (pat)
|
||||
return pat->num;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
FcPatternObjectPosition (const FcPattern *p, FcObject object)
|
||||
{
|
||||
|
@ -406,7 +416,7 @@ FcPatternObjectPosition (const FcPattern *p, FcObject object)
|
|||
FcPatternElt *elts = FcPatternElts(p);
|
||||
|
||||
low = 0;
|
||||
high = p->num - 1;
|
||||
high = FcPatternObjectCount (p) - 1;
|
||||
c = 1;
|
||||
mid = 0;
|
||||
while (low <= high)
|
||||
|
@ -452,7 +462,7 @@ FcPatternObjectInsertElt (FcPattern *p, FcObject object)
|
|||
i = -i - 1;
|
||||
|
||||
/* reallocate array */
|
||||
if (p->num + 1 >= p->size)
|
||||
if (FcPatternObjectCount (p) + 1 >= p->size)
|
||||
{
|
||||
int s = p->size + 16;
|
||||
if (p->size)
|
||||
|
@ -463,7 +473,7 @@ FcPatternObjectInsertElt (FcPattern *p, FcObject object)
|
|||
{
|
||||
e = malloc(s * sizeof (FcPatternElt));
|
||||
if (e)
|
||||
memcpy(e, e0, p->num * sizeof (FcPatternElt));
|
||||
memcpy(e, e0, FcPatternObjectCount (p) * sizeof (FcPatternElt));
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -484,7 +494,7 @@ FcPatternObjectInsertElt (FcPattern *p, FcObject object)
|
|||
memmove (e + i + 1,
|
||||
e + i,
|
||||
sizeof (FcPatternElt) *
|
||||
(p->num - i));
|
||||
(FcPatternObjectCount (p) - i));
|
||||
|
||||
/* bump count */
|
||||
p->num++;
|
||||
|
@ -499,24 +509,26 @@ FcPatternObjectInsertElt (FcPattern *p, FcObject object)
|
|||
FcBool
|
||||
FcPatternEqual (const FcPattern *pa, const FcPattern *pb)
|
||||
{
|
||||
int i;
|
||||
FcPatternElt *pae, *pbe;
|
||||
FcPatternIter ia, ib;
|
||||
|
||||
if (pa == pb)
|
||||
return FcTrue;
|
||||
|
||||
if (pa->num != pb->num)
|
||||
if (FcPatternObjectCount (pa) != FcPatternObjectCount (pb))
|
||||
return FcFalse;
|
||||
pae = FcPatternElts(pa);
|
||||
pbe = FcPatternElts(pb);
|
||||
for (i = 0; i < pa->num; i++)
|
||||
{
|
||||
if (pae[i].object != pbe[i].object)
|
||||
FcPatternIterStart (pa, &ia);
|
||||
FcPatternIterStart (pb, &ib);
|
||||
do {
|
||||
FcBool ra, rb;
|
||||
|
||||
if (!FcPatternIterEqual (pa, &ia, pb, &ib))
|
||||
return FcFalse;
|
||||
if (!FcValueListEqual (FcPatternEltValues(&pae[i]),
|
||||
FcPatternEltValues(&pbe[i])))
|
||||
return FcFalse;
|
||||
}
|
||||
ra = FcPatternIterNext (pa, &ia);
|
||||
rb = FcPatternIterNext (pb, &ib);
|
||||
if (!ra && !rb)
|
||||
break;
|
||||
} while (1);
|
||||
|
||||
return FcTrue;
|
||||
}
|
||||
|
||||
|
@ -527,7 +539,7 @@ FcPatternHash (const FcPattern *p)
|
|||
FcChar32 h = 0;
|
||||
FcPatternElt *pe = FcPatternElts(p);
|
||||
|
||||
for (i = 0; i < p->num; i++)
|
||||
for (i = 0; i < FcPatternObjectCount (p); i++)
|
||||
{
|
||||
h = (((h << 1) | (h >> 31)) ^
|
||||
pe[i].object ^
|
||||
|
@ -713,10 +725,10 @@ FcPatternObjectDel (FcPattern *p, FcObject object)
|
|||
|
||||
/* shuffle existing ones down */
|
||||
memmove (e, e+1,
|
||||
(FcPatternElts(p) + p->num - (e + 1)) *
|
||||
(FcPatternElts(p) + FcPatternObjectCount (p) - (e + 1)) *
|
||||
sizeof (FcPatternElt));
|
||||
p->num--;
|
||||
e = FcPatternElts(p) + p->num;
|
||||
e = FcPatternElts(p) + FcPatternObjectCount (p);
|
||||
e->object = 0;
|
||||
e->values = NULL;
|
||||
return FcTrue;
|
||||
|
@ -1115,8 +1127,7 @@ FcPattern *
|
|||
FcPatternDuplicate (const FcPattern *orig)
|
||||
{
|
||||
FcPattern *new;
|
||||
FcPatternElt *e;
|
||||
int i;
|
||||
FcPatternIter iter;
|
||||
FcValueListPtr l;
|
||||
|
||||
if (!orig)
|
||||
|
@ -1126,20 +1137,18 @@ FcPatternDuplicate (const FcPattern *orig)
|
|||
if (!new)
|
||||
goto bail0;
|
||||
|
||||
e = FcPatternElts(orig);
|
||||
|
||||
for (i = 0; i < orig->num; i++)
|
||||
FcPatternIterStart (orig, &iter);
|
||||
do
|
||||
{
|
||||
for (l = FcPatternEltValues(e + i); l; l = FcValueListNext(l))
|
||||
for (l = FcPatternIterGetValues (orig, &iter); l; l = FcValueListNext (l))
|
||||
{
|
||||
if (!FcPatternObjectAddWithBinding (new, e[i].object,
|
||||
if (!FcPatternObjectAddWithBinding (new, FcPatternIterGetObjectId (orig, &iter),
|
||||
FcValueCanonicalize(&l->value),
|
||||
l->binding,
|
||||
FcTrue))
|
||||
goto bail1;
|
||||
|
||||
}
|
||||
}
|
||||
} while (FcPatternIterNext (orig, &iter));
|
||||
|
||||
return new;
|
||||
|
||||
|
@ -1184,21 +1193,21 @@ FcPatternBuild (FcPattern *p, ...)
|
|||
FcBool
|
||||
FcPatternAppend (FcPattern *p, FcPattern *s)
|
||||
{
|
||||
int i;
|
||||
FcPatternElt *e;
|
||||
FcValueListPtr v;
|
||||
FcPatternIter iter;
|
||||
FcValueListPtr v;
|
||||
|
||||
for (i = 0; i < s->num; i++)
|
||||
FcPatternIterStart (s, &iter);
|
||||
do
|
||||
{
|
||||
e = FcPatternElts(s)+i;
|
||||
for (v = FcPatternEltValues(e); v; v = FcValueListNext(v))
|
||||
for (v = FcPatternIterGetValues (s, &iter); v; v = FcValueListNext (v))
|
||||
{
|
||||
if (!FcPatternObjectAddWithBinding (p, e->object,
|
||||
if (!FcPatternObjectAddWithBinding (p, FcPatternIterGetObjectId (s, &iter),
|
||||
FcValueCanonicalize(&v->value),
|
||||
v->binding, FcTrue))
|
||||
return FcFalse;
|
||||
}
|
||||
}
|
||||
} while (FcPatternIterNext (s, &iter));
|
||||
|
||||
return FcTrue;
|
||||
}
|
||||
|
||||
|
@ -1239,6 +1248,148 @@ bail0:
|
|||
return NULL;
|
||||
}
|
||||
|
||||
typedef struct _FcPatternPrivateIter {
|
||||
FcPatternElt *elt;
|
||||
int pos;
|
||||
} FcPatternPrivateIter;
|
||||
|
||||
static void
|
||||
FcPatternIterSet (const FcPattern *pat, FcPatternPrivateIter *iter)
|
||||
{
|
||||
iter->elt = FcPatternObjectCount (pat) > 0 && iter->pos < FcPatternObjectCount (pat) ? &FcPatternElts (pat)[iter->pos] : NULL;
|
||||
}
|
||||
|
||||
void
|
||||
FcPatternIterStart (const FcPattern *pat, FcPatternIter *iter)
|
||||
{
|
||||
FcPatternPrivateIter *priv = (FcPatternPrivateIter *) iter;
|
||||
|
||||
priv->pos = 0;
|
||||
FcPatternIterSet (pat, priv);
|
||||
}
|
||||
|
||||
FcBool
|
||||
FcPatternIterNext (const FcPattern *pat, FcPatternIter *iter)
|
||||
{
|
||||
FcPatternPrivateIter *priv = (FcPatternPrivateIter *) iter;
|
||||
|
||||
priv->pos++;
|
||||
if (priv->pos >= FcPatternObjectCount (pat))
|
||||
return FcFalse;
|
||||
FcPatternIterSet (pat, priv);
|
||||
|
||||
return FcTrue;
|
||||
}
|
||||
|
||||
FcBool
|
||||
FcPatternIterEqual (const FcPattern *p1, FcPatternIter *i1,
|
||||
const FcPattern *p2, FcPatternIter *i2)
|
||||
{
|
||||
FcBool b1 = FcPatternIterIsValid (p1, i1);
|
||||
FcBool b2 = FcPatternIterIsValid (p2, i2);
|
||||
|
||||
if (!i1 && !i2)
|
||||
return FcTrue;
|
||||
if (!b1 || !b2)
|
||||
return FcFalse;
|
||||
if (FcPatternIterGetObjectId (p1, i1) != FcPatternIterGetObjectId (p2, i2))
|
||||
return FcFalse;
|
||||
|
||||
return FcValueListEqual (FcPatternIterGetValues (p1, i1),
|
||||
FcPatternIterGetValues (p2, i2));
|
||||
}
|
||||
|
||||
FcBool
|
||||
FcPatternFindObjectIter (const FcPattern *pat, FcPatternIter *iter, FcObject object)
|
||||
{
|
||||
FcPatternPrivateIter *priv = (FcPatternPrivateIter *) iter;
|
||||
int i = FcPatternObjectPosition (pat, object);
|
||||
|
||||
priv->elt = NULL;
|
||||
if (i < 0)
|
||||
return FcFalse;
|
||||
|
||||
priv->pos = i;
|
||||
FcPatternIterSet (pat, priv);
|
||||
|
||||
return FcTrue;
|
||||
}
|
||||
|
||||
FcBool
|
||||
FcPatternFindIter (const FcPattern *pat, FcPatternIter *iter, const char *object)
|
||||
{
|
||||
return FcPatternFindObjectIter (pat, iter, FcObjectFromName (object));
|
||||
}
|
||||
|
||||
FcBool
|
||||
FcPatternIterIsValid (const FcPattern *pat, FcPatternIter *iter)
|
||||
{
|
||||
FcPatternPrivateIter *priv = (FcPatternPrivateIter *)iter;
|
||||
|
||||
if (priv && priv->elt)
|
||||
return FcTrue;
|
||||
|
||||
return FcFalse;
|
||||
}
|
||||
|
||||
FcObject
|
||||
FcPatternIterGetObjectId (const FcPattern *pat, FcPatternIter *iter)
|
||||
{
|
||||
FcPatternPrivateIter *priv = (FcPatternPrivateIter *) iter;
|
||||
|
||||
if (priv && priv->elt)
|
||||
return priv->elt->object;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char *
|
||||
FcPatternIterGetObject (const FcPattern *pat, FcPatternIter *iter)
|
||||
{
|
||||
return FcObjectName (FcPatternIterGetObjectId (pat, iter));
|
||||
}
|
||||
|
||||
FcValueListPtr
|
||||
FcPatternIterGetValues (const FcPattern *pat, FcPatternIter *iter)
|
||||
{
|
||||
FcPatternPrivateIter *priv = (FcPatternPrivateIter *) iter;
|
||||
|
||||
if (priv && priv->elt)
|
||||
return FcPatternEltValues (priv->elt);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int
|
||||
FcPatternIterValueCount (const FcPattern *pat, FcPatternIter *iter)
|
||||
{
|
||||
int count = 0;
|
||||
FcValueListPtr l;
|
||||
|
||||
for (l = FcPatternIterGetValues (pat, iter); l; l = FcValueListNext (l))
|
||||
count++;
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
FcResult
|
||||
FcPatternIterGetValue (const FcPattern *pat, FcPatternIter *iter, int id, FcValue *v, FcValueBinding *b)
|
||||
{
|
||||
FcValueListPtr l;
|
||||
|
||||
for (l = FcPatternIterGetValues (pat, iter); l; l = FcValueListNext (l))
|
||||
{
|
||||
if (id == 0)
|
||||
{
|
||||
*v = FcValueCanonicalize (&l->value);
|
||||
if (b)
|
||||
*b = l->binding;
|
||||
return FcResultMatch;
|
||||
}
|
||||
id--;
|
||||
}
|
||||
return FcResultNoId;
|
||||
}
|
||||
|
||||
FcBool
|
||||
FcPatternSerializeAlloc (FcSerialize *serialize, const FcPattern *pat)
|
||||
|
@ -1248,9 +1399,9 @@ FcPatternSerializeAlloc (FcSerialize *serialize, const FcPattern *pat)
|
|||
|
||||
if (!FcSerializeAlloc (serialize, pat, sizeof (FcPattern)))
|
||||
return FcFalse;
|
||||
if (!FcSerializeAlloc (serialize, elts, pat->num * sizeof (FcPatternElt)))
|
||||
if (!FcSerializeAlloc (serialize, elts, FcPatternObjectCount (pat) * sizeof (FcPatternElt)))
|
||||
return FcFalse;
|
||||
for (i = 0; i < pat->num; i++)
|
||||
for (i = 0; i < FcPatternObjectCount (pat); i++)
|
||||
if (!FcValueListSerializeAlloc (serialize, FcPatternEltValues(elts+i)))
|
||||
return FcFalse;
|
||||
return FcTrue;
|
||||
|
@ -1269,7 +1420,7 @@ FcPatternSerialize (FcSerialize *serialize, const FcPattern *pat)
|
|||
if (!pat_serialized)
|
||||
return NULL;
|
||||
*pat_serialized = *pat;
|
||||
pat_serialized->size = pat->num;
|
||||
pat_serialized->size = FcPatternObjectCount (pat);
|
||||
FcRefSetConst (&pat_serialized->ref);
|
||||
|
||||
elts_serialized = FcSerializePtr (serialize, elts);
|
||||
|
@ -1279,7 +1430,7 @@ FcPatternSerialize (FcSerialize *serialize, const FcPattern *pat)
|
|||
pat_serialized->elts_offset = FcPtrToOffset (pat_serialized,
|
||||
elts_serialized);
|
||||
|
||||
for (i = 0; i < pat->num; i++)
|
||||
for (i = 0; i < FcPatternObjectCount (pat); i++)
|
||||
{
|
||||
values_serialized = FcValueListSerialize (serialize, FcPatternEltValues (elts+i));
|
||||
if (!values_serialized)
|
||||
|
|
Loading…
Reference in New Issue