Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenftinit.c
Go to the documentation of this file.
00001 /***************************************************************************/ 00002 /* */ 00003 /* ftinit.c */ 00004 /* */ 00005 /* FreeType initialization layer (body). */ 00006 /* */ 00007 /* Copyright 1996-2001, 2002, 2005, 2007, 2009 by */ 00008 /* David Turner, Robert Wilhelm, and Werner Lemberg. */ 00009 /* */ 00010 /* This file is part of the FreeType project, and may only be used, */ 00011 /* modified, and distributed under the terms of the FreeType project */ 00012 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ 00013 /* this file you indicate that you have read the license and */ 00014 /* understand and accept it fully. */ 00015 /* */ 00016 /***************************************************************************/ 00017 00018 /*************************************************************************/ 00019 /* */ 00020 /* The purpose of this file is to implement the following two */ 00021 /* functions: */ 00022 /* */ 00023 /* FT_Add_Default_Modules(): */ 00024 /* This function is used to add the set of default modules to a */ 00025 /* fresh new library object. The set is taken from the header file */ 00026 /* `freetype/config/ftmodule.h'. See the document `FreeType 2.0 */ 00027 /* Build System' for more information. */ 00028 /* */ 00029 /* FT_Init_FreeType(): */ 00030 /* This function creates a system object for the current platform, */ 00031 /* builds a library out of it, then calls FT_Default_Drivers(). */ 00032 /* */ 00033 /* Note that even if FT_Init_FreeType() uses the implementation of the */ 00034 /* system object defined at build time, client applications are still */ 00035 /* able to provide their own `ftsystem.c'. */ 00036 /* */ 00037 /*************************************************************************/ 00038 00039 00040 #include <ft2build.h> 00041 #include FT_CONFIG_CONFIG_H 00042 #include FT_INTERNAL_OBJECTS_H 00043 #include FT_INTERNAL_DEBUG_H 00044 #include FT_MODULE_H 00045 #include "basepic.h" 00046 00047 00048 /*************************************************************************/ 00049 /* */ 00050 /* The macro FT_COMPONENT is used in trace mode. It is an implicit */ 00051 /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */ 00052 /* messages during execution. */ 00053 /* */ 00054 #undef FT_COMPONENT 00055 #define FT_COMPONENT trace_init 00056 00057 #ifndef FT_CONFIG_OPTION_PIC 00058 00059 #undef FT_USE_MODULE 00060 #ifdef __cplusplus 00061 #define FT_USE_MODULE( type, x ) extern "C" const type x; 00062 #else 00063 #define FT_USE_MODULE( type, x ) extern const type x; 00064 #endif 00065 00066 00067 #include FT_CONFIG_MODULES_H 00068 00069 00070 #undef FT_USE_MODULE 00071 #define FT_USE_MODULE( type, x ) (const FT_Module_Class*)&(x), 00072 00073 static 00074 const FT_Module_Class* const ft_default_modules[] = 00075 { 00076 #include FT_CONFIG_MODULES_H 00077 0 00078 }; 00079 00080 #else /* FT_CONFIG_OPTION_PIC */ 00081 00082 #ifdef __cplusplus 00083 #define FT_EXTERNC extern "C" 00084 #else 00085 #define FT_EXTERNC extern 00086 #endif 00087 00088 /* declare the module's class creation/destruction functions */ 00089 #undef FT_USE_MODULE 00090 #define FT_USE_MODULE( type, x ) \ 00091 FT_EXTERNC FT_Error FT_Create_Class_##x( FT_Library library, FT_Module_Class** output_class ); \ 00092 FT_EXTERNC void FT_Destroy_Class_##x( FT_Library library, FT_Module_Class* clazz ); 00093 00094 #include FT_CONFIG_MODULES_H 00095 00096 00097 /* count all module classes */ 00098 #undef FT_USE_MODULE 00099 #define FT_USE_MODULE( type, x ) MODULE_CLASS_##x, 00100 00101 enum 00102 { 00103 #include FT_CONFIG_MODULES_H 00104 FT_NUM_MODULE_CLASSES 00105 }; 00106 00107 /* destroy all module classes */ 00108 #undef FT_USE_MODULE 00109 #define FT_USE_MODULE( type, x ) \ 00110 if ( classes[i] ) { FT_Destroy_Class_##x(library, classes[i]); } \ 00111 i++; \ 00112 00113 FT_BASE_DEF( void ) 00114 ft_destroy_default_module_classes( FT_Library library ) 00115 { 00116 FT_Module_Class** classes; 00117 FT_Memory memory; 00118 FT_UInt i; 00119 BasePIC* pic_container = (BasePIC*)library->pic_container.base; 00120 00121 if ( !pic_container->default_module_classes ) 00122 return; 00123 00124 memory = library->memory; 00125 classes = pic_container->default_module_classes; 00126 i = 0; 00127 00128 #include FT_CONFIG_MODULES_H 00129 00130 FT_FREE( classes ); 00131 pic_container->default_module_classes = 0; 00132 } 00133 00134 /* initialize all module classes and the pointer table */ 00135 #undef FT_USE_MODULE 00136 #define FT_USE_MODULE( type, x ) \ 00137 error = FT_Create_Class_##x(library, &clazz); \ 00138 if (error) goto Exit; \ 00139 classes[i++] = clazz; 00140 00141 FT_BASE_DEF( FT_Error ) 00142 ft_create_default_module_classes( FT_Library library ) 00143 { 00144 FT_Error error; 00145 FT_Memory memory; 00146 FT_Module_Class** classes; 00147 FT_Module_Class* clazz; 00148 FT_UInt i; 00149 BasePIC* pic_container = (BasePIC*)library->pic_container.base; 00150 00151 memory = library->memory; 00152 pic_container->default_module_classes = 0; 00153 00154 if ( FT_ALLOC(classes, sizeof(FT_Module_Class*) * (FT_NUM_MODULE_CLASSES + 1) ) ) 00155 return error; 00156 /* initialize all pointers to 0, especially the last one */ 00157 for (i = 0; i < FT_NUM_MODULE_CLASSES; i++) 00158 classes[i] = 0; 00159 classes[FT_NUM_MODULE_CLASSES] = 0; 00160 00161 i = 0; 00162 00163 #include FT_CONFIG_MODULES_H 00164 00165 Exit: 00166 if (error) ft_destroy_default_module_classes( library ); 00167 else pic_container->default_module_classes = classes; 00168 00169 return error; 00170 } 00171 00172 00173 #endif /* FT_CONFIG_OPTION_PIC */ 00174 00175 /* documentation is in ftmodapi.h */ 00176 00177 FT_EXPORT_DEF( void ) 00178 FT_Add_Default_Modules( FT_Library library ) 00179 { 00180 FT_Error error; 00181 const FT_Module_Class* const* cur; 00182 00183 00184 /* test for valid `library' delayed to FT_Add_Module() */ 00185 00186 cur = FT_DEFAULT_MODULES_GET; 00187 while ( *cur ) 00188 { 00189 error = FT_Add_Module( library, *cur ); 00190 /* notify errors, but don't stop */ 00191 if ( error ) 00192 FT_TRACE0(( "FT_Add_Default_Module:" 00193 " Cannot install `%s', error = 0x%x\n", 00194 (*cur)->module_name, error )); 00195 cur++; 00196 } 00197 } 00198 00199 00200 /* documentation is in freetype.h */ 00201 00202 FT_EXPORT_DEF( FT_Error ) 00203 FT_Init_FreeType( FT_Library *alibrary ) 00204 { 00205 FT_Error error; 00206 FT_Memory memory; 00207 00208 00209 /* First of all, allocate a new system object -- this function is part */ 00210 /* of the system-specific component, i.e. `ftsystem.c'. */ 00211 00212 memory = FT_New_Memory(); 00213 if ( !memory ) 00214 { 00215 FT_ERROR(( "FT_Init_FreeType: cannot find memory manager\n" )); 00216 return FT_Err_Unimplemented_Feature; 00217 } 00218 00219 /* build a library out of it, then fill it with the set of */ 00220 /* default drivers. */ 00221 00222 error = FT_New_Library( memory, alibrary ); 00223 if ( error ) 00224 FT_Done_Memory( memory ); 00225 else 00226 FT_Add_Default_Modules( *alibrary ); 00227 00228 return error; 00229 } 00230 00231 00232 /* documentation is in freetype.h */ 00233 00234 FT_EXPORT_DEF( FT_Error ) 00235 FT_Done_FreeType( FT_Library library ) 00236 { 00237 if ( library ) 00238 { 00239 FT_Memory memory = library->memory; 00240 00241 00242 /* Discard the library object */ 00243 FT_Done_Library( library ); 00244 00245 /* discard memory manager */ 00246 FT_Done_Memory( memory ); 00247 } 00248 00249 return FT_Err_Ok; 00250 } 00251 00252 00253 /* END */ Generated on Sun May 27 2012 04:33:35 for ReactOS by
1.7.6.1
|