| 1 | /***************************************************************************/ |
|---|
| 2 | /* */ |
|---|
| 3 | /* ftinit.c */ |
|---|
| 4 | /* */ |
|---|
| 5 | /* FreeType initialization layer (body). */ |
|---|
| 6 | /* */ |
|---|
| 7 | /* Copyright 1996-2001, 2002, 2005, 2007 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 | /* */ |
|---|
| 20 | /* The purpose of this file is to implement the following two */ |
|---|
| 21 | /* functions: */ |
|---|
| 22 | /* */ |
|---|
| 23 | /* FT_Add_Default_Modules(): */ |
|---|
| 24 | /* This function is used to add the set of default modules to a */ |
|---|
| 25 | /* fresh new library object. The set is taken from the header file */ |
|---|
| 26 | /* `freetype/config/ftmodule.h'. See the document `FreeType 2.0 */ |
|---|
| 27 | /* Build System' for more information. */ |
|---|
| 28 | /* */ |
|---|
| 29 | /* FT_Init_FreeType(): */ |
|---|
| 30 | /* This function creates a system object for the current platform, */ |
|---|
| 31 | /* builds a library out of it, then calls FT_Default_Drivers(). */ |
|---|
| 32 | /* */ |
|---|
| 33 | /* Note that even if FT_Init_FreeType() uses the implementation of the */ |
|---|
| 34 | /* system object defined at build time, client applications are still */ |
|---|
| 35 | /* able to provide their own `ftsystem.c'. */ |
|---|
| 36 | /* */ |
|---|
| 37 | /*************************************************************************/ |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | #include <ft2build.h> |
|---|
| 41 | #include FT_CONFIG_CONFIG_H |
|---|
| 42 | #include FT_INTERNAL_OBJECTS_H |
|---|
| 43 | #include FT_INTERNAL_DEBUG_H |
|---|
| 44 | #include FT_MODULE_H |
|---|
| 45 | |
|---|
| 46 | |
|---|
| 47 | /*************************************************************************/ |
|---|
| 48 | /* */ |
|---|
| 49 | /* The macro FT_COMPONENT is used in trace mode. It is an implicit */ |
|---|
| 50 | /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */ |
|---|
| 51 | /* messages during execution. */ |
|---|
| 52 | /* */ |
|---|
| 53 | #undef FT_COMPONENT |
|---|
| 54 | #define FT_COMPONENT trace_init |
|---|
| 55 | |
|---|
| 56 | #undef FT_USE_MODULE |
|---|
| 57 | #ifdef __cplusplus |
|---|
| 58 | #define FT_USE_MODULE( type, x ) extern "C" const type x; |
|---|
| 59 | #else |
|---|
| 60 | #define FT_USE_MODULE( type, x ) extern const type x; |
|---|
| 61 | #endif |
|---|
| 62 | |
|---|
| 63 | |
|---|
| 64 | #include FT_CONFIG_MODULES_H |
|---|
| 65 | |
|---|
| 66 | |
|---|
| 67 | #undef FT_USE_MODULE |
|---|
| 68 | #define FT_USE_MODULE( type, x ) (const FT_Module_Class*)&(x), |
|---|
| 69 | |
|---|
| 70 | static |
|---|
| 71 | const FT_Module_Class* const ft_default_modules[] = |
|---|
| 72 | { |
|---|
| 73 | #include FT_CONFIG_MODULES_H |
|---|
| 74 | 0 |
|---|
| 75 | }; |
|---|
| 76 | |
|---|
| 77 | |
|---|
| 78 | /* documentation is in ftmodapi.h */ |
|---|
| 79 | |
|---|
| 80 | FT_EXPORT_DEF( void ) |
|---|
| 81 | FT_Add_Default_Modules( FT_Library library ) |
|---|
| 82 | { |
|---|
| 83 | FT_Error error; |
|---|
| 84 | const FT_Module_Class* const* cur; |
|---|
| 85 | |
|---|
| 86 | |
|---|
| 87 | /* test for valid `library' delayed to FT_Add_Module() */ |
|---|
| 88 | |
|---|
| 89 | cur = ft_default_modules; |
|---|
| 90 | while ( *cur ) |
|---|
| 91 | { |
|---|
| 92 | error = FT_Add_Module( library, *cur ); |
|---|
| 93 | /* notify errors, but don't stop */ |
|---|
| 94 | if ( error ) |
|---|
| 95 | { |
|---|
| 96 | FT_ERROR(( "FT_Add_Default_Module: Cannot install `%s', error = 0x%x\n", |
|---|
| 97 | (*cur)->module_name, error )); |
|---|
| 98 | } |
|---|
| 99 | cur++; |
|---|
| 100 | } |
|---|
| 101 | } |
|---|
| 102 | |
|---|
| 103 | |
|---|
| 104 | /* documentation is in freetype.h */ |
|---|
| 105 | |
|---|
| 106 | FT_EXPORT_DEF( FT_Error ) |
|---|
| 107 | FT_Init_FreeType( FT_Library *alibrary ) |
|---|
| 108 | { |
|---|
| 109 | FT_Error error; |
|---|
| 110 | FT_Memory memory; |
|---|
| 111 | |
|---|
| 112 | |
|---|
| 113 | /* First of all, allocate a new system object -- this function is part */ |
|---|
| 114 | /* of the system-specific component, i.e. `ftsystem.c'. */ |
|---|
| 115 | |
|---|
| 116 | memory = FT_New_Memory(); |
|---|
| 117 | if ( !memory ) |
|---|
| 118 | { |
|---|
| 119 | FT_ERROR(( "FT_Init_FreeType: cannot find memory manager\n" )); |
|---|
| 120 | return FT_Err_Unimplemented_Feature; |
|---|
| 121 | } |
|---|
| 122 | |
|---|
| 123 | /* build a library out of it, then fill it with the set of */ |
|---|
| 124 | /* default drivers. */ |
|---|
| 125 | |
|---|
| 126 | error = FT_New_Library( memory, alibrary ); |
|---|
| 127 | if ( error ) |
|---|
| 128 | FT_Done_Memory( memory ); |
|---|
| 129 | else |
|---|
| 130 | { |
|---|
| 131 | (*alibrary)->version_major = FREETYPE_MAJOR; |
|---|
| 132 | (*alibrary)->version_minor = FREETYPE_MINOR; |
|---|
| 133 | (*alibrary)->version_patch = FREETYPE_PATCH; |
|---|
| 134 | |
|---|
| 135 | FT_Add_Default_Modules( *alibrary ); |
|---|
| 136 | } |
|---|
| 137 | |
|---|
| 138 | return error; |
|---|
| 139 | } |
|---|
| 140 | |
|---|
| 141 | |
|---|
| 142 | /* documentation is in freetype.h */ |
|---|
| 143 | |
|---|
| 144 | FT_EXPORT_DEF( FT_Error ) |
|---|
| 145 | FT_Done_FreeType( FT_Library library ) |
|---|
| 146 | { |
|---|
| 147 | if ( library ) |
|---|
| 148 | { |
|---|
| 149 | FT_Memory memory = library->memory; |
|---|
| 150 | |
|---|
| 151 | |
|---|
| 152 | /* Discard the library object */ |
|---|
| 153 | FT_Done_Library( library ); |
|---|
| 154 | |
|---|
| 155 | /* discard memory manager */ |
|---|
| 156 | FT_Done_Memory( memory ); |
|---|
| 157 | } |
|---|
| 158 | |
|---|
| 159 | return FT_Err_Ok; |
|---|
| 160 | } |
|---|
| 161 | |
|---|
| 162 | |
|---|
| 163 | /* END */ |
|---|