2 * fontconfig/fc-query/fc-query.c
4 * Copyright © 2003 Keith Packard
5 * Copyright © 2008 Red Hat, Inc.
6 * Red Hat Author(s): Behdad Esfahbod
8 * Permission to use, copy, modify, distribute, and sell this software and its
9 * documentation for any purpose is hereby granted without fee, provided that
10 * the above copyright notice appear in all copies and that both that
11 * copyright notice and this permission notice appear in supporting
12 * documentation, and that the name of the author(s) not be used in
13 * advertising or publicity pertaining to distribution of the software without
14 * specific, written prior permission. The authors make no
15 * representations about the suitability of this software for any purpose. It
16 * is provided "as is" without express or implied warranty.
18 * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
19 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
20 * EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR
21 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
22 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
23 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
24 * PERFORMANCE OF THIS SOFTWARE.
31 #define HAVE_GETOPT_LONG 1
36 #include <fontconfig/fontconfig.h>
37 #include <fontconfig/fcfreetype.h>
46 #define _(x) (dgettext(GETTEXT_PACKAGE, x))
48 #define dgettext(d, s) (s)
55 #ifndef HAVE_GETOPT_LONG
56 #define HAVE_GETOPT_LONG 0
63 static const struct option longopts[] = {
66 {"format", 1, 0, 'f'},
67 {"version", 0, 0, 'V'},
74 extern int optind, opterr, optopt;
79 usage (char *program, int error)
81 FILE *file = error ? stderr : stdout;
83 fprintf (file, _("usage: %s [-bVh] [-i index] [-f FORMAT] [--index index] [--brief] [--format FORMAT] [--version] [--help] font-file...\n"),
86 fprintf (file, _("usage: %s [-bVh] [-i index] [-f FORMAT] font-file...\n"),
89 fprintf (file, _("Query font files and print resulting pattern(s)\n"));
92 fprintf (file, _(" -i, --index INDEX display the INDEX face of each font file only\n"));
93 fprintf (file, _(" -b, --brief display font pattern briefly\n"));
94 fprintf (file, _(" -f, --format=FORMAT use the given output format\n"));
95 fprintf (file, _(" -V, --version display font config version and exit\n"));
96 fprintf (file, _(" -h, --help display this help and exit\n"));
98 fprintf (file, _(" -i INDEX (index) display the INDEX face of each font file only\n"));
99 fprintf (file, _(" -b (brief) display font pattern briefly\n"));
100 fprintf (file, _(" -f FORMAT (format) use the given output format\n"));
101 fprintf (file, _(" -V (version) display font config version and exit\n"));
102 fprintf (file, _(" -h (help) display this help and exit\n"));
108 main (int argc, char **argv)
110 unsigned int id = (unsigned int) -1;
113 FcChar8 *format = NULL;
116 #if HAVE_GETOPT_LONG || HAVE_GETOPT
119 setlocale (LC_ALL, "");
121 while ((c = getopt_long (argc, argv, "i:bf:Vh", longopts, NULL)) != -1)
123 while ((c = getopt (argc, argv, "i:bf:Vh")) != -1)
128 id = (unsigned int) strtol (optarg, NULL, 0); /* strtol() To handle -1. */
134 format = (FcChar8 *) strdup (optarg);
137 fprintf (stderr, "fontconfig version %d.%d.%d\n",
138 FC_MAJOR, FC_MINOR, FC_REVISION);
154 fs = FcFontSetCreate ();
156 for (; i < argc; i++)
158 if (!FcFreeTypeQueryAll ((FcChar8*) argv[i], id, NULL, NULL, fs))
160 fprintf (stderr, _("Can't query face %u of font file %s\n"), id, argv[i]);
165 for (i = 0; i < fs->nfont; i++)
167 FcPattern *pat = fs->fonts[i];
171 FcPatternDel (pat, FC_CHARSET);
172 FcPatternDel (pat, FC_LANG);
179 s = FcPatternFormat (pat, format);
188 FcPatternPrint (pat);
192 FcFontSetDestroy (fs);