1
/***************************************************************************/
5
/* FreeType initialization layer (body). */
7
/* Copyright 1996-2001, 2002, 2005, 2007, 2009 by */
8
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
10
/* This file is part of the FreeType project, and may only be used, */
11
/* modified, and distributed under the terms of the FreeType project */
12
/* license, LICENSE.TXT. By continuing to use, modify, or distribute */
13
/* this file you indicate that you have read the license and */
14
/* understand and accept it fully. */
16
/***************************************************************************/
18
/*************************************************************************/
20
/* The purpose of this file is to implement the following two */
23
/* FT_Add_Default_Modules(): */
24
/* This function is used to add the set of default modules to a */
25
/* fresh new library object. The set is taken from the header file */
26
/* `freetype/config/ftmodule.h'. See the document `FreeType 2.0 */
27
/* Build System' for more information. */
29
/* FT_Init_FreeType(): */
30
/* This function creates a system object for the current platform, */
31
/* builds a library out of it, then calls FT_Default_Drivers(). */
33
/* Note that even if FT_Init_FreeType() uses the implementation of the */
34
/* system object defined at build time, client applications are still */
35
/* able to provide their own `ftsystem.c'. */
37
/*************************************************************************/
41
#include FT_CONFIG_CONFIG_H
42
#include FT_INTERNAL_OBJECTS_H
43
#include FT_INTERNAL_DEBUG_H
48
/*************************************************************************/
50
/* The macro FT_COMPONENT is used in trace mode. It is an implicit */
51
/* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
52
/* messages during execution. */
55
#define FT_COMPONENT trace_init
57
#ifndef FT_CONFIG_OPTION_PIC
61
#define FT_USE_MODULE( type, x ) extern "C" const type x;
63
#define FT_USE_MODULE( type, x ) extern const type x;
67
#include FT_CONFIG_MODULES_H
71
#define FT_USE_MODULE( type, x ) (const FT_Module_Class*)&(x),
74
const FT_Module_Class* const ft_default_modules[] =
76
#include FT_CONFIG_MODULES_H
80
#else /* FT_CONFIG_OPTION_PIC */
83
#define FT_EXTERNC extern "C"
85
#define FT_EXTERNC extern
88
/* declare the module's class creation/destruction functions */
90
#define FT_USE_MODULE( type, x ) \
91
FT_EXTERNC FT_Error FT_Create_Class_##x( FT_Library library, FT_Module_Class** output_class ); \
92
FT_EXTERNC void FT_Destroy_Class_##x( FT_Library library, FT_Module_Class* clazz );
94
#include FT_CONFIG_MODULES_H
97
/* count all module classes */
99
#define FT_USE_MODULE( type, x ) MODULE_CLASS_##x,
103
#include FT_CONFIG_MODULES_H
104
FT_NUM_MODULE_CLASSES
107
/* destroy all module classes */
109
#define FT_USE_MODULE( type, x ) \
110
if ( classes[i] ) { FT_Destroy_Class_##x(library, classes[i]); } \
114
ft_destroy_default_module_classes( FT_Library library )
116
FT_Module_Class** classes;
119
BasePIC* pic_container = (BasePIC*)library->pic_container.base;
121
if ( !pic_container->default_module_classes )
124
memory = library->memory;
125
classes = pic_container->default_module_classes;
128
#include FT_CONFIG_MODULES_H
131
pic_container->default_module_classes = 0;
134
/* initialize all module classes and the pointer table */
136
#define FT_USE_MODULE( type, x ) \
137
error = FT_Create_Class_##x(library, &clazz); \
138
if (error) goto Exit; \
139
classes[i++] = clazz;
141
FT_BASE_DEF( FT_Error )
142
ft_create_default_module_classes( FT_Library library )
146
FT_Module_Class** classes;
147
FT_Module_Class* clazz;
149
BasePIC* pic_container = (BasePIC*)library->pic_container.base;
151
memory = library->memory;
152
pic_container->default_module_classes = 0;
154
if ( FT_ALLOC(classes, sizeof(FT_Module_Class*) * (FT_NUM_MODULE_CLASSES + 1) ) )
156
/* initialize all pointers to 0, especially the last one */
157
for (i = 0; i < FT_NUM_MODULE_CLASSES; i++)
159
classes[FT_NUM_MODULE_CLASSES] = 0;
163
#include FT_CONFIG_MODULES_H
166
if (error) ft_destroy_default_module_classes( library );
167
else pic_container->default_module_classes = classes;
173
#endif /* FT_CONFIG_OPTION_PIC */
175
/* documentation is in ftmodapi.h */
177
FT_EXPORT_DEF( void )
178
FT_Add_Default_Modules( FT_Library library )
181
const FT_Module_Class* const* cur;
184
/* test for valid `library' delayed to FT_Add_Module() */
186
cur = FT_DEFAULT_MODULES_GET;
189
error = FT_Add_Module( library, *cur );
190
/* notify errors, but don't stop */
192
FT_TRACE0(( "FT_Add_Default_Module:"
193
" Cannot install `%s', error = 0x%x\n",
194
(*cur)->module_name, error ));
200
/* documentation is in freetype.h */
202
FT_EXPORT_DEF( FT_Error )
203
FT_Init_FreeType( FT_Library *alibrary )
209
/* First of all, allocate a new system object -- this function is part */
210
/* of the system-specific component, i.e. `ftsystem.c'. */
212
memory = FT_New_Memory();
215
FT_ERROR(( "FT_Init_FreeType: cannot find memory manager\n" ));
216
return FT_Err_Unimplemented_Feature;
219
/* build a library out of it, then fill it with the set of */
220
/* default drivers. */
222
error = FT_New_Library( memory, alibrary );
224
FT_Done_Memory( memory );
226
FT_Add_Default_Modules( *alibrary );
232
/* documentation is in freetype.h */
234
FT_EXPORT_DEF( FT_Error )
235
FT_Done_FreeType( FT_Library library )
239
FT_Memory memory = library->memory;
242
/* Discard the library object */
243
FT_Done_Library( library );
245
/* discard memory manager */
246
FT_Done_Memory( memory );