introduce service and service list template files, modify cff driver to use them

This commit is contained in:
David Turner 2009-04-13 03:13:29 +02:00
parent f9ed3bd40c
commit 675a903548
12 changed files with 333 additions and 86 deletions

View File

@ -62,6 +62,11 @@ FT_BEGIN_HEADER
#endif
#define FT_GLUE(x,y) FT_GLUE_(x,y)
#define FT_GLUE_(x,y) x##y
#define FT_GLUE3(x,y,z) FT_GLUE(FT_GLUE(x,y),z)
/*************************************************************************/
/* */
/* The min and max functions missing in C. As usual, be careful not to */

View File

@ -47,5 +47,11 @@
#define FT_INTERNAL_AUTOHINT_H <freetype/internal/autohint.h>
#define FT_INTERNAL_SERVICE_DECLARE_H <freetype/internal/services/declare.h>
#define FT_INTERNAL_SERVICE_DEFINE_H <freetype/internal/services/define.h>
#define FT_INTERNAL_SERVICE_LIST_DECLARE_H <freetype/internal/services/listdecl.h>
#define FT_INTERNAL_SERVICE_LIST_DEFINE_H <freetype/internal/services/listdef.h>
/* END */

View File

@ -0,0 +1,57 @@
/***************************************************************************/
/* */
/* services/declare.h */
/* */
/* The FreeType PostScript info service (specification). */
/* */
/* Copyright 2009 by David Turner */
/* */
/* 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. */
/* */
/***************************************************************************/
/* this header file can be included multipled times and is used
* to declare the types corresponding to a given service described
* by FT_SERVICE_NAME and FT_SERVICE_FIELDS
*
* FT_SERVICE_NAME is the name of the service
* FT_SERVICE_FIELDS is a list of _FT_SERVICE_FIELD(type,varname)
* statements that will be used to define the corresponding service
* structure and pointer types.
*/
#ifndef FT_SERVICE_FIELDS
#error FT_SERVICE_FIELDS must be defined
#endif
#ifndef FT_SERVICE_NAME
#error FT_SERVICE_NAME must be defined
#endif
/* define the service structure and pointer types */
typedef struct FT_GLUE3(FT_Service_,FT_SERVICE_NAME,Rec_)
FT_GLUE3(FT_Service_,FT_SERVICE_NAME,Rec);
typedef struct FT_GLUE3(FT_Service_,FT_SERVICE_NAME,Rec_) const*
FT_GLUE(FT_Service_,FT_SERVICE_NAME);
struct FT_GLUE3(FT_Service_,FT_SERVICE_NAME,Rec_)
{
#define _FT_SERVICE_FIELD(type_,name_) type_ name_;
FT_SERVICE_FIELDS
#undef _FT_SERVICE_FIELD
};
/* declare initialization function for PIC code */
#ifdef FT_CONFIG_OPTION_PIC
void FT_GLUE(ft_pic_service_init_,FT_SERVICE_NAME)
( FT_GLUE3(FT_Service_,FT_SERVICE_NAME,Rec)* clazz );
#endif /* FT_CONFIG_OPTION_PIC */
#undef FT_SERVICE_NAME
#undef FT_SERVICE_FIELDS

View File

