summaryrefslogtreecommitdiff
path: root/fc-query
diff options
context:
space:
mode:
authorBehdad Esfahbod <behdad@behdad.org>2017-09-12 16:43:33 -0400
committerBehdad Esfahbod <behdad@behdad.org>2017-09-12 17:17:05 -0400
commit27a6a299e0fefca9c244213784d3c78b34281cd5 (patch)
tree9d6a5bdee1df7904fc133384bc9221a899cb8585 /fc-query
parentc524522bb45f71dfeaa8fd1ec277537dd6e85afa (diff)
Add FcFreeTypeQueryAll()
Like FcFreeTypeQuery(), but adds patterns for all fonts found, including named instances of variable fonts. If id is -1, then all collection faces are queried. Returns number of fonts added. This merges the same face loop that was in fc-query. and fcdir.c. Needs documentation update.
Diffstat (limited to 'fc-query')
-rw-r--r--fc-query/Makefile.am2
-rw-r--r--fc-query/fc-query.c88
2 files changed, 27 insertions, 63 deletions
diff --git a/fc-query/Makefile.am b/fc-query/Makefile.am
index 6fe357b9..73b3f11e 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 $(FREETYPE_LIBS)
+fc_query_LDADD = ${top_builddir}/src/libfontconfig.la
if USEDOCBOOK
diff --git a/fc-query/fc-query.c b/fc-query/fc-query.c
index 6cd5abd3..a5b2cda7 100644
--- a/fc-query/fc-query.c
+++ b/fc-query/fc-query.c
@@ -98,12 +98,9 @@ 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 id = -1;
int ignore_blanks = 0;
+ FcFontSet *fs;
FcChar8 *format = NULL;
FcBlanks *blanks = NULL;
int err = 0;
@@ -122,8 +119,7 @@ main (int argc, char **argv)
ignore_blanks = 1;
break;
case 'i':
- index_set = 1;
- set_index = atoi (optarg);
+ id = atoi (optarg);
break;
case 'f':
format = (FcChar8 *) strdup (optarg);
@@ -146,74 +142,42 @@ main (int argc, char **argv)
if (i == argc)
usage (argv[0], 1);
- if (FT_Init_FreeType (&ftLibrary))
- return 1;
-
+ fs = FcFontSetCreate ();
if (!ignore_blanks)
blanks = FcConfigGetBlanks (NULL);
+
for (; i < argc; i++)
{
- FT_Face face;
- int num_faces = 0;
- int num_instances = 0;
- int face_num = 0;
- int instance_num = 0;
- int id;
-
- if (index_set)
+ if (!FcFreeTypeQueryAll ((FcChar8*) argv[i], id, blanks, NULL, fs))
{
- face_num = set_face_num = set_index & 0xFFFF;
- instance_num = set_instance_num = set_index >> 16;
+ fprintf (stderr, "Can't query face %d of font file %s\n", id, argv[i]);
+ err = 1;
}
+ }
- do {
- FcPattern *pat;
-
- id = ((instance_num << 16) + face_num);
- 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)
- {
- FcChar8 *s;
-
- s = FcPatternFormat (pat, format);
- if (s)
- {
- printf ("%s", s);
- FcStrFree (s);
- }
- }
- else
- {
- FcPatternPrint (pat);
- }
+ for (i = 0; i < fs->nfont; i++)
+ {
+ FcPattern *pat = fs->fonts[i];
- FcPatternDestroy (pat);
- }
- else
- {
- fprintf (stderr, "Can't query face %d of font file %s\n", id, argv[i]);
- err = 1;
- }
+ if (format)
+ {
+ FcChar8 *s;
- if (instance_num < num_instances && !set_instance_num)
- instance_num++;
- else
+ s = FcPatternFormat (pat, format);
+ if (s)
{
- face_num++;
- instance_num = 0;
+ printf ("%s", s);
+ FcStrFree (s);
}
- } while (!err && (!index_set || face_num == set_face_num) && face_num < num_faces);
+ }
+ else
+ {
+ FcPatternPrint (pat);
+ }
}
- FT_Done_FreeType (ftLibrary);
+ FcFontSetDestroy (fs);
+
FcFini ();
return err;
}