]> git.wh0rd.org - fontconfig.git/blobdiff - src/fcpat.c
Add FcPatternFilter() (#13016)
[fontconfig.git] / src / fcpat.c
index 35127f2a38558751fd09178bd7f49fcdac695740..350c4c288d48258db9d9602627098c5a15dcd169 100644 (file)
@@ -997,6 +997,43 @@ FcPatternAppend (FcPattern *p, FcPattern *s)
     return FcTrue;
 }
 
+FcPattern *
+FcPatternFilter (FcPattern *p, const FcObjectSet *os)
+{
+    int                    i;
+    FcPattern      *ret;
+    FcPatternElt    *e;
+    FcValueListPtr  v;
+
+    if (!os)
+       return FcPatternDuplicate (p);
+
+    ret = FcPatternCreate ();
+    if (!ret)
+       return NULL;
+
+    for (i = 0; i < os->nobject; i++)
+    {
+       FcObject object = FcObjectFromName (os->objects[i]);
+       e = FcPatternObjectFindElt (p, object);
+       if (e)
+       {
+           for (v = FcPatternEltValues(e); v; v = FcValueListNext(v))
+           {
+               if (!FcPatternObjectAddWithBinding (ret, e->object,
+                                                   FcValueCanonicalize(&v->value),
+                                                   v->binding, FcTrue))
+                   goto bail0;
+           }
+       }
+    }
+    return p;
+
+bail0:
+    FcPatternDestroy (ret);
+    return NULL;
+}
+
 #define OBJECT_HASH_SIZE    31
 static struct objectBucket {
     struct objectBucket        *next;