| OLD | NEW |
| 1 /***************************************************************************/ | 1 /***************************************************************************/ |
| 2 /* */ | 2 /* */ |
| 3 /* ftinit.c */ | 3 /* ftinit.c */ |
| 4 /* */ | 4 /* */ |
| 5 /* FreeType initialization layer (body). */ | 5 /* FreeType initialization layer (body). */ |
| 6 /* */ | 6 /* */ |
| 7 /* Copyright 1996-2001, 2002, 2005, 2007, 2009 by */ | 7 /* Copyright 1996-2001, 2002, 2005, 2007, 2009, 2012 by */ |
| 8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */ | 8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */ |
| 9 /* */ | 9 /* */ |
| 10 /* This file is part of the FreeType project, and may only be used, */ | 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 */ | 11 /* modified, and distributed under the terms of the FreeType project */ |
| 12 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ | 12 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ |
| 13 /* this file you indicate that you have read the license and */ | 13 /* this file you indicate that you have read the license and */ |
| 14 /* understand and accept it fully. */ | 14 /* understand and accept it fully. */ |
| 15 /* */ | 15 /* */ |
| 16 /***************************************************************************/ | 16 /***************************************************************************/ |
| 17 | 17 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 47 | 47 |
| 48 /*************************************************************************/ | 48 /*************************************************************************/ |
| 49 /* */ | 49 /* */ |
| 50 /* The macro FT_COMPONENT is used in trace mode. It is an implicit */ | 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 */ | 51 /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */ |
| 52 /* messages during execution. */ | 52 /* messages during execution. */ |
| 53 /* */ | 53 /* */ |
| 54 #undef FT_COMPONENT | 54 #undef FT_COMPONENT |
| 55 #define FT_COMPONENT trace_init | 55 #define FT_COMPONENT trace_init |
| 56 | 56 |
| 57 |
| 57 #ifndef FT_CONFIG_OPTION_PIC | 58 #ifndef FT_CONFIG_OPTION_PIC |
| 58 | 59 |
| 60 |
| 59 #undef FT_USE_MODULE | 61 #undef FT_USE_MODULE |
| 60 #ifdef __cplusplus | 62 #ifdef __cplusplus |
| 61 #define FT_USE_MODULE( type, x ) extern "C" const type x; | 63 #define FT_USE_MODULE( type, x ) extern "C" const type x; |
| 62 #else | 64 #else |
| 63 #define FT_USE_MODULE( type, x ) extern const type x; | 65 #define FT_USE_MODULE( type, x ) extern const type x; |
| 64 #endif | 66 #endif |
| 65 | 67 |
| 66 | |
| 67 #include FT_CONFIG_MODULES_H | 68 #include FT_CONFIG_MODULES_H |
| 68 | 69 |
| 69 | |
| 70 #undef FT_USE_MODULE | 70 #undef FT_USE_MODULE |
| 71 #define FT_USE_MODULE( type, x ) (const FT_Module_Class*)&(x), | 71 #define FT_USE_MODULE( type, x ) (const FT_Module_Class*)&(x), |
| 72 | 72 |
| 73 static | 73 static |
| 74 const FT_Module_Class* const ft_default_modules[] = | 74 const FT_Module_Class* const ft_default_modules[] = |
| 75 { | 75 { |
| 76 #include FT_CONFIG_MODULES_H | 76 #include FT_CONFIG_MODULES_H |
| 77 0 | 77 0 |
| 78 }; | 78 }; |
| 79 | 79 |
| 80 |
| 80 #else /* FT_CONFIG_OPTION_PIC */ | 81 #else /* FT_CONFIG_OPTION_PIC */ |
| 81 | 82 |
| 83 |
| 82 #ifdef __cplusplus | 84 #ifdef __cplusplus |
| 83 #define FT_EXTERNC extern "C" | 85 #define FT_EXTERNC extern "C" |
| 84 #else | 86 #else |
| 85 #define FT_EXTERNC extern | 87 #define FT_EXTERNC extern |
| 86 #endif | 88 #endif |
| 87 | 89 |
| 88 /* declare the module's class creation/destruction functions */ | 90 /* declare the module's class creation/destruction functions */ |
| 89 #undef FT_USE_MODULE | 91 #undef FT_USE_MODULE |
| 90 #define FT_USE_MODULE( type, x ) \ | 92 #define FT_USE_MODULE( type, x ) \ |
| 91 FT_EXTERNC FT_Error FT_Create_Class_##x( FT_Library library, FT_Module_Class**
output_class ); \ | 93 FT_EXTERNC FT_Error \ |
| 92 FT_EXTERNC void FT_Destroy_Class_##x( FT_Library library, FT_Module_Class*
clazz ); | 94 FT_Create_Class_ ## x( FT_Library library, \ |
| 95 FT_Module_Class* *output_class ); \ |
| 96 FT_EXTERNC void \ |
| 97 FT_Destroy_Class_ ## x( FT_Library library, \ |
| 98 FT_Module_Class* clazz ); |
| 93 | 99 |
| 94 #include FT_CONFIG_MODULES_H | 100 #include FT_CONFIG_MODULES_H |
| 95 | 101 |
| 96 | |
| 97 /* count all module classes */ | 102 /* count all module classes */ |
| 98 #undef FT_USE_MODULE | 103 #undef FT_USE_MODULE |
| 99 #define FT_USE_MODULE( type, x ) MODULE_CLASS_##x, | 104 #define FT_USE_MODULE( type, x ) MODULE_CLASS_ ## x, |
| 100 | 105 |
| 101 enum | 106 enum |
| 102 { | 107 { |
| 103 #include FT_CONFIG_MODULES_H | 108 #include FT_CONFIG_MODULES_H |
| 104 FT_NUM_MODULE_CLASSES | 109 FT_NUM_MODULE_CLASSES |
| 105 }; | 110 }; |
| 106 | 111 |
| 107 /* destroy all module classes */ | 112 /* destroy all module classes */ |
| 108 #undef FT_USE_MODULE | 113 #undef FT_USE_MODULE |
| 109 #define FT_USE_MODULE( type, x ) \ | 114 #define FT_USE_MODULE( type, x ) \ |
| 110 if ( classes[i] ) { FT_Destroy_Class_##x(library, classes[i]); } \ | 115 if ( classes[i] ) \ |
| 111 i++; \ | 116 { \ |
| 117 FT_Destroy_Class_ ## x( library, classes[i] ); \ |
| 118 } \ |
| 119 i++; |
| 120 |
| 112 | 121 |
| 113 FT_BASE_DEF( void ) | 122 FT_BASE_DEF( void ) |
| 114 ft_destroy_default_module_classes( FT_Library library ) | 123 ft_destroy_default_module_classes( FT_Library library ) |
| 115 { | 124 { |
| 116 FT_Module_Class** classes; | 125 FT_Module_Class* *classes; |
| 117 FT_Memory memory; | 126 FT_Memory memory; |
| 118 FT_UInt i; | 127 FT_UInt i; |
| 119 BasePIC* pic_container = (BasePIC*)library->pic_container.base; | 128 BasePIC* pic_container = (BasePIC*)library->pic_container.base; |
| 129 |
| 120 | 130 |
| 121 if ( !pic_container->default_module_classes ) | 131 if ( !pic_container->default_module_classes ) |
| 122 return; | 132 return; |
| 123 | 133 |
| 124 memory = library->memory; | 134 memory = library->memory; |
| 125 classes = pic_container->default_module_classes; | 135 classes = pic_container->default_module_classes; |
| 126 i = 0; | 136 i = 0; |
| 127 | 137 |
| 128 #include FT_CONFIG_MODULES_H | 138 #include FT_CONFIG_MODULES_H |
| 129 | 139 |
| 130 FT_FREE( classes ); | 140 FT_FREE( classes ); |
| 131 pic_container->default_module_classes = 0; | 141 pic_container->default_module_classes = 0; |
| 132 } | 142 } |
| 133 | 143 |
| 144 |
| 134 /* initialize all module classes and the pointer table */ | 145 /* initialize all module classes and the pointer table */ |
| 135 #undef FT_USE_MODULE | 146 #undef FT_USE_MODULE |
| 136 #define FT_USE_MODULE( type, x ) \ | 147 #define FT_USE_MODULE( type, x ) \ |
| 137 error = FT_Create_Class_##x(library, &clazz); \ | 148 error = FT_Create_Class_ ## x( library, &clazz ); \ |
| 138 if (error) goto Exit; \ | 149 if ( error ) \ |
| 150 goto Exit; \ |
| 139 classes[i++] = clazz; | 151 classes[i++] = clazz; |
| 140 | 152 |
| 153 |
| 141 FT_BASE_DEF( FT_Error ) | 154 FT_BASE_DEF( FT_Error ) |
| 142 ft_create_default_module_classes( FT_Library library ) | 155 ft_create_default_module_classes( FT_Library library ) |
| 143 { | 156 { |
| 144 FT_Error error; | 157 FT_Error error; |
| 145 FT_Memory memory; | 158 FT_Memory memory; |
| 146 FT_Module_Class** classes; | 159 FT_Module_Class* *classes; |
| 147 FT_Module_Class* clazz; | 160 FT_Module_Class* clazz; |
| 148 FT_UInt i; | 161 FT_UInt i; |
| 149 BasePIC* pic_container = (BasePIC*)library->pic_container.base; | 162 BasePIC* pic_container = (BasePIC*)library->pic_container.base; |
| 150 | 163 |
| 151 memory = library->memory; | 164 |
| 165 memory = library->memory; |
| 166 |
| 152 pic_container->default_module_classes = 0; | 167 pic_container->default_module_classes = 0; |
| 153 | 168 |
| 154 if ( FT_ALLOC(classes, sizeof(FT_Module_Class*) * (FT_NUM_MODULE_CLASSES + 1
) ) ) | 169 if ( FT_ALLOC( classes, sizeof ( FT_Module_Class* ) * |
| 170 ( FT_NUM_MODULE_CLASSES + 1 ) ) ) |
| 155 return error; | 171 return error; |
| 172 |
| 156 /* initialize all pointers to 0, especially the last one */ | 173 /* initialize all pointers to 0, especially the last one */ |
| 157 for (i = 0; i < FT_NUM_MODULE_CLASSES; i++) | 174 for ( i = 0; i < FT_NUM_MODULE_CLASSES; i++ ) |
| 158 classes[i] = 0; | 175 classes[i] = 0; |
| 159 classes[FT_NUM_MODULE_CLASSES] = 0; | 176 classes[FT_NUM_MODULE_CLASSES] = 0; |
| 160 | 177 |
| 161 i = 0; | 178 i = 0; |
| 162 | 179 |
| 163 #include FT_CONFIG_MODULES_H | 180 #include FT_CONFIG_MODULES_H |
| 164 | 181 |
| 165 Exit: | 182 Exit: |
| 166 if (error) ft_destroy_default_module_classes( library ); | 183 if ( error ) |
| 167 else pic_container->default_module_classes = classes; | 184 ft_destroy_default_module_classes( library ); |
| 185 else |
| 186 pic_container->default_module_classes = classes; |
| 168 | 187 |
| 169 return error; | 188 return error; |
| 170 } | 189 } |
| 171 | 190 |
| 172 | 191 |
| 173 #endif /* FT_CONFIG_OPTION_PIC */ | 192 #endif /* FT_CONFIG_OPTION_PIC */ |
| 174 | 193 |
| 194 |
| 175 /* documentation is in ftmodapi.h */ | 195 /* documentation is in ftmodapi.h */ |
| 176 | 196 |
| 177 FT_EXPORT_DEF( void ) | 197 FT_EXPORT_DEF( void ) |
| 178 FT_Add_Default_Modules( FT_Library library ) | 198 FT_Add_Default_Modules( FT_Library library ) |
| 179 { | 199 { |
| 180 FT_Error error; | 200 FT_Error error; |
| 181 const FT_Module_Class* const* cur; | 201 const FT_Module_Class* const* cur; |
| 182 | 202 |
| 183 | 203 |
| 204 /* FT_DEFAULT_MODULES_GET dereferences `library' in PIC mode */ |
| 205 #ifdef FT_CONFIG_OPTION_PIC |
| 206 if ( !library ) |
| 207 return; |
| 208 #endif |
| 209 |
| 210 /* GCC 4.6 warns the type difference: |
| 211 * FT_Module_Class** != const FT_Module_Class* const* |
| 212 */ |
| 213 cur = (const FT_Module_Class* const*)FT_DEFAULT_MODULES_GET; |
| 214 |
| 184 /* test for valid `library' delayed to FT_Add_Module() */ | 215 /* test for valid `library' delayed to FT_Add_Module() */ |
| 185 | |
| 186 cur = FT_DEFAULT_MODULES_GET; | |
| 187 while ( *cur ) | 216 while ( *cur ) |
| 188 { | 217 { |
| 189 error = FT_Add_Module( library, *cur ); | 218 error = FT_Add_Module( library, *cur ); |
| 190 /* notify errors, but don't stop */ | 219 /* notify errors, but don't stop */ |
| 191 if ( error ) | 220 if ( error ) |
| 192 FT_TRACE0(( "FT_Add_Default_Module:" | 221 FT_TRACE0(( "FT_Add_Default_Module:" |
| 193 " Cannot install `%s', error = 0x%x\n", | 222 " Cannot install `%s', error = 0x%x\n", |
| 194 (*cur)->module_name, error )); | 223 (*cur)->module_name, error )); |
| 195 cur++; | 224 cur++; |
| 196 } | 225 } |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 | 273 |
| 245 /* discard memory manager */ | 274 /* discard memory manager */ |
| 246 FT_Done_Memory( memory ); | 275 FT_Done_Memory( memory ); |
| 247 } | 276 } |
| 248 | 277 |
| 249 return FT_Err_Ok; | 278 return FT_Err_Ok; |
| 250 } | 279 } |
| 251 | 280 |
| 252 | 281 |
| 253 /* END */ | 282 /* END */ |
| OLD | NEW |