/modules/freetype2/include/freetype/internal/ftvalid.h

http://github.com/zpao/v8monkey · C Header · 150 lines · 46 code · 33 blank · 71 comment · 0 complexity · 778daadc124e4c9e83e6a80a6be8d05e MD5 · raw file

  1. /***************************************************************************/
  2. /* */
  3. /* ftvalid.h */
  4. /* */
  5. /* FreeType validation support (specification). */
  6. /* */
  7. /* Copyright 2004 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. /* validator structure */
  67. typedef struct FT_ValidatorRec_
  68. {
  69. const FT_Byte* base; /* address of table in memory */
  70. const FT_Byte* limit; /* `base' + sizeof(table) in memory */
  71. FT_ValidationLevel level; /* validation level */
  72. FT_Error error; /* error returned. 0 means success */
  73. ft_jmp_buf jump_buffer; /* used for exception handling */
  74. } FT_ValidatorRec;
  75. #define FT_VALIDATOR( x ) ((FT_Validator)( x ))
  76. FT_BASE( void )
  77. ft_validator_init( FT_Validator valid,
  78. const FT_Byte* base,
  79. const FT_Byte* limit,
  80. FT_ValidationLevel level );
  81. /* Do not use this. It's broken and will cause your validator to crash */
  82. /* if you run it on an invalid font. */
  83. FT_BASE( FT_Int )
  84. ft_validator_run( FT_Validator valid );
  85. /* Sets the error field in a validator, then calls `longjmp' to return */
  86. /* to high-level caller. Using `setjmp/longjmp' avoids many stupid */
  87. /* error checks within the validation routines. */
  88. /* */
  89. FT_BASE( void )
  90. ft_validator_error( FT_Validator valid,
  91. FT_Error error );
  92. /* Calls ft_validate_error. Assumes that the `valid' local variable */
  93. /* holds a pointer to the current validator object. */
  94. /* */
  95. /* Use preprocessor prescan to pass FT_ERR_PREFIX. */
  96. /* */
  97. #define FT_INVALID( _prefix, _error ) FT_INVALID_( _prefix, _error )
  98. #define FT_INVALID_( _prefix, _error ) \
  99. ft_validator_error( valid, _prefix ## _error )
  100. /* called when a broken table is detected */
  101. #define FT_INVALID_TOO_SHORT \
  102. FT_INVALID( FT_ERR_PREFIX, Invalid_Table )
  103. /* called when an invalid offset is detected */
  104. #define FT_INVALID_OFFSET \
  105. FT_INVALID( FT_ERR_PREFIX, Invalid_Offset )
  106. /* called when an invalid format/value is detected */
  107. #define FT_INVALID_FORMAT \
  108. FT_INVALID( FT_ERR_PREFIX, Invalid_Table )
  109. /* called when an invalid glyph index is detected */
  110. #define FT_INVALID_GLYPH_ID \
  111. FT_INVALID( FT_ERR_PREFIX, Invalid_Glyph_Index )
  112. /* called when an invalid field value is detected */
  113. #define FT_INVALID_DATA \
  114. FT_INVALID( FT_ERR_PREFIX, Invalid_Table )
  115. FT_END_HEADER
  116. #endif /* __FTVALID_H__ */
  117. /* END */