/src/compiler/android-ndk/jni/freetype/src/base/ftinit.c

http://ftk.googlecode.com/ · C · 252 lines · 135 code · 58 blank · 59 comment · 12 complexity · 6d4bd8db14814c0d222960bd55215745 MD5 · raw file

  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. /***************************************************************************/
  17. /*************************************************************************/
  18. /* */
  19. /* The purpose of this file is to implement the following two */
  20. /* functions: */
  21. /* */
  22. /* FT_Add_Default_Modules(): */
  23. /* This function is used to add the set of default modules to a */
  24. /* fresh new library object. The set is taken from the header file */
  25. /* `freetype/config/ftmodule.h'. See the document `FreeType 2.0 */
  26. /* Build System' for more information. */
  27. /* */
  28. /* FT_Init_FreeType(): */
  29. /* This function creates a system object for the current platform, */
  30. /* builds a library out of it, then calls FT_Default_Drivers(). */
  31. /* */
  32. /* Note that even if FT_Init_FreeType() uses the implementation of the */
  33. /* system object defined at build time, client applications are still */
  34. /* able to provide their own `ftsystem.c'. */
  35. /* */
  36. /*************************************************************************/
  37. #include <ft2build.h>
  38. #include FT_CONFIG_CONFIG_H
  39. #include FT_INTERNAL_OBJECTS_H
  40. #include FT_INTERNAL_DEBUG_H
  41. #include FT_MODULE_H
  42. #include "basepic.h"
  43. /*************************************************************************/
  44. /* */
  45. /* The macro FT_COMPONENT is used in trace mode. It is an implicit */
  46. /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
  47. /* messages during execution. */
  48. /* */
  49. #undef FT_COMPONENT
  50. #define FT_COMPONENT trace_init
  51. #ifndef FT_CONFIG_OPTION_PIC
  52. #undef FT_USE_MODULE
  53. #ifdef __cplusplus
  54. #define FT_USE_MODULE( type, x ) extern "C" const type x;
  55. #else
  56. #define FT_USE_MODULE( type, x ) extern const type x;
  57. #endif
  58. #include FT_CONFIG_MODULES_H
  59. #undef FT_USE_MODULE
  60. #define FT_USE_MODULE( type, x ) (const FT_Module_Class*)&(x),
  61. static
  62. const FT_Module_Class* const ft_default_modules[] =
  63. {
  64. #include FT_CONFIG_MODULES_H
  65. 0
  66. };
  67. #else /* FT_CONFIG_OPTION_PIC */
  68. #ifdef __cplusplus
  69. #define FT_EXTERNC extern "C"
  70. #else
  71. #define FT_EXTERNC extern
  72. #endif
  73. /* declare the module's class creation/destruction functions */
  74. #undef FT_USE_MODULE
  75. #define FT_USE_MODULE( type, x ) \
  76. FT_EXTERNC FT_Error FT_Create_Class_##x( FT_Library library, FT_Module_Class** output_class ); \
  77. FT_EXTERNC void FT_Destroy_Class_##x( FT_Library library, FT_Module_Class* clazz );
  78. #include FT_CONFIG_MODULES_H
  79. /* count all module classes */
  80. #undef FT_USE_MODULE
  81. #define FT_USE_MODULE( type, x ) MODULE_CLASS_##x,
  82. enum {
  83. #include FT_CONFIG_MODULES_H
  84. FT_NUM_MODULE_CLASSES
  85. };
  86. /* destroy all module classes */
  87. #undef FT_USE_MODULE
  88. #define FT_USE_MODULE( type, x ) \
  89. if ( classes[i] ) { FT_Destroy_Class_##x(library, classes[i]); } \
  90. i++; \
  91. FT_BASE_DEF( void )
  92. ft_destroy_default_module_classes( FT_Library library )
  93. {
  94. FT_Module_Class** classes;
  95. FT_Memory memory;
  96. FT_UInt i;
  97. BasePIC* pic_container = (BasePIC*)library->pic_container.base;
  98. if ( !pic_container->default_module_classes )
  99. return;
  100. memory = library->memory;
  101. classes = pic_container->default_module_classes;
  102. i = 0;
  103. #include FT_CONFIG_MODULES_H
  104. FT_FREE( classes );
  105. pic_container->default_module_classes = 0;
  106. }
  107. /* initialize all module classes and the pointer table */
  108. #undef FT_USE_MODULE
  109. #define FT_USE_MODULE( type, x ) \
  110. error = FT_Create_Class_##x(library, &clazz); \
  111. if (error) goto Exit; \
  112. classes[i++] = clazz;
  113. FT_BASE_DEF( FT_Error )
  114. ft_create_default_module_classes( FT_Library library )
  115. {
  116. FT_Error error;
  117. FT_Memory memory;
  118. FT_Module_Class** classes;
  119. FT_Module_Class* clazz;
  120. FT_UInt i;
  121. BasePIC* pic_container = (BasePIC*)library->pic_container.base;
  122. memory = library->memory;
  123. pic_container->default_module_classes = 0;
  124. if ( FT_ALLOC(classes, sizeof(FT_Module_Class*) * (FT_NUM_MODULE_CLASSES + 1) ) )
  125. return error;
  126. /* initialize all pointers to 0, especially the last one */
  127. for (i = 0; i < FT_NUM_MODULE_CLASSES; i++)
  128. classes[i] = 0;
  129. classes[FT_NUM_MODULE_CLASSES] = 0;
  130. i = 0;
  131. #include FT_CONFIG_MODULES_H
  132. Exit:
  133. if (error) ft_destroy_default_module_classes( library );
  134. else pic_container->default_module_classes = classes;
  135. return error;
  136. }
  137. #endif /* FT_CONFIG_OPTION_PIC */
  138. /* documentation is in ftmodapi.h */
  139. FT_EXPORT_DEF( void )
  140. FT_Add_Default_Modules( FT_Library library )
  141. {
  142. FT_Error error;
  143. const FT_Module_Class* const* cur;
  144. /* test for valid `library' delayed to FT_Add_Module() */
  145. cur = FT_DEFAULT_MODULES_GET;
  146. while ( *cur )
  147. {
  148. error = FT_Add_Module( library, *cur );
  149. /* notify errors, but don't stop */
  150. if ( error )
  151. FT_TRACE0(( "FT_Add_Default_Module:"
  152. " Cannot install `%s', error = 0x%x\n",
  153. (*cur)->module_name, error ));
  154. cur++;
  155. }
  156. }
  157. /* documentation is in freetype.h */
  158. FT_EXPORT_DEF( FT_Error )
  159. FT_Init_FreeType( FT_Library *alibrary )
  160. {
  161. FT_Error error;
  162. FT_Memory memory;
  163. /* First of all, allocate a new system object -- this function is part */
  164. /* of the system-specific component, i.e. `ftsystem.c'. */
  165. memory = FT_New_Memory();
  166. if ( !memory )
  167. {
  168. FT_ERROR(( "FT_Init_FreeType: cannot find memory manager\n" ));
  169. return FT_Err_Unimplemented_Feature;
  170. }
  171. /* build a library out of it, then fill it with the set of */
  172. /* default drivers. */
  173. error = FT_New_Library( memory, alibrary );
  174. if ( error )
  175. FT_Done_Memory( memory );
  176. else
  177. FT_Add_Default_Modules( *alibrary );
  178. return error;
  179. }
  180. /* documentation is in freetype.h */
  181. FT_EXPORT_DEF( FT_Error )
  182. FT_Done_FreeType( FT_Library library )
  183. {
  184. if ( library )
  185. {
  186. FT_Memory memory = library->memory;
  187. /* Discard the library object */
  188. FT_Done_Library( library );
  189. /* discard memory manager */
  190. FT_Done_Memory( memory );
  191. }
  192. return FT_Err_Ok;
  193. }
  194. /* END */