Skip to content

Instantly share code, notes, and snippets.

@ebassi
Created January 15, 2019 15:32
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 ebassi/aaf98268d4979dd62bbaf23f6fadba71 to your computer and use it in GitHub Desktop.
Save ebassi/aaf98268d4979dd62bbaf23f6fadba71 to your computer and use it in GitHub Desktop.
Find a UTF-8 glyph in your fonts
/* fc-search-point.c: Search for a UTF-8 code point in the installed fonts
*
* Requires: fontconfig
*
* Build with:
*
* ```sh
* $ cc \
* `pkg-config --cflags fontconfig` \
* -o fc-search-point fc-search-point.c \
* `pkg-config --libs fontconfig`
* ```
*
* Usage: `fc-search-point CHAR [CHAR...]`
*
* Released under the terms of the CC0
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <fontconfig/fontconfig.h>
int
main (int argc,
char *argv[])
{
if (argc < 2) {
fprintf (stderr, "Usage: fc-search-point CHAR [CHAR...]\n");
return EXIT_FAILURE;
}
FcObjectSet *os = FcObjectSetBuild (FC_CHARSET, FC_FILE, NULL);
FcPattern *pat = FcPatternCreate ();
FcFontSet *fs = FcFontList (0, pat, os);
FcPatternDestroy (pat);
FcObjectSetDestroy (os);
for (int i = 0; i < fs->nfont; i++) {
FcPattern *font_pat = fs->fonts[i];
FcCharSet *cs;
if (FcPatternGetCharSet (font_pat, FC_CHARSET, 0, &cs) != FcResultMatch)
continue;
for (int j = 1; j < argc; j++) {
FcChar32 ch;
FcUtf8ToUcs4 ((FcChar8 *) argv[j], &ch, strlen (argv[j]));
if (FcCharSetHasChar (cs, ch)) {
fprintf (stdout, "UTF-8 code point '%s' found:\n", argv[j]);
FcPatternDel (font_pat, FC_CHARSET);
FcPatternDel (font_pat, FC_LANG);
FcPatternPrint (font_pat);
}
}
}
FcFontSetDestroy (fs);
FcFini ();
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment