Position Independent Code (PIC) support in truetype driver.

* include/freetype/internal/services/svmm.h add macros to init
instances of FT_Service_MultiMastersRec.
* include/freetype/internal/services/svttglyf.h add macros to init
instances of FT_Service_TTGlyfRec.

* src/truetype/ttdriver.h declare tt_driver_class using macros from
ftdriver.h, when FT_CONFIG_OPTION_PIC is defined create and destroy
functions will be declared.
* src/truetype/ttdriver.c when FT_CONFIG_OPTION_PIC is defined
the following structs:
tt_service_gx_multi_masters, tt_service_truetype_glyf, tt_driver_class
and tt_services array,
will have functions to init or create and destroy them
instead of being allocated in the global scope.
And macros will be used from ttpic.h in order to access them
from the pic_container.
* src/truetype/ttobjs.c change trick_names array to be
PIC-compatible by being a two dimentional array rather than array
of pointers.

New Files:
* src/truetype/ttpic.h declare struct to hold PIC globals for truetype
driver and macros to access them.
* src/truetype/ttpic.c implement functions to allocate, destroy and
initialize PIC globals for truetype driver.

* src/truetype/truetype.c add new file to build: ttpic.c.
* src/truetype/jamfile add new files to FT2_MULTI build: ttpic.c.
This commit is contained in:
Oran Agra 2009-04-05 18:03:02 +03:00
parent 636c294bef
commit 2e7a4e9b7f
10 changed files with 263 additions and 42 deletions

View File

@ -1,3 +1,36 @@
2009-04-05 Oran Agra <oran@monfort.co.il>
Position Independent Code (PIC) support in truetype driver.
* include/freetype/internal/services/svmm.h add macros to init
instances of FT_Service_MultiMastersRec.
* include/freetype/internal/services/svttglyf.h add macros to init
instances of FT_Service_TTGlyfRec.
* src/truetype/ttdriver.h declare tt_driver_class using macros from
ftdriver.h, when FT_CONFIG_OPTION_PIC is defined create and destroy
functions will be declared.
* src/truetype/ttdriver.c when FT_CONFIG_OPTION_PIC is defined
the following structs:
tt_service_gx_multi_masters, tt_service_truetype_glyf, tt_driver_class
and tt_services array,
will have functions to init or create and destroy them
instead of being allocated in the global scope.
And macros will be used from ttpic.h in order to access them
from the pic_container.
* src/truetype/ttobjs.c change trick_names array to be
PIC-compatible by being a two dimentional array rather than array
of pointers.
New Files:
* src/truetype/ttpic.h declare struct to hold PIC globals for truetype
driver and macros to access them.
* src/truetype/ttpic.c implement functions to allocate, destroy and
initialize PIC globals for truetype driver.
* src/truetype/truetype.c add new file to build: ttpic.c.
* src/truetype/jamfile add new files to FT2_MULTI build: ttpic.c.
2009-04-05 Oran Agra <oran@monfort.co.il>
Position Independent Code (PIC) support and infrastructure in base.

View File

@ -68,6 +68,31 @@ FT_BEGIN_HEADER
FT_Set_Var_Design_Func set_var_design;
};
#ifndef FT_CONFIG_OPTION_PIC
#define FT_DEFINE_SERVICE_MULTIMASTERSREC(class_, get_mm_, set_mm_design_, \
set_mm_blend_, get_mm_var_, set_var_design_) \
static const FT_Service_MultiMastersRec class_ = \
{ \
get_mm_, set_mm_design_, set_mm_blend_, get_mm_var_, set_var_design_ \
};
#else /* FT_CONFIG_OPTION_PIC */
#define FT_DEFINE_SERVICE_MULTIMASTERSREC(class_, get_mm_, set_mm_design_, \
set_mm_blend_, get_mm_var_, set_var_design_) \
void \
FT_Init_Class_##class_( FT_Service_MultiMastersRec* clazz ) \
{ \
clazz->get_mm = get_mm_; \
clazz->set_mm_design = set_mm_design_; \
clazz->set_mm_blend = set_mm_blend_; \
clazz->get_mm_var = get_mm_var_; \
clazz->set_var_design = set_var_design_; \
}
#endif /* FT_CONFIG_OPTION_PIC */
/* */

