clarify the gui
[open-ps2-loader.git] / thirdparty / freetype-2.3.12 / src / base / ftinit.c
blobf94f25a83c1061a48229c4005ccb8feb519cbd57
1 /***************************************************************************/
2 /* */
3 /* ftinit.c */
4 /* */
5 /* FreeType initialization layer (body). */
6 /* */
7 /* Copyright 1996-2001, 2002, 2005, 2007, 2009 by */
8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */
9 /* */
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. */
15 /* */
16 /***************************************************************************/
18 /*************************************************************************/
19 /* */
20 /* The purpose of this file is to implement the following two */
21 /* functions: */
22 /* */
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. */
28 /* */
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(). */
32 /* */
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'. */
36 /* */
37 /*************************************************************************/
40 #include <ft2build.h>
41 #include FT_CONFIG_CONFIG_H
42 #include FT_INTERNAL_OBJECTS_H
43 #include FT_INTERNAL_DEBUG_H
44 #include FT_MODULE_H
45 #include "basepic.h"
48 /*************************************************************************/
49 /* */
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. */
53 /* */
54 #undef FT_COMPONENT
55 #define FT_COMPONENT trace_init
57 #ifndef FT_CONFIG_OPTION_PIC
59 #undef FT_USE_MODULE
60 #ifdef __cplusplus
61 #define FT_USE_MODULE( type, x ) extern "C" const type x;
62 #else
63 #define FT_USE_MODULE( type, x ) extern const type x;
64 #endif
67 #include FT_CONFIG_MODULES_H
70 #undef FT_USE_MODULE
71 #define FT_USE_MODULE( type, x ) (const FT_Module_Class*)&(x),
73 static
74 const FT_Module_Class* const ft_default_modules[] =
76 #include FT_CONFIG_MODULES_H
80 #else /* FT_CONFIG_OPTION_PIC */
82 #ifdef __cplusplus
83 #define FT_EXTERNC extern "C"
84 #else
85 #define FT_EXTERNC extern
86 #endif
88 /* declare the module's class creation/destruction functions */
89 #undef FT_USE_MODULE
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 */
98 #undef FT_USE_MODULE
99 #define FT_USE_MODULE( type, x ) MODULE_CLASS_##x,
101 enum {
102 #include FT_CONFIG_MODULES_H
103 FT_NUM_MODULE_CLASSES
106 /* destroy all module classes */
107 #undef FT_USE_MODULE
108 #define FT_USE_MODULE( type, x ) \
109 if ( classes[i] ) { FT_Destroy_Class_##x(library, classes[i]); } \
110 i++; \
112 FT_BASE_DEF( void )
113 ft_destroy_default_module_classes( FT_Library library )
115 FT_Module_Class** classes;
116 FT_Memory memory;
117 FT_UInt i;
118 BasePIC* pic_container = (BasePIC*)library->pic_container.base;
120 if ( !pic_container->default_module_classes )
121 return;
123 memory = library->memory;
124 classes = pic_container->default_module_classes;
125 i = 0;
127 #include FT_CONFIG_MODULES_H
129 FT_FREE( classes );
130 pic_container->default_module_classes = 0;
133 /* initialize all module classes and the pointer table */
134 #undef FT_USE_MODULE
135 #define FT_USE_MODULE( type, x ) \
136 error = FT_Create_Class_##x(library, &clazz); \
137 if (error) goto Exit; \
138 classes[i++] = clazz;
140 FT_BASE_DEF( FT_Error )
141 ft_create_default_module_classes( FT_Library library )
143 FT_Error error;
144 FT_Memory memory;
145 FT_Module_Class** classes;
146 FT_Module_Class* clazz;
147 FT_UInt i;
148 BasePIC* pic_container = (BasePIC*)library->pic_container.base;
150 memory = library->memory;
151 pic_container->default_module_classes = 0;
153 if ( FT_ALLOC(classes, sizeof(FT_Module_Class*) * (FT_NUM_MODULE_CLASSES + 1) ) )
154 return error;
155 /* initialize all pointers to 0, especially the last one */
156 for (i = 0; i < FT_NUM_MODULE_CLASSES; i++)
157 classes[i] = 0;
158 classes[FT_NUM_MODULE_CLASSES] = 0;
160 i = 0;
162 #include FT_CONFIG_MODULES_H
164 Exit:
165 if (error) ft_destroy_default_module_classes( library );
166 else pic_container->default_module_classes = classes;
168 return error;
172 #endif /* FT_CONFIG_OPTION_PIC */
174 /* documentation is in ftmodapi.h */
176 FT_EXPORT_DEF( void )
177 FT_Add_Default_Modules( FT_Library library )
179 FT_Error error;
180 const FT_Module_Class* const* cur;
183 /* test for valid `library' delayed to FT_Add_Module() */
185 cur = FT_DEFAULT_MODULES_GET;
186 while ( *cur )
188 error = FT_Add_Module( library, *cur );
189 /* notify errors, but don't stop */
190 if ( error )
191 FT_TRACE0(( "FT_Add_Default_Module:"
192 " Cannot install `%s', error = 0x%x\n",
193 (*cur)->module_name, error ));
194 cur++;
199 /* documentation is in freetype.h */
201 FT_EXPORT_DEF( FT_Error )
202 FT_Init_FreeType( FT_Library *alibrary )
204 FT_Error error;
205 FT_Memory memory;
208 /* First of all, allocate a new system object -- this function is part */
209 /* of the system-specific component, i.e. `ftsystem.c'. */
211 memory = FT_New_Memory();
212 if ( !memory )
214 FT_ERROR(( "FT_Init_FreeType: cannot find memory manager\n" ));
215 return FT_Err_Unimplemented_Feature;
218 /* build a library out of it, then fill it with the set of */
219 /* default drivers. */
221 error = FT_New_Library( memory, alibrary );
222 if ( error )
223 FT_Done_Memory( memory );
224 else
225 FT_Add_Default_Modules( *alibrary );
227 return error;
231 /* documentation is in freetype.h */
233 FT_EXPORT_DEF( FT_Error )
234 FT_Done_FreeType( FT_Library library )
236 if ( library )
238 FT_Memory memory = library->memory;
241 /* Discard the library object */
242 FT_Done_Library( library );
244 /* discard memory manager */
245 FT_Done_Memory( memory );
248 return FT_Err_Ok;
252 /* END */