/src/freetype/src/base/ftinit.c

https://bitbucket.org/cabalistic/ogredeps/ · C · 282 lines · 151 code · 68 blank · 63 comment · 12 complexity · a66f4eff2c6b5d1b425ab90a7befc711 MD5 · raw file

  1. /***************************************************************************/
  2. /* */
  3. /* ftinit.c */
  4. /* */
  5. /* FreeType initialization layer (body). */
  6. /* */
  7. /* Copyright 1996-2001, 2002, 2005, 2007, 2009, 2012 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 \
  77. FT_Create_Class_ ## x( FT_Library library, \
  78. FT_Module_Class* *output_class ); \
  79. FT_EXTERNC void \
  80. FT_Destroy_Class_ ## x( FT_Library library, \
  81. FT_Module_Class* clazz );
  82. #include FT_CONFIG_MODULES_H
  83. /* count all module classes */
  84. #undef FT_USE_MODULE
  85. #define FT_USE_MODULE( type, x ) MODULE_CLASS_ ## x,
  86. enum
  87. {
  88. #include FT_CONFIG_MODULES_H
  89. FT_NUM_MODULE_CLASSES
  90. };
  91. /* destroy all module classes */
  92. #undef FT_USE_MODULE
  93. #define FT_USE_MODULE( type, x ) \
  94. if ( classes[i] ) \
  95. { \
  96. FT_Destroy_Class_ ## x( library, classes[i] ); \
  97. } \
  98. i++;
  99. FT_BASE_DEF( void )
  100. ft_destroy_default_module_classes( FT_Library library )
  101. {
  102. FT_Module_Class* *classes;
  103. FT_Memory memory;
  104. FT_UInt i;
  105. BasePIC* pic_container = (BasePIC*)library->pic_container.base;
  106. if ( !pic_container->default_module_classes )
  107. return;
  108. memory = library->memory;
  109. classes = pic_container->default_module_classes;
  110. i = 0;
  111. #include FT_CONFIG_MODULES_H
  112. FT_FREE( classes );
  113. pic_container->default_module_classes = 0;
  114. }
  115. /* initialize all module classes and the pointer table */
  116. #undef FT_USE_MODULE
  117. #define FT_USE_MODULE( type, x ) \
  118. error = FT_Create_Class_ ## x( library, &clazz ); \
  119. if ( error ) \
  120. goto Exit; \
  121. classes[i++] = clazz;
  122. FT_BASE_DEF( FT_Error )
  123. ft_create_default_module_classes( FT_Library library )
  124. {
  125. FT_Error error;
  126. FT_Memory memory;
  127. FT_Module_Class* *classes;
  128. FT_Module_Class* clazz;
  129. FT_UInt i;
  130. BasePIC* pic_container = (BasePIC*)library->pic_container.base;
  131. memory = library->memory;
  132. pic_container->default_module_classes = 0;
  133. if ( FT_ALLOC( classes, sizeof ( FT_Module_Class* ) *
  134. ( FT_NUM_MODULE_CLASSES + 1 ) ) )
  135. return error;
  136. /* initialize all pointers to 0, especially the last one */
  137. for ( i = 0; i < FT_NUM_MODULE_CLASSES; i++ )
  138. classes[i] = 0;
  139. classes[FT_NUM_MODULE_CLASSES] = 0;
  140. i = 0;
  141. #include FT_CONFIG_MODULES_H
  142. Exit:
  143. if ( error )
  144. ft_destroy_default_module_classes( library );
  145. else
  146. pic_container->default_module_classes = classes;
  147. return error;
  148. }
  149. #endif /* FT_CONFIG_OPTION_PIC */
  150. /* documentation is in ftmodapi.h */
  151. FT_EXPORT_DEF( void )
  152. FT_Add_Default_Modules( FT_Library library )
  153. {
  154. FT_Error error;
  155. const FT_Module_Class* const* cur;
  156. /* FT_DEFAULT_MODULES_GET dereferences `library' in PIC mode */
  157. #ifdef FT_CONFIG_OPTION_PIC
  158. if ( !library )
  159. return;
  160. #endif
  161. /* GCC 4.6 warns the type difference:
  162. * FT_Module_Class** != const FT_Module_Class* const*
  163. */
  164. cur = (const FT_Module_Class* const*)FT_DEFAULT_MODULES_GET;
  165. /* test for valid `library' delayed to FT_Add_Module() */
  166. while ( *cur )
  167. {
  168. error = FT_Add_Module( library, *cur );
  169. /* notify errors, but don't stop */
  170. if ( error )
  171. FT_TRACE0(( "FT_Add_Default_Module:"
  172. " Cannot install `%s', error = 0x%x\n",
  173. (*cur)->module_name, error ));
  174. cur++;
  175. }
  176. }
  177. /* documentation is in freetype.h */
  178. FT_EXPORT_DEF( FT_Error )
  179. FT_Init_FreeType( FT_Library *alibrary )
  180. {
  181. FT_Error error;
  182. FT_Memory memory;
  183. /* First of all, allocate a new system object -- this function is part */
  184. /* of the system-specific component, i.e. `ftsystem.c'. */
  185. memory = FT_New_Memory();
  186. if ( !memory )
  187. {
  188. FT_ERROR(( "FT_Init_FreeType: cannot find memory manager\n" ));
  189. return FT_Err_Unimplemented_Feature;
  190. }
  191. /* build a library out of it, then fill it with the set of */
  192. /* default drivers. */
  193. error = FT_New_Library( memory, alibrary );
  194. if ( error )
  195. FT_Done_Memory( memory );
  196. else
  197. FT_Add_Default_Modules( *alibrary );
  198. return error;
  199. }
  200. /* documentation is in freetype.h */
  201. FT_EXPORT_DEF( FT_Error )
  202. FT_Done_FreeType( FT_Library library )
  203. {
  204. if ( library )
  205. {
  206. FT_Memory memory = library->memory;
  207. /* Discard the library object */
  208. FT_Done_Library( library );
  209. /* discard memory manager */
  210. FT_Done_Memory( memory );
  211. }
  212. return FT_Err_Ok;
  213. }
  214. /* END */