diff --git a/doc/fcpattern.fncs b/doc/fcpattern.fncs
index 9552918..4775dbd 100644
--- a/doc/fcpattern.fncs
+++ b/doc/fcpattern.fncs
@@ -77,6 +77,18 @@ Returns whether pa and pb have exa
objects in os.
@@
+@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
+p that are in os.
+If os is NULL, a duplicate of
+p is returned.
+@@
+
@RET@ FcChar32
@FUNC@ FcPatternHash
@TYPE1@ const FcPattern * @ARG1@ p
diff --git a/fontconfig/fontconfig.h b/fontconfig/fontconfig.h
index 499e831..5139bbc 100644
--- a/fontconfig/fontconfig.h
+++ b/fontconfig/fontconfig.h
@@ -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);
diff --git a/src/fcpat.c b/src/fcpat.c
index 35127f2..350c4c2 100644
--- a/src/fcpat.c
+++ b/src/fcpat.c
@@ -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;