1 /**************************************************************************** 2 * 3 * gxvmod.c 4 * 5 * FreeType's TrueTypeGX/AAT validation module implementation (body). 6 * 7 * Copyright (C) 2004-2020 by 8 * suzuki toshiya, Masatake YAMATO, Red Hat K.K., 9 * David Turner, Robert Wilhelm, and Werner Lemberg. 10 * 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. 16 * 17 */ 18 19 /**************************************************************************** 20 * 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. 24 * 25 */ 26 27 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> 33 34 #include "gxvmod.h" 35 #include "gxvalid.h" 36 #include "gxvcommn.h" 37 38 39 /************************************************************************** 40 * 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. 44 */ 45 #undef FT_COMPONENT 46 #define FT_COMPONENT gxvmodule 47 48 49 static FT_Error gxv_load_table(FT_Face face,FT_Tag tag,FT_Byte * volatile * table,FT_ULong * table_len)50 gxv_load_table( FT_Face face, 51 FT_Tag tag, 52 FT_Byte* volatile* table, 53 FT_ULong* table_len ) 54 { 55 FT_Error error; 56 FT_Memory memory = FT_FACE_MEMORY( face ); 57 58 59 error = FT_Load_Sfnt_Table( face, tag, 0, NULL, table_len ); 60 if ( FT_ERR_EQ( error, Table_Missing ) ) 61 return FT_Err_Ok; 62 if ( error ) 63 goto Exit; 64 65 if ( FT_ALLOC( *table, *table_len ) ) 66 goto Exit; 67 68 error = FT_Load_Sfnt_Table( face, tag, 0, *table, table_len ); 69 70 Exit: 71 return error; 72 } 73 74 75 #define GXV_TABLE_DECL( _sfnt ) \ 76 FT_Byte* volatile _sfnt = NULL; \ 77 FT_ULong len_ ## _sfnt = 0 78 79 #define GXV_TABLE_LOAD( _sfnt ) \ 80 if ( ( FT_VALIDATE_ ## _sfnt ## _INDEX < table_count ) && \ 81 ( gx_flags & FT_VALIDATE_ ## _sfnt ) ) \ 82 { \ 83 error = gxv_load_table( face, TTAG_ ## _sfnt, \ 84 &_sfnt, &len_ ## _sfnt ); \ 85 if ( error ) \ 86 goto Exit; \ 87 } 88 89 #define GXV_TABLE_VALIDATE( _sfnt ) \ 90 if ( _sfnt ) \ 91 { \ 92 ft_validator_init( &valid, _sfnt, _sfnt + len_ ## _sfnt, \ 93 FT_VALIDATE_DEFAULT ); \ 94 if ( ft_setjmp( valid.jump_buffer ) == 0 ) \ 95 gxv_ ## _sfnt ## _validate( _sfnt, face, &valid ); \ 96 error = valid.error; \ 97 if ( error ) \ 98 goto Exit; \ 99 } 100 101 #define GXV_TABLE_SET( _sfnt ) \ 102 if ( FT_VALIDATE_ ## _sfnt ## _INDEX < table_count ) \ 103 tables[FT_VALIDATE_ ## _sfnt ## _INDEX] = (FT_Bytes)_sfnt 104 105 106 static FT_Error gxv_validate(FT_Face face,FT_UInt gx_flags,FT_Bytes tables[FT_VALIDATE_GX_LENGTH],FT_UInt table_count)107 gxv_validate( FT_Face face, 108 FT_UInt gx_flags, 109 FT_Bytes tables[FT_VALIDATE_GX_LENGTH], 110 FT_UInt table_count ) 111 { 112 FT_Memory volatile memory = FT_FACE_MEMORY( face ); 113 114 FT_Error error = FT_Err_Ok; 115 FT_ValidatorRec volatile valid; 116 117 FT_UInt i; 118 119 120 GXV_TABLE_DECL( feat ); 121 GXV_TABLE_DECL( bsln ); 122 GXV_TABLE_DECL( trak ); 123 GXV_TABLE_DECL( just ); 124 GXV_TABLE_DECL( mort ); 125 GXV_TABLE_DECL( morx ); 126 GXV_TABLE_DECL( kern ); 127 GXV_TABLE_DECL( opbd ); 128 GXV_TABLE_DECL( prop ); 129 GXV_TABLE_DECL( lcar ); 130 131 for ( i = 0; i < table_count; i++ ) 132 tables[i] = 0; 133 134 /* load tables */ 135 GXV_TABLE_LOAD( feat ); 136 GXV_TABLE_LOAD( bsln ); 137 GXV_TABLE_LOAD( trak ); 138 GXV_TABLE_LOAD( just ); 139 GXV_TABLE_LOAD( mort ); 140 GXV_TABLE_LOAD( morx ); 141 GXV_TABLE_LOAD( kern ); 142 GXV_TABLE_LOAD( opbd ); 143 GXV_TABLE_LOAD( prop ); 144 GXV_TABLE_LOAD( lcar ); 145 146 /* validate tables */ 147 GXV_TABLE_VALIDATE( feat ); 148 GXV_TABLE_VALIDATE( bsln ); 149 GXV_TABLE_VALIDATE( trak ); 150 GXV_TABLE_VALIDATE( just ); 151 GXV_TABLE_VALIDATE( mort ); 152 GXV_TABLE_VALIDATE( morx ); 153 GXV_TABLE_VALIDATE( kern ); 154 GXV_TABLE_VALIDATE( opbd ); 155 GXV_TABLE_VALIDATE( prop ); 156 GXV_TABLE_VALIDATE( lcar ); 157 158 /* Set results */ 159 GXV_TABLE_SET( feat ); 160 GXV_TABLE_SET( mort ); 161 GXV_TABLE_SET( morx ); 162 GXV_TABLE_SET( bsln ); 163 GXV_TABLE_SET( just ); 164 GXV_TABLE_SET( kern ); 165 GXV_TABLE_SET( opbd ); 166 GXV_TABLE_SET( trak ); 167 GXV_TABLE_SET( prop ); 168 GXV_TABLE_SET( lcar ); 169 170 Exit: 171 if ( error ) 172 { 173 FT_FREE( feat ); 174 FT_FREE( bsln ); 175 FT_FREE( trak ); 176 FT_FREE( just ); 177 FT_FREE( mort ); 178 FT_FREE( morx ); 179 FT_FREE( kern ); 180 FT_FREE( opbd ); 181 FT_FREE( prop ); 182 FT_FREE( lcar ); 183 } 184 185 return error; 186 } 187 188 189 static FT_Error classic_kern_validate(FT_Face face,FT_UInt ckern_flags,FT_Bytes * ckern_table)190 classic_kern_validate( FT_Face face, 191 FT_UInt ckern_flags, 192 FT_Bytes* ckern_table ) 193 { 194 FT_Memory volatile memory = FT_FACE_MEMORY( face ); 195 196 FT_Byte* volatile ckern = NULL; 197 FT_ULong len_ckern = 0; 198 199 /* without volatile on `error' GCC 4.1.1. emits: */ 200 /* warning: variable 'error' might be clobbered by 'longjmp' or 'vfork' */ 201 /* this warning seems spurious but --- */ 202 FT_Error volatile error; 203 FT_ValidatorRec volatile valid; 204 205 206 *ckern_table = NULL; 207 208 error = gxv_load_table( face, TTAG_kern, &ckern, &len_ckern ); 209 if ( error ) 210 goto Exit; 211 212 if ( ckern ) 213 { 214 ft_validator_init( &valid, ckern, ckern + len_ckern, 215 FT_VALIDATE_DEFAULT ); 216 if ( ft_setjmp( valid.jump_buffer ) == 0 ) 217 gxv_kern_validate_classic( ckern, face, 218 ckern_flags & FT_VALIDATE_CKERN, &valid ); 219 error = valid.error; 220 if ( error ) 221 goto Exit; 222 } 223 224 *ckern_table = ckern; 225 226 Exit: 227 if ( error ) 228 FT_FREE( ckern ); 229 230 return error; 231 } 232 233 234 static 235 const FT_Service_GXvalidateRec gxvalid_interface = 236 { 237 gxv_validate /* validate */ 238 }; 239 240 241 static 242 const FT_Service_CKERNvalidateRec ckernvalid_interface = 243 { 244 classic_kern_validate /* validate */ 245 }; 246 247 248 static 249 const FT_ServiceDescRec gxvalid_services[] = 250 { 251 { FT_SERVICE_ID_GX_VALIDATE, &gxvalid_interface }, 252 { FT_SERVICE_ID_CLASSICKERN_VALIDATE, &ckernvalid_interface }, 253 { NULL, NULL } 254 }; 255 256 257 static FT_Pointer gxvalid_get_service(FT_Module module,const char * service_id)258 gxvalid_get_service( FT_Module module, 259 const char* service_id ) 260 { 261 FT_UNUSED( module ); 262 263 return ft_service_list_lookup( gxvalid_services, service_id ); 264 } 265 266 267 FT_CALLBACK_TABLE_DEF 268 const FT_Module_Class gxv_module_class = 269 { 270 0, 271 sizeof ( FT_ModuleRec ), 272 "gxvalid", 273 0x10000L, 274 0x20000L, 275 276 NULL, /* module-specific interface */ 277 278 (FT_Module_Constructor)NULL, /* module_init */ 279 (FT_Module_Destructor) NULL, /* module_done */ 280 (FT_Module_Requester) gxvalid_get_service /* get_interface */ 281 }; 282 283 284 /* END */ 285