Created
January 15, 2019 15:32
-
-
Save ebassi/aaf98268d4979dd62bbaf23f6fadba71 to your computer and use it in GitHub Desktop.
Find a UTF-8 glyph in your fonts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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