diff --git a/src/cff/cffparse.c b/src/cff/cffparse.c index 34af4ed63..3a0852c47 100644 --- a/src/cff/cffparse.c +++ b/src/cff/cffparse.c @@ -559,20 +559,6 @@ return error; } - -#define CFF_FIELD_NUM( code, name ) \ - CFF_FIELD( code, name, cff_kind_num ) -#define CFF_FIELD_FIXED( code, name ) \ - CFF_FIELD( code, name, cff_kind_fixed ) -#define CFF_FIELD_FIXED_1000( code, name ) \ - CFF_FIELD( code, name, cff_kind_fixed_thousand ) -#define CFF_FIELD_STRING( code, name ) \ - CFF_FIELD( code, name, cff_kind_string ) -#define CFF_FIELD_BOOL( code, name ) \ - CFF_FIELD( code, name, cff_kind_bool ) -#define CFF_FIELD_DELTA( code, name, max ) \ - CFF_FIELD( code, name, cff_kind_delta ) - #define CFFCODE_TOPDICT 0x1000 #define CFFCODE_PRIVATE 0x2000 @@ -587,7 +573,6 @@ 0, 0 \ }, -#undef CFF_FIELD #define CFF_FIELD( code, name, kind ) \ { \ kind, \ @@ -597,7 +582,6 @@ 0, 0, 0 \ }, -#undef CFF_FIELD_DELTA #define CFF_FIELD_DELTA( code, name, max ) \ { \ cff_kind_delta, \ @@ -620,81 +604,48 @@ #else /* FT_CONFIG_OPTION_PIC */ - void ft_library_pic_free_cff_field_handlers(FT_Library library, CFF_Field_Handler* clazz) + void + cff_field_handlers_init( CFF_Field_Handler* clazz ) { - FT_Memory memory = library->memory; - FT_FREE( clazz ); - } +#define CFF_FIELD_CALLBACK( code_, name_ ) \ + clazz->kind = cff_kind_callback; \ + clazz->code = code_ | CFFCODE; \ + clazz->offset = 0; \ + clazz->size = 0; \ + clazz->reader = cff_parse_ ## name_; \ + clazz->array_max = 0; \ + clazz->count_offset = 0; \ + clazz++; - FT_Error ft_library_pic_alloc_cff_field_handlers(FT_Library library, CFF_Field_Handler** output_class) - { - CFF_Field_Handler* clazz; - FT_Error error; - FT_Memory memory = library->memory; - int i=0; +#define CFF_FIELD( code_, name_, kind_ ) \ + clazz->kind = kind_; \ + clazz->code = code_ | CFFCODE; \ + clazz->offset = FT_FIELD_OFFSET( name_ ); \ + clazz->size = FT_FIELD_SIZE( name_ ); \ + clazz->reader = 0; \ + clazz->array_max = 0; \ + clazz->count_offset = 0; \ + clazz++; -#undef CFF_FIELD -#undef CFF_FIELD_DELTA -#undef CFF_FIELD_CALLBACK -#define CFF_FIELD_CALLBACK( code, name ) i++; -#define CFF_FIELD( code, name, kind ) i++; -#define CFF_FIELD_DELTA( code, name, max ) i++; - -#include "cfftoken.h" - i++;/*{ 0, 0, 0, 0, 0, 0, 0 }*/ - - if ( FT_NEW_ARRAY( clazz, i ) ) - return error; - - i=0; -#undef CFF_FIELD -#undef CFF_FIELD_DELTA -#undef CFF_FIELD_CALLBACK - -#define CFF_FIELD_CALLBACK( code_, name_ ) \ - clazz[i].kind = cff_kind_callback; \ - clazz[i].code = code_ | CFFCODE; \ - clazz[i].offset = 0; \ - clazz[i].size = 0; \ - clazz[i].reader = cff_parse_ ## name_; \ - clazz[i].array_max = 0; \ - clazz[i].count_offset = 0; \ - i++; - -#undef CFF_FIELD -#define CFF_FIELD( code_, name_, kind_ ) \ - clazz[i].kind = kind_; \ - clazz[i].code = code_ | CFFCODE; \ - clazz[i].offset = FT_FIELD_OFFSET( name_ ); \ - clazz[i].size = FT_FIELD_SIZE( name_ ); \ - clazz[i].reader = 0; \ - clazz[i].array_max = 0; \ - clazz[i].count_offset = 0; \ - i++; \ - -#undef CFF_FIELD_DELTA -#define CFF_FIELD_DELTA( code_, name_, max_ ) \ - clazz[i].kind = cff_kind_delta; \ - clazz[i].code = code_ | CFFCODE; \ - clazz[i].offset = FT_FIELD_OFFSET( name_ ); \ - clazz[i].size = FT_FIELD_SIZE_DELTA( name_ ); \ - clazz[i].reader = 0; \ - clazz[i].array_max = max_; \ - clazz[i].count_offset = FT_FIELD_OFFSET( num_ ## name_ ); \ - i++; +#define CFF_FIELD_DELTA( code_, name_, max_ ) \ + clazz->kind = cff_kind_delta; \ + clazz->code = code_ | CFFCODE; \ + clazz->offset = FT_FIELD_OFFSET( name_ ); \ + clazz->size = FT_FIELD_SIZE_DELTA( name_ ); \ + clazz->reader = 0; \ + clazz->array_max = max_; \ + clazz->count_offset = FT_FIELD_OFFSET( num_ ## name_ ); \ + clazz++; #include "cfftoken.h" - clazz[i].kind = 0; - clazz[i].code = 0; - clazz[i].offset = 0; - clazz[i].size = 0; - clazz[i].reader = 0; - clazz[i].array_max = 0; - clazz[i].count_offset = 0; - - *output_class = clazz; - return FT_Err_Ok; + clazz->kind = 0; + clazz->code = 0; + clazz->offset = 0; + clazz->size = 0; + clazz->reader = 0; + clazz->array_max = 0; + clazz->count_offset = 0; } diff --git a/src/cff/cffpic.c b/src/cff/cffpic.c index 80e2bb06e..d7767f4d7 100644 --- a/src/cff/cffpic.c +++ b/src/cff/cffpic.c @@ -33,8 +33,7 @@ void ft_pic_init_cff_service_cid_info( FT_Library, FT_Service_CIDRec*); /* forward declaration of PIC init functions from cffparse.c */ - FT_Error ft_library_pic_alloc_cff_field_handlers( FT_Library, CFF_Field_Handler**); - void ft_library_pic_free_cff_field_handlers( FT_Library, CFF_Field_Handler*); + void cff_pic_field_handlers_init( CFF_Field_Handler* ); #if 0 /* defined by cffcmap.h */ /* forward declaration of PIC init functions from cffcmap.c */ @@ -53,12 +52,6 @@ ft_library_pic_free_cff_services(pic->library, container->cff_services); container->cff_services = NULL; } - - if(container->cff_field_handlers) - { - ft_library_pic_free_cff_field_handlers(pic->library, container->cff_field_handlers); - container->cff_field_handlers = NULL; - } } @@ -74,9 +67,7 @@ if(error) goto Exit; - error = ft_library_pic_alloc_cff_field_handlers(library, &container->cff_field_handlers); - if(error) - goto Exit; + cff_pic_field_handlers_init(container->cff_field_handlers); ft_pic_init_cff_service_ps_info (library, &container->cff_service_ps_info); ft_pic_init_cff_service_glyph_dict (library, &container->cff_service_glyph_dict); diff --git a/src/cff/cffpic.h b/src/cff/cffpic.h index 9f4d739ad..6038e1dcb 100644 --- a/src/cff/cffpic.h +++ b/src/cff/cffpic.h @@ -36,6 +36,18 @@ FT_BEGIN_HEADER #include FT_SERVICE_TT_CMAP_H #include FT_SERVICE_CID_H +#define COUNT__(prefix_) prefix_##__LINE__ +#define COUNT_(prefix_) COUNT__(prefix_) + +/* count the number of items declared by cfftoken.h */ +enum { + CFF_FIELD_HANDLER_COUNT = 0 +#define CFF_FIELD(x,y,z) +1 +#define CFF_FIELD_CALLBACK(x,y) +1 +#define CFF_FIELD_DELTA(x,y,z) +1 +#include "cfftoken.h" +}; + typedef struct CffModulePIC_ { FT_ServiceDescRec* cff_services; @@ -46,7 +58,7 @@ FT_BEGIN_HEADER FT_Service_CIDRec cff_service_cid_info; FT_CMap_ClassRec cff_cmap_encoding_class_rec; FT_CMap_ClassRec cff_cmap_unicode_class_rec; - CFF_Field_Handler* cff_field_handlers; + CFF_Field_Handler cff_field_handlers[CFF_FIELD_HANDLER_COUNT+1]; } CffModulePIC; #define CFF_GET_PIC(lib) ((CffModulePIC*)((lib)->pic_table.cff)) diff --git a/src/cff/cfftoken.h b/src/cff/cfftoken.h index 6bb27d5ca..7996df2e7 100644 --- a/src/cff/cfftoken.h +++ b/src/cff/cfftoken.h @@ -15,6 +15,42 @@ /* */ /***************************************************************************/ +#ifndef CFF_FIELD +#error CFF_FIELD must be defined +#endif + +#ifndef CFF_FIELD_DELTA +#error CFF_FIELD_DELTA must be defined +#endif + +#ifndef CFF_FIELD_CALLBACK +#error CFF_FIELD_CALLBACK must be defined +#endif + +#ifndef CFF_FIELD_NUM +#define CFF_FIELD_NUM( code, name ) \ + CFF_FIELD( code, name, cff_kind_num ) +#endif + +#ifndef CFF_FIELD_FIXED +#define CFF_FIELD_FIXED( code, name ) \ + CFF_FIELD( code, name, cff_kind_fixed ) +#endif + +#ifndef CFF_FIELD_FIXED_1000 +#define CFF_FIELD_FIXED_1000( code, name ) \ + CFF_FIELD( code, name, cff_kind_fixed_thousand ) +#endif + +#ifndef CFF_FIELD_STRING +#define CFF_FIELD_STRING( code, name ) \ + CFF_FIELD( code, name, cff_kind_string ) +#endif + +#ifndef CFF_FIELD_BOOL +#define CFF_FIELD_BOOL( code, name ) \ + CFF_FIELD( code, name, cff_kind_bool ) +#endif #undef FT_STRUCTURE #define FT_STRUCTURE CFF_FontRecDictRec @@ -93,5 +129,14 @@ CFF_FIELD_NUM ( 20, default_width ) CFF_FIELD_NUM ( 21, nominal_width ) +#undef CFF_FIELD_STRING +#undef CFF_FIELD_BOOL +#undef CFF_FIELD_NUM +#undef CFF_FIELD_FIXED +#undef CFF_FIELD_FIXED_1000 + +#undef CFF_FIELD_DELTA +#undef CFF_FIELD_CALLBACK +#undef CFF_FIELD /* END */