vrshoot
diff libs/ft2static/freetype/internal/ftvalid.h @ 0:b2f14e535253
initial commit
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 01 Feb 2014 19:58:19 +0200 |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/libs/ft2static/freetype/internal/ftvalid.h Sat Feb 01 19:58:19 2014 +0200 1.3 @@ -0,0 +1,150 @@ 1.4 +/***************************************************************************/ 1.5 +/* */ 1.6 +/* ftvalid.h */ 1.7 +/* */ 1.8 +/* FreeType validation support (specification). */ 1.9 +/* */ 1.10 +/* Copyright 2004 by */ 1.11 +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ 1.12 +/* */ 1.13 +/* This file is part of the FreeType project, and may only be used, */ 1.14 +/* modified, and distributed under the terms of the FreeType project */ 1.15 +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ 1.16 +/* this file you indicate that you have read the license and */ 1.17 +/* understand and accept it fully. */ 1.18 +/* */ 1.19 +/***************************************************************************/ 1.20 + 1.21 + 1.22 +#ifndef __FTVALID_H__ 1.23 +#define __FTVALID_H__ 1.24 + 1.25 +#include <ft2build.h> 1.26 +#include FT_CONFIG_STANDARD_LIBRARY_H /* for ft_setjmp and ft_longjmp */ 1.27 + 1.28 + 1.29 +FT_BEGIN_HEADER 1.30 + 1.31 + 1.32 + /*************************************************************************/ 1.33 + /*************************************************************************/ 1.34 + /*************************************************************************/ 1.35 + /**** ****/ 1.36 + /**** ****/ 1.37 + /**** V A L I D A T I O N ****/ 1.38 + /**** ****/ 1.39 + /**** ****/ 1.40 + /*************************************************************************/ 1.41 + /*************************************************************************/ 1.42 + /*************************************************************************/ 1.43 + 1.44 + /* handle to a validation object */ 1.45 + typedef struct FT_ValidatorRec_ volatile* FT_Validator; 1.46 + 1.47 + 1.48 + /*************************************************************************/ 1.49 + /* */ 1.50 + /* There are three distinct validation levels defined here: */ 1.51 + /* */ 1.52 + /* FT_VALIDATE_DEFAULT :: */ 1.53 + /* A table that passes this validation level can be used reliably by */ 1.54 + /* FreeType. It generally means that all offsets have been checked to */ 1.55 + /* prevent out-of-bound reads, that array counts are correct, etc. */ 1.56 + /* */ 1.57 + /* FT_VALIDATE_TIGHT :: */ 1.58 + /* A table that passes this validation level can be used reliably and */ 1.59 + /* doesn't contain invalid data. For example, a charmap table that */ 1.60 + /* returns invalid glyph indices will not pass, even though it can */ 1.61 + /* be used with FreeType in default mode (the library will simply */ 1.62 + /* return an error later when trying to load the glyph). */ 1.63 + /* */ 1.64 + /* It also checks that fields which must be a multiple of 2, 4, or 8, */ 1.65 + /* don't have incorrect values, etc. */ 1.66 + /* */ 1.67 + /* FT_VALIDATE_PARANOID :: */ 1.68 + /* Only for font debugging. Checks that a table follows the */ 1.69 + /* specification by 100%. Very few fonts will be able to pass this */ 1.70 + /* level anyway but it can be useful for certain tools like font */ 1.71 + /* editors/converters. */ 1.72 + /* */ 1.73 + typedef enum FT_ValidationLevel_ 1.74 + { 1.75 + FT_VALIDATE_DEFAULT = 0, 1.76 + FT_VALIDATE_TIGHT, 1.77 + FT_VALIDATE_PARANOID 1.78 + 1.79 + } FT_ValidationLevel; 1.80 + 1.81 + 1.82 + /* validator structure */ 1.83 + typedef struct FT_ValidatorRec_ 1.84 + { 1.85 + const FT_Byte* base; /* address of table in memory */ 1.86 + const FT_Byte* limit; /* `base' + sizeof(table) in memory */ 1.87 + FT_ValidationLevel level; /* validation level */ 1.88 + FT_Error error; /* error returned. 0 means success */ 1.89 + 1.90 + ft_jmp_buf jump_buffer; /* used for exception handling */ 1.91 + 1.92 + } FT_ValidatorRec; 1.93 + 1.94 + 1.95 +#define FT_VALIDATOR( x ) ((FT_Validator)( x )) 1.96 + 1.97 + 1.98 + FT_BASE( void ) 1.99 + ft_validator_init( FT_Validator valid, 1.100 + const FT_Byte* base, 1.101 + const FT_Byte* limit, 1.102 + FT_ValidationLevel level ); 1.103 + 1.104 + /* Do not use this. It's broken and will cause your validator to crash */ 1.105 + /* if you run it on an invalid font. */ 1.106 + FT_BASE( FT_Int ) 1.107 + ft_validator_run( FT_Validator valid ); 1.108 + 1.109 + /* Sets the error field in a validator, then calls `longjmp' to return */ 1.110 + /* to high-level caller. Using `setjmp/longjmp' avoids many stupid */ 1.111 + /* error checks within the validation routines. */ 1.112 + /* */ 1.113 + FT_BASE( void ) 1.114 + ft_validator_error( FT_Validator valid, 1.115 + FT_Error error ); 1.116 + 1.117 + 1.118 + /* Calls ft_validate_error. Assumes that the `valid' local variable */ 1.119 + /* holds a pointer to the current validator object. */ 1.120 + /* */ 1.121 + /* Use preprocessor prescan to pass FT_ERR_PREFIX. */ 1.122 + /* */ 1.123 +#define FT_INVALID( _prefix, _error ) FT_INVALID_( _prefix, _error ) 1.124 +#define FT_INVALID_( _prefix, _error ) \ 1.125 + ft_validator_error( valid, _prefix ## _error ) 1.126 + 1.127 + /* called when a broken table is detected */ 1.128 +#define FT_INVALID_TOO_SHORT \ 1.129 + FT_INVALID( FT_ERR_PREFIX, Invalid_Table ) 1.130 + 1.131 + /* called when an invalid offset is detected */ 1.132 +#define FT_INVALID_OFFSET \ 1.133 + FT_INVALID( FT_ERR_PREFIX, Invalid_Offset ) 1.134 + 1.135 + /* called when an invalid format/value is detected */ 1.136 +#define FT_INVALID_FORMAT \ 1.137 + FT_INVALID( FT_ERR_PREFIX, Invalid_Table ) 1.138 + 1.139 + /* called when an invalid glyph index is detected */ 1.140 +#define FT_INVALID_GLYPH_ID \ 1.141 + FT_INVALID( FT_ERR_PREFIX, Invalid_Glyph_Index ) 1.142 + 1.143 + /* called when an invalid field value is detected */ 1.144 +#define FT_INVALID_DATA \ 1.145 + FT_INVALID( FT_ERR_PREFIX, Invalid_Table ) 1.146 + 1.147 + 1.148 +FT_END_HEADER 1.149 + 1.150 +#endif /* __FTVALID_H__ */ 1.151 + 1.152 + 1.153 +/* END */