Path: blob/master/src/java.desktop/share/native/libfreetype/src/base/ftinit.c
42232 views
/****************************************************************************1*2* ftinit.c3*4* FreeType initialization layer (body).5*6* Copyright (C) 1996-2020 by7* David Turner, Robert Wilhelm, and Werner Lemberg.8*9* This file is part of the FreeType project, and may only be used,10* modified, and distributed under the terms of the FreeType project11* license, LICENSE.TXT. By continuing to use, modify, or distribute12* this file you indicate that you have read the license and13* understand and accept it fully.14*15*/1617/**************************************************************************18*19* The purpose of this file is to implement the following two20* functions:21*22* FT_Add_Default_Modules():23* This function is used to add the set of default modules to a24* fresh new library object. The set is taken from the header file25* `freetype/config/ftmodule.h'. See the document `FreeType 2.026* 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 the33* system object defined at build time, client applications are still34* able to provide their own `ftsystem.c'.35*36*/373839#include <ft2build.h>40#include FT_CONFIG_CONFIG_H41#include <freetype/internal/ftobjs.h>42#include <freetype/internal/ftdebug.h>43#include <freetype/ftmodapi.h>444546/**************************************************************************47*48* The macro FT_COMPONENT is used in trace mode. It is an implicit49* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log50* messages during execution.51*/52#undef FT_COMPONENT53#define FT_COMPONENT init545556#undef FT_USE_MODULE57#ifdef __cplusplus58#define FT_USE_MODULE( type, x ) extern "C" const type x;59#else60#define FT_USE_MODULE( type, x ) extern const type x;61#endif6263#include FT_CONFIG_MODULES_H6465#undef FT_USE_MODULE66#define FT_USE_MODULE( type, x ) (const FT_Module_Class*)&(x),6768static69const FT_Module_Class* const ft_default_modules[] =70{71#include FT_CONFIG_MODULES_H72073};747576/* documentation is in ftmodapi.h */7778FT_EXPORT_DEF( void )79FT_Add_Default_Modules( FT_Library library )80{81FT_Error error;82const FT_Module_Class* const* cur;838485/* GCC 4.6 warns the type difference:86* FT_Module_Class** != const FT_Module_Class* const*87*/88cur = (const FT_Module_Class* const*)ft_default_modules;8990/* test for valid `library' delayed to FT_Add_Module() */91while ( *cur )92{93error = FT_Add_Module( library, *cur );94/* notify errors, but don't stop */95if ( error )96FT_TRACE0(( "FT_Add_Default_Module:"97" Cannot install `%s', error = 0x%x\n",98(*cur)->module_name, error ));99cur++;100}101}102103104#ifdef FT_CONFIG_OPTION_ENVIRONMENT_PROPERTIES105106#define MAX_LENGTH 128107108/* documentation is in ftmodapi.h */109110FT_EXPORT_DEF( void )111FT_Set_Default_Properties( FT_Library library )112{113const char* env;114const char* p;115const char* q;116117char module_name[MAX_LENGTH + 1];118char property_name[MAX_LENGTH + 1];119char property_value[MAX_LENGTH + 1];120121int i;122123124env = ft_getenv( "FREETYPE_PROPERTIES" );125if ( !env )126return;127128for ( p = env; *p; p++ )129{130/* skip leading whitespace and separators */131if ( *p == ' ' || *p == '\t' )132continue;133134/* read module name, followed by `:' */135q = p;136for ( i = 0; i < MAX_LENGTH; i++ )137{138if ( !*p || *p == ':' )139break;140module_name[i] = *p++;141}142module_name[i] = '\0';143144if ( !*p || *p != ':' || p == q )145break;146147/* read property name, followed by `=' */148q = ++p;149for ( i = 0; i < MAX_LENGTH; i++ )150{151if ( !*p || *p == '=' )152break;153property_name[i] = *p++;154}155property_name[i] = '\0';156157if ( !*p || *p != '=' || p == q )158break;159160/* read property value, followed by whitespace (if any) */161q = ++p;162for ( i = 0; i < MAX_LENGTH; i++ )163{164if ( !*p || *p == ' ' || *p == '\t' )165break;166property_value[i] = *p++;167}168property_value[i] = '\0';169170if ( !( *p == '\0' || *p == ' ' || *p == '\t' ) || p == q )171break;172173/* we completely ignore errors */174ft_property_string_set( library,175module_name,176property_name,177property_value );178179if ( !*p )180break;181}182}183184#else185186FT_EXPORT_DEF( void )187FT_Set_Default_Properties( FT_Library library )188{189FT_UNUSED( library );190}191192#endif193194195/* documentation is in freetype.h */196197FT_EXPORT_DEF( FT_Error )198FT_Init_FreeType( FT_Library *alibrary )199{200FT_Error error;201FT_Memory memory;202203204/* check of `alibrary' delayed to `FT_New_Library' */205206/* First of all, allocate a new system object -- this function is part */207/* of the system-specific component, i.e. `ftsystem.c'. */208209memory = FT_New_Memory();210if ( !memory )211{212FT_ERROR(( "FT_Init_FreeType: cannot find memory manager\n" ));213return FT_THROW( Unimplemented_Feature );214}215216/* build a library out of it, then fill it with the set of */217/* default drivers. */218219error = FT_New_Library( memory, alibrary );220if ( error )221FT_Done_Memory( memory );222else223FT_Add_Default_Modules( *alibrary );224225FT_Set_Default_Properties( *alibrary );226227return error;228}229230231/* documentation is in freetype.h */232233FT_EXPORT_DEF( FT_Error )234FT_Done_FreeType( FT_Library library )235{236FT_Memory memory;237238239if ( !library )240return FT_THROW( Invalid_Library_Handle );241242memory = library->memory;243244/* Discard the library object */245FT_Done_Library( library );246247/* discard memory manager */248FT_Done_Memory( memory );249250return FT_Err_Ok;251}252253254/* END */255256257