@ -0,0 +1,65 @@
/***************************************************************************/
/* */
/* services/define.h */
/* */
/* The FreeType PostScript info service (specification). */
/* */
/* Copyright 2009 by David Turner */
/* */
/* 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. */
/* */
/***************************************************************************/
/* this header file can be included multipled times and is used
* to declare the types corresponding to a given service described
* by FT_SERVICE_NAME and FT_SERVICE_FIELDS
*
* FT_SERVICE_NAME is the name of the service
* FT_SERVICE_FIELDS is a list of _FT_SERVICE_FIELD(type,varname)
* statements that will be used to define the corresponding service
* structure and pointer types.
*/
#ifndef FT_SERVICE_FIELDS
#error FT_SERVICE_FIELDS must be defined
#endif
#ifndef FT_SERVICE_PREFIX
#error FT_SERVICE_PREFIX must be defined
#endif
#ifndef FT_SERVICE_NAME
#error FT_SERVICE_NAME must be defined
#endif
#ifndef FT_CONFIG_OPTION_PIC
static const FT_GLUE3(FT_Service_,FT_SERVICE_NAME,Rec)
FT_GLUE(ft_service_,FT_SERVICE_NAME) =
{
#define _FT_SERVICE_FIELD(type_,name_) \
FT_GLUE(FT_SERVICE_PREFIX,name_),
FT_SERVICE_FIELDS
#undef _FT_SERVICE_FIELD
};
#else /* FT_CONFIG_OPTION_PIC */
void FT_GLUE(ft_pic_service_init_,FT_SERVICE_NAME)(
FT_GLUE3(FT_Service_,FT_SERVICE_NAME,Rec)* clazz )
{
#define _FT_SERVICE_FIELD(type_,name_) \
clazz->name_ = FT_GLUE(FT_SERVICE_PREFIX,name_);
FT_SERVICE_FIELDS
#undef _FT_SERVICE_FIELD
}
#endif /* FT_CONFIG_OPTION_PIC */
#undef FT_SERVICE_NAME
#undef FT_SERVICE_FIELDS
#undef FT_SERVICE_PREFIX

View File

@ -0,0 +1,58 @@
/***************************************************************************/
/* */
/* services/listdecl.h */
/* */
/* Service list declaration template */
/* */
/* Copyright 2009 by David Turner */
/* */
/* 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. */
/* */
/***************************************************************************/
/* this header file can be included multipled times and is used
* to declare a list of services in a given module. It relies on
* FT_SERVICE_LIST_NAME and FT_SERVICE_LIST_FIELDS being defined
*
* FT_SERVICE_NAME is the name of the service list
* FT_SERVICE_ITEMS is a list of _FT_SERVICE_ITEM(id,value)
* statements that will be used to define the corresponding service
* item in the list
*/
#ifndef FT_SERVICE_ITEMS
#error FT_SERVICE_ITEMS must be defined
#endif
#ifndef FT_SERVICE_NAME
#error FT_SERVICE_NAME must be defined
#endif
#ifdef FT_CONFIG_OPTION_PIC
/* For PIC mode, count the number of items in the list
* and define the appropriate array type.
*/
/* compute number of active items in array */
enum {
FT_GLUE(_ft_service_count_,FT_SERVICE_NAME) = 0
#define _FT_SERVICE_ITEM(x,y) +1
FT_SERVICE_ITEMS
#undef _FT_SERVICE_ITEM
};
typedef FT_ServiceDescRec FT_GLUE(FT_ServiceItems_,FT_SERVICE_NAME)
[ FT_GLUE(_ft_service_count_,FT_SERVICE_NAME)+1 ];
void
FT_GLUE(ft_pic_services_init_,FT_SERVICE_NAME)
( FT_ServiceDescRec* items, FT_Library library );
#endif /* FT_CONFIG_OPTION_PIC */
#undef FT_SERVICE_NAME
#undef FT_SERVICE_ITEMS

View File

@ -0,0 +1,70 @@
/***************************************************************************/
/* */
/* services/listdef.h */
/* */
/* Service list definition template */
/* */
/* Copyright 2009 by David Turner */
/* */
/* 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. */
/* */
/***************************************************************************/
/* this header file can be included multipled times and is used
* to declare a list of services in a given module. It relies on
* FT_SERVICE_LIST_NAME and FT_SERVICE_LIST_FIELDS being defined
*
* FT_SERVICE_NAME is the name of the service list
* FT_SERVICE_ITEMS is a list of _FT_SERVICE_ITEM(id,value)
* statements that will be used to define the corresponding service
* item in the list
*/
#ifndef FT_SERVICE_ITEMS
#error FT_SERVICE_ITEMS must be defined
#endif
#ifndef FT_SERVICE_NAME
#error FT_SERVICE_NAME must be defined
#endif
#ifndef FT_SERVICE_VARNAME
#error FT_SERVICE_VARNAME must be defined
#endif
#ifndef FT_CONFIG_OPTION_PIC
static const FT_ServiceDescRec FT_SERVICE_VARNAME[] =
{
#define _FT_SERVICE_ITEM(id_,value_) { id_, value_ },
FT_SERVICE_ITEMS
#undef _FT_SERVICE_ITEM
{ NULL, NULL }
};
#else /* FT_CONFIG_OPTION_PIC */
void
FT_GLUE(ft_pic_services_init_,FT_SERVICE_NAME)
( FT_ServiceDescRec* items, FT_Library library )
{
FT_ServiceDescRec* desc = items;
#define _FT_SERVICE_ITEM(id_,value_) \
desc->serv_id = FT_GLUE(FT_SERVICE_ID_,id_); \
desc->serv_data = value_; \
desc ++;
FT_SERVICE_ITEMS
#undef _FT_SERVICE_ITEM
desc->serv_id = NULL;
desc->serv_data = NULL;
}
#endif /* FT_CONFIG_OPTION_PIC */
#undef FT_SERVICE_NAME
#undef FT_SERVICE_VARNAME
#undef FT_SERVICE_ITEMS

