1 /****************************************************************************
5 * FreeType's TrueTypeGX/AAT validation module implementation (body).
7 * Copyright (C) 2004-2023 by
8 * suzuki toshiya, Masatake YAMATO, Red Hat K.K.,
9 * David Turner, Robert Wilhelm, and Werner Lemberg.
11 * This file is part of the FreeType project, and may only be used,
12 * modified, and distributed under the terms of the FreeType project
13 * license, LICENSE.TXT. By continuing to use, modify, or distribute
14 * this file you indicate that you have read the license and
15 * understand and accept it fully.
19 /****************************************************************************
21 * gxvalid is derived from both gxlayout module and otvalid module.
22 * Development of gxlayout is supported by the Information-technology
23 * Promotion Agency(IPA), Japan.
28 #include <freetype/tttables.h>
29 #include <freetype/tttags.h>
30 #include <freetype/ftgxval.h>
31 #include <freetype/internal/ftobjs.h>
32 #include <freetype/internal/services/svgxval.h>
39 /**************************************************************************
41 * The macro FT_COMPONENT is used in trace mode. It is an implicit
42 * parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log
43 * messages during execution.
46 #define FT_COMPONENT gxvmodule
50 gxv_load_table( FT_Face face,
52 FT_Byte* volatile* table,
56 FT_Memory memory = FT_FACE_MEMORY( face );
59 error = FT_Load_Sfnt_Table( face, tag, 0, NULL, table_len );
60 if ( FT_ERR_EQ( error, Table_Missing ) )
65 if ( FT_QALLOC( *table, *table_len ) )
68 error = FT_Load_Sfnt_Table( face, tag, 0, *table, table_len );
75 #define GXV_TABLE_DECL( _sfnt ) \
76 FT_Byte* volatile _sfnt = NULL; \
77 FT_ULong len_ ## _sfnt = 0
79 #define GXV_TABLE_LOAD( _sfnt ) \
81 if ( ( FT_VALIDATE_ ## _sfnt ## _INDEX < table_count ) && \
82 ( gx_flags & FT_VALIDATE_ ## _sfnt ) ) \
84 error = gxv_load_table( face, TTAG_ ## _sfnt, \
85 &_sfnt, &len_ ## _sfnt ); \
91 #define GXV_TABLE_VALIDATE( _sfnt ) \
95 ft_validator_init( &valid, _sfnt, _sfnt + len_ ## _sfnt, \
96 FT_VALIDATE_DEFAULT ); \
97 if ( ft_setjmp( valid.jump_buffer ) == 0 ) \
98 gxv_ ## _sfnt ## _validate( _sfnt, face, &valid ); \
99 error = valid.error; \
105 #define GXV_TABLE_SET( _sfnt ) \
106 if ( FT_VALIDATE_ ## _sfnt ## _INDEX < table_count ) \
107 tables[FT_VALIDATE_ ## _sfnt ## _INDEX] = (FT_Bytes)_sfnt
111 gxv_validate( FT_Face face,
113 FT_Bytes tables[FT_VALIDATE_GX_LENGTH],
114 FT_UInt table_count )
116 FT_Memory volatile memory = FT_FACE_MEMORY( face );
118 FT_Error error = FT_Err_Ok;
119 FT_ValidatorRec volatile valid;
124 GXV_TABLE_DECL( feat );
125 GXV_TABLE_DECL( bsln );
126 GXV_TABLE_DECL( trak );
127 GXV_TABLE_DECL( just );
128 GXV_TABLE_DECL( mort );
129 GXV_TABLE_DECL( morx );
130 GXV_TABLE_DECL( kern );
131 GXV_TABLE_DECL( opbd );
132 GXV_TABLE_DECL( prop );
133 GXV_TABLE_DECL( lcar );
135 for ( i = 0; i < table_count; i++ )
139 GXV_TABLE_LOAD( feat );
140 GXV_TABLE_LOAD( bsln );
141 GXV_TABLE_LOAD( trak );
142 GXV_TABLE_LOAD( just );
143 GXV_TABLE_LOAD( mort );
144 GXV_TABLE_LOAD( morx );
145 GXV_TABLE_LOAD( kern );
146 GXV_TABLE_LOAD( opbd );
147 GXV_TABLE_LOAD( prop );
148 GXV_TABLE_LOAD( lcar );
150 /* validate tables */
151 GXV_TABLE_VALIDATE( feat );
152 GXV_TABLE_VALIDATE( bsln );
153 GXV_TABLE_VALIDATE( trak );
154 GXV_TABLE_VALIDATE( just );
155 GXV_TABLE_VALIDATE( mort );
156 GXV_TABLE_VALIDATE( morx );
157 GXV_TABLE_VALIDATE( kern );
158 GXV_TABLE_VALIDATE( opbd );
159 GXV_TABLE_VALIDATE( prop );
160 GXV_TABLE_VALIDATE( lcar );
163 GXV_TABLE_SET( feat );
164 GXV_TABLE_SET( mort );
165 GXV_TABLE_SET( morx );
166 GXV_TABLE_SET( bsln );
167 GXV_TABLE_SET( just );
168 GXV_TABLE_SET( kern );
169 GXV_TABLE_SET( opbd );
170 GXV_TABLE_SET( trak );
171 GXV_TABLE_SET( prop );
172 GXV_TABLE_SET( lcar );
194 classic_kern_validate( FT_Face face,
196 FT_Bytes* ckern_table )
198 FT_Memory volatile memory = FT_FACE_MEMORY( face );
200 FT_Byte* volatile ckern = NULL;
201 FT_ULong len_ckern = 0;
203 /* without volatile on `error' GCC 4.1.1. emits: */
204 /* warning: variable 'error' might be clobbered by 'longjmp' or 'vfork' */
205 /* this warning seems spurious but --- */
206 FT_Error volatile error;
207 FT_ValidatorRec volatile valid;
212 error = gxv_load_table( face, TTAG_kern, &ckern, &len_ckern );
218 ft_validator_init( &valid, ckern, ckern + len_ckern,
219 FT_VALIDATE_DEFAULT );
220 if ( ft_setjmp( valid.jump_buffer ) == 0 )
221 gxv_kern_validate_classic( ckern, face,
222 ckern_flags & FT_VALIDATE_CKERN, &valid );
228 *ckern_table = ckern;
239 const FT_Service_GXvalidateRec gxvalid_interface =
241 gxv_validate /* validate */
246 const FT_Service_CKERNvalidateRec ckernvalid_interface =
248 classic_kern_validate /* validate */
253 const FT_ServiceDescRec gxvalid_services[] =
255 { FT_SERVICE_ID_GX_VALIDATE, &gxvalid_interface },
256 { FT_SERVICE_ID_CLASSICKERN_VALIDATE, &ckernvalid_interface },
262 gxvalid_get_service( FT_Module module,
263 const char* service_id )
267 return ft_service_list_lookup( gxvalid_services, service_id );
271 FT_CALLBACK_TABLE_DEF
272 const FT_Module_Class gxv_module_class =
275 sizeof ( FT_ModuleRec ),
280 NULL, /* module-specific interface */
282 (FT_Module_Constructor)NULL, /* module_init */
283 (FT_Module_Destructor) NULL, /* module_done */
284 (FT_Module_Requester) gxvalid_get_service /* get_interface */