*** empty log message ***
[m17n/libotf.git] / example / otflist.c
1 #include <stdio.h>
2 #include <unistd.h>
3 #include <string.h>
4 #include <dirent.h>
5
6 #include <ft2build.h>
7 #include FT_FREETYPE_H
8
9 int
10 filter (const struct dirent *direntry)
11 {
12   int len = strlen (direntry->d_name);
13   const char *ext = direntry->d_name + (len - 4);
14
15   return (len >= 5
16           && (! strncmp (ext, ".ttf", 4)
17               || ! strncmp (ext, ".TTF", 4)
18               || ! strncmp (ext, ".otf", 4)
19               || ! strncmp (ext, ".OTF", 4)
20               || ! strncmp (ext, ".PFA", 4)
21               || ! strncmp (ext, ".pfa", 4)
22               || ! strncmp (ext, ".PFB", 4)
23               || ! strncmp (ext, ".pfb", 4)));
24 }
25
26 int
27 main (int argc, char **argv)
28
29   struct dirent **namelist;
30   int n;
31   int i, j;
32   FT_Library ft_library;
33   FT_Face face;
34
35   if (FT_Init_FreeType (&ft_library))
36     exit (1);
37
38   if (argc == 2)
39     chdir (argv[1]);
40   n = scandir (".", &namelist, filter, alphasort);
41
42   for (i = 0; i < n; i++)
43     if (! FT_New_Face (ft_library, namelist[i]->d_name, 0, &face))
44       {
45         char *name = alloca (strlen (namelist[i]->d_name)
46                              + strlen (face->family_name)
47                              + 4);
48         sprintf (name, "%s (%s)", namelist[i]->d_name, face->family_name);
49         printf ("%-40s %s", name, face->style_name);
50         for (j = 0; j < face->num_charmaps; j++)
51           printf (" %d-%d", face->charmaps[j]->platform_id,
52                   face->charmaps[j]->encoding_id);
53         printf ("\n");
54       }
55     else
56       {
57         printf ("%s fail to open\n", namelist[i]->d_name);
58       }
59   exit (0);
60 }