]> git.wh0rd.org - fontconfig.git/blobdiff - src/fclang.c
Place language name in constant array instead of pointer.
[fontconfig.git] / src / fclang.c
index 28b2d9b9c6965755b72b80981da54eafc7d3b1b3..13f0ca21fb932c232c58a4eecc5ec17b6e769072 100644 (file)
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-#include <fcntl.h>
-#include <sys/mman.h>
 #include "fcint.h"
 
 typedef struct {
-    FcChar8    *lang;
-    FcCharSet  charset;
+    const FcChar8      lang[8];
+    const FcCharSet    charset;
 } FcLangCharSet;
 
 typedef struct {
@@ -40,7 +38,7 @@ typedef struct {
 
 struct _FcLangSet {
     FcChar32   map[NUM_LANG_SET_MAP];
-    FcStrSetPtr        extra;
+    FcStrSet   *extra;
 };
 
 #define FcLangSetBitSet(ls, id)        ((ls)->map[(id)>>5] |= ((FcChar32) 1 << ((id) & 0x1f)))
@@ -54,15 +52,27 @@ FcFreeTypeLangSet (const FcCharSet  *charset,
     FcChar32       missing;
     const FcCharSet *exclusiveCharset = 0;
     FcLangSet      *ls;
-    
 
     if (exclusiveLang)
        exclusiveCharset = FcCharSetForLang (exclusiveLang);
     ls = FcLangSetCreate ();
     if (!ls)
        return 0;
+    if (FcDebug() & FC_DBG_LANGSET) 
+    {
+       printf ("font charset\n");
+       FcCharSetPrint (charset);
+       printf ("\n");
+    }
     for (i = 0; i < NUM_LANG_CHAR_SET; i++)
     {
+       if (FcDebug() & FC_DBG_LANGSET) 
+       {
+           printf ("%s charset\n", fcLangCharSets[i].lang);
+           FcCharSetPrint (&fcLangCharSets[i].charset);
+           printf ("\n");
+       }
+       
        /*
         * Check for Han charsets to make fonts
         * which advertise support for a single language
@@ -75,8 +85,8 @@ FcFreeTypeLangSet (const FcCharSet  *charset,
                continue;
 
            for (j = 0; j < fcLangCharSets[i].charset.num; j++)
-               if (FcCharSetGetLeaf(&fcLangCharSets[i].charset, j) != 
-                   FcCharSetGetLeaf(exclusiveCharset, j))
+               if (FcCharSetLeaf(&fcLangCharSets[i].charset, j) != 
+                   FcCharSetLeaf(exclusiveCharset, j))
                    continue;
        }
        missing = FcCharSetSubtractCount (&fcLangCharSets[i].charset, charset);
@@ -90,7 +100,7 @@ FcFreeTypeLangSet (const FcCharSet  *charset,
                FcChar32    map[FC_CHARSET_MAP_SIZE];
                FcChar32    next;
 
-               printf ("\n%s(%d) ", fcLangCharSets[i].lang, missing);
+               printf ("\n%s(%u) ", fcLangCharSets[i].lang, missing);
                printf ("{");
                for (ucs4 = FcCharSetFirstPage (missed, map, &next);
                     ucs4 != FC_CHARSET_DONE;
@@ -109,7 +119,7 @@ FcFreeTypeLangSet (const FcCharSet  *charset,
                FcCharSetDestroy (missed);
            }
            else
-               printf ("%s(%d) ", fcLangCharSets[i].lang, missing);
+               printf ("%s(%u) ", fcLangCharSets[i].lang, missing);
        }
        if (!missing)
            FcLangSetBitSet (ls, i);
@@ -190,6 +200,7 @@ FcCharSetForLang (const FcChar8 *lang)
 {
     int                i;
     int                country = -1;
+
     for (i = 0; i < NUM_LANG_CHAR_SET; i++)
     {
        switch (FcLangCompare (lang, fcLangCharSets[i].lang)) {
@@ -204,7 +215,7 @@ FcCharSetForLang (const FcChar8 *lang)
     }
     if (country == -1)
        return 0;
-    return &fcLangCharSets[i].charset;
+    return &fcLangCharSets[country].charset;
 }
 
 FcLangSet *
@@ -217,22 +228,15 @@ FcLangSetCreate (void)
        return 0;
     FcMemAlloc (FC_MEM_LANGSET, sizeof (FcLangSet));
     memset (ls->map, '\0', sizeof (ls->map));
-    ls->extra = FcStrSetPtrCreateDynamic(0);
+    ls->extra = 0;
     return ls;
 }
 
-void
-FcLangSetPtrDestroy (FcLangSetPtr li)
-{
-    if (li.storage == FcStorageDynamic)
-       FcLangSetDestroy(FcLangSetPtrU(li));
-}
-
 void
 FcLangSetDestroy (FcLangSet *ls)
 {
-    if (FcStrSetPtrU(ls->extra))
-       FcStrSetDestroy (FcStrSetPtrU(ls->extra));
+    if (ls->extra)
+       FcStrSetDestroy (ls->extra);
     FcMemFree (FC_MEM_LANGSET, sizeof (FcLangSet));
     free (ls);
 }
@@ -246,21 +250,21 @@ FcLangSetCopy (const FcLangSet *ls)
     if (!new)
        goto bail0;
     memcpy (new->map, ls->map, sizeof (new->map));
-    if (FcStrSetPtrU(ls->extra))
+    if (ls->extra)
     {
        FcStrList       *list;
        FcChar8         *extra;
        
-       new->extra = FcStrSetPtrCreateDynamic(FcStrSetCreate ());
-       if (!FcStrSetPtrU(new->extra))
+       new->extra = FcStrSetCreate ();
+       if (!new->extra)
            goto bail1;
 
-       list = FcStrListCreate (FcStrSetPtrU(ls->extra));
+       list = FcStrListCreate (ls->extra);     
        if (!list)
            goto bail1;
        
        while ((extra = FcStrListNext (list)))
-           if (!FcStrSetAdd (FcStrSetPtrU(new->extra), extra))
+           if (!FcStrSetAdd (new->extra, extra))
            {
                FcStrListDone (list);
                goto bail1;
@@ -341,13 +345,13 @@ FcLangSetAdd (FcLangSet *ls, const FcChar8 *lang)
        FcLangSetBitSet (ls, id);
        return FcTrue;
     }
-    if (!FcStrSetPtrU(ls->extra))
+    if (!ls->extra)
     {
-       ls->extra = FcStrSetPtrCreateDynamic(FcStrSetCreate ());
-       if (!FcStrSetPtrU(ls->extra))
+       ls->extra = FcStrSetCreate ();
+       if (!ls->extra)
            return FcFalse;
     }
-    return FcStrSetAdd (FcStrSetPtrU(ls->extra), lang);
+    return FcStrSetAdd (ls->extra, lang);
 }
 
 FcLangResult
@@ -379,11 +383,10 @@ FcLangSetHasLang (const FcLangSet *ls, const FcChar8 *lang)
        if (FcLangSetBitGet (ls, i) && r < best)
            best = r;
     }
-    if (FcStrSetPtrU(ls->extra))
+    if (ls->extra)
     {
-       FcStrList       *list = FcStrListCreate (FcStrSetPtrU(ls->extra));
+       FcStrList       *list = FcStrListCreate (ls->extra);
        FcChar8         *extra;
-       FcLangResult    r;
        
        if (list)
        {
@@ -437,15 +440,15 @@ FcLangSetCompare (const FcLangSet *lsa, const FcLangSet *lsb)
                best = FcLangDifferentCountry;
                break;
            }
-    if (FcStrSetPtrU(lsa->extra))
+    if (lsa->extra)
     {
-       r = FcLangSetCompareStrSet (lsb, FcStrSetPtrU(lsa->extra));
+       r = FcLangSetCompareStrSet (lsb, lsa->extra);
        if (r < best)
            best = r;
     }
-    if (best > FcLangEqual && FcStrSetPtrU(lsb->extra))
+    if (best > FcLangEqual && lsb->extra)
     {
-       r = FcLangSetCompareStrSet (lsa, FcStrSetPtrU(lsb->extra));
+       r = FcLangSetCompareStrSet (lsa, lsb->extra);
        if (r < best)
            best = r;
     }
@@ -464,7 +467,7 @@ FcLangSetPromote (const FcChar8 *lang)
     int                        id;
 
     memset (ls.map, '\0', sizeof (ls.map));
-    ls.extra = FcStrSetPtrCreateDynamic(0);
+    ls.extra = 0;
     id = FcLangSetIndex (lang);
     if (id > 0)
     {
@@ -472,11 +475,10 @@ FcLangSetPromote (const FcChar8 *lang)
     }
     else
     {
-       ls.extra = FcStrSetPtrCreateDynamic(&strs);
+       ls.extra = &strs;
        strs.num = 1;
        strs.size = 1;
-       strs.storage = FcStorageDynamic;
-       strs.u.strs = &str;
+       strs.strs = &str;
        strs.ref = 1;
        str = (FcChar8 *) lang;
     }
@@ -491,8 +493,8 @@ FcLangSetHash (const FcLangSet *ls)
 
     for (i = 0; i < NUM_LANG_SET_MAP; i++)
        h ^= ls->map[i];
-    if (FcStrSetPtrU(ls->extra))
-       h ^= FcStrSetPtrU(ls->extra)->num;
+    if (ls->extra)
+       h ^= ls->extra->num;
     return h;
 }
 
@@ -553,9 +555,9 @@ FcNameUnparseLangSet (FcStrBuf *buf, const FcLangSet *ls)
                }
        }
     }
-    if (FcStrSetPtrU(ls->extra))
+    if (ls->extra)
     {
-       FcStrList   *list = FcStrListCreate (FcStrSetPtrU(ls->extra));
+       FcStrList   *list = FcStrListCreate (ls->extra);
        FcChar8     *extra;
 
        if (!list)
@@ -564,11 +566,18 @@ FcNameUnparseLangSet (FcStrBuf *buf, const FcLangSet *ls)
        {
            if (!first)
                if (!FcStrBufChar (buf, '|'))
+                {
+                    FcStrListDone (list);
                    return FcFalse;
+                }
            if (!FcStrBufString (buf, extra))
-               return FcFalse;
+                {
+                    FcStrListDone (list);
+                    return FcFalse;
+                }
            first = FcFalse;
        }
+        FcStrListDone (list);
     }
     return FcTrue;
 }
@@ -583,10 +592,10 @@ FcLangSetEqual (const FcLangSet *lsa, const FcLangSet *lsb)
        if (lsa->map[i] != lsb->map[i])
            return FcFalse;
     }
-    if (!FcStrSetPtrU(lsa->extra) && !FcStrSetPtrU(lsb->extra))
+    if (!lsa->extra && !lsb->extra)
        return FcTrue;
-    if (FcStrSetPtrU(lsa->extra) && FcStrSetPtrU(lsb->extra))
-       return FcStrSetEqual (FcStrSetPtrU(lsa->extra), FcStrSetPtrU(lsb->extra));
+    if (lsa->extra && lsb->extra)
+       return FcStrSetEqual (lsa->extra, lsb->extra);
     return FcFalse;
 }
 
@@ -620,9 +629,9 @@ FcLangSetContainsLang (const FcLangSet *ls, const FcChar8 *lang)
            FcLangContains (fcLangCharSets[i].lang, lang))
            return FcTrue;
     }
-    if (FcStrSetPtrU(ls->extra))
+    if (ls->extra)
     {
-       FcStrList       *list = FcStrListCreate (FcStrSetPtrU(ls->extra));
+       FcStrList       *list = FcStrListCreate (ls->extra);
        FcChar8         *extra;
        
        if (list)
@@ -676,9 +685,9 @@ FcLangSetContains (const FcLangSet *lsa, const FcLangSet *lsb)
                }
        }
     }
-    if (FcStrSetPtrU(lsb->extra))
+    if (lsb->extra)
     {
-       FcStrList   *list = FcStrListCreate (FcStrSetPtrU(lsb->extra));
+       FcStrList   *list = FcStrListCreate (lsb->extra);
        FcChar8     *extra;
 
        if (list)
@@ -700,77 +709,24 @@ FcLangSetContains (const FcLangSet *lsa, const FcLangSet *lsb)
     return FcTrue;
 }
 
-static FcLangSet * langsets = 0;
-static int langset_ptr = 0, langset_count = 0;
-
-FcLangSet *
-FcLangSetPtrU (FcLangSetPtr li)
-{
-    switch (li.storage)
-    {
-    case FcStorageDynamic:
-       return li.u.dyn;
-    case FcStorageStatic:
-       return &langsets[li.u.stat];
-    default:
-       return 0;
-
-    }
-}
-
-FcLangSetPtr
-FcLangSetPtrCreateDynamic (FcLangSet *li)
-{
-    FcLangSetPtr new;
-    new.storage = FcStorageDynamic;
-    new.u.dyn = li;
-    return new;
-}
-
-void
-FcLangSetClearStatic (void)
-{
-    FcStrSetClearStatic();
-    langset_ptr = 0;
-    langset_count = 0;
-}
-
-/* should only write one copy of any particular FcLangSet */
 FcBool
-FcLangSetPrepareSerialize (FcLangSet *l)
+FcLangSetSerializeAlloc (FcSerialize *serialize, const FcLangSet *l)
 {
-    langset_count++;
-    if (l && FcStrSetPtrU(l->extra))
-       return FcStrSetPrepareSerialize (FcStrSetPtrU(l->extra));
+    if (!FcSerializeAlloc (serialize, l, sizeof (FcLangSet)))
+       return FcFalse;
     return FcTrue;
 }
 
-FcLangSetPtr
-FcLangSetSerialize(FcLangSet *l)
+FcLangSet *
+FcLangSetSerialize(FcSerialize *serialize, const FcLangSet *l)
 {
-    FcLangSetPtr new;
-    int p = langset_ptr;
+    FcLangSet  *l_serialize = FcSerializePtr (serialize, l);
 
-    if (!l) return FcLangSetPtrCreateDynamic(0);
-
-    if (!langsets)
-    {
-       FcLangSet* t;
-       t = (FcLangSet *)malloc(langset_count * sizeof(FcLangSet));
-       if (!t)
-           return FcLangSetPtrCreateDynamic(0);
-       langsets = t;
-       langset_ptr = 0;
-    }
-
-    langsets[langset_ptr] = *l;
-    if (FcStrSetPtrU(l->extra))
-       langsets[langset_ptr].extra = 
-           FcStrSetSerialize(FcStrSetPtrU(l->extra));
-    else
-       langsets[langset_ptr].extra = FcStrSetPtrCreateDynamic(0);
-    langset_ptr++;
-    new.storage = FcStorageStatic;
-    new.u.stat = p;
-    return new;
+    if (!l_serialize)
+       return NULL;
+    *l_serialize = *l;
+    return l_serialize;
 }
+#define __fclang__
+#include "fcaliastail.h"
+#undef __fclang__