1 /****************************************************************************
5 * FreeType initialization layer (body).
7 * Copyright (C) 1996-2020 by
8 * David Turner, Robert Wilhelm, and Werner Lemberg.
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.
18 /**************************************************************************
20 * The purpose of this file is to implement the following two
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.
30 * This function creates a system object for the current platform,
31 * builds a library out of it, then calls FT_Default_Drivers().
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'.
41 #include FT_CONFIG_CONFIG_H
42 #include <freetype/internal/ftobjs.h>
43 #include <freetype/internal/ftdebug.h>
44 #include <freetype/ftmodapi.h>
47 /**************************************************************************
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.
54 #define FT_COMPONENT init
59 #define FT_USE_MODULE( type, x ) extern "C" const type x;
61 #define FT_USE_MODULE( type, x ) extern const type x;
64 #include FT_CONFIG_MODULES_H
67 #define FT_USE_MODULE( type, x ) (const FT_Module_Class*)&(x),
70 const FT_Module_Class* const ft_default_modules[] =
72 #include FT_CONFIG_MODULES_H
77 /* documentation is in ftmodapi.h */
80 FT_Add_Default_Modules( FT_Library library )
83 const FT_Module_Class* const* cur;
86 /* GCC 4.6 warns the type difference:
87 * FT_Module_Class** != const FT_Module_Class* const*
89 cur = (const FT_Module_Class* const*)ft_default_modules;
91 /* test for valid `library' delayed to FT_Add_Module() */
94 error = FT_Add_Module( library, *cur );
95 /* notify errors, but don't stop */
97 FT_TRACE0(( "FT_Add_Default_Module:"
98 " Cannot install `%s', error = 0x%x\n",
99 (*cur)->module_name, error ));
105 #ifdef FT_CONFIG_OPTION_ENVIRONMENT_PROPERTIES
107 #define MAX_LENGTH 128
109 /* documentation is in ftmodapi.h */
111 FT_EXPORT_DEF( void )
112 FT_Set_Default_Properties( FT_Library library )
118 char module_name[MAX_LENGTH + 1];
119 char property_name[MAX_LENGTH + 1];
120 char property_value[MAX_LENGTH + 1];
125 env = ft_getenv( "FREETYPE_PROPERTIES" );
129 for ( p = env; *p; p++ )
131 /* skip leading whitespace and separators */
132 if ( *p == ' ' || *p == '\t' )
135 /* read module name, followed by `:' */
137 for ( i = 0; i < MAX_LENGTH; i++ )
139 if ( !*p || *p == ':' )
141 module_name[i] = *p++;
143 module_name[i] = '\0';
145 if ( !*p || *p != ':' || p == q )
148 /* read property name, followed by `=' */
150 for ( i = 0; i < MAX_LENGTH; i++ )
152 if ( !*p || *p == '=' )
154 property_name[i] = *p++;
156 property_name[i] = '\0';
158 if ( !*p || *p != '=' || p == q )
161 /* read property value, followed by whitespace (if any) */
163 for ( i = 0; i < MAX_LENGTH; i++ )
165 if ( !*p || *p == ' ' || *p == '\t' )
167 property_value[i] = *p++;
169 property_value[i] = '\0';
171 if ( !( *p == '\0' || *p == ' ' || *p == '\t' ) || p == q )
174 /* we completely ignore errors */
175 ft_property_string_set( library,
187 FT_EXPORT_DEF( void )
188 FT_Set_Default_Properties( FT_Library library )
190 FT_UNUSED( library );
196 /* documentation is in freetype.h */
198 FT_EXPORT_DEF( FT_Error )
199 FT_Init_FreeType( FT_Library *alibrary )
205 /* check of `alibrary' delayed to `FT_New_Library' */
207 /* First of all, allocate a new system object -- this function is part */
208 /* of the system-specific component, i.e. `ftsystem.c'. */
210 memory = FT_New_Memory();
213 FT_ERROR(( "FT_Init_FreeType: cannot find memory manager\n" ));
214 return FT_THROW( Unimplemented_Feature );
217 /* build a library out of it, then fill it with the set of */
218 /* default drivers. */
220 error = FT_New_Library( memory, alibrary );
222 FT_Done_Memory( memory );
224 FT_Add_Default_Modules( *alibrary );
226 FT_Set_Default_Properties( *alibrary );
232 /* documentation is in freetype.h */
234 FT_EXPORT_DEF( FT_Error )
235 FT_Done_FreeType( FT_Library library )
241 return FT_THROW( Invalid_Library_Handle );
243 memory = library->memory;
245 /* Discard the library object */
246 FT_Done_Library( library );
248 /* discard memory manager */
249 FT_Done_Memory( memory );