Skip to content

Instantly share code, notes, and snippets.

@marguerite
Created November 28, 2022 11:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marguerite/e6eaab12010f6e7845d3ca351b253581 to your computer and use it in GitHub Desktop.
Save marguerite/e6eaab12010f6e7845d3ca351b253581 to your computer and use it in GitHub Desktop.
fc-emoji-subtract
# fc-emoji-subtract copyright marguerite@opensuse.org
# description: it calculates the charset of emoji fonts installed on your system and find what need to subtract for you specified font
diff --git a/Makefile.am b/Makefile.am
index 6d4cd32..70c61a0 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -22,7 +22,7 @@
# PERFORMANCE OF THIS SOFTWARE.
SUBDIRS=fontconfig fc-case fc-lang src \
- fc-cache fc-cat fc-conflist fc-list fc-match \
+ fc-cache fc-cat fc-conflist fc-list fc-emoji-subtract fc-match \
fc-pattern fc-query fc-scan fc-validate conf.d \
its po po-conf test
if ENABLE_DOCS
diff --git a/configure.ac b/configure.ac
index 60871dc..b37649a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -821,6 +821,7 @@ fc-cache/Makefile
fc-cat/Makefile
fc-conflist/Makefile
fc-list/Makefile
+fc-emoji-subtract/Makefile
fc-match/Makefile
fc-pattern/Makefile
fc-query/Makefile
diff --git a/fc-emoji-subtract/Makefile.am b/fc-emoji-subtract/Makefile.am
new file mode 100644
index 0000000..28695b7
--- /dev/null
+++ b/fc-emoji-subtract/Makefile.am
@@ -0,0 +1,35 @@
+#
+# fontconfig/fc-list/Makefile.am
+#
+# Copyright © 2003 Keith Packard
+#
+# Permission to use, copy, modify, distribute, and sell this software and its
+# documentation for any purpose is hereby granted without fee, provided that
+# the above copyright notice appear in all copies and that both that
+# copyright notice and this permission notice appear in supporting
+# documentation, and that the name of the author(s) not be used in
+# advertising or publicity pertaining to distribution of the software without
+# specific, written prior permission. The authors make no
+# representations about the suitability of this software for any purpose. It
+# is provided "as is" without express or implied warranty.
+#
+# THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+# INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+# EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+# DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+# TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+# PERFORMANCE OF THIS SOFTWARE.
+FC_LIST_SRC=${top_srcdir}/fc-emoji-subtract
+
+bin_PROGRAMS=fc-emoji-subtract
+
+AM_CPPFLAGS=-I${top_srcdir} $(WARN_CFLAGS)
+
+CLEANFILES =
+
+fc_emoji_subtract_LDADD = ${top_builddir}/src/libfontconfig.la
+
+all-local:
+
+-include $(top_srcdir)/git.mk
diff --git a/fc-emoji-subtract/fc-emoji-subtract.c b/fc-emoji-subtract/fc-emoji-subtract.c
new file mode 100644
index 0000000..d18115c
--- /dev/null
+++ b/fc-emoji-subtract/fc-emoji-subtract.c
@@ -0,0 +1,79 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <fontconfig/fontconfig.h>
+
+int main(int argc, char **argv){
+ FcFontSet* fs;
+ FcPattern* pat;
+ FcObjectSet* os;
+
+ FcChar8* strpat = (FcChar8*)":lang=und-zsye";
+ pat = FcNameParse(strpat);
+ os = FcObjectSetBuild(FC_FAMILY, FC_CHARSET, FC_FILE, (char*)0);
+
+ fs = FcFontList(0, pat, os);
+
+ FcPatternDestroy(pat);
+ FcObjectSetDestroy(os);
+
+ FcCharSet* cs = FcCharSetCreate();
+ int i;
+ for(i=0; i<fs->nfont; i++){
+ FcCharSet* tmp;
+ if (FcPatternGetCharSet(fs->fonts[i], FC_CHARSET, 0, &tmp) != FcResultMatch) {
+ goto nofont;
+ }
+ cs = FcCharSetUnion(cs, tmp);
+ }
+
+ FcFontSetDestroy(fs);
+
+ FcPattern* pat1;
+ FcFontSet* fs1;
+ FcObjectSet* os1;
+
+ if (argc == 1) {
+ printf("you have to specify a font family to subtract.\n");
+ goto nofont;
+ }
+
+ FcChar8* strpat1 = (FcChar8*)argv[1];
+ pat1 = FcNameParse(strpat1);
+ os1 = FcObjectSetBuild(FC_FAMILY, FC_CHARSET, FC_FILE, (char*)0);
+ fs1 = FcFontList(0, pat1, os1);
+
+ FcPatternDestroy(pat1);
+ FcObjectSetDestroy(os1);
+
+ FcCharSet* cs1 = FcCharSetCreate();
+ for(i=0; i<fs1->nfont; i++){
+ if (FcPatternGetCharSet(fs1->fonts[i], FC_CHARSET, 0, &cs1) != FcResultMatch) {
+ goto nofont;
+ }
+ }
+
+ FcFontSetDestroy(fs1);
+
+ FcCharSet* cs2 = FcCharSetCreate();
+ cs2 = FcCharSetIntersect(cs1, cs);
+
+ FcStrBuf buf;
+ FcChar8 init_buf[1024];
+ FcStrBufInit(&buf, init_buf, sizeof(init_buf));
+
+ if (FcNameUnparseCharSet(&buf, cs2) && FcStrBufChar(&buf, '\0')) {
+ printf("%s\n", buf.buf);
+ } else {
+ printf("charset (alloc error)\n");
+ }
+
+ FcStrBufDestroy(&buf);
+ FcCharSetDestroy(cs);
+ FcCharSetDestroy(cs1);
+ FcCharSetDestroy(cs2);
+
+ return 0;
+
+nofont:
+ return 1;
+}
diff --git a/fontconfig/fontconfig.h b/fontconfig/fontconfig.h
index 09292a3..15cae3f 100644
--- a/fontconfig/fontconfig.h
+++ b/fontconfig/fontconfig.h
@@ -494,6 +494,27 @@ FcConfigFileInfoIterGet (FcConfig *config,
FcChar8 **description,
FcBool *enabled);
+typedef struct _FcStrBuf {
+ FcChar8 *buf;
+ FcBool allocated;
+ FcBool failed;
+ int len;
+ int size;
+ FcChar8 buf_static[16 * sizeof (void *)];
+} FcStrBuf;
+
+FcPublic FcBool
+FcNameUnparseCharSet (FcStrBuf *buf, const FcCharSet *c);
+
+FcPublic void
+FcStrBufInit (FcStrBuf *buf, FcChar8 *init, int size);
+
+FcPublic void
+FcStrBufDestroy (FcStrBuf *buf);
+
+FcPublic FcBool
+FcStrBufChar (FcStrBuf *buf, FcChar8 c);
+
/* fccharset.c */
FcPublic FcCharSet*
FcCharSetCreate (void);
diff --git a/src/fcint.h b/src/fcint.h
index c615b66..8c66ad3 100644
--- a/src/fcint.h
+++ b/src/fcint.h
@@ -397,14 +397,14 @@ struct _FcStrList {
int n;
};
-typedef struct _FcStrBuf {
+/*typedef struct _FcStrBuf {
FcChar8 *buf;
FcBool allocated;
FcBool failed;
int len;
int size;
FcChar8 buf_static[16 * sizeof (void *)];
-} FcStrBuf;
+} FcStrBuf;*/
typedef struct _FcHashTable FcHashTable;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment