ftinit.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 #include FT_CONFIG_MODULES_H
00103     FT_NUM_MODULE_CLASSES
00104   };
00105 
00106   /* destroy all module classes */  
00107 #undef  FT_USE_MODULE
00108 #define FT_USE_MODULE( type, x )  \
00109   if ( classes[i] ) { FT_Destroy_Class_##x(library, classes[i]); } \
00110   i++;                                                             \
00111 
00112   FT_BASE_DEF( void )
00113   ft_destroy_default_module_classes( FT_Library  library )
00114   {
00115     FT_Module_Class** classes;
00116     FT_Memory         memory;
00117     FT_UInt           i;
00118     BasePIC*          pic_container = (BasePIC*)library->pic_container.base;
00119 
00120     if ( !pic_container->default_module_classes )
00121       return;
00122 
00123     memory = library->memory;
00124     classes = pic_container->default_module_classes;
00125     i = 0;
00126 
00127 #include FT_CONFIG_MODULES_H
00128 
00129     FT_FREE( classes );
00130     pic_container->default_module_classes = 0;
00131   }
00132 
00133   /* initialize all module classes and the pointer table */
00134 #undef  FT_USE_MODULE
00135 #define FT_USE_MODULE( type, x )                \
00136   error = FT_Create_Class_##x(library, &clazz); \
00137   if (error) goto Exit;                         \
00138   classes[i++] = clazz;
00139 
00140   FT_BASE_DEF( FT_Error )
00141   ft_create_default_module_classes( FT_Library  library )
00142   {
00143     FT_Error          error;
00144     FT_Memory         memory;
00145     FT_Module_Class** classes;
00146     FT_Module_Class*  clazz;
00147     FT_UInt           i;
00148     BasePIC*          pic_container = (BasePIC*)library->pic_container.base;
00149 
00150     memory = library->memory;  
00151     pic_container->default_module_classes = 0;
00152 
00153     if ( FT_ALLOC(classes, sizeof(FT_Module_Class*) * (FT_NUM_MODULE_CLASSES + 1) ) )
00154       return error;
00155     /* initialize all pointers to 0, especially the last one */
00156     for (i = 0; i < FT_NUM_MODULE_CLASSES; i++)
00157       classes[i] = 0;
00158     classes[FT_NUM_MODULE_CLASSES] = 0;
00159 
00160     i = 0;
00161 
00162 #include FT_CONFIG_MODULES_H
00163 
00164 Exit:    
00165     if (error) ft_destroy_default_module_classes( library );
00166     else pic_container->default_module_classes = classes;
00167 
00168     return error;    
00169   }
00170 
00171 
00172 #endif /* FT_CONFIG_OPTION_PIC */
00173 
00174   /* documentation is in ftmodapi.h */
00175 
00176   FT_EXPORT_DEF( void )
00177   FT_Add_Default_Modules( FT_Library  library )
00178   {
00179     FT_Error                       error;
00180     const FT_Module_Class* const*  cur;
00181 
00182 
00183     /* test for valid `library' delayed to FT_Add_Module() */
00184 
00185     cur = FT_DEFAULT_MODULES_GET;
00186     while ( *cur )
00187     {
00188       error = FT_Add_Module( library, *cur );
00189       /* notify errors, but don't stop */
00190       if ( error )
00191         FT_TRACE0(( "FT_Add_Default_Module:"
00192                     " Cannot install `%s', error = 0x%x\n",
00193                     (*cur)->module_name, error ));
00194       cur++;
00195     }
00196   }
00197 
00198 
00199   /* documentation is in freetype.h */
00200 
00201   FT_EXPORT_DEF( FT_Error )
00202   FT_Init_FreeType( FT_Library  *alibrary )
00203   {
00204     FT_Error   error;
00205     FT_Memory  memory;
00206 
00207 
00208     /* First of all, allocate a new system object -- this function is part */
00209     /* of the system-specific component, i.e. `ftsystem.c'.                */
00210 
00211     memory = FT_New_Memory();
00212     if ( !memory )
00213     {
00214       FT_ERROR(( "FT_Init_FreeType: cannot find memory manager\n" ));
00215       return FT_Err_Unimplemented_Feature;
00216     }
00217 
00218     /* build a library out of it, then fill it with the set of */
00219     /* default drivers.                                        */
00220 
00221     error = FT_New_Library( memory, alibrary );
00222     if ( error )
00223       FT_Done_Memory( memory );
00224     else
00225       FT_Add_Default_Modules( *alibrary );
00226 
00227     return error;
00228   }
00229 
00230 
00231   /* documentation is in freetype.h */
00232 
00233   FT_EXPORT_DEF( FT_Error )
00234   FT_Done_FreeType( FT_Library  library )
00235   {
00236     if ( library )
00237     {
00238       FT_Memory  memory = library->memory;
00239 
00240 
00241       /* Discard the library object */
00242       FT_Done_Library( library );
00243 
00244       /* discard memory manager */
00245       FT_Done_Memory( memory );
00246     }
00247 
00248     return FT_Err_Ok;
00249   }
00250 
00251 
00252 /* END */

Generated on Tue Jul 5 14:13:42 2011 for ROOT_528-00b_version by  doxygen 1.5.1