2 * fontconfig/fc-validate/fc-validate.c
4 * Copyright © 2003 Keith Packard
5 * Copyright © 2012 Red Hat, Inc.
6 * Red Hat Author(s): Akira TAGOH
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 {"verbose", 0, 0, 'v'},
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 [-Vhv] [-i index] [-l LANG] [--index index] [--lang LANG] [--verbose] [--version] [--help] font-file...\n"),
86 fprintf (file, _("usage: %s [-Vhv] [-i index] [-l LANG] font-file...\n"),
89 fprintf (file, _("Validate font files and print result\n"));
92 fprintf (file, _(" -i, --index INDEX display the INDEX face of each font file only\n"));
93 fprintf (file, _(" -l, --lang=LANG set LANG instead of current locale\n"));
94 fprintf (file, _(" -v, --verbose show more detailed information\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, _(" -l LANG (lang) set LANG instead of current locale\n"));
100 fprintf (file, _(" -v (verbose) show more detailed information\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)
112 FcChar8 *lang = NULL;
113 const FcCharSet *fcs_lang = NULL;
117 FcBool verbose = FcFalse;
118 #if HAVE_GETOPT_LONG || HAVE_GETOPT
121 setlocale (LC_ALL, "");
124 while ((c = getopt_long (argc, argv, "i:l:mVhv", longopts, NULL)) != -1)
126 while ((c = getopt (argc, argv, "i:l:mVhv")) != -1)
132 set_index = atoi (optarg);
135 lang = (FcChar8 *) FcLangNormalize ((const FcChar8 *) optarg);
141 fprintf (stderr, "fontconfig version %d.%d.%d\n",
142 FC_MAJOR, FC_MINOR, FC_REVISION);
160 lang = FcLangNormalize ((const FcChar8 *) setlocale (LC_CTYPE, NULL));
163 fcs_lang = FcLangGetCharSet (lang);
165 if (FT_Init_FreeType (&ftlib))
167 fprintf (stderr, _("Can't initalize FreeType library\n"));
171 for (; i < argc; i++)
179 FcCharSet *fcs, *fcs_sub;
181 if (FT_New_Face (ftlib, argv[i], index, &face))
183 if (!index_set && index > 0)
185 fprintf (stderr, _("Unable to open %s\n"), argv[i]);
192 fcs = FcFreeTypeCharSet (face, NULL);
193 fcs_sub = FcCharSetSubtract (fcs_lang, fcs);
195 count = FcCharSetCount (fcs_sub);
198 FcChar32 ucs4, pos, map[FC_CHARSET_MAP_SIZE];
200 printf (_("%s:%d Missing %d glyph(s) to satisfy the coverage for %s language\n"),
201 argv[i], index, count, lang);
205 for (ucs4 = FcCharSetFirstPage (fcs_sub, map, &pos);
206 ucs4 != FC_CHARSET_DONE;
207 ucs4 = FcCharSetNextPage (fcs_sub, map, &pos))
211 for (j = 0; j < FC_CHARSET_MAP_SIZE; j++)
213 FcChar32 bits = map[j];
214 FcChar32 base = ucs4 + j * 32;
220 printf (" 0x%04x\n", base + b);
230 printf (_("%s:%d Satisfy the coverage for %s language\n"), argv[i], index, lang);
233 FcCharSetDestroy (fcs);
234 FcCharSetDestroy (fcs_sub);
240 } while (index_set == 0);
243 FT_Done_FreeType (ftlib);