[fc-query] Support listing named instances

This commit is contained in:
Behdad Esfahbod 2017-08-01 14:41:02 +01:00
parent d7f3437ade
commit e5a51c8994
2 changed files with 37 additions and 9 deletions

View File

@ -41,7 +41,7 @@ EXTRA_DIST=fc-query.sgml $(BUILT_MANS)
CLEANFILES = CLEANFILES =
fc_query_LDADD = ${top_builddir}/src/libfontconfig.la fc_query_LDADD = $(FREETYPE_LIBS) ${top_builddir}/src/libfontconfig.la
if USEDOCBOOK if USEDOCBOOK

View File

@ -98,8 +98,11 @@ usage (char *program, int error)
int int
main (int argc, char **argv) main (int argc, char **argv)
{ {
FT_Library ftLibrary;
int index_set = 0; int index_set = 0;
int set_index = 0; int set_index = 0;
int set_face_num = 0;
int set_instance_num = 0;
int ignore_blanks = 0; int ignore_blanks = 0;
FcChar8 *format = NULL; FcChar8 *format = NULL;
FcBlanks *blanks = NULL; FcBlanks *blanks = NULL;
@ -143,19 +146,38 @@ main (int argc, char **argv)
if (i == argc) if (i == argc)
usage (argv[0], 1); usage (argv[0], 1);
if (FT_Init_FreeType (&ftLibrary))
return 1;
if (!ignore_blanks) if (!ignore_blanks)
blanks = FcConfigGetBlanks (NULL); blanks = FcConfigGetBlanks (NULL);
for (; i < argc; i++) for (; i < argc; i++)
{ {
int index; FT_Face face;
int count = 0; int num_faces = 0;
int num_instances = 0;
int face_num = 0;
int instance_num = 0;
int id;
index = set_index; if (index_set)
{
face_num = set_face_num = set_index & 0xFFFF;
instance_num = set_instance_num = set_index >> 16;
}
do { do {
FcPattern *pat; 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 (pat)
{ {
if (format) if (format)
@ -178,15 +200,21 @@ main (int argc, char **argv)
} }
else else
{ {
fprintf (stderr, "Can't query face %d of font file %s\n", fprintf (stderr, "Can't query face %d of font file %s\n", id, argv[i]);
index, argv[i]);
err = 1; err = 1;
} }
index++; if (instance_num < num_instances && !set_instance_num)
} while (!index_set && index < count); 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 (); FcFini ();
return err; return err;
} }