From 773601da120d49c2e95066fcc2ad41d16cf45429 Mon Sep 17 00:00:00 2001 From: Werner Lemberg Date: Fri, 2 Aug 2013 19:51:17 +0200 Subject: [PATCH] [autofit] Move declaration of writing systems into separate file. This has the benefit that we don't need to duplicate the data at different places. * src/autofit/afwrtsys.h: New file. * src/autofit/aftypes.h (AF_WritingSystem): Include `afwrtsys.h' to define the enumeration values. * src/autofit/afglobal.c: Include `afwrtsys.h' to get the writing system specific header files. Include `afpic.h'. (af_writing_system_classes): Include `afwrtsys.h' to fill this array. * src/autofit/afpic.c: Include `afwrtsys.h' to get the writing system specific header files. (autofit_module_class_pic_init): Include `afwrtsys.h' for initialization. * src/autofit/afpic.h (AF_WRITING_SYSTEM_CLASSES_COUNT, AF_WRITING_SYSTEM_CLASSES_REC_COUNT): Removed. Use `AF_WRITING_SYSTEM_MAX' instead. --- ChangeLog | 26 +++++++++++++++++++++ src/autofit/afglobal.c | 27 +++++++++++----------- src/autofit/afpic.c | 36 +++++++++++------------------ src/autofit/afpic.h | 10 ++------- src/autofit/aftypes.h | 17 +++++++------- src/autofit/afwrtsys.h | 51 ++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 114 insertions(+), 53 deletions(-) create mode 100644 src/autofit/afwrtsys.h diff --git a/ChangeLog b/ChangeLog index 28008f125..4b4071b85 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,29 @@ +2013-08-02 Werner Lemberg + + [autofit] Move declaration of writing systems into separate file. + + This has the benefit that we don't need to duplicate the data at + different places. + + * src/autofit/afwrtsys.h: New file. + + * src/autofit/aftypes.h (AF_WritingSystem): Include `afwrtsys.h' to + define the enumeration values. + + * src/autofit/afglobal.c: Include `afwrtsys.h' to get the writing + system specific header files. + Include `afpic.h'. + (af_writing_system_classes): Include `afwrtsys.h' to fill this + array. + + * src/autofit/afpic.c: Include `afwrtsys.h' to get the writing + system specific header files. + (autofit_module_class_pic_init): Include `afwrtsys.h' for + initialization. + * src/autofit/afpic.h (AF_WRITING_SYSTEM_CLASSES_COUNT, + AF_WRITING_SYSTEM_CLASSES_REC_COUNT): Removed. Use + `AF_WRITING_SYSTEM_MAX' instead. + 2013-08-02 Werner Lemberg [sfnt] Fix compilation with g++. diff --git a/src/autofit/afglobal.c b/src/autofit/afglobal.c index 4e9138a15..ad6c9ba18 100644 --- a/src/autofit/afglobal.c +++ b/src/autofit/afglobal.c @@ -17,11 +17,11 @@ #include "afglobal.h" -#include "afdummy.h" -#include "aflatin.h" -#include "afcjk.h" -#include "afindic.h" -#include "afpic.h" + + /* get writing system specific header files */ +#undef WRITING_SYSTEM +#define WRITING_SYSTEM( ws, WS ) /* empty */ +#include "afwrtsys.h" #include "aferrors.h" @@ -29,22 +29,23 @@ #include "aflatin2.h" #endif +#include "afpic.h" + #ifndef FT_CONFIG_OPTION_PIC /* when updating this table, don't forget to update */ /* AF_WRITING_SYSTEM_CLASSES_COUNT and autofit_module_class_pic_init */ - /* populate this list when you add new writing systems */ +#undef WRITING_SYSTEM +#define WRITING_SYSTEM( ws, WS ) \ + &af_ ## ws ## _writing_system_class, + FT_LOCAL_ARRAY_DEF( AF_WritingSystemClass ) af_writing_system_classes[] = { - &af_dummy_writing_system_class, - &af_latin_writing_system_class, - &af_cjk_writing_system_class, - &af_indic_writing_system_class, -#ifdef FT_OPTION_AUTOFIT2 - &af_latin2_writing_system_class, -#endif + +#include "afwrtsys.h" + NULL /* do not remove */ }; diff --git a/src/autofit/afpic.c b/src/autofit/afpic.c index f19dfd22d..3b993b1fe 100644 --- a/src/autofit/afpic.c +++ b/src/autofit/afpic.c @@ -43,13 +43,10 @@ /* forward declaration of PIC init functions from script classes */ -#include "aflatin.h" -#ifdef FT_OPTION_AUTOFIT2 -#include "aflatin2.h" -#endif -#include "afcjk.h" -#include "afdummy.h" -#include "afindic.h" +#undef WRITING_SYSTEM +#define WRITING_SYSTEM( ws, WS ) /* empty */ + +#include "afwrtsys.h" void @@ -100,11 +97,11 @@ FT_Init_Class_af_service_properties( &container->af_service_properties ); - for ( ss = 0; ss < AF_WRITING_SYSTEM_CLASSES_REC_COUNT; ss++ ) + for ( ss = 0; ss < AF_WRITING_SYSTEM_MAX - 1; ss++ ) container->af_writing_system_classes[ss] = &container->af_writing_system_classes_rec[ss]; container->af_writing_system_classes - [AF_WRITING_SYSTEM_CLASSES_COUNT - 1] = NULL; + [AF_WRITING_SYSTEM_MAX - 1] = NULL; for ( ss = 0; ss < AF_SCRIPT_CLASSES_REC_COUNT; ss++ ) container->af_script_classes[ss] = @@ -112,21 +109,14 @@ container->af_script_classes [AF_SCRIPT_CLASSES_COUNT - 1] = NULL; - /* add call to initialization function when you add new scripts */ - /* or writing systems */ +#undef WRITING_SYSTEM +#define WRITING_SYSTEM( ws, WS ) \ + FT_Init_Class_af_ ## ws ## _writing_system_class( \ + &container->af_writing_system_classes_rec[ss++] ); + ss = 0; - FT_Init_Class_af_dummy_writing_system_class( - &container->af_writing_system_classes_rec[ss++] ); - FT_Init_Class_af_latin_writing_system_class( - &container->af_writing_system_classes_rec[ss++] ); - FT_Init_Class_af_cjk_writing_system_class( - &container->af_writing_system_classes_rec[ss++] ); - FT_Init_Class_af_indic_writing_system_class( - &container->af_writing_system_classes_rec[ss++] ); -#ifdef FT_OPTION_AUTOFIT2 - FT_Init_Class_af_latin2_writing_system_class( - &container->af_writing_system_classes_rec[ss++] ); -#endif + +#include "afwrtsys.h" ss = 0; FT_Init_Class_af_dflt_script_class( diff --git a/src/autofit/afpic.h b/src/autofit/afpic.h index 22b0abefc..36ff9ad19 100644 --- a/src/autofit/afpic.h +++ b/src/autofit/afpic.h @@ -41,20 +41,14 @@ FT_BEGIN_HEADER #include "aftypes.h" - /* increase these when you add new scripts or writing systems, */ - /* and update autofit_module_class_pic_init */ #ifdef FT_OPTION_AUTOFIT2 -#define AF_WRITING_SYSTEM_CLASSES_COUNT 6 #define AF_SCRIPT_CLASSES_COUNT 6 #else -#define AF_WRITING_SYSTEM_CLASSES_COUNT 5 #define AF_SCRIPT_CLASSES_COUNT 5 #endif #define AF_SCRIPT_CLASSES_REC_COUNT \ ( AF_SCRIPT_CLASSES_COUNT - 1 ) -#define AF_WRITING_SYSTEM_CLASSES_REC_COUNT \ - ( AF_WRITING_SYSTEM_CLASSES_COUNT - 1 ) typedef struct AFModulePIC_ @@ -63,9 +57,9 @@ FT_BEGIN_HEADER FT_Service_PropertiesRec af_service_properties; AF_WritingSystemClass af_writing_system_classes - [AF_WRITING_SYSTEM_CLASSES_COUNT]; + [AF_WRITING_SYSTEM_MAX]; AF_WritingSystemClassRec af_writing_system_classes_rec - [AF_WRITING_SYSTEM_CLASSES_REC_COUNT]; + [AF_WRITING_SYSTEM_MAX - 1]; AF_ScriptClass af_script_classes [AF_SCRIPT_CLASSES_COUNT]; diff --git a/src/autofit/aftypes.h b/src/autofit/aftypes.h index 85f0febc2..3599f843a 100644 --- a/src/autofit/aftypes.h +++ b/src/autofit/aftypes.h @@ -273,24 +273,23 @@ extern void* _af_debug_hints; * outline according to the results of the glyph analyzer. */ +#define __AFWRTSYS_H__ /* don't load header files */ +#undef WRITING_SYSTEM +#define WRITING_SYSTEM( ws, WS ) \ + AF_WRITING_SYSTEM_ ## WS, + /* The list of known writing systems. */ typedef enum AF_WritingSystem_ { - AF_WRITING_SYSTEM_DUMMY = 0, - AF_WRITING_SYSTEM_LATIN = 1, - AF_WRITING_SYSTEM_CJK = 2, - AF_WRITING_SYSTEM_INDIC = 3, -#ifdef FT_OPTION_AUTOFIT2 - AF_WRITING_SYSTEM_LATIN2 = 4, -#endif - /* Add new writing systems here. Don't forget to update */ - /* the list in `afglobal.c'. */ +#include "afwrtsys.h" AF_WRITING_SYSTEM_MAX /* do not remove */ } AF_WritingSystem; +#undef __AFWRTSYS_H__ + typedef struct AF_WritingSystemClassRec_ { diff --git a/src/autofit/afwrtsys.h b/src/autofit/afwrtsys.h new file mode 100644 index 000000000..602c55884 --- /dev/null +++ b/src/autofit/afwrtsys.h @@ -0,0 +1,51 @@ +/***************************************************************************/ +/* */ +/* afwrtsys.h */ +/* */ +/* Auto-fitter writing systems (specification only). */ +/* */ +/* Copyright 2013 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* 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 __AFWRTSYS_H__ +#define __AFWRTSYS_H__ + + /* Since preprocessor directives can't create other preprocessor */ + /* directives, we have to include the header files manually. */ + +#include "afdummy.h" +#include "aflatin.h" +#include "afcjk.h" +#include "afindic.h" +#ifdef FT_OPTION_AUTOFIT2 +#include "aflatin2.h" +#endif + +#endif /* __AFWRTSYS_H__ */ + + + /* The following part can be included multiple times. */ + /* Define `WRITING_SYSTEM' as needed. */ + + + /* Add new writing systems here. */ + + WRITING_SYSTEM( dummy, DUMMY ) + WRITING_SYSTEM( latin, LATIN ) + WRITING_SYSTEM( cjk, CJK ) + WRITING_SYSTEM( indic, INDIC ) +#ifdef FT_OPTION_AUTOFIT2 + WRITING_SYSTEM( latin2, LATIN2 ) +#endif + + +/* END */