*** empty log message ***
[m17n/libotf.git] / example / otflist.c
1 /* otflist.c -- List OpenType fonts.
2
3 Copyright (C) 2003, 2004
4   National Institute of Advanced Industrial Science and Technology (AIST)
5   Registration Number H15PRO167
6
7 This file is part of libotf.
8
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.
13
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.
18
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.  */
23
24 #include <stdio.h>
25 #include <unistd.h>
26 #include <string.h>
27 #include <dirent.h>
28
29 #include <ft2build.h>
30 #include FT_FREETYPE_H
31
32 int
33 filter (const struct dirent *direntry)
34 {
35   int len = strlen (direntry->d_name);
36   const char *ext = direntry->d_name + (len - 4);
37
38   return (len >= 5
39           && (! strncmp (ext, ".ttf", 4)
40               || ! strncmp (ext, ".TTF", 4)
41               || ! strncmp (ext, ".otf", 4)
42               || ! strncmp (ext, ".OTF", 4)
43               || ! strncmp (ext, ".PFA", 4)
44               || ! strncmp (ext, ".pfa", 4)
45               || ! strncmp (ext, ".PFB", 4)
46               || ! strncmp (ext, ".pfb", 4)));
47 }
48
49 int
50 main (int argc, char **argv)
51
52   struct dirent **namelist;
53   int n;
54   int i, j;
55   FT_Library ft_library;
56   FT_Face face;
57
58   if (FT_Init_FreeType (&ft_library))
59     exit (1);
60
61   if (argc == 2)
62     chdir (argv[1]);
63   n = scandir (".", &namelist, filter, alphasort);
64
65   for (i = 0; i < n; i++)
66     if (! FT_New_Face (ft_library, namelist[i]->d_name, 0, &face))
67       {
68         char *name = alloca (strlen (namelist[i]->d_name)
69                              + strlen (face->family_name)
70                              + 4);
71         sprintf (name, "%s (%s)", namelist[i]->d_name, face->family_name);
72         printf ("%-40s %s", name, face->style_name);
73         for (j = 0; j < face->num_charmaps; j++)
74           printf (" %d-%d", face->charmaps[j]->platform_id,
75                   face->charmaps[j]->encoding_id);
76         printf ("\n");
77       }
78     else
79       {
80         printf ("%s fail to open\n", namelist[i]->d_name);
81       }
82   exit (0);
83 }