1 /* otflist.c -- List OpenType fonts.
3 Copyright (C) 2003, 2004
4 National Institute of Advanced Industrial Science and Technology (AIST)
5 Registration Number H15PRO167
7 This file is part of libotf.
9 Libotf is free software; you can redistribute it and/or modify it
10 under the terms of the GNU Lesser General Public License as published
11 by the Free Software Foundation; either version 2.1 of the License, or
12 (at your option) any later version.
14 Libotf is distributed in the hope that it will be useful, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17 License for more details.
19 You should have received a copy of the GNU Lesser General Public
20 License along with this library, in a file named COPYING; if not,
21 write to the Free Software Foundation, Inc., 59 Temple Place, Suite
22 330, Boston, MA 02111-1307, USA. */
30 #include FT_FREETYPE_H
34 /* Format MSG by FMT and print the result to the stderr, and exit. */
36 #define FATAL_ERROR(fmt, arg) \
38 fprintf (stderr, fmt, arg); \
43 help_and_exit (char *prog)
45 printf ("otflist %s\n", LIBOTF_VERSION);
46 printf ("Usage: %s [-l] [-h] [DIR]\n", prog);
47 printf ("List information about OpenType font files in the directory DIR.\n");
48 printf ("It actually lists all fonts that can be handled by Freetype.\n");
49 printf (" -h print this help, then exit\n");
50 printf (" -l use a long listing mode\n");
55 filter (const struct dirent *direntry)
57 int len = strlen (direntry->d_name);
58 const char *ext = direntry->d_name + (len - 4);
61 && (! strncmp (ext, ".ttf", 4)
62 || ! strncmp (ext, ".TTF", 4)
63 || ! strncmp (ext, ".otf", 4)
64 || ! strncmp (ext, ".OTF", 4)
65 || ! strncmp (ext, ".PFA", 4)
66 || ! strncmp (ext, ".pfa", 4)
67 || ! strncmp (ext, ".PFB", 4)
68 || ! strncmp (ext, ".pfb", 4)));
72 main (int argc, char **argv)
74 FT_Library ft_library;
77 struct dirent **namelist;
81 if (FT_Init_FreeType (&ft_library))
86 if (! strcmp (argv[1], "-h") || ! strcmp (argv[1], "--help"))
87 help_and_exit (argv[0]);
88 if (! strcmp (argv[1], "-l"))
89 long_format = 1, argc--, argv++;
93 if (chdir (argv[1]) < 0)
94 FATAL_ERROR ("Can't change directory to %s\n", argv[1]);
96 n = scandir (".", &namelist, filter, alphasort);
98 for (i = 0; i < n; i++)
99 if (! FT_New_Face (ft_library, namelist[i]->d_name, 0, &face))
101 OTF *otf = OTF_open (namelist[i]->d_name);
102 char *name, *family, *style;
106 OTF_get_table (otf, "name");
108 if (! (family = otf->name->name[16]))
109 family = otf->name->name[1];
110 if (! (style = otf->name->name[17]))
111 style = otf->name->name[2];
114 family = face->family_name;
116 style = face->style_name;
118 name = alloca (strlen (namelist[i]->d_name)
121 sprintf (name, "%s (%s)", namelist[i]->d_name, family);
122 printf ("%-40s %s", name, style);
123 for (j = 0; j < face->num_charmaps; j++)
124 printf (" %d-%d", face->charmaps[j]->platform_id,
125 face->charmaps[j]->encoding_id);
130 printf ("%s fail to open\n", namelist[i]->d_name);