]> git.wh0rd.org - fontconfig.git/blobdiff - src/fclang.c
Replace 'KEITH PACKARD' with 'THE AUTHOR(S)' in license text in all files
[fontconfig.git] / src / fclang.c
index 552253d2dee366db68685f1670e5ea8ab5dc41e3..90426a049f7ef7b96855c8d91cac60328c754c4e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $RCSId: xc/lib/fontconfig/src/fclang.c,v 1.7 2002/08/26 23:34:31 keithp Exp $
+ * fontconfig/src/fclang.c
  *
  * Copyright © 2002 Keith Packard
  *
@@ -13,9 +13,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"
 
 typedef struct {
-    const FcChar8      *lang;
+    const FcChar8      lang[8];
     const FcCharSet    charset;
 } FcLangCharSet;
 
@@ -44,8 +45,6 @@ struct _FcLangSet {
 #define FcLangSetBitSet(ls, id)        ((ls)->map[(id)>>5] |= ((FcChar32) 1 << ((id) & 0x1f)))
 #define FcLangSetBitGet(ls, id) (((ls)->map[(id)>>5] >> ((id) & 0x1f)) & 1)
 
-static FcBool langsets_populated = FcFalse;
-
 FcLangSet *
 FcFreeTypeLangSet (const FcCharSet  *charset, 
                   const FcChar8    *exclusiveLang)
@@ -55,19 +54,26 @@ FcFreeTypeLangSet (const FcCharSet  *charset,
     const FcCharSet *exclusiveCharset = 0;
     FcLangSet      *ls;
 
-    if (!langsets_populated)
-    {
-        FcLangCharSetPopulate ();
-        langsets_populated = FcTrue;
-    }
-
     if (exclusiveLang)
-       exclusiveCharset = FcCharSetForLang (exclusiveLang);
+       exclusiveCharset = FcLangGetCharSet (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
@@ -80,8 +86,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);
@@ -145,13 +151,13 @@ FcLangCompare (const FcChar8 *s1, const FcChar8 *s2)
        if (c1 != c2)
        {
            if (FcLangEnd (c1) && FcLangEnd (c2))
-               result = FcLangDifferentCountry;
+               result = FcLangDifferentTerritory;
            return result;
        }
        else if (!c1)
            return FcLangEqual;
        else if (c1 == '-')
-           result = FcLangDifferentCountry;
+           result = FcLangDifferentTerritory;
     }
 }
 
@@ -191,23 +197,17 @@ FcLangContains (const FcChar8 *super, const FcChar8 *sub)
 }
 
 const FcCharSet *
