]> git.wh0rd.org - fontconfig.git/blobdiff - src/fccharset.c
Consistently use FcStat() over stat() in all places
[fontconfig.git] / src / fccharset.c
index 5da131283d07f17991fbe361c239511282dd9a61..98ced278703dfd7f1d3a109cc2dc6ef94dca9e7f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $RCSId: xc/lib/fontconfig/src/fccharset.c,v 1.18 2002/08/22 07:36:44 keithp Exp $
+ * fontconfig/src/fccharset.c
  *
  * Copyright © 2001 Keith Packard
  *
@@ -452,6 +452,68 @@ FcCharSetUnion (const FcCharSet *a, const FcCharSet *b)
     return FcCharSetOperate (a, b, FcCharSetUnionLeaf, FcTrue, FcTrue);
 }
 
+FcCharSet *
+FcCharSetMerge (FcCharSet *a, const FcCharSet *b)
+{
+    FcCharSet      *fcs;
+    FcCharSetIter    ai, bi;
+
+    if (a == NULL) {
+       return FcCharSetCopy ((FcCharSet *) b);
+    } else if (a->ref == FC_REF_CONSTANT) {
+       fcs = FcCharSetCreate ();
+       if (fcs == NULL)
+           return NULL;
+    } else
+       fcs = a;
+
+    FcCharSetIterStart (a, &ai);
+    FcCharSetIterStart (b, &bi);
+    while (ai.leaf || bi.leaf)
+    {
+       if (ai.ucs4 < bi.ucs4)
+       {
+           if (!FcCharSetAddLeaf (fcs, ai.ucs4, ai.leaf))
+               goto bail;
+
+           FcCharSetIterNext (a, &ai);
+       }
+       else if (bi.ucs4 < ai.ucs4)
+       {
+           if (!FcCharSetAddLeaf (fcs, bi.ucs4, bi.leaf))
+               goto bail;
+
+           FcCharSetIterNext (b, &bi);
+       }
+       else
+       {
+           FcCharLeaf  leaf;
+
+           if (FcCharSetUnionLeaf (&leaf, ai.leaf, bi.leaf))
+           {
+               if (!FcCharSetAddLeaf (fcs, ai.ucs4, &leaf))
+                   goto bail;
+           }
+
+           FcCharSetIterNext (a, &ai);
+           FcCharSetIterNext (b, &bi);
+       }
+    }
+
+    if (fcs != a)
+       FcCharSetDestroy (a);
+
+    return fcs;
+
+bail:
+    FcCharSetDestroy (fcs);
+
+    if (fcs != a)
+       FcCharSetDestroy (a);
+
+    return NULL;
+}
+
 static FcBool
 FcCharSetSubtractLeaf (FcCharLeaf *result,
                       const FcCharLeaf *al,
@@ -1239,6 +1301,9 @@ FcCharSetFreezerDestroy (FcCharSetFreezer *freezer)
        for (ent = freezer->set_hash_table[i]; ent; ent = next)
        {
            next = ent->next;
+           FcMemFree (FC_MEM_CHARSET, (sizeof (FcCharSetEnt) +
+                                       ent->set.num * sizeof (FcCharLeaf *) +
+                                       ent->set.num * sizeof (FcChar16)));
            free (ent);
        }
     }
@@ -1254,7 +1319,10 @@ FcCharSetFreezerDestroy (FcCharSetFreezer *freezer)
     }
 
     for (i = 0; i < freezer->leaf_block_count; i++)
+    {
        free (freezer->leaf_blocks[i]);
+       FcMemFree (FC_MEM_CHARLEAF, FC_CHAR_LEAF_BLOCK * sizeof (FcCharLeafEnt));
+    }
 
     free (freezer->leaf_blocks);
     free (freezer);