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,
102 #include FT_CONFIG_MODULES_H
103 FT_NUM_MODULE_CLASSES
106 /* destroy all module classes */
108 #define FT_USE_MODULE( type, x ) \
109 if ( classes[i] ) { FT_Destroy_Class_##x(library, classes[i]); } \
113 ft_destroy_default_module_classes( FT_Library library
)
115 FT_Module_Class
** classes
;
118 BasePIC
* pic_container
= (BasePIC
*)library
->pic_container
.base
;
120 if ( !pic_container
->default_module_classes
)
123 memory
= library
->memory
;
124 classes
= pic_container
->default_module_classes
;
127 #include FT_CONFIG_MODULES_H
130 pic_container
->default_module_classes
= 0;
133 /* initialize all module classes and the pointer table */
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
)
145 FT_Module_Class
** classes
;
146 FT_Module_Class
* clazz
;
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) ) )
155 /* initialize all pointers to 0, especially the last one */
156 for (i
= 0; i
< FT_NUM_MODULE_CLASSES
; i
++)
158 classes
[FT_NUM_MODULE_CLASSES
] = 0;
162 #include FT_CONFIG_MODULES_H
165 if (error
) ft_destroy_default_module_classes( library
);
166 else pic_container
->default_module_classes
= classes
;
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
)
180 const FT_Module_Class
* const* cur
;
183 /* test for valid `library' delayed to FT_Add_Module() */
185 cur
= FT_DEFAULT_MODULES_GET
;
188 error
= FT_Add_Module( library
, *cur
);
189 /* notify errors, but don't stop */
191 FT_TRACE0(( "FT_Add_Default_Module:"
192 " Cannot install `%s', error = 0x%x\n",
193 (*cur
)->module_name
, error
));
199 /* documentation is in freetype.h */
201 FT_EXPORT_DEF( FT_Error
)
202 FT_Init_FreeType( FT_Library
*alibrary
)
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();
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
);
223 FT_Done_Memory( memory
);
225 FT_Add_Default_Modules( *alibrary
);
231 /* documentation is in freetype.h */
233 FT_EXPORT_DEF( FT_Error
)
234 FT_Done_FreeType( FT_Library 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
);