]>
git.wh0rd.org - fontconfig.git/blob - fc-match/fc-match.c
8e133c6407475d126fef570fd8c5e91e6c5e6fe6
2 * fontconfig/fc-match/fc-match.c
4 * Copyright © 2003 Keith Packard
6 * Permission to use, copy, modify, distribute, and sell this software and its
7 * documentation for any purpose is hereby granted without fee, provided that
8 * the above copyright notice appear in all copies and that both that
9 * copyright notice and this permission notice appear in supporting
10 * documentation, and that the name of Keith Packard not be used in
11 * advertising or publicity pertaining to distribution of the software without
12 * specific, written prior permission. Keith Packard makes no
13 * representations about the suitability of this software for any purpose. It
14 * is provided "as is" without express or implied warranty.
16 * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
17 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
18 * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
19 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
20 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
21 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
22 * PERFORMANCE OF THIS SOFTWARE.
29 #define HAVE_GETOPT_LONG 1
34 #include <fontconfig/fontconfig.h>
43 #ifndef HAVE_GETOPT_LONG
44 #define HAVE_GETOPT_LONG 0
51 static const struct option longopts
[] = {
54 {"version", 0, 0, 'V'},
55 {"verbose", 0, 0, 'v'},
62 extern int optind
, opterr
, optopt
;
66 static void usage (char *program
)
69 fprintf (stderr
, "usage: %s [-svV?] [--sort] [--all] [--verbose] [--version] [--help] [pattern]\n",
72 fprintf (stderr
, "usage: %s [-svV?] [pattern]\n",
75 fprintf (stderr
, "List fonts matching [pattern]\n");
76 fprintf (stderr
, "\n");
78 fprintf (stderr
, " -s, --sort display sorted list of matches\n");
79 fprintf (stderr
, " -a, --all display unpruned sorted list of matches\n");
80 fprintf (stderr
, " -v, --verbose display entire font pattern\n");
81 fprintf (stderr
, " -V, --version display font config version and exit\n");
82 fprintf (stderr
, " -?, --help display this help and exit\n");
84 fprintf (stderr
, " -s, (sort) display sorted list of matches\n");
85 fprintf (stderr
, " -a (all) display unpruned sorted list of matches\n");
86 fprintf (stderr
, " -v (verbose) display entire font pattern\n");
87 fprintf (stderr
, " -V (version) display font config version and exit\n");
88 fprintf (stderr
, " -? (help) display this help and exit\n");
94 main (int argc
, char **argv
)
97 int sort
= 0, all
= 0;
102 #if HAVE_GETOPT_LONG || HAVE_GETOPT
106 while ((c
= getopt_long (argc
, argv
, "asVv?", longopts
, NULL
)) != -1)
108 while ((c
= getopt (argc
, argv
, "asVv?")) != -1)
119 fprintf (stderr
, "fontconfig version %d.%d.%d\n",
120 FC_MAJOR
, FC_MINOR
, FC_REVISION
);
136 fprintf (stderr
, "Can't init font config library\n");
140 pat
= FcNameParse ((FcChar8
*) argv
[i
]);
142 pat
= FcPatternCreate ();
147 FcConfigSubstitute (0, pat
, FcMatchPattern
);
148 FcDefaultSubstitute (pat
);
150 fs
= FcFontSetCreate ();
154 FcFontSet
*font_patterns
;
156 font_patterns
= FcFontSort (0, pat
, all
? FcFalse
: FcTrue
, 0, &result
);
158 for (j
= 0; j
< font_patterns
->nfont
; j
++)
160 FcPattern
*font_pattern
;
162 font_pattern
= FcFontRenderPrepare (NULL
, pat
, font_patterns
->fonts
[j
]);
164 FcFontSetAdd (fs
, font_pattern
);
167 FcFontSetSortDestroy (font_patterns
);
172 match
= FcFontMatch (0, pat
, &result
);
174 FcFontSetAdd (fs
, match
);
176 FcPatternDestroy (pat
);
182 for (j
= 0; j
< fs
->nfont
; j
++)
186 FcPatternPrint (fs
->fonts
[j
]);
194 if (FcPatternGetString (fs
->fonts
[j
], FC_FILE
, 0, &file
) != FcResultMatch
)
195 file
= (FcChar8
*) "<unknown filename>";
198 FcChar8
*slash
= (FcChar8
*) strrchr ((char *) file
, '/');
202 if (FcPatternGetString (fs
->fonts
[j
], FC_FAMILY
, 0, &family
) != FcResultMatch
)
203 family
= (FcChar8
*) "<unknown family>";
204 if (FcPatternGetString (fs
->fonts
[j
], FC_STYLE
, 0, &style
) != FcResultMatch
)
205 style
= (FcChar8
*) "<unknown style>";
207 printf ("%s: \"%s\" \"%s\"\n", file
, family
, style
);
210 FcFontSetDestroy (fs
);