*** empty log message ***
[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               || ! strncmp (ext, ".PFA", 4)
20               || ! strncmp (ext, ".pfa", 4)
21               || ! strncmp (ext, ".PFB", 4)
22               || ! strncmp (ext, ".pfb", 4)));
23 }
24
25 int
26 main ()
27
28   struct dirent **namelist;
29   int n = scandir (".", &namelist, filter, alphasort);
30   int i, j;
31   FT_Library ft_library;
32   FT_Face face;
33
34   if (FT_Init_FreeType (&ft_library))
35     exit (1);
36
37   for (i = 0; i < n; i++)
38     if (! FT_New_Face (ft_library, namelist[i]->d_name, 0, &face))
39       {
40         printf ("%s: %s: %s\n", namelist[i]->d_name,
41                 face->family_name, face->style_name);
42         if (face->num_charmaps == 0)
43           continue;
44         for (j = 0; j < face->num_charmaps; j++)
45           {
46             if (face->charmaps[j]->encoding == ft_encoding_symbol)
47               printf (" symbol");
48             else if (face->charmaps[j]->encoding == ft_encoding_unicode)
49               printf (" unicode");
50             else if (face->charmaps[j]->encoding == ft_encoding_latin_1)
51               printf (" latin_1");
52             else if (face->charmaps[j]->encoding == ft_encoding_latin_2)
53               printf (" latin_2");
54             else if (face->charmaps[j]->encoding == ft_encoding_sjis)
55               printf (" sjis");
56             else if (face->charmaps[j]->encoding == ft_encoding_gb2312)
57               printf (" gb2312");
58             else if (face->charmaps[j]->encoding == ft_encoding_big5)
59               printf (" big5");
60             else if (face->charmaps[j]->encoding == ft_encoding_wansung)
61               printf (" wansung");
62             else if (face->charmaps[j]->encoding == ft_encoding_johab)
63               printf (" johab");
64             else if (face->charmaps[j]->encoding == ft_encoding_adobe_standard)
65               printf (" adobe_standard");
66             else if (face->charmaps[j]->encoding == ft_encoding_adobe_expert)
67               printf (" adobe_expert");
68             else if (face->charmaps[j]->encoding == ft_encoding_adobe_custom)
69               printf (" adobe_custom");
70             else if (face->charmaps[j]->encoding == ft_encoding_apple_roman)
71               printf (" apple_roman");
72             else if (face->charmaps[j]->encoding == ft_encoding_none)
73               printf (" none");
74             else
75               printf (" 0x%X", (unsigned) face->charmaps[j]->encoding);
76             printf ("(%d-%d),", face->charmaps[j]->platform_id,
77                     face->charmaps[j]->encoding_id);
78           }
79         printf ("\n");
80       }
81   exit (0);
82 }