5851b96e35c8fc8b83ee48fbe8f8558a3afbeefe
[m17n/libotf.git] / example / otflist.c
1 #include <stdio.h>
2 #include <string.h>
3 #include <dirent.h>
4
5 #include <ft2build.h>
6 #include FT_FREETYPE_H
7
8 int
9 filter (const struct dirent *direntry)
10 {
11   int len = strlen (direntry->d_name);
12   const char *ext = direntry->d_name + (len - 4);
13
14   return (len >= 5
15           && (! strncmp (ext, ".ttf", 4)
16               || ! strncmp (ext, ".TTF", 4)
17               || ! strncmp (ext, ".otf", 4)
18               || ! strncmp (ext, ".OTF", 4)));
19 }
20
21 int
22 main ()
23
24   struct dirent **namelist;
25   int n = scandir (".", &namelist, filter, alphasort);
26   int i, j;
27   FT_Library ft_library;
28   FT_Face face;
29
30   if (FT_Init_FreeType (&ft_library))
31     exit (1);
32
33   for (i = 0; i < n; i++)
34     if (! FT_New_Face (ft_library, namelist[i]->d_name, 0, &face))
35       {
36         printf ("%s: %s: %s\n", namelist[i]->d_name,
37                 face->family_name, face->style_name);
38         if (face->num_charmaps == 0)
39           continue;
40         for (j = 0; j < face->num_charmaps; j++)
41           {
42             if (face->charmaps[j]->encoding == ft_encoding_symbol)
43               printf ("  symbol,");
44             else if (face->charmaps[j]->encoding == ft_encoding_unicode)
45               printf ("  unicode,");
46             else if (face->charmaps[j]->encoding == ft_encoding_latin_1)
47               printf ("  latin_1,");
48             else if (face->charmaps[j]->encoding == ft_encoding_latin_2)
49               printf ("  latin_2,");
50             else if (face->charmaps[j]->encoding == ft_encoding_sjis)
51               printf ("  sjis,");
52             else if (face->charmaps[j]->encoding == ft_encoding_gb2312)
53               printf ("  gb2312,");
54             else if (face->charmaps[j]->encoding == ft_encoding_big5)
55               printf ("  big5,");
56             else if (face->charmaps[j]->encoding == ft_encoding_wansung)
57               printf ("  wansung,");
58             else if (face->charmaps[j]->encoding == ft_encoding_johab)
59               printf ("  johab,");
60             else if (face->charmaps[j]->encoding == ft_encoding_adobe_standard)
61               printf ("  adobe_standard,");
62             else if (face->charmaps[j]->encoding == ft_encoding_adobe_expert)
63               printf ("  adobe_expert,");
64             else if (face->charmaps[j]->encoding == ft_encoding_adobe_custom)
65               printf ("  adobe_custom,");
66             else if (face->charmaps[j]->encoding == ft_encoding_apple_roman)
67               printf ("  apple_roman,");
68             else if (face->charmaps[j]->encoding == ft_encoding_none)
69               printf ("  none,");
70             else
71               printf ("  0x%X,", (unsigned) face->charmaps[j]->encoding);
72           }
73         printf ("\n");
74       }
75   exit (0);
76 }