-FcCharSetForLang (const FcChar8 *lang)
+FcLangGetCharSet (const FcChar8 *lang)
 {
     int                i;
     int                country = -1;
 
-    if (!langsets_populated)
-    {
-        FcLangCharSetPopulate ();
-        langsets_populated = FcTrue;
-    }
-
     for (i = 0; i < NUM_LANG_CHAR_SET; i++)
     {
        switch (FcLangCompare (lang, fcLangCharSets[i].lang)) {
        case FcLangEqual:
            return &fcLangCharSets[i].charset;
-       case FcLangDifferentCountry:
+       case FcLangDifferentTerritory:
            if (country == -1)
                country = i;
        default:
@@ -219,6 +219,22 @@ FcCharSetForLang (const FcChar8 *lang)
     return &fcLangCharSets[country].charset;
 }
 
+FcStrSet *
+FcGetLangs (void)
+{
+    FcStrSet *langs;
+    int        i;
+
+    langs = FcStrSetCreate();
+    if (!langs)
+       return 0;
+
+    for (i = 0; i < NUM_LANG_CHAR_SET; i++)
+       FcStrSetAdd (langs, fcLangCharSets[i].lang);
+
+    return langs;
+}
+
 FcLangSet *
 FcLangSetCreate (void)
 {
@@ -438,7 +454,7 @@ FcLangSetCompare (const FcLangSet *lsa, const FcLangSet *lsb)
            if ((lsa->map[i] & fcLangCountrySets[j][i]) &&
                (lsb->map[i] & fcLangCountrySets[j][i]))
            {
-               best = FcLangDifferentCountry;
+               best = FcLangDifferentTerritory;
                break;
            }
     if (lsa->extra)
@@ -710,90 +726,57 @@ FcLangSetContains (const FcLangSet *lsa, const FcLangSet *lsb)
     return FcTrue;
 }
 
-static FcLangSet ** langsets = 0;
-static int langset_bank_count = 0, langset_ptr = 0, langset_count = 0;
-
-void
-FcLangSetNewBank (void)
+FcBool
+FcLangSetSerializeAlloc (FcSerialize *serialize, const FcLangSet *l)
 {
-    langset_count = 0;
+    if (!FcSerializeAlloc (serialize, l, sizeof (FcLangSet)))
+       return FcFalse;
+    return FcTrue;
 }
 
-/* ideally, should only write one copy of any particular FcLangSet */
-int
-FcLangSetNeededBytes (const FcLangSet *l)
+FcLangSet *
+FcLangSetSerialize(FcSerialize *serialize, const FcLangSet *l)
 {
-    langset_count++;
-    return sizeof (FcLangSet);
-}
+    FcLangSet  *l_serialize = FcSerializePtr (serialize, l);
 
-int
-FcLangSetNeededBytesAlign (void)
-{
-    return fc_alignof (FcLangSet);
+    if (!l_serialize)
+       return NULL;
+    *l_serialize = *l;
+    return l_serialize;
 }
 
-static FcBool
-FcLangSetEnsureBank (int bi)
+FcStrSet *
+FcLangSetGetLangs (const FcLangSet *ls)
 {
-    if (!langsets || bi >= langset_bank_count)
-    {
-       int new_count = langset_bank_count + 2;
-       int i;
-       FcLangSet** tt;
-       tt = realloc(langsets, new_count * sizeof(FcLangSet *));
-       if (!tt)
-           return FcFalse;
-
-       langsets = tt;
-       for (i = langset_bank_count; i < new_count; i++)
-           langsets[i] = 0; 
-       langset_bank_count = new_count;
-    }
-
-    return FcTrue;
-}
+    FcStrSet *langs;
+    int              i;
 
-void *
-FcLangSetDistributeBytes (FcCache * metadata, void * block_ptr)
-{
-    int bi = FcCacheBankToIndex(metadata->bank);
-    if (!FcLangSetEnsureBank(bi))
+    langs = FcStrSetCreate();
+    if (!langs)
        return 0;
 
-    block_ptr = ALIGN(block_ptr, FcLangSet);
-    langsets[bi] = block_ptr;
-    block_ptr = (void *)((char *)block_ptr +
-                        langset_count * sizeof(FcLangSet));
-    langset_ptr = 0;
-    metadata->langset_count = langset_count;
-    return block_ptr;
-}
-
-FcLangSet *
-FcLangSetSerialize(int bank, FcLangSet *l)
-{
-    int p = langset_ptr, bi = FcCacheBankToIndex(bank);
+    for (i = 0; i < NUM_LANG_CHAR_SET; i++)
+       if (FcLangSetBitGet (ls, i))
+           FcStrSetAdd (langs, fcLangCharSets[i].lang);
 
-    if (!l) return 0;
+    if (ls->extra)
+    {
+       FcStrList       *list = FcStrListCreate (ls->extra);
+       FcChar8         *extra;
 
-    langsets[bi][langset_ptr] = *l;
-    langsets[bi][langset_ptr].extra = 0;
-    langset_ptr++;
-    return &langsets[bi][p];
-}
+       if (list)
+       {
+           while ((extra = FcStrListNext (list)))
+               FcStrSetAdd (langs, extra);
 
-void *
-FcLangSetUnserialize (FcCache * metadata, void *block_ptr)
-{
-    int bi = FcCacheBankToIndex(metadata->bank);
-    if (!FcLangSetEnsureBank(bi))
-       return 0;
+           FcStrListDone (list);
+       }
+    }
 
-    FcMemAlloc (FC_MEM_LANGSET, metadata->langset_count * sizeof(FcLangSet));
-    block_ptr = ALIGN(block_ptr, FcLangSet);
-    langsets[bi] = (FcLangSet *)block_ptr;
-    block_ptr = (void *)((char *)block_ptr +
-                        metadata->langset_count * sizeof(FcLangSet));
-    return block_ptr;
+    return langs;
 }
+
+#define __fclang__
+#include "fcaliastail.h"
+#include "fcftaliastail.h"
+#undef __fclang__