ftinit.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /***************************************************************************/
  2. /* */
  3. /* ftinit.c */
  4. /* */
  5. /* FreeType initialization layer (body). */
  6. /* */
  7. /* Copyright 1996-2001, 2002 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. /*************************************************************************/
  43. /* */
  44. /* The macro FT_COMPONENT is used in trace mode. It is an implicit */
  45. /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
  46. /* messages during execution. */
  47. /* */
  48. #undef FT_COMPONENT
  49. #define FT_COMPONENT trace_init
  50. #undef FT_USE_MODULE
  51. #ifdef __cplusplus
  52. #define FT_USE_MODULE( x ) extern "C" const FT_Module_Class* x;
  53. #else
  54. #define FT_USE_MODULE( x ) extern const FT_Module_Class* x;
  55. #endif
  56. #include FT_CONFIG_MODULES_H
  57. #undef FT_USE_MODULE
  58. #define FT_USE_MODULE( x ) (const FT_Module_Class*)&x,
  59. static
  60. const FT_Module_Class* const ft_default_modules[] =
  61. {
  62. #include FT_CONFIG_MODULES_H
  63. 0
  64. };
  65. /* documentation is in ftmodule.h */
  66. FT_EXPORT_DEF( void )
  67. FT_Add_Default_Modules( FT_Library library )
  68. {
  69. FT_Error error;
  70. const FT_Module_Class* const* cur;
  71. /* test for valid `library' delayed to FT_Add_Module() */
  72. cur = ft_default_modules;
  73. while ( *cur )
  74. {
  75. error = FT_Add_Module( library, *cur );
  76. /* notify errors, but don't stop */
  77. if ( error )
  78. {
  79. FT_ERROR(( "FT_Add_Default_Module: Cannot install `%s', error = 0x%x\n",
  80. (*cur)->module_name, error ));
  81. }
  82. cur++;
  83. }
  84. }
  85. /* documentation is in freetype.h */
  86. FT_EXPORT_DEF( FT_Error )
  87. FT_Init_FreeType( FT_Library *alibrary )
  88. {
  89. FT_Error error;
  90. FT_Memory memory;
  91. /* First of all, allocate a new system object -- this function is part */
  92. /* of the system-specific component, i.e. `ftsystem.c'. */
  93. memory = FT_New_Memory();
  94. if ( !memory )
  95. {
  96. FT_ERROR(( "FT_Init_FreeType: cannot find memory manager\n" ));
  97. return FT_Err_Unimplemented_Feature;
  98. }
  99. /* build a library out of it, then fill it with the set of */
  100. /* default drivers. */
  101. error = FT_New_Library( memory, alibrary );
  102. if ( !error )
  103. {
  104. (*alibrary)->version_major = FREETYPE_MAJOR;
  105. (*alibrary)->version_minor = FREETYPE_MINOR;
  106. (*alibrary)->version_patch = FREETYPE_PATCH;
  107. FT_Add_Default_Modules( *alibrary );
  108. }
  109. return error;
  110. }
  111. /* documentation is in freetype.h */
  112. FT_EXPORT_DEF( FT_Error )
  113. FT_Done_FreeType( FT_Library library )
  114. {
  115. if ( library )
  116. {
  117. FT_Memory memory = library->memory;
  118. /* Discard the library object */
  119. FT_Done_Library( library );
  120. /* discard memory manager */
  121. FT_Done_Memory( memory );
  122. }
  123. return FT_Err_Ok;
  124. }
  125. /* END */