1 /* otflist.c -- List OpenType fonts.
3 Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
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. */
27 #include <sys/types.h>
31 #include FT_FREETYPE_H
40 /* Format MSG by FMT and print the result to the stderr, and exit. */
42 #define FATAL_ERROR(fmt, arg) \
44 fprintf (stderr, fmt, arg); \
50 print_tag (OTF_Tag tag)
54 OTF_tag_name (tag, name);
59 print_gsub_gpos_info (OTF *otf, char *table)
63 if (OTF_get_table (otf, table) == 0)
65 OTF_ScriptList *scripts;
66 OTF_FeatureList *features;
68 if (! strcmp (table, "GSUB"))
69 scripts = &otf->gsub->ScriptList, features = &otf->gsub->FeatureList;
71 scripts = &otf->gpos->ScriptList, features = &otf->gpos->FeatureList;
73 printf (" %s scripts: ", table);
74 for (i = 0; i < scripts->ScriptCount; i++)
76 OTF_Script *script = scripts->Script + i;
80 print_tag (script->ScriptTag);
81 if (script->LangSysCount > 0)
84 for (j = 0; j < script->LangSysCount; j++)
88 print_tag (script->LangSysRecord[j].LangSysTag);
95 printf (" %s features: ", table);
96 for (i = 0; i < features->FeatureCount; i++)
100 print_tag (features->Feature[i].FeatureTag);
106 help_and_exit (char *prog)
108 printf ("otflist %s\n", LIBOTF_VERSION);
109 printf ("Usage: %s [-l] [-h] [DIR]\n", prog);
110 printf ("List information about OpenType font files in the directory DIR.\n");
111 printf ("It actually lists all fonts that can be handled by Freetype.\n");
112 printf (" -h print this help, then exit\n");
113 printf (" -l use a long listing mode\n");
118 filter (const struct dirent *direntry)
120 int len = strlen (direntry->d_name);
121 const char *ext = direntry->d_name + (len - 4);
124 && (! strncmp (ext, ".ttf", 4)
125 || ! strncmp (ext, ".TTF", 4)
126 || ! strncmp (ext, ".ttc", 4)
127 || ! strncmp (ext, ".TTC", 4)
128 || ! strncmp (ext, ".otf", 4)
129 || ! strncmp (ext, ".OTF", 4)
130 || ! strncmp (ext, ".PFA", 4)
131 || ! strncmp (ext, ".pfa", 4)
132 || ! strncmp (ext, ".PFB", 4)
133 || ! strncmp (ext, ".pfb", 4)));
140 struct dirent **namelist = NULL;
144 next_file (char *dirname)
148 #ifdef HAVE_ALPHASORT
149 num_files = scandir (".", &namelist, filter, alphasort);
151 num_files = scandir (".", &namelist, filter, NULL);
154 if (dir_index == num_files)
156 return namelist[dir_index++]->d_name;
159 #else /* not HAVE_SCANDIR */
164 next_file (char *dirname)
166 struct dirent *dirent;
169 dirp = opendir (dirname);
170 while ((dirent = readdir (dirp))
171 && (strcmp (dirent->d_name, ".") == 0
172 || strcmp (dirent->d_name, "..") == 0));
176 return dirent->d_name;
179 #endif /* not HAVE_SCANDIR */
182 main (int argc, char **argv)
184 FT_Library ft_library;
190 if (FT_Init_FreeType (&ft_library))
191 FATAL_ERROR ("%s\n", "!! Freetype initialization failed.");
195 if (! strcmp (argv[1], "-h") || ! strcmp (argv[1], "--help"))
196 help_and_exit (argv[0]);
197 if (! strcmp (argv[1], "-l"))
198 long_format = 1, argc--, argv++;
202 if (chdir (argv[1]) < 0)
203 FATAL_ERROR ("Can't change directory to %s\n", argv[1]);
206 while ((filename = next_file (".")) != NULL)
208 if (! FT_New_Face (ft_library, filename, 0, &face))
210 OTF *otf = OTF_open (filename);
211 char *name, *family = NULL, *style = NULL;
215 OTF_get_table (otf, "name");
217 if (! (family = otf->name->name[16]))
218 family = otf->name->name[1];
219 if (! (style = otf->name->name[17]))
220 style = otf->name->name[2];
223 family = face->family_name;
225 style = face->style_name;
227 name = alloca (strlen (filename)
230 sprintf (name, "%s (%s)", filename, family);
231 printf ("%-40s %s", name, style);
232 for (i = 0; i < face->num_charmaps; i++)
233 printf (" %d-%d", face->charmaps[i]->platform_id,
234 face->charmaps[i]->encoding_id);
236 if (otf && long_format)
238 print_gsub_gpos_info (otf, "GSUB");
239 print_gsub_gpos_info (otf, "GPOS");
246 printf ("%s fail to open\n", filename);