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>
47 #ifndef HAVE_GETOPT_LONG
48 #define HAVE_GETOPT_LONG 0
55 static const struct option longopts[] = {
58 {"verbose", 0, 0, 'v'},
59 {"version", 0, 0, 'V'},
66 extern int optind, opterr, optopt;
71 usage (char *program, int error)
73 FILE *file = error ? stderr : stdout;
75 fprintf (file, "usage: %s [-Vhv] [-i index] [-l LANG] [--index index] [--lang LANG] [--verbose] [--version] [--help] font-file...\n",
78 fprintf (file, "usage: %s [-Vhv] [-i index] [-l LANG] font-file...\n",
81 fprintf (file, "Validate font files and print result\n");
84 fprintf (file, " -i, --index INDEX display the INDEX face of each font file only\n");
85 fprintf (file, " -l, --lang=LANG set LANG instead of current locale\n");
86 fprintf (file, " -v, --verbose show more detailed information\n");
87 fprintf (file, " -V, --version display font config version and exit\n");
88 fprintf (file, " -h, --help display this help and exit\n");
90 fprintf (file, " -i INDEX (index) display the INDEX face of each font file only\n");
91 fprintf (file, " -l LANG (lang) set LANG instead of current locale\n");
92 fprintf (file, " -v (verbose) show more detailed information\n");
93 fprintf (file, " -V (version) display font config version and exit\n");
94 fprintf (file, " -h (help) display this help and exit\n");
100 main (int argc, char **argv)
104 FcChar8 *lang = NULL;
105 const FcCharSet *fcs_lang = NULL;
109 FcBool verbose = FcFalse;
110 #if HAVE_GETOPT_LONG || HAVE_GETOPT
113 setlocale (LC_ALL, "");
116 while ((c = getopt_long (argc, argv, "i:l:mVhv", longopts, NULL)) != -1)
118 while ((c = getopt (argc, argv, "i:l:mVhv")) != -1)
124 set_index = atoi (optarg);
127 lang = (FcChar8 *) FcLangNormalize ((const FcChar8 *) optarg);
133 fprintf (stderr, "fontconfig version %d.%d.%d\n",
134 FC_MAJOR, FC_MINOR, FC_REVISION);
152 lang = FcLangNormalize ((const FcChar8 *) setlocale (LC_CTYPE, NULL));
155 fcs_lang = FcLangGetCharSet (lang);
157 if (FT_Init_FreeType (&ftlib))
159 fprintf (stderr, "Can't initalize FreeType library\n");
163 for (; i < argc; i++)
171 FcCharSet *fcs, *fcs_sub;
173 if (FT_New_Face (ftlib, argv[i], index, &face))
175 if (!index_set && index > 0)
177 fprintf (stderr, "Unable to open %s\n", argv[i]);
184 fcs = FcFreeTypeCharSet (face, NULL);
185 fcs_sub = FcCharSetSubtract (fcs_lang, fcs);
187 count = FcCharSetCount (fcs_sub);
190 FcChar32 ucs4, pos, map[FC_CHARSET_MAP_SIZE];
192 printf ("%s:%d Missing %d glyph(s) to satisfy the coverage for %s language\n",
193 argv[i], index, count, lang);
197 for (ucs4 = FcCharSetFirstPage (fcs_sub, map, &pos);
198 ucs4 != FC_CHARSET_DONE;
199 ucs4 = FcCharSetNextPage (fcs_sub, map, &pos))
203 for (j = 0; j < FC_CHARSET_MAP_SIZE; j++)
205 FcChar32 bits = map[j];
206 FcChar32 base = ucs4 + j * 32;
212 printf (" 0x%04x\n", base + b);
222 printf ("%s:%d Satisfy the coverage for %s language\n", argv[i], index, lang);
225 FcCharSetDestroy (fcs);
226 FcCharSetDestroy (fcs_sub);
232 } while (index_set == 0);
235 FT_Done_FreeType (ftlib);