summaryrefslogtreecommitdiff
path: root/packages/opie-ttf-support/files/update-qtttffontdir.c
blob: fa45e38a8b136a817435928226ba493533cb2862 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
 * Utility to generate 'fontdir' for Qt/Embedded
 *
 * (C) 2004-2005 Marcin Juszkiewicz <openembedded@hrw.one.pl>
 *
 * License: GPLv2
 *
 * History:
 * 
 * v0.1 2004.10.06 - first version (sent to OPIE devel ML)
 * v0.2 2005.03.12 - added Oblique fonts support
 * v1.0 2005.06.29 - switched font style handling to not based on filenames
 * v1.1 2005.06.29 - fixed filename comparing
 * 
 */ 


#include <ft2build.h>
#include FT_FREETYPE_H 

#include <stdio.h>
#include <dirent.h>
#include <unistd.h>


int main(int argc, char* argv[])
{
	DIR *katalog;
	struct dirent *plik;

	FT_Library  library;
	FT_Face face;
	
	if(argc == 1)
	{
		fprintf(stderr, "Usage: %s <path to TTF fonts>\n", argv[0]);
		exit(10);
	}
	
	if(FT_Init_FreeType(&library))
	{
		fprintf(stderr, "Error during initialising FreeType library.\n");
		exit(5);
	}

	chdir(argv[1]);
	if((katalog = opendir(".")))
	{
		int found_fixed = 0;

		while((plik = readdir(katalog)))
		{
			if(!strstr(plik->d_name, ".ttf"))
			{
				continue;
			}

			if(!FT_New_Face(library, plik->d_name, 0, &face))
			{
				/*
				 *	change spaces in family_name into _
				 */
				
				char* ptr;

				for(ptr = strchr(face->family_name,' '); (ptr = strchr(ptr, ' ')); ) *ptr = '_';

				if(
						face->face_flags & FT_FACE_FLAG_FIXED_WIDTH &&
						!found_fixed &&
						!(face->style_flags & FT_STYLE_FLAG_ITALIC) &&
						!(face->style_flags & FT_STYLE_FLAG_BOLD)
					)
				{
					found_fixed = 1;
					printf("fixed %s/%s FT", argv[1], plik->d_name);

					if(face->style_flags & FT_STYLE_FLAG_ITALIC)
					{
						printf(" y");
					}
					else
					{
						printf(" n");
					}

					if(face->style_flags & FT_STYLE_FLAG_BOLD)
					{
						printf(" 75");
					}
					else
					{
						printf(" 50");
					}

					printf(" 60 su \n");
				}

				printf("%s %s/%s FT", face->family_name, argv[1], plik->d_name);

				if(face->style_flags & FT_STYLE_FLAG_ITALIC)
				{
					printf(" y");
				}
				else
				{
					printf(" n");
				}

				if(face->style_flags & FT_STYLE_FLAG_BOLD)
				{
					printf(" 75");
				}
				else
				{
					printf(" 50");
				}

				printf(" 60 su \n");

				FT_Done_Face(face);
			}
		}
	}

	return 0;
}