View File

@ -25,7 +25,6 @@
FT_BEGIN_HEADER
#define FT_SERVICE_ID_POSTSCRIPT_INFO "postscript-info"
@ -44,41 +43,16 @@ FT_BEGIN_HEADER
(*PS_GetFontPrivateFunc)( FT_Face face,
PS_PrivateRec* afont_private );
#define FT_PSINFO_SERVICE_FIELDS \
_FT_SERVICE_FIELD( PS_GetFontInfoFunc, get_font_info ) \
_FT_SERVICE_FIELD( PS_GetFontExtraFunc, get_font_extra ) \
_FT_SERVICE_FIELD( PS_HasGlyphNamesFunc, has_glyph_names ) \
_FT_SERVICE_FIELD( PS_GetFontPrivateFunc, get_font_private ) \
FT_DEFINE_SERVICE( PsInfo )
{
PS_GetFontInfoFunc ps_get_font_info;
PS_GetFontExtraFunc ps_get_font_extra;
PS_HasGlyphNamesFunc ps_has_glyph_names;
PS_GetFontPrivateFunc ps_get_font_private;
};
#define FT_SERVICE_NAME PsInfo
#define FT_SERVICE_FIELDS FT_PSINFO_SERVICE_FIELDS
#ifndef FT_CONFIG_OPTION_PIC
#define FT_DEFINE_SERVICE_PSINFOREC(class_, get_font_info_, \
ps_get_font_extra_, has_glyph_names_, get_font_private_) \
static const FT_Service_PsInfoRec class_ = \
{ \
get_font_info_, ps_get_font_extra_, has_glyph_names_, \
get_font_private_ \
};
#else /* FT_CONFIG_OPTION_PIC */
#define FT_DEFINE_SERVICE_PSINFOREC(class_, get_font_info_, \
ps_get_font_extra_, has_glyph_names_, get_font_private_) \
void \
ft_pic_init_##class_( FT_Library library, \
FT_Service_PsInfoRec* clazz) \
{ \
FT_UNUSED(library); \
clazz->ps_get_font_info = get_font_info_; \
clazz->ps_get_font_extra = ps_get_font_extra_; \
clazz->ps_has_glyph_names = has_glyph_names_; \
clazz->ps_get_font_private = get_font_private_; \
}
#endif /* FT_CONFIG_OPTION_PIC */
#include FT_INTERNAL_SERVICE_DECLARE_H
/* */

View File

@ -38,12 +38,12 @@
FT_FACE_FIND_SERVICE( face, service, POSTSCRIPT_INFO );
if ( service && service->ps_get_font_extra )
if ( service && service->get_font_extra )
{
PS_FontExtraRec extra;
if ( !service->ps_get_font_extra( face, &extra ) &&
if ( !service->get_font_extra( face, &extra ) &&
extra.fs_type != 0 )
return extra.fs_type;
}

View File

@ -38,8 +38,8 @@
FT_FACE_FIND_SERVICE( face, service, POSTSCRIPT_INFO );
if ( service && service->ps_get_font_info )
error = service->ps_get_font_info( face, afont_info );
if ( service && service->get_font_info )
error = service->get_font_info( face, afont_info );
}
return error;
@ -59,8 +59,8 @@
{
FT_FACE_FIND_SERVICE( face, service, POSTSCRIPT_INFO );
if ( service && service->ps_has_glyph_names )
result = service->ps_has_glyph_names( face );
if ( service && service->has_glyph_names )
result = service->has_glyph_names( face );
}
return result;
@ -83,8 +83,8 @@
FT_FACE_FIND_SERVICE( face, service, POSTSCRIPT_INFO );
if ( service && service->ps_get_font_private )
error = service->ps_get_font_private( face, afont_private );
if ( service && service->get_font_private )
error = service->get_font_private( face, afont_private );
}
return error;

