]> git.wh0rd.org - fontconfig.git/blobdiff - src/fclist.c
Eliminate .so PLT entries for local symbols. (thanks to Arjan van de Ven)
[fontconfig.git] / src / fclist.c
index b3ecdb82cf2d71e792355093fd88fcad315475da..3de04a009ec645992fbc9f9c151c41a5a150bacc 100644 (file)
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-#include <stdlib.h>
-#include <sys/types.h>
-#include <sys/mman.h>
-#include <unistd.h>
 #include "fcint.h"
+#include <stdlib.h>
 
 FcObjectSet *
 FcObjectSetCreate (void)
@@ -47,18 +44,17 @@ FcBool
 FcObjectSetAdd (FcObjectSet *os, const char *object)
 {
     int                s;
-    FcObjectPtr        *objects;
-    FcObjectPtr obj;
+    const char **objects;
     int                high, low, mid, c;
     
     if (os->nobject == os->sobject)
     {
        s = os->sobject + 4;
        if (os->objects)
-           objects = (FcObjectPtr *) realloc ((void *) os->objects,
-                                              s * sizeof (FcObjectPtr));
+           objects = (const char **) realloc ((void *) os->objects,
+                                              s * sizeof (const char *));
        else
-           objects = (FcObjectPtr *) malloc (s * sizeof (FcObjectPtr));
+           objects = (const char **) malloc (s * sizeof (const char *));
        if (!objects)
            return FcFalse;
        if (os->sobject)
@@ -71,11 +67,11 @@ FcObjectSetAdd (FcObjectSet *os, const char *object)
     low = 0;
     mid = 0;
     c = 1;
-    obj = FcObjectStaticName (object);
+    object = (char *)FcStrStaticName ((FcChar8 *)object);
     while (low <= high)
     {
        mid = (low + high) >> 1;
-       c = FcObjectPtrCompare(os->objects[mid], obj);
+       c = os->objects[mid] - object;
        if (c == 0)
            return FcTrue;
        if (c < 0)
@@ -86,8 +82,8 @@ FcObjectSetAdd (FcObjectSet *os, const char *object)
     if (c < 0)
        mid++;
     memmove (os->objects + mid + 1, os->objects + mid, 
-            (os->nobject - mid) * sizeof (FcObjectPtr));
-    os->objects[mid] = obj;
+            (os->nobject - mid) * sizeof (const char *));
+    os->objects[mid] = object;
     os->nobject++;
     return FcTrue;
 }
@@ -134,23 +130,21 @@ FcListValueListMatchAny (FcValueListPtr patOrig,      /* pattern */
 {
     FcValueListPtr      pat, fnt;
 
-    for (pat = patOrig; FcValueListPtrU(pat); 
-        pat = FcValueListPtrU(pat)->next)
+    for (pat = patOrig; pat != NULL; pat = FcValueListNext(pat))
     {
-       for (fnt = fntOrig; FcValueListPtrU(fnt); 
-            fnt = FcValueListPtrU(fnt)->next)
+       for (fnt = fntOrig; fnt != NULL; fnt = FcValueListNext(fnt))
        {
            /*
             * make sure the font 'contains' the pattern.
             * (OpListing is OpContains except for strings
             *  where it requires an exact match)
             */
-           if (FcConfigCompareValue (FcValueListPtrU(fnt)->value,
+           if (FcConfigCompareValue (&fnt->value,
                                      FcOpListing, 
-                                     FcValueListPtrU(pat)->value)) 
+                                     &pat->value)) 
                break;
        }
-       if (!FcValueListPtrU(fnt))
+       if (fnt == NULL)
            return FcFalse;
     }
     return FcTrue;
@@ -162,26 +156,22 @@ FcListValueListEqual (FcValueListPtr v1orig,
 {
     FcValueListPtr         v1, v2;
 
-    for (v1 = v1orig; FcValueListPtrU(v1); 
-        v1 = FcValueListPtrU(v1)->next)
+    for (v1 = v1orig; v1 != NULL; v1 = FcValueListNext(v1))
     {
-       for (v2 = v2orig; FcValueListPtrU(v2); 
-            v2 = FcValueListPtrU(v2)->next)
-           if (FcValueEqual (FcValueListPtrU(v1)->value, 
-                             FcValueListPtrU(v2)->value))
+       for (v2 = v2orig; v2 != NULL; v2 = FcValueListNext(v2))
+           if (FcValueEqual (FcValueCanonicalize(&(v1)->value),
+                             FcValueCanonicalize(&(v2)->value)))
                break;
-       if (!FcValueListPtrU(v2))
+       if (v2 == NULL)
            return FcFalse;
     }
-    for (v2 = v2orig; FcValueListPtrU(v2); 
-        v2 = FcValueListPtrU(v2)->next)
+    for (v2 = v2orig; v2 != NULL; v2 = FcValueListNext(v2))
     {
-       for (v1 = v1orig; FcValueListPtrU(v1); 
-            v1 = FcValueListPtrU(v1)->next)
-           if (FcValueEqual (FcValueListPtrU(v1)->value, 
-                             FcValueListPtrU(v2)->value))
+       for (v1 = v1orig; v1 != NULL; v1 = FcValueListNext(v1))
+           if (FcValueEqual (FcValueCanonicalize(&v1->value),
+                             FcValueCanonicalize(&v2->value)))
                break;
-       if (!FcValueListPtrU(v1))
+       if (v1 == NULL)
            return FcFalse;
     }
     return FcTrue;
@@ -197,13 +187,14 @@ FcListPatternEqual (FcPattern     *p1,
 
     for (i = 0; i < os->nobject; i++)
     {
-       e1 = FcPatternFindElt (p1, FcObjectPtrU(os->objects[i]));
-       e2 = FcPatternFindElt (p2, FcObjectPtrU(os->objects[i]));
+       e1 = FcPatternObjectFindElt (p1, FcObjectFromName (os->objects[i]));
+       e2 = FcPatternObjectFindElt (p2, FcObjectFromName (os->objects[i]));
        if (!e1 && !e2)
            continue;
        if (!e1 || !e2)
            return FcFalse;
-       if (!FcListValueListEqual (e1->values, e2->values))
+       if (!FcListValueListEqual (FcPatternEltValues(e1),
+                                  FcPatternEltValues(e2)))
            return FcFalse;
     }
     return FcTrue;
@@ -218,16 +209,15 @@ FcListPatternMatchAny (const FcPattern *p,
                       const FcPattern *font)
 {
     int                    i;
-    FcPatternElt   *e;
 
     for (i = 0; i < p->num; i++)
     {
-       e = FcPatternFindElt (font, 
-                             FcObjectPtrU((FcPatternEltU(p->elts)+i)->object));
-       if (!e)
+       FcPatternElt    *pe = &FcPatternElts(p)[i];
+       FcPatternElt    *fe = FcPatternObjectFindElt (font, pe->object);
+       if (!fe)
            return FcFalse;
-       if (!FcListValueListMatchAny ((FcPatternEltU(p->elts)+i)->values,    /* pat elts */
-                                     e->values))           /* font elts */
+       if (!FcListValueListMatchAny (FcPatternEltValues(pe),    /* pat elts */
+                                     FcPatternEltValues(fe)))   /* font elts */
            return FcFalse;
     }
     return FcTrue;
@@ -245,8 +235,9 @@ FcListMatrixHash (const FcMatrix *m)
 }
 
 static FcChar32
-FcListValueHash (FcValue    v)
+FcListValueHash (FcValue    *value)
 {
+    FcValue v = FcValueCanonicalize(value);
     switch (v.type) {
     case FcTypeVoid:
        return 0;
@@ -255,17 +246,17 @@ FcListValueHash (FcValue    v)
     case FcTypeDouble:
        return (FcChar32) (int) v.u.d;
     case FcTypeString:
-       return FcStrHashIgnoreCase (FcObjectPtrU(v.u.si));
+       return FcStrHashIgnoreCase (v.u.s);
     case FcTypeBool:
        return (FcChar32) v.u.b;
     case FcTypeMatrix:
-       return FcListMatrixHash (FcMatrixPtrU(v.u.mi));
+       return FcListMatrixHash (v.u.m);
     case FcTypeCharSet:
-       return FcCharSetCount (FcCharSetPtrU(v.u.ci));
+       return FcCharSetCount (v.u.c);
     case FcTypeFTFace:
        return (long) v.u.f;
     case FcTypeLangSet:
-       return FcLangSetHash (FcLangSetPtrU(v.u.li));
+       return FcLangSetHash (v.u.l);
     }
     return 0;
 }
@@ -275,10 +266,10 @@ FcListValueListHash (FcValueListPtr list)
 {
     FcChar32   h = 0;
     
-    while (FcValueListPtrU(list))
+    while (list != NULL)
     {
-       h = h ^ FcListValueHash (FcValueListPtrU(list)->value);
-       list = FcValueListPtrU(list)->next;
+       h = h ^ FcListValueHash (&list->value);
+       list = FcValueListNext(list);
     }
     return h;
 }
@@ -293,9 +284,9 @@ FcListPatternHash (FcPattern        *font,
 
     for (n = 0; n < os->nobject; n++)
     {
-       e = FcPatternFindElt (font, FcObjectPtrU(os->objects[n]));
+       e = FcPatternObjectFindElt (font, FcObjectFromName (os->objects[n]));
        if (e)
-           h = h ^ FcListValueListHash (e->values);
+           h = h ^ FcListValueListHash (FcPatternEltValues(e));
     }
     return h;
 }
@@ -340,6 +331,34 @@ FcListHashTableCleanup (FcListHashTable *table)
     table->entries = 0;
 }
 
+static int
+FcGetDefaultObjectLangIndex (FcPattern *font, FcObject object)
+{
+    FcChar8       *lang = FcGetDefaultLang ();
+    FcPatternElt   *e = FcPatternObjectFindElt (font, object);
+    FcValueListPtr  v;
+    FcValue         value;
+    int             idx = -1;
+    int             i;
+
+    if (e)
+    {
+       for (v = FcPatternEltValues(e), i = 0; v; v = FcValueListNext(v), ++i)
+       {
+           value = FcValueCanonicalize (&v->value);
+
+           if (value.type == FcTypeString)
+           {
+               FcLangResult res = FcLangCompare (value.u.s, lang);
+               if (res == FcLangEqual || (res == FcLangDifferentCountry && idx < 0))
+                   idx = i;
+           }
+       }
+    }
+
+    return (idx > 0) ? idx : 0;
+}
+
 static FcBool
 FcListAppend (FcListHashTable  *table,
              FcPattern         *font,
@@ -350,6 +369,11 @@ FcListAppend (FcListHashTable      *table,
     FcValueListPtr  v;
     FcChar32       hash;
     FcListBucket    **prev, *bucket;
+    int             familyidx = -1;
+    int             fullnameidx = -1;
+    int             styleidx = -1;
+    int             defidx = 0;
+    int             idx;
 
     hash = FcListPatternHash (font, os);
     for (prev = &table->buckets[hash % FC_LIST_HASH_SIZE];
@@ -371,15 +395,36 @@ FcListAppend (FcListHashTable     *table,
     
     for (o = 0; o < os->nobject; o++)
     {
-       e = FcPatternFindElt (font, FcObjectPtrU(os->objects[o]));
+       if (!strcmp (os->objects[o], FC_FAMILY) || !strcmp (os->objects[o], FC_FAMILYLANG))
+       {
+           if (familyidx < 0)
+               familyidx = FcGetDefaultObjectLangIndex (font, FC_FAMILYLANG_OBJECT);
+           defidx = familyidx;
+       }
+       else if (!strcmp (os->objects[o], FC_FULLNAME) || !strcmp (os->objects[o], FC_FULLNAMELANG))
+       {
+           if (fullnameidx < 0)
+               fullnameidx = FcGetDefaultObjectLangIndex (font, FC_FULLNAMELANG_OBJECT);
+           defidx = fullnameidx;
+       }
+       else if (!strcmp (os->objects[o], FC_STYLE) || !strcmp (os->objects[o], FC_STYLELANG))
+       {
+           if (styleidx < 0)
+               styleidx = FcGetDefaultObjectLangIndex (font, FC_STYLELANG_OBJECT);
+           defidx = styleidx;
+       }
+       else
+           defidx = 0;
+
+       e = FcPatternObjectFindElt (font, FcObjectFromName (os->objects[o]));
        if (e)
        {
-           for (v = e->values; FcValueListPtrU(v); 
-                v = FcValueListPtrU(v)->next)
+           for (v = FcPatternEltValues(e), idx = 0; v;
+                v = FcValueListNext(v), ++idx)
            {
                if (!FcPatternAdd (bucket->pattern, 
-                                  FcObjectPtrU(os->objects[o])
-                                  FcValueListPtrU(v)->value, FcTrue))
+                                  os->objects[o]
+                                  FcValueCanonicalize(&v->value), defidx != idx))
                    goto bail2;
            }
        }
@@ -511,3 +556,6 @@ FcFontList (FcConfig        *config,
        sets[nsets++] = config->fonts[FcSetApplication];
     return FcFontSetList (config, sets, nsets, p, os);
 }
+#define __fclist__
+#include "fcaliastail.h"
+#undef __fclist__