diff options
author | Behdad Esfahbod <behdad@behdad.org> | 2017-08-01 14:41:02 +0100 |
---|---|---|
committer | Behdad Esfahbod <behdad@behdad.org> | 2017-08-01 14:41:02 +0100 |
commit | e5a51c899480c3bd99c36e49d1c24932f6a08810 (patch) | |
tree | ad413db19203aff60e1d5d494320fc2125bfb50c /fc-query | |
parent | d7f3437ade668c60a7e31f93669b73680be6512a (diff) |
[fc-query] Support listing named instances
Diffstat (limited to 'fc-query')
-rw-r--r-- | fc-query/Makefile.am | 2 | ||||
-rw-r--r-- | fc-query/fc-query.c | 46 |
2 files changed, 38 insertions, 10 deletions
diff --git a/fc-query/Makefile.am b/fc-query/Makefile.am index 73b3f11e..6e8ef5cc 100644 --- a/fc-query/Makefile.am +++ b/fc-query/Makefile.am @@ -41,7 +41,7 @@ EXTRA_DIST=fc-query.sgml $(BUILT_MANS) CLEANFILES = -fc_query_LDADD = ${top_builddir}/src/libfontconfig.la +fc_query_LDADD = $(FREETYPE_LIBS) ${top_builddir}/src/libfontconfig.la if USEDOCBOOK diff --git a/fc-query/fc-query.c b/fc-query/fc-query.c index 9bd39805..842a8b6f 100644 --- a/fc-query/fc-query.c +++ b/fc-query/fc-query.c @@ -98,8 +98,11 @@ usage (char *program, int error) int main (int argc, char **argv) { + FT_Library ftLibrary; int index_set = 0; int set_index = 0; + int set_face_num = 0; + int set_instance_num = 0; int ignore_blanks = 0; FcChar8 *format = NULL; FcBlanks *blanks = NULL; @@ -143,19 +146,38 @@ main (int argc, char **argv) if (i == argc) usage (argv[0], 1); + if (FT_Init_FreeType (&ftLibrary)) + return 1; + if (!ignore_blanks) blanks = FcConfigGetBlanks (NULL); for (; i < argc; i++) { - int index; - int count = 0; - - index = set_index; + FT_Face face; + int num_faces = 0; + int num_instances = 0; + int face_num = 0; + int instance_num = 0; + int id; + + if (index_set) + { + face_num = set_face_num = set_index & 0xFFFF; + instance_num = set_instance_num = set_index >> 16; + } do { FcPattern *pat; - pat = FcFreeTypeQuery ((FcChar8 *) argv[i], index, blanks, &count); + id = ((instance_num << 16) + face_num); + printf("id %d\n", id); + if (FT_New_Face (ftLibrary, argv[i], id, &face)) + break; + num_faces = face->num_faces; + num_instances = face->style_flags >> 16; + pat = FcFreeTypeQueryFace (face, (const FcChar8 *) argv[i], id, blanks); + FT_Done_Face (face); + if (pat) { if (format) @@ -178,15 +200,21 @@ main (int argc, char **argv) } else { - fprintf (stderr, "Can't query face %d of font file %s\n", - index, argv[i]); + fprintf (stderr, "Can't query face %d of font file %s\n", id, argv[i]); err = 1; } - index++; - } while (!index_set && index < count); + if (instance_num < num_instances && !set_instance_num) + instance_num++; + else + { + face_num++; + instance_num = 0; + } + } while (!err && (!index_set || face_num == set_face_num) && face_num < num_faces); } + FT_Done_FreeType (ftLibrary); FcFini (); return err; } |