View File

@ -329,9 +329,10 @@
static FT_Error
cff_ps_get_font_info( CFF_Face face,
cff_ps_get_font_info( FT_Face face_,
PS_FontInfoRec* afont_info )
{
CFF_Face face = (CFF_Face)face_;
CFF_Font cff = (CFF_Font)face->extra.data;
FT_Error error = FT_Err_Ok;
@ -378,13 +379,22 @@
}
#define FT_SERVICE_FIELDS FT_PSINFO_SERVICE_FIELDS
#define FT_SERVICE_NAME PsInfo
#define FT_SERVICE_PREFIX cff_ps_
#define cff_ps_get_font_extra NULL
#define cff_ps_get_font_private NULL
#include FT_INTERNAL_SERVICE_DEFINE_H
#if 0
FT_DEFINE_SERVICE_PSINFOREC(cff_service_ps_info,
(PS_GetFontInfoFunc) cff_ps_get_font_info,
(PS_GetFontExtraFunc) NULL,
(PS_HasGlyphNamesFunc) cff_ps_has_glyph_names,
(PS_GetFontPrivateFunc)NULL /* unsupported with CFF fonts */
)
#endif
/*
* POSTSCRIPT NAME SERVICE
@ -585,20 +595,20 @@
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/
#ifndef FT_CONFIG_OPTION_NO_GLYPH_NAMES
#define FT_SERVICE_ITEMS CFF_SERVICE_ITEMS
#define FT_SERVICE_NAME cff
#define FT_SERVICE_VARNAME cff_services
#include FT_INTERNAL_SERVICE_LIST_DEFINE_H
#if 0
FT_DEFINE_SERVICEDESCREC6(cff_services,
FT_SERVICE_ID_XF86_NAME, FT_XF86_FORMAT_CFF,
FT_SERVICE_ID_POSTSCRIPT_INFO, &FT_CFF_SERVICE_PS_INFO_GET,
FT_SERVICE_ID_POSTSCRIPT_FONT_NAME, &FT_CFF_SERVICE_PS_NAME_GET,
FT_SERVICE_ID_GLYPH_DICT, &FT_CFF_SERVICE_GLYPH_DICT_GET,
FT_SERVICE_ID_TT_CMAP, &FT_CFF_SERVICE_GET_CMAP_INFO_GET,
FT_SERVICE_ID_CID, &FT_CFF_SERVICE_CID_INFO_GET
)
#else
FT_DEFINE_SERVICEDESCREC5(cff_services,
FT_SERVICE_ID_XF86_NAME, FT_XF86_FORMAT_CFF,
FT_SERVICE_ID_POSTSCRIPT_INFO, &FT_CFF_SERVICE_PS_INFO_GET,
FT_SERVICE_ID_POSTSCRIPT_FONT_NAME, &FT_CFF_SERVICE_PS_NAME_GET,
IF_GLYPH_NAMES(
FT_SERVICE_ID_GLYPH_DICT, &FT_CFF_SERVICE_GLYPH_DICT_GET,
)
FT_SERVICE_ID_TT_CMAP, &FT_CFF_SERVICE_GET_CMAP_INFO_GET,
FT_SERVICE_ID_CID, &FT_CFF_SERVICE_CID_INFO_GET
)

View File

@ -24,8 +24,6 @@
#ifdef FT_CONFIG_OPTION_PIC
/* forward declaration of PIC init functions from cffdrivr.c */
FT_Error ft_library_pic_alloc_cff_services( FT_Library, FT_ServiceDescRec**);
void ft_library_pic_free_cff_services( FT_Library, FT_ServiceDescRec*);
void ft_pic_init_cff_service_ps_info( FT_Library, FT_Service_PsInfoRec*);
void ft_pic_init_cff_service_glyph_dict( FT_Library, FT_Service_GlyphDictRec*);
void ft_pic_init_cff_service_ps_name( FT_Library, FT_Service_PsFontNameRec*);
@ -41,20 +39,6 @@
void ft_pic_init_cff_cmap_unicode_class_rec( FT_Library, FT_CMap_ClassRec*);
#endif
static void
pic_cff_done( void* _cff, FT_PicTable pic )
{
CffModulePIC* container = (CffModulePIC*) _cff;
if (container->cff_services)
{
ft_library_pic_free_cff_services(pic->library, container->cff_services);
container->cff_services = NULL;
}
}
static FT_Error
pic_cff_init( void* _cff, FT_PicTable pic )
{
@ -62,13 +46,6 @@
FT_Error error = FT_Err_Ok;
CffModulePIC* container = (CffModulePIC*) _cff;
/* initialize pointer table - this is how the module usually expects this data */
error = ft_library_pic_alloc_cff_services(library, &container->cff_services);
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);
ft_pic_init_cff_service_ps_name (library, &container->cff_service_ps_name);
@ -80,8 +57,11 @@
&container->cff_cmap_encoding_class_rec);
ft_pic_init_cff_cmap_unicode_class_rec (library,
&container->cff_cmap_unicode_class_rec);
Exit:
return error;
cff_pic_field_handlers_init(container->cff_field_handlers);
ft_pic_services_init_Cff( &container->cff_services, library );
return 0;
}
@ -93,7 +73,7 @@ Exit:
return ft_pic_table_init_data( pic, pic->cff,
sizeof(CffModulePIC),
pic_cff_init,
pic_cff_done );
NULL );
}
#endif /* FT_CONFIG_OPTION_PIC */

