]> git.wh0rd.org - fontconfig.git/blobdiff - src/fccharset.c
Add a few more common font families to the default configuration
[fontconfig.git] / src / fccharset.c
index 86c59adfff65c3fe3b22a19afa812abffd3dfb55..c5941ee879a1e99083be1a34051ffaebcb79f4c1 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $XFree86: xc/lib/fontconfig/src/fccharset.c,v 1.10 2002/05/31 04:42:42 keithp Exp $
+ * $XFree86: xc/lib/fontconfig/src/fccharset.c,v 1.13 2002/06/26 22:56:51 keithp Exp $
  *
  * Copyright © 2001 Keith Packard, member of The XFree86 Project, Inc.
  *
@@ -858,7 +858,7 @@ static int  FcCharLeafTotal;
 static int     FcCharLeafUsed;
 
 static FcCharLeaf *
-FcNameParseBuildLeaf (FcCharLeaf *leaf)
+FcCharSetFreezeLeaf (FcCharLeaf *leaf)
 {
     static FcCharLeafEnt       *hashTable[FC_CHAR_LEAF_HASH_SIZE];
     FcChar32                   hash = FcCharLeafHash (leaf);
@@ -915,7 +915,7 @@ static int  FcCharSetUsed;
 static int     FcCharSetTotalEnts, FcCharSetUsedEnts;
 
 static FcCharSet *
-FcNameParseBuildSet (FcCharSet *fcs)
+FcCharSetFreezeBase (FcCharSet *fcs)
 {
     static FcCharSetEnt        *hashTable[FC_CHAR_SET_HASH_SIZE];
     FcChar32           hash = FcCharSetHash (fcs);
@@ -948,10 +948,18 @@ FcNameParseBuildSet (FcCharSet *fcs)
     ent->set.ref = 0;
     ent->set.constant = FcTrue;
     ent->set.num = fcs->num;
-    ent->set.leaves = (FcCharLeaf **) (ent + 1);
-    ent->set.numbers = (FcChar16 *) (ent->set.leaves + fcs->num);
-    memcpy (ent->set.leaves, fcs->leaves, fcs->num * sizeof (FcCharLeaf *));
-    memcpy (ent->set.numbers, fcs->numbers, fcs->num * sizeof (FcChar16));
+    if (fcs->num)
+    {
+       ent->set.leaves = (FcCharLeaf **) (ent + 1);
+       ent->set.numbers = (FcChar16 *) (ent->set.leaves + fcs->num);
+       memcpy (ent->set.leaves, fcs->leaves, fcs->num * sizeof (FcCharLeaf *));
+       memcpy (ent->set.numbers, fcs->numbers, fcs->num * sizeof (FcChar16));
+    }
+    else
+    {
+       ent->set.leaves = 0;
+       ent->set.numbers = 0;
+    }
 
     ent->hash = hash;
     ent->next = *bucket;
@@ -959,6 +967,36 @@ FcNameParseBuildSet (FcCharSet *fcs)
     return &ent->set;
 }
 
+FcCharSet *
+FcCharSetFreeze (FcCharSet *fcs)
+{
+    FcCharSet  *b;
+    FcCharSet  *n = 0;
+    FcCharLeaf *l;
+    int                i;
+
+    b = FcCharSetCreate ();
+    if (!b)
+       goto bail0;
+    for (i = 0; i < fcs->num; i++)
+    {
+       l = FcCharSetFreezeLeaf (fcs->leaves[i]);
+       if (!l)
+           goto bail1;
+       if (!FcCharSetInsertLeaf (b, fcs->numbers[i] << 8, l))
+           goto bail1;
+    }
+    n = FcCharSetFreezeBase (b);
+bail1:
+    if (b->leaves)
+       free (b->leaves);
+    if (b->numbers)
+       free (b->numbers);
+    free (b);
+bail0:
+    return n;
+}
+
 FcCharSet *
 FcNameParseCharSet (FcChar8 *string)
 {
@@ -987,7 +1025,7 @@ FcNameParseCharSet (FcChar8 *string)
        }
        if (bits)
        {
-           leaf = FcNameParseBuildLeaf (&temp);
+           leaf = FcCharSetFreezeLeaf (&temp);
            if (!leaf)
                goto bail1;
            if (!FcCharSetInsertLeaf (c, ucs4, leaf))
@@ -1015,7 +1053,7 @@ FcNameParseCharSet (FcChar8 *string)
            sizeof (FcCharSet) * FcCharSetUsed +
            FcCharSetUsedEnts * (sizeof (FcCharLeaf *) + sizeof (FcChar16)));
 #endif
-    n = FcNameParseBuildSet (c);
+    n = FcCharSetFreezeBase (c);
 bail1:
     if (c->leaves)
        free (c->leaves);