]> git.wh0rd.org - fontconfig.git/blobdiff - src/fclang.c
Add consts to variables so as to move arrays into .rodata.
[fontconfig.git] / src / fclang.c
index fabf36a15d7c15584e9a0840c2dbf5948c57c5ed..a10641edf953c89586dc9aa03f87879b1712384a 100644 (file)
@@ -25,8 +25,8 @@
 #include "fcint.h"
 
 typedef struct {
-    FcChar8    *lang;
-    FcCharSet  charset;
+    const FcChar8      *lang;
+    const FcCharSet    charset;
 } FcLangCharSet;
 
 typedef struct {
@@ -48,7 +48,7 @@ FcLangSet *
 FcFreeTypeLangSet (const FcCharSet  *charset, 
                   const FcChar8    *exclusiveLang)
 {
-    int                    i;
+    int                    i, j;
     FcChar32       missing;
     const FcCharSet *exclusiveCharset = 0;
     FcLangSet      *ls;
@@ -67,10 +67,15 @@ FcFreeTypeLangSet (const FcCharSet  *charset,
         * not support other Han languages
         */
        if (exclusiveCharset &&
-           FcFreeTypeIsExclusiveLang (fcLangCharSets[i].lang) &&
-           fcLangCharSets[i].charset.leaves != exclusiveCharset->leaves)
+           FcFreeTypeIsExclusiveLang (fcLangCharSets[i].lang))
        {
-           continue;
+           if (fcLangCharSets[i].charset.num != exclusiveCharset->num)
+               continue;
+
+           for (j = 0; j < fcLangCharSets[i].charset.num; j++)
+               if (FcCharSetGetLeaf(&fcLangCharSets[i].charset, j) != 
+                   FcCharSetGetLeaf(exclusiveCharset, j))
+                   continue;
        }
        missing = FcCharSetSubtractCount (&fcLangCharSets[i].charset, charset);
         if (FcDebug() & FC_DBG_SCANV)
@@ -684,3 +689,83 @@ 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)
+{
+    langset_count = 0;
+}
+
+/* ideally, should only write one copy of any particular FcLangSet */
+int
+FcLangSetNeededBytes (const FcLangSet *l)
+{
+    langset_count++;
+    return sizeof (FcLangSet);
+}
+
+static FcBool
+FcLangSetEnsureBank (int bi)
+{
+    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;
+}
+
+void *
+FcLangSetDistributeBytes (FcCache * metadata, void * block_ptr)
+{
+    int bi = FcCacheBankToIndex(metadata->bank);
+    if (!FcLangSetEnsureBank(bi))
+       return 0;
+
+    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);
+
+    if (!l) return 0;
+
+    langsets[bi][langset_ptr] = *l;
+    langsets[bi][langset_ptr].extra = 0;
+    langset_ptr++;
+    return &langsets[bi][p];
+}
+
+void *
+FcLangSetUnserialize (FcCache metadata, void *block_ptr)
+{
+    int bi = FcCacheBankToIndex(metadata.bank);
+    if (!FcLangSetEnsureBank(bi))
+       return 0;
+
+    FcMemAlloc (FC_MEM_LANGSET, metadata.langset_count * sizeof(FcLangSet));
+    langsets[bi] = (FcLangSet *)block_ptr;
+    block_ptr = (void *)((char *)block_ptr +
+                        metadata.langset_count * sizeof(FcLangSet));
+    return block_ptr;
+}