]> pilppa.org Git - familiar-h63xx-build.git/blob - org.handhelds.familiar/packages/opie-ttf-support/files/update-qtttffontdir.c
OE tree imported from monotone branch org.openembedded.oz354fam083 at revision 8b12e3...
[familiar-h63xx-build.git] / org.handhelds.familiar / packages / opie-ttf-support / files / update-qtttffontdir.c
1 /*
2  * Utility to generate 'fontdir' for Qt/Embedded
3  *
4  * (C) 2004-2005 Marcin Juszkiewicz <openembedded@hrw.one.pl>
5  *
6  * License: GPLv2
7  *
8  * History:
9  * 
10  * v0.1 2004.10.06 - first version (sent to OPIE devel ML)
11  * v0.2 2005.03.12 - added Oblique fonts support
12  * v1.0 2005.06.29 - switched font style handling to not based on filenames
13  * v1.1 2005.06.29 - fixed filename comparing
14  * 
15  */ 
16
17
18 #include <ft2build.h>
19 #include FT_FREETYPE_H 
20
21 #include <stdio.h>
22 #include <dirent.h>
23 #include <unistd.h>
24
25
26 int main(int argc, char* argv[])
27 {
28         DIR *katalog;
29         struct dirent *plik;
30
31         FT_Library  library;
32         FT_Face face;
33         
34         if(argc == 1)
35         {
36                 fprintf(stderr, "Usage: %s <path to TTF fonts>\n", argv[0]);
37                 exit(10);
38         }
39         
40         if(FT_Init_FreeType(&library))
41         {
42                 fprintf(stderr, "Error during initialising FreeType library.\n");
43                 exit(5);
44         }
45
46         chdir(argv[1]);
47         if((katalog = opendir(".")))
48         {
49                 int found_fixed = 0;
50
51                 while((plik = readdir(katalog)))
52                 {
53                         if(!strstr(plik->d_name, ".ttf"))
54                         {
55                                 continue;
56                         }
57
58                         if(!FT_New_Face(library, plik->d_name, 0, &face))
59                         {
60                                 /*
61                                  *      change spaces in family_name into _
62                                  */
63                                 
64                                 char* ptr;
65
66                                 for(ptr = strchr(face->family_name,' '); (ptr = strchr(ptr, ' ')); ) *ptr = '_';
67
68                                 if(
69                                                 face->face_flags & FT_FACE_FLAG_FIXED_WIDTH &&
70                                                 !found_fixed &&
71                                                 !(face->style_flags & FT_STYLE_FLAG_ITALIC) &&
72                                                 !(face->style_flags & FT_STYLE_FLAG_BOLD)
73                                         )
74                                 {
75                                         found_fixed = 1;
76                                         printf("fixed %s/%s FT", argv[1], plik->d_name);
77
78                                         if(face->style_flags & FT_STYLE_FLAG_ITALIC)
79                                         {
80                                                 printf(" y");
81                                         }
82                                         else
83                                         {
84                                                 printf(" n");
85                                         }
86
87                                         if(face->style_flags & FT_STYLE_FLAG_BOLD)
88                                         {
89                                                 printf(" 75");
90                                         }
91                                         else
92                                         {
93                                                 printf(" 50");
94                                         }
95
96                                         printf(" 60 su \n");
97                                 }
98
99                                 printf("%s %s/%s FT", face->family_name, argv[1], plik->d_name);
100
101                                 if(face->style_flags & FT_STYLE_FLAG_ITALIC)
102                                 {
103                                         printf(" y");
104                                 }
105                                 else
106                                 {
107                                         printf(" n");
108                                 }
109
110                                 if(face->style_flags & FT_STYLE_FLAG_BOLD)
111                                 {
112                                         printf(" 75");
113                                 }
114                                 else
115                                 {
116                                         printf(" 50");
117                                 }
118
119                                 printf(" 60 su \n");
120
121                                 FT_Done_Face(face);
122                         }
123                 }
124         }
125
126         return 0;
127 }