]> git.wh0rd.org Git - fontconfig.git/commitdiff
Add FcPatternFilter() (#13016)
authorBehdad Esfahbod <behdad@behdad.org>
Wed, 13 Aug 2008 06:50:35 +0000 (02:50 -0400)
committerBehdad Esfahbod <behdad@behdad.org>
Sat, 14 Feb 2009 00:53:56 +0000 (16:53 -0800)
doc/fcpattern.fncs
fontconfig/fontconfig.h
src/fcpat.c

index 95529184e37c643f5b9789e2e876dc3f481f712f..4775dbd7aefe07746b85407145f0819e176b4f5a 100644 (file)
@@ -77,6 +77,18 @@ Returns whether <parameter>pa</parameter> and <parameter>pb</parameter> have exa
 objects in <parameter>os</parameter>.
 @@
 
+@RET@          FcPattern *
+@FUNC@         FcPatternFilter
+@TYPE1@                FcPattern *                     @ARG1@           p
+@TYPE2@                const FcObjectSet *             @ARG1@           os
+@PURPOSE@      Filter the objects of pattern
+@DESC@
+Returns a new pattern that only has those objects from
+<parameter>p</parameter> that are in <parameter>os</parameter>.
+If <parameter>os</parameter> is NULL, a duplicate of
+<parameter>p</parameter> is returned.
+@@
+
 @RET@          FcChar32
 @FUNC@         FcPatternHash
 @TYPE1@                const FcPattern *               @ARG1@          p
index 499e83136c631a03a3b76a7d1c3ee4da8dd79704..5139bbc043ba5c92ade7d0b4cff2de8135094aa6 100644 (file)
@@ -740,6 +740,9 @@ FcPatternDuplicate (const FcPattern *p);
 FcPublic void
 FcPatternReference (FcPattern *p);
 
+FcPublic FcPattern *
+FcPatternFilter (FcPattern *p, const FcObjectSet *os);
+
 FcPublic void
 FcValueDestroy (FcValue v);
 
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;