]> git.wh0rd.org - fontconfig.git/blobdiff - src/fcpat.c
Bump libtool revision in preparation for release
[fontconfig.git] / src / fcpat.c
index 9cd01a02a9303c10ed0d9c578ed850b5d7df8dda..76263b655b479145c482888fe63176cacc0d5c0c 100644 (file)
@@ -11,9 +11,9 @@
  * 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,
+ * THE AUTHOR(S) 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
+ * EVENT SHALL THE AUTHOR(S) 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
  */
 
 #include "fcint.h"
+#include "fcftint.h"
 #include <stdlib.h>
 #include <string.h>
 #include <assert.h>
 
 static FcBool
-FcStrHashed (const FcChar8 *name);
+FcHashOwnsName(const FcChar8 *name);
 
 FcPattern *
 FcPatternCreate (void)
@@ -49,7 +50,7 @@ FcValueDestroy (FcValue v)
 {
     switch (v.type) {
     case FcTypeString:
-        if (!FcStrHashed (v.u.s))
+        if (!FcHashOwnsName(v.u.s))
             FcStrFree ((FcChar8 *) v.u.s);
        break;
     case FcTypeMatrix:
@@ -74,15 +75,15 @@ FcValueCanonicalize (const FcValue *v)
     switch (v->type)
     {
     case FcTypeString:
-       new.u.s = fc_value_string(v);
+       new.u.s = FcValueString(v);
        new.type = FcTypeString;
        break;
     case FcTypeCharSet:
-       new.u.c = fc_value_charset(v);
+       new.u.c = FcValueCharSet(v);
        new.type = FcTypeCharSet;
        break;
     case FcTypeLangSet:
-       new.u.l = fc_value_langset(v);
+       new.u.l = FcValueLangSet(v);
        new.type = FcTypeLangSet;
        break;
     default:
@@ -97,7 +98,7 @@ FcValueSave (FcValue v)
 {
     switch (v.type) {
     case FcTypeString:
-       v.u.s = FcStrCopy (v.u.s);
+       v.u.s = FcStrStaticName (v.u.s);
        if (!v.u.s)
            v.type = FcTypeVoid;
        break;
@@ -130,7 +131,7 @@ FcValueListDestroy (FcValueListPtr l)
     {
        switch (l->value.type) {
        case FcTypeString:
-            if (!FcStrHashed ((FcChar8 *)l->value.u.s))
+            if (!FcHashOwnsName((FcChar8 *)l->value.u.s))
                 FcStrFree ((FcChar8 *)l->value.u.s);
            break;
        case FcTypeMatrix:
@@ -219,7 +220,7 @@ FcStringHash (const FcChar8 *s)
 static FcChar32
 FcValueHash (const FcValue *v)
 {
-    switch (fc_storage_type(v)) {
+    switch (v->type) {
     case FcTypeVoid:
        return 0;
     case FcTypeInteger:
@@ -227,7 +228,7 @@ FcValueHash (const FcValue *v)
     case FcTypeDouble:
        return FcDoubleHash (v->u.d);
     case FcTypeString:
-       return FcStringHash (fc_value_string(v));
+       return FcStringHash (FcValueString(v));
     case FcTypeBool:
        return (FcChar32) v->u.b;
     case FcTypeMatrix:
@@ -236,12 +237,12 @@ FcValueHash (const FcValue *v)
                FcDoubleHash (v->u.m->yx) ^ 
                FcDoubleHash (v->u.m->yy));
     case FcTypeCharSet:
-       return (FcChar32) fc_value_charset(v)->num;
+       return (FcChar32) FcValueCharSet(v)->num;
     case FcTypeFTFace:
        return FcStringHash ((const FcChar8 *) ((FT_Face) v->u.f)->family_name) ^
               FcStringHash ((const FcChar8 *) ((FT_Face) v->u.f)->style_name);
     case FcTypeLangSet:
-       return FcLangSetHash (fc_value_langset(v));
+       return FcLangSetHash (FcValueLangSet(v));
     }
     return FcFalse;
 }
@@ -282,7 +283,13 @@ FcPatternDestroy (FcPattern *p)
     int                    i;
     FcPatternElt    *elts;
     
-    if (p->ref == FC_REF_CONSTANT || --p->ref > 0)
+    if (p->ref == FC_REF_CONSTANT)
+    {
+       FcCacheObjectDereference (p);
+       return;
+    }
+       
+    if (--p->ref > 0)
        return;
 
     elts = FcPatternElts (p);
@@ -475,15 +482,7 @@ FcPatternObjectAddWithBinding  (FcPattern  *p,
 
     memset(new, 0, sizeof (FcValueList));
     FcMemAlloc (FC_MEM_VALLIST, sizeof (FcValueList));
-    /* dup string */
-    if (value.type == FcTypeString)
-    {
-       value.u.s = FcStrStaticName (value.u.s);
-       if (!value.u.s)
-           value.type = FcTypeVoid;
-    }
-    else
-       value = FcValueSave (value);
+    value = FcValueSave (value);
     if (value.type == FcTypeVoid)
        goto bail1;
 
@@ -919,10 +918,14 @@ FcPatternDuplicate (const FcPattern *orig)
     for (i = 0; i < orig->num; i++)
     {
        for (l = FcPatternEltValues(e + i); l; l = FcValueListNext(l))
-           if (!FcPatternObjectAdd (new, e[i].object,
-                                    FcValueCanonicalize(&l->value),
-                                    FcTrue))
+       {
+           if (!FcPatternObjectAddWithBinding (new, e[i].object,
+                                               FcValueCanonicalize(&l->value),
+                                               l->binding,
+                                               FcTrue))
                goto bail1;
+           
+       }
     }
 
     return new;
@@ -938,26 +941,28 @@ FcPatternReference (FcPattern *p)
 {
     if (p->ref != FC_REF_CONSTANT)
        p->ref++;
+    else
+       FcCacheObjectReference (p);
 }
 
 FcPattern *
-FcPatternVaBuild (FcPattern *orig, va_list va)
+FcPatternVaBuild (FcPattern *p, va_list va)
 {
     FcPattern  *ret;
     
-    FcPatternVapBuild (ret, orig, va);
+    FcPatternVapBuild (ret, p, va);
     return ret;
 }
 
 FcPattern *
-FcPatternBuild (FcPattern *orig, ...)
+FcPatternBuild (FcPattern *p, ...)
 {
     va_list    va;
     
-    va_start (va, orig);
-    FcPatternVapBuild (orig, orig, va);
+    va_start (va, p);
+    FcPatternVapBuild (p, p, va);
     va_end (va);
-    return orig;
+    return p;
 }
 
 /*
@@ -984,6 +989,43 @@ FcPatternAppend (FcPattern *p, FcPattern *s)
     return FcTrue;
 }
 
+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;
+           }
+       }
+    }
+    return ret;
+
+bail0:
+    FcPatternDestroy (ret);
+    return NULL;
+}
+
 #define OBJECT_HASH_SIZE    31
 static struct objectBucket {
     struct objectBucket        *next;
@@ -991,14 +1033,14 @@ static struct objectBucket {
 } *FcObjectBuckets[OBJECT_HASH_SIZE];
 
 static FcBool
-FcStrHashed (const FcChar8 *name)
+FcHashOwnsName (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)))
+       if (b->hash == hash && ((char *)name == (char *) (b + 1)))
             return FcTrue;
     return FcFalse;
 }
@@ -1041,7 +1083,7 @@ FcStrStaticNameFini (void)
            next = b->next;
            name = (char *) (b + 1);
            size = sizeof (struct objectBucket) + strlen (name) + 1;
-           FcMemFree (FC_MEM_STATICSTR, size);
+           FcMemFree (FC_MEM_STATICSTR, size + sizeof (int));
            free (b);
        }
        FcObjectBuckets[i] = 0;
@@ -1166,8 +1208,14 @@ FcValueListSerialize (FcSerialize *serialize, const FcValueList *vl)
            head_serialized = vl_serialized;
        
        vl_serialized->next = NULL;
-       vl_serialized->value = vl->value;
+       vl_serialized->value.type = vl->value.type;
        switch (vl->value.type) {
+       case FcTypeInteger:
+           vl_serialized->value.u.i = vl->value.u.i;
+           break;
+       case FcTypeDouble:
+           vl_serialized->value.u.d = vl->value.u.d;
+           break;
        case FcTypeString:
            s_serialized = FcStrSerialize (serialize, vl->value.u.s);
            if (!s_serialized)
@@ -1176,6 +1224,12 @@ FcValueListSerialize (FcSerialize *serialize, const FcValueList *vl)
                                                             s_serialized,
                                                             FcChar8);
            break;
+       case FcTypeBool:
+           vl_serialized->value.u.b = vl->value.u.b;
+           break;
+       case FcTypeMatrix:
+           /* can't happen */
+           break;
        case FcTypeCharSet:
            c_serialized = FcCharSetSerialize (serialize, vl->value.u.c);
            if (!c_serialized)
@@ -1184,6 +1238,9 @@ FcValueListSerialize (FcSerialize *serialize, const FcValueList *vl)
                                                             c_serialized,
                                                             FcCharSet);
            break;
+       case FcTypeFTFace:
+           /* can't happen */
+           break;
        case FcTypeLangSet:
            l_serialized = FcLangSetSerialize (serialize, vl->value.u.l);
            if (!l_serialized)
@@ -1200,3 +1257,7 @@ FcValueListSerialize (FcSerialize *serialize, const FcValueList *vl)
     }
     return head_serialized;
 }
+#define __fcpat__
+#include "fcaliastail.h"
+#include "fcftaliastail.h"
+#undef __fcpat__