View File

@ -37,6 +37,25 @@ FT_BEGIN_HEADER
TT_Glyf_GetLocationFunc get_location;
};
#ifndef FT_CONFIG_OPTION_PIC
#define FT_DEFINE_SERVICE_TTGLYFREC(class_, get_location_ ) \
static const FT_Service_TTGlyfRec class_ = \
{ \
get_location_ \
};
#else /* FT_CONFIG_OPTION_PIC */
#define FT_DEFINE_SERVICE_TTGLYFREC(class_, get_location_ ) \
void \
FT_Init_Class_##class_( FT_Service_TTGlyfRec* clazz ) \
{ \
clazz->get_location = get_location_; \
}
#endif /* FT_CONFIG_OPTION_PIC */
/* */

View File

@ -16,7 +16,7 @@ SubDir FT2_TOP $(FT2_SRC_DIR) truetype ;
if $(FT2_MULTI)
{
_sources = ttdriver ttobjs ttpload ttgload ttinterp ttgxvar ;
_sources = ttdriver ttobjs ttpload ttgload ttinterp ttgxvar ttpic ;
}
else
{

View File

@ -19,6 +19,7 @@
#define FT_MAKE_OPTION_SINGLE_OBJECT
#include <ft2build.h>
#include "ttpic.c"
#include "ttdriver.c" /* driver interface */
#include "ttpload.c" /* tables loader */
#include "ttgload.c" /* glyph loader */

View File

@ -40,6 +40,7 @@
#include "tterrors.h"
#include "ttpic.h"
/*************************************************************************/
/* */
@ -343,14 +344,13 @@
/*************************************************************************/
#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
static const FT_Service_MultiMastersRec tt_service_gx_multi_masters =
{
FT_DEFINE_SERVICE_MULTIMASTERSREC(tt_service_gx_multi_masters,
(FT_Get_MM_Func) NULL,
(FT_Set_MM_Design_Func) NULL,
(FT_Set_MM_Blend_Func) TT_Set_MM_Blend,
(FT_Get_MM_Var_Func) TT_Get_MM_Var,
(FT_Set_Var_Design_Func)TT_Set_Var_Design
};
)
#endif
static const FT_Service_TrueTypeEngineRec tt_service_truetype_engine =
@ -370,33 +370,36 @@
#endif /* TT_USE_BYTECODE_INTERPRETER */
};
static const FT_Service_TTGlyfRec tt_service_truetype_glyf =
{
FT_DEFINE_SERVICE_TTGLYFREC(tt_service_truetype_glyf,
(TT_Glyf_GetLocationFunc)tt_face_get_location
};
)
static const FT_ServiceDescRec tt_services[] =
{
{ FT_SERVICE_ID_XF86_NAME, FT_XF86_FORMAT_TRUETYPE },
#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
{ FT_SERVICE_ID_MULTI_MASTERS, &tt_service_gx_multi_masters },
FT_DEFINE_SERVICEDESCREC4(tt_services,
FT_SERVICE_ID_XF86_NAME, FT_XF86_FORMAT_TRUETYPE,
FT_SERVICE_ID_MULTI_MASTERS, &FT_TT_SERVICE_GX_MULTI_MASTERS_GET,
FT_SERVICE_ID_TRUETYPE_ENGINE, &tt_service_truetype_engine,
FT_SERVICE_ID_TT_GLYF, &FT_TT_SERVICE_TRUETYPE_GLYF_GET
)
#else
FT_DEFINE_SERVICEDESCREC3(tt_services,
FT_SERVICE_ID_XF86_NAME, FT_XF86_FORMAT_TRUETYPE,
FT_SERVICE_ID_TRUETYPE_ENGINE, &tt_service_truetype_engine,
FT_SERVICE_ID_TT_GLYF, &FT_TT_SERVICE_TRUETYPE_GLYF_GET
)
#endif
{ FT_SERVICE_ID_TRUETYPE_ENGINE, &tt_service_truetype_engine },
{ FT_SERVICE_ID_TT_GLYF, &tt_service_truetype_glyf },
{ NULL, NULL }
};
FT_CALLBACK_DEF( FT_Module_Interface )
tt_get_interface( FT_Module driver, /* TT_Driver */
const char* tt_interface )
{
FT_Library library = driver->library;
FT_Module_Interface result;
FT_Module sfntd;
SFNT_Service sfnt;
FT_UNUSED(library);
result = ft_service_list_lookup( tt_services, tt_interface );
result = ft_service_list_lookup( FT_TT_SERVICES_GET, tt_interface );
if ( result != NULL )
return result;
@ -415,17 +418,24 @@
/* The FT_DriverInterface structure is defined in ftdriver.h. */
FT_CALLBACK_TABLE_DEF
const FT_Driver_ClassRec tt_driver_class =
{
{
#ifdef TT_USE_BYTECODE_INTERPRETER
#define TT_HINTER_FLAG FT_MODULE_DRIVER_HAS_HINTER
#else
#define TT_HINTER_FLAG 0
#endif
#ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
#define TT_SIZE_SELECT tt_size_select
#else
#define TT_SIZE_SELECT 0
#endif
FT_DEFINE_DRIVER(tt_driver_class,
FT_MODULE_FONT_DRIVER |
FT_MODULE_DRIVER_SCALABLE |
#ifdef TT_USE_BYTECODE_INTERPRETER
FT_MODULE_DRIVER_HAS_HINTER,
#else
0,
#endif
TT_HINTER_FLAG,
sizeof ( TT_DriverRec ),
@ -438,7 +448,6 @@
tt_driver_init,
tt_driver_done,
tt_get_interface,
},
sizeof ( TT_FaceRec ),
sizeof ( TT_SizeRec ),
@ -451,10 +460,9 @@
tt_slot_init,
0, /* FT_Slot_DoneFunc */
#ifdef FT_CONFIG_OPTION_OLD_INTERNALS
ft_stub_set_char_sizes,
ft_stub_set_pixel_sizes,
#endif
ft_stub_set_char_sizes, /* FT_CONFIG_OPTION_OLD_INTERNALS */
ft_stub_set_pixel_sizes, /* FT_CONFIG_OPTION_OLD_INTERNALS */
Load_Glyph,
tt_get_kerning,
@ -462,12 +470,8 @@
tt_get_advances,
tt_size_request,
#ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
tt_size_select
#else
0 /* FT_Size_SelectFunc */
#endif
};
TT_SIZE_SELECT
)
/* END */

View File

@ -27,7 +27,7 @@
FT_BEGIN_HEADER
FT_EXPORT_VAR( const FT_Driver_ClassRec ) tt_driver_class;
FT_DECLARE_DRIVER( tt_driver_class )
FT_END_HEADER

View File

@ -148,7 +148,9 @@
static FT_Bool
tt_check_trickyness( FT_String* name )
{
static const char* const trick_names[] =
#define TRICK_NAMES_MAX_CHARACTERS 16
#define TRICK_NAMES_COUNT 7
static const char trick_names[TRICK_NAMES_COUNT][TRICK_NAMES_MAX_CHARACTERS+1] =
{
"DFKaiSho-SB", /* dfkaisb.ttf */
"DFKaiShu",
@ -157,7 +159,6 @@
"MingLiU", /* mingliu.ttf & mingliu.ttc */
"PMingLiU", /* mingliu.ttc */
"MingLi43", /* mingli.ttf */
NULL
};
int nn;
@ -167,7 +168,7 @@
/* Note that we only check the face name at the moment; it might */
/* be worth to do more checks for a few special cases. */
for ( nn = 0; trick_names[nn] != NULL; nn++ )
for ( nn = 0; nn < TRICK_NAMES_COUNT; nn++ )
if ( ft_strstr( name, trick_names[nn] ) )
return TRUE;

79
src/truetype/ttpic.c Normal file
View File

@ -0,0 +1,79 @@
/***************************************************************************/
/* */
/* ttpic.c */
/* */
/* The FreeType position independent code services for truetype module. */
/* */
/* Copyright 2009 by */
/* Oran Agra and Mickey Gabel. */
/* */
/* This file is part of the FreeType project, and may only be used, */
/* modified, and distributed under the terms of the FreeType project */
/* license, LICENSE.TXT. By continuing to use, modify, or distribute */
/* this file you indicate that you have read the license and */
/* understand and accept it fully. */
/* */
/***************************************************************************/
#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_INTERNAL_OBJECTS_H
#include "ttpic.h"
#ifdef FT_CONFIG_OPTION_PIC
/* forward declaration of PIC init functions from ttdriver.c */
FT_Error FT_Create_Class_tt_services( FT_Library, FT_ServiceDescRec**);
void FT_Destroy_Class_tt_services( FT_Library, FT_ServiceDescRec*);
void FT_Init_Class_tt_service_gx_multi_masters(FT_Service_MultiMastersRec*);
void FT_Init_Class_tt_service_truetype_glyf(FT_Service_TTGlyfRec*);
void
tt_driver_class_pic_free( FT_Library library )
{
FT_PIC_Container* pic_container = &library->pic_container;
FT_Memory memory = library->memory;
if ( pic_container->truetype )
{
TTModulePIC* container = (TTModulePIC*)pic_container->truetype;
if(container->tt_services)
FT_Destroy_Class_tt_services(library, container->tt_services);
container->tt_services = NULL;
FT_FREE( container );
pic_container->truetype = NULL;
}
}
FT_Error
tt_driver_class_pic_init( FT_Library library )
{
FT_PIC_Container* pic_container = &library->pic_container;
FT_Error error = FT_Err_Ok;
TTModulePIC* container;
FT_Memory memory = library->memory;
/* allocate pointer, clear and set global container pointer */
if ( FT_ALLOC ( container, sizeof ( *container ) ) )
return error;
FT_MEM_SET( container, 0, sizeof(*container) );
pic_container->truetype = container;
/* initialize pointer table - this is how the module usually expects this data */
error = FT_Create_Class_tt_services(library, &container->tt_services);
if(error)
goto Exit;
#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
FT_Init_Class_tt_service_gx_multi_masters(&container->tt_service_gx_multi_masters);
#endif
FT_Init_Class_tt_service_truetype_glyf(&container->tt_service_truetype_glyf);
Exit:
if(error)
tt_driver_class_pic_free(library);
return error;
}
#endif /* FT_CONFIG_OPTION_PIC */
/* END */

59
src/truetype/ttpic.h Normal file
View File

@ -0,0 +1,59 @@
/***************************************************************************/
/* */
/* ttpic.h */
/* */
/* The FreeType position independent code services for truetype module. */
/* */
/* Copyright 2009 by */
/* Oran Agra and Mickey Gabel. */
/* */
/* This file is part of the FreeType project, and may only be used, */
/* modified, and distributed under the terms of the FreeType project */
/* license, LICENSE.TXT. By continuing to use, modify, or distribute */
/* this file you indicate that you have read the license and */
/* understand and accept it fully. */
/* */
/***************************************************************************/
#ifndef __TTPIC_H__
#define __TTPIC_H__
FT_BEGIN_HEADER
#ifndef FT_CONFIG_OPTION_PIC
#define FT_TT_SERVICES_GET tt_services
#define FT_TT_SERVICE_GX_MULTI_MASTERS_GET tt_service_gx_multi_masters
#define FT_TT_SERVICE_TRUETYPE_GLYF_GET tt_service_truetype_glyf
#else /* FT_CONFIG_OPTION_PIC */
#include FT_MULTIPLE_MASTERS_H
#include FT_SERVICE_MULTIPLE_MASTERS_H
#include FT_SERVICE_TRUETYPE_GLYF_H
typedef struct TTModulePIC_
{
FT_ServiceDescRec* tt_services;
#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
FT_Service_MultiMastersRec tt_service_gx_multi_masters;
#endif
FT_Service_TTGlyfRec tt_service_truetype_glyf;
} TTModulePIC;
#define GET_PIC(lib) ((TTModulePIC*)((lib)->pic_container.truetype))
#define FT_TT_SERVICES_GET (GET_PIC(library)->tt_services)
#define FT_TT_SERVICE_GX_MULTI_MASTERS_GET (GET_PIC(library)->tt_service_gx_multi_masters)
#define FT_TT_SERVICE_TRUETYPE_GLYF_GET (GET_PIC(library)->tt_service_truetype_glyf)
#endif /* FT_CONFIG_OPTION_PIC */
/* */
FT_END_HEADER
#endif /* __TTPIC_H__ */
/* END */