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>
49 #define _(x) (dgettext(GETTEXT_PACKAGE, x))
51 #define dgettext(d, s) (s)
58 #ifndef HAVE_GETOPT_LONG
59 #define HAVE_GETOPT_LONG 0
66 static const struct option longopts[] = {
69 {"format", 1, 0, 'f'},
70 {"version", 0, 0, 'V'},
77 extern int optind, opterr, optopt;
82 usage (char *program, int error)
84 FILE *file = error ? stderr : stdout;
86 fprintf (file, _("usage: %s [-bVh] [-i index] [-f FORMAT] [--index index] [--brief] [--format FORMAT] [--version] [--help] font-file...\n"),
89 fprintf (file, _("usage: %s [-bVh] [-i index] [-f FORMAT] font-file...\n"),
92 fprintf (file, _("Query font files and print resulting pattern(s)\n"));
95 fprintf (file, _(" -i, --index INDEX display the INDEX face of each font file only\n"));
96 fprintf (file, _(" -b, --brief display font pattern briefly\n"));
97 fprintf (file, _(" -f, --format=FORMAT use the given output format\n"));
98 fprintf (file, _(" -V, --version display font config version and exit\n"));
99 fprintf (file, _(" -h, --help display this help and exit\n"));
101 fprintf (file, _(" -i INDEX (index) display the INDEX face of each font file only\n"));
102 fprintf (file, _(" -b (brief) display font pattern briefly\n"));
103 fprintf (file, _(" -f FORMAT (format) use the given output format\n"));
104 fprintf (file, _(" -V (version) display font config version and exit\n"));
105 fprintf (file, _(" -h (help) display this help and exit\n"));
111 main (int argc, char **argv)
113 unsigned int id = (unsigned int) -1;
116 FcChar8 *format = NULL;
119 #if HAVE_GETOPT_LONG || HAVE_GETOPT
122 setlocale (LC_ALL, "");
124 while ((c = getopt_long (argc, argv, "i:bf:Vh", longopts, NULL)) != -1)
126 while ((c = getopt (argc, argv, "i:bf:Vh")) != -1)
131 id = (unsigned int) strtol (optarg, NULL, 0); /* strtol() To handle -1. */
137 format = (FcChar8 *) strdup (optarg);
140 fprintf (stderr, "fontconfig version %d.%d.%d\n",
141 FC_MAJOR, FC_MINOR, FC_REVISION);
157 fs = FcFontSetCreate ();
159 for (; i < argc; i++)
161 if (!FcFreeTypeQueryAll ((FcChar8*) argv[i], id, NULL, NULL, fs))
163 fprintf (stderr, _("Can't query face %u of font file %s\n"), id, argv[i]);
168 for (i = 0; i < fs->nfont; i++)
170 FcPattern *pat = fs->fonts[i];
174 FcPatternDel (pat, FC_CHARSET);
175 FcPatternDel (pat, FC_LANG);
182 s = FcPatternFormat (pat, format);
191 FcPatternPrint (pat);
195 FcFontSetDestroy (fs);