View File

@ -19,9 +19,34 @@
#ifndef __CFFPIC_H__
#define __CFFPIC_H__
FT_BEGIN_HEADER
#include FT_INTERNAL_OBJECTS_H
/* CFF services list */
#ifndef FT_CONFIG_OPTION_NO_GLYPH_NAMES
# define IF_GLYPH_NAMES(x) x
#else
# define IF_GLYPH_NAMES(x) /* nothing */
#endif
#define CFF_SERVICE_ITEMS \
_FT_SERVICE_ITEM( XF86_NAME, FT_XF86_FORMAT_CFF ) \
_FT_SERVICE_ITEM( POSTSCRIPT_INFO, &FT_CFF_SERVICE_PS_INFO_GET ) \
_FT_SERVICE_ITEM( POSTSCRIPT_FONT_NAME, &FT_CFF_SERVICE_PS_NAME_GET ) \
IF_GLYPH_NAMES( \
_FT_SERVICE_ITEM( GLYPH_DICT, &FT_CFF_SERVICE_GLYPH_DICT_GET ) \
) \
_FT_SERVICE_ITEM( TT_CMAP, &FT_CFF_SERVICE_GET_CMAP_INFO_GET ) \
_FT_SERVICE_ITEM( CID, &FT_CFF_SERVICE_CID_INFO_GET ) \
#define FT_SERVICE_NAME Cff
#define FT_SERVICE_ITEMS CFF_SERVICE_ITEMS
#include FT_INTERNAL_SERVICE_LIST_DECLARE_H
#include FT_INTERNAL_PIC_H
#ifndef FT_CONFIG_OPTION_PIC
@ -36,9 +61,6 @@ 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
@ -50,7 +72,6 @@ enum {
typedef struct CffModulePIC_
{
FT_ServiceDescRec* cff_services;
FT_Service_PsInfoRec cff_service_ps_info;
FT_Service_GlyphDictRec cff_service_glyph_dict;
FT_Service_PsFontNameRec cff_service_ps_name;
@ -59,9 +80,10 @@ enum {
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_COUNT+1];
FT_ServiceItems_Cff cff_services;
} CffModulePIC;
#define CFF_GET_PIC(lib) ((CffModulePIC*)((lib)->pic_table.cff))
#define CFF_GET_PIC(lib) ((CffModulePIC*)FT_LIBRARY_GET_PIC_DATA(lib,cff))
#define FT_CFF_CONST_(name_) (CFF_GET_PIC(library)->cff_##name_)
#endif /* FT_CONFIG_OPTION_PIC */