1
0

ftvalid.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /***************************************************************************/
  2. /* */
  3. /* ftvalid.h */
  4. /* */
  5. /* FreeType validation support (specification). */
  6. /* */
  7. /* Copyright 2004, 2013 by */
  8. /* David Turner, Robert Wilhelm, and Werner Lemberg. */
  9. /* */
  10. /* This file is part of the FreeType project, and may only be used, */
  11. /* modified, and distributed under the terms of the FreeType project */
  12. /* license, LICENSE.TXT. By continuing to use, modify, or distribute */
  13. /* this file you indicate that you have read the license and */
  14. /* understand and accept it fully. */
  15. /* */
  16. /***************************************************************************/
  17. #ifndef __FTVALID_H__
  18. #define __FTVALID_H__
  19. #include <ft2build.h>
  20. #include FT_CONFIG_STANDARD_LIBRARY_H /* for ft_setjmp and ft_longjmp */
  21. FT_BEGIN_HEADER
  22. /*************************************************************************/
  23. /*************************************************************************/
  24. /*************************************************************************/
  25. /**** ****/
  26. /**** ****/
  27. /**** V A L I D A T I O N ****/
  28. /**** ****/
  29. /**** ****/
  30. /*************************************************************************/
  31. /*************************************************************************/
  32. /*************************************************************************/
  33. /* handle to a validation object */
  34. typedef struct FT_ValidatorRec_ volatile* FT_Validator;
  35. /*************************************************************************/
  36. /* */
  37. /* There are three distinct validation levels defined here: */
  38. /* */
  39. /* FT_VALIDATE_DEFAULT :: */
  40. /* A table that passes this validation level can be used reliably by */
  41. /* FreeType. It generally means that all offsets have been checked to */
  42. /* prevent out-of-bound reads, that array counts are correct, etc. */
  43. /* */
  44. /* FT_VALIDATE_TIGHT :: */
  45. /* A table that passes this validation level can be used reliably and */
  46. /* doesn't contain invalid data. For example, a charmap table that */
  47. /* returns invalid glyph indices will not pass, even though it can */
  48. /* be used with FreeType in default mode (the library will simply */
  49. /* return an error later when trying to load the glyph). */
  50. /* */
  51. /* It also checks that fields which must be a multiple of 2, 4, or 8, */
  52. /* don't have incorrect values, etc. */
  53. /* */
  54. /* FT_VALIDATE_PARANOID :: */
  55. /* Only for font debugging. Checks that a table follows the */
  56. /* specification by 100%. Very few fonts will be able to pass this */
  57. /* level anyway but it can be useful for certain tools like font */
  58. /* editors/converters. */
  59. /* */
  60. typedef enum FT_ValidationLevel_
  61. {
  62. FT_VALIDATE_DEFAULT = 0,
  63. FT_VALIDATE_TIGHT,
  64. FT_VALIDATE_PARANOID
  65. } FT_ValidationLevel;
  66. #if defined( _MSC_VER ) /* Visual C++ (and Intel C++) */
  67. /* We disable the warning `structure was padded due to */
  68. /* __declspec(align())' in order to compile cleanly with */
  69. /* the maximum level of warnings. */
  70. #pragma warning( push )
  71. #pragma warning( disable : 4324 )
  72. #endif /* _MSC_VER */
  73. /* validator structure */
  74. typedef struct FT_ValidatorRec_
  75. {
  76. const FT_Byte* base; /* address of table in memory */
  77. const FT_Byte* limit; /* `base' + sizeof(table) in memory */
  78. FT_ValidationLevel level; /* validation level */
  79. FT_Error error; /* error returned. 0 means success */
  80. ft_jmp_buf jump_buffer; /* used for exception handling */
  81. } FT_ValidatorRec;
  82. #if defined( _MSC_VER )
  83. #pragma warning( pop )
  84. #endif
  85. #define FT_VALIDATOR( x ) ( (FT_Validator)( x ) )
  86. FT_BASE( void )
  87. ft_validator_init( FT_Validator valid,
  88. const FT_Byte* base,
  89. const FT_Byte* limit,
  90. FT_ValidationLevel level );
  91. /* Do not use this. It's broken and will cause your validator to crash */
  92. /* if you run it on an invalid font. */
  93. FT_BASE( FT_Int )
  94. ft_validator_run( FT_Validator valid );
  95. /* Sets the error field in a validator, then calls `longjmp' to return */
  96. /* to high-level caller. Using `setjmp/longjmp' avoids many stupid */
  97. /* error checks within the validation routines. */
  98. /* */
  99. FT_BASE( void )
  100. ft_validator_error( FT_Validator valid,
  101. FT_Error error );
  102. /* Calls ft_validate_error. Assumes that the `valid' local variable */
  103. /* holds a pointer to the current validator object. */
  104. /* */
  105. /* Use preprocessor prescan to pass FT_ERR_PREFIX. */
  106. /* */
  107. #define FT_INVALID( _prefix, _error ) FT_INVALID_( _prefix, _error )
  108. #define FT_INVALID_( _prefix, _error ) \
  109. ft_validator_error( valid, _prefix ## _error )
  110. /* called when a broken table is detected */
  111. #define FT_INVALID_TOO_SHORT \
  112. FT_INVALID( FT_ERR_PREFIX, Invalid_Table )
  113. /* called when an invalid offset is detected */
  114. #define FT_INVALID_OFFSET \
  115. FT_INVALID( FT_ERR_PREFIX, Invalid_Offset )
  116. /* called when an invalid format/value is detected */
  117. #define FT_INVALID_FORMAT \
  118. FT_INVALID( FT_ERR_PREFIX, Invalid_Table )
  119. /* called when an invalid glyph index is detected */
  120. #define FT_INVALID_GLYPH_ID \
  121. FT_INVALID( FT_ERR_PREFIX, Invalid_Glyph_Index )
  122. /* called when an invalid field value is detected */
  123. #define FT_INVALID_DATA \
  124. FT_INVALID( FT_ERR_PREFIX, Invalid_Table )
  125. FT_END_HEADER
  126. #endif /* __FTVALID_H__ */
  127. /* END */