1 /***************************************************************************/
5 /* FreeType initialization layer (body). */
7 /* Copyright 1996-2016 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. */
16 /***************************************************************************/
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. */
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(). */
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'. */
37 /*************************************************************************/
41 #include FT_CONFIG_CONFIG_H
42 #include FT_INTERNAL_OBJECTS_H
43 #include FT_INTERNAL_DEBUG_H
48 /*************************************************************************/
50 /* The macro FT_COMPONENT is used in trace mode. It is an implicit */
51 /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
52 /* messages during execution. */
55 #define FT_COMPONENT trace_init
58 #ifndef FT_CONFIG_OPTION_PIC
63 #define FT_USE_MODULE( type, x ) extern "C" const type x;
65 #define FT_USE_MODULE( type, x ) extern const type x;
68 #include FT_CONFIG_MODULES_H
71 #define FT_USE_MODULE( type, x ) (const FT_Module_Class*)&(x),
74 const FT_Module_Class
* const ft_default_modules
[] =
76 #include FT_CONFIG_MODULES_H
81 #else /* FT_CONFIG_OPTION_PIC */
85 #define FT_EXTERNC extern "C"
87 #define FT_EXTERNC extern
90 /* declare the module's class creation/destruction functions */
92 #define FT_USE_MODULE( type, x ) \
94 FT_Create_Class_ ## x( FT_Library library, \
95 FT_Module_Class* *output_class ); \
97 FT_Destroy_Class_ ## x( FT_Library library, \
98 FT_Module_Class* clazz );
100 #include FT_CONFIG_MODULES_H
102 /* count all module classes */
104 #define FT_USE_MODULE( type, x ) MODULE_CLASS_ ## x,
108 #include FT_CONFIG_MODULES_H
109 FT_NUM_MODULE_CLASSES
112 /* destroy all module classes */
114 #define FT_USE_MODULE( type, x ) \
117 FT_Destroy_Class_ ## x( library, classes[i] ); \
123 ft_destroy_default_module_classes( FT_Library library
)
125 FT_Module_Class
* *classes
;
128 BasePIC
* pic_container
= (BasePIC
*)library
->pic_container
.base
;
131 if ( !pic_container
->default_module_classes
)
134 memory
= library
->memory
;
135 classes
= pic_container
->default_module_classes
;
138 #include FT_CONFIG_MODULES_H
141 pic_container
->default_module_classes
= NULL
;
145 /* initialize all module classes and the pointer table */
147 #define FT_USE_MODULE( type, x ) \
148 error = FT_Create_Class_ ## x( library, &clazz ); \
151 classes[i++] = clazz;
154 FT_BASE_DEF( FT_Error
)
155 ft_create_default_module_classes( FT_Library library
)
159 FT_Module_Class
* *classes
= NULL
;
160 FT_Module_Class
* clazz
;
162 BasePIC
* pic_container
= (BasePIC
*)library
->pic_container
.base
;
165 memory
= library
->memory
;
167 pic_container
->default_module_classes
= NULL
;
169 if ( FT_ALLOC( classes
, sizeof ( FT_Module_Class
* ) *
170 ( FT_NUM_MODULE_CLASSES
+ 1 ) ) )
173 /* initialize all pointers to 0, especially the last one */
174 for ( i
= 0; i
< FT_NUM_MODULE_CLASSES
; i
++ )
176 classes
[FT_NUM_MODULE_CLASSES
] = NULL
;
180 #include FT_CONFIG_MODULES_H
184 ft_destroy_default_module_classes( library
);
186 pic_container
->default_module_classes
= classes
;
192 #endif /* FT_CONFIG_OPTION_PIC */
195 /* documentation is in ftmodapi.h */
197 FT_EXPORT_DEF( void )
198 FT_Add_Default_Modules( FT_Library library
)
201 const FT_Module_Class
* const* cur
;
204 /* FT_DEFAULT_MODULES_GET dereferences `library' in PIC mode */
205 #ifdef FT_CONFIG_OPTION_PIC
210 /* GCC 4.6 warns the type difference:
211 * FT_Module_Class** != const FT_Module_Class* const*
213 cur
= (const FT_Module_Class
* const*)FT_DEFAULT_MODULES_GET
;
215 /* test for valid `library' delayed to FT_Add_Module() */
218 error
= FT_Add_Module( library
, *cur
);
219 /* notify errors, but don't stop */
221 FT_TRACE0(( "FT_Add_Default_Module:"
222 " Cannot install `%s', error = 0x%x\n",
223 (*cur
)->module_name
, error
));
229 #ifdef FT_CONFIG_OPTION_ENVIRONMENT_PROPERTIES
231 #define MAX_LENGTH 128
234 * Set default properties derived from the `FREETYPE_PROPERTIES'
235 * environment variable.
237 * `FREETYPE_PROPERTIES' has the following syntax form (broken here into
238 * multiple lines for better readability)
240 * <optional whitespace>
242 * <property-name1> '=' <property-value1>
245 * <property-name2> '=' <property-value2>
250 * FREETYPE_PROPERTIES=truetype:interpreter-version=35 \
251 * cff:no-stem-darkening=1 \
252 * autofitter:warping=1
257 ft_set_default_properties( FT_Library library
)
263 char module_name
[MAX_LENGTH
+ 1];
264 char property_name
[MAX_LENGTH
+ 1];
265 char property_value
[MAX_LENGTH
+ 1];
270 env
= ft_getenv( "FREETYPE_PROPERTIES" );
274 for ( p
= env
; *p
; p
++ )
276 /* skip leading whitespace and separators */
277 if ( *p
== ' ' || *p
== '\t' )
280 /* read module name, followed by `:' */
282 for ( i
= 0; i
< MAX_LENGTH
; i
++ )
284 if ( !*p
|| *p
== ':' )
286 module_name
[i
] = *p
++;
288 module_name
[i
] = '\0';
290 if ( !*p
|| *p
!= ':' || p
== q
)
293 /* read property name, followed by `=' */
295 for ( i
= 0; i
< MAX_LENGTH
; i
++ )
297 if ( !*p
|| *p
== '=' )
299 property_name
[i
] = *p
++;
301 property_name
[i
] = '\0';
303 if ( !*p
|| *p
!= '=' || p
== q
)
306 /* read property value, followed by whitespace (if any) */
308 for ( i
= 0; i
< MAX_LENGTH
; i
++ )
310 if ( !*p
|| *p
== ' ' || *p
== '\t' )
312 property_value
[i
] = *p
++;
314 property_value
[i
] = '\0';
316 if ( !( *p
== '\0' || *p
== ' ' || *p
== '\t' ) || p
== q
)
319 /* we completely ignore errors */
320 ft_property_string_set( library
,
330 ft_set_default_properties( FT_Library library
)
332 FT_UNUSED( library
);
338 /* documentation is in freetype.h */
340 FT_EXPORT_DEF( FT_Error
)
341 FT_Init_FreeType( FT_Library
*alibrary
)
347 /* check of `alibrary' delayed to `FT_New_Library' */
349 /* First of all, allocate a new system object -- this function is part */
350 /* of the system-specific component, i.e. `ftsystem.c'. */
352 memory
= FT_New_Memory();
355 FT_ERROR(( "FT_Init_FreeType: cannot find memory manager\n" ));
356 return FT_THROW( Unimplemented_Feature
);
359 /* build a library out of it, then fill it with the set of */
360 /* default drivers. */
362 error
= FT_New_Library( memory
, alibrary
);
364 FT_Done_Memory( memory
);
366 FT_Add_Default_Modules( *alibrary
);
368 ft_set_default_properties( *alibrary
);
374 /* documentation is in freetype.h */
376 FT_EXPORT_DEF( FT_Error
)
377 FT_Done_FreeType( FT_Library library
)
383 return FT_THROW( Invalid_Library_Handle
);
385 memory
= library
->memory
;
387 /* Discard the library object */
388 FT_Done_Library( library
);
390 /* discard memory manager */
391 FT_Done_Memory( memory
);