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