ftvalid.h

Go to the documentation of this file.
00001 /***************************************************************************/
00002 /*                                                                         */
00003 /*  ftvalid.h                                                              */
00004 /*                                                                         */
00005 /*    FreeType validation support (specification).                         */
00006 /*                                                                         */
00007 /*  Copyright 2004 by                                                      */
00008 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
00009 /*                                                                         */
00010 /*  This file is part of the FreeType project, and may only be used,       */
00011 /*  modified, and distributed under the terms of the FreeType project      */
00012 /*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
00013 /*  this file you indicate that you have read the license and              */
00014 /*  understand and accept it fully.                                        */
00015 /*                                                                         */
00016 /***************************************************************************/
00017 
00018 
00019 #ifndef __FTVALID_H__
00020 #define __FTVALID_H__
00021 
00022 #include <ft2build.h>
00023 #include FT_CONFIG_STANDARD_LIBRARY_H   /* for ft_setjmp and ft_longjmp */
00024 
00025 
00026 FT_BEGIN_HEADER
00027 
00028 
00029   /*************************************************************************/
00030   /*************************************************************************/
00031   /*************************************************************************/
00032   /****                                                                 ****/
00033   /****                                                                 ****/
00034   /****                    V A L I D A T I O N                          ****/
00035   /****                                                                 ****/
00036   /****                                                                 ****/
00037   /*************************************************************************/
00038   /*************************************************************************/
00039   /*************************************************************************/
00040 
00041   /* handle to a validation object */
00042   typedef struct FT_ValidatorRec_ volatile*  FT_Validator;
00043 
00044 
00045   /*************************************************************************/
00046   /*                                                                       */
00047   /* There are three distinct validation levels defined here:              */
00048   /*                                                                       */
00049   /* FT_VALIDATE_DEFAULT ::                                                */
00050   /*   A table that passes this validation level can be used reliably by   */
00051   /*   FreeType.  It generally means that all offsets have been checked to */
00052   /*   prevent out-of-bound reads, that array counts are correct, etc.     */
00053   /*                                                                       */
00054   /* FT_VALIDATE_TIGHT ::                                                  */
00055   /*   A table that passes this validation level can be used reliably and  */
00056   /*   doesn't contain invalid data.  For example, a charmap table that    */
00057   /*   returns invalid glyph indices will not pass, even though it can     */
00058   /*   be used with FreeType in default mode (the library will simply      */
00059   /*   return an error later when trying to load the glyph).               */
00060   /*                                                                       */
00061   /*   It also checks that fields which must be a multiple of 2, 4, or 8,  */
00062   /*   don't have incorrect values, etc.                                   */
00063   /*                                                                       */
00064   /* FT_VALIDATE_PARANOID ::                                               */
00065   /*   Only for font debugging.  Checks that a table follows the           */
00066   /*   specification by 100%.  Very few fonts will be able to pass this    */
00067   /*   level anyway but it can be useful for certain tools like font       */
00068   /*   editors/converters.                                                 */
00069   /*                                                                       */
00070   typedef enum  FT_ValidationLevel_
00071   {
00072     FT_VALIDATE_DEFAULT = 0,
00073     FT_VALIDATE_TIGHT,
00074     FT_VALIDATE_PARANOID
00075 
00076   } FT_ValidationLevel;
00077 
00078 
00079   /* validator structure */
00080   typedef struct  FT_ValidatorRec_
00081   {
00082     const FT_Byte*      base;        /* address of table in memory       */
00083     const FT_Byte*      limit;       /* `base' + sizeof(table) in memory */
00084     FT_ValidationLevel  level;       /* validation level                 */
00085     FT_Error            error;       /* error returned. 0 means success  */
00086 
00087     ft_jmp_buf          jump_buffer; /* used for exception handling      */
00088 
00089   } FT_ValidatorRec;
00090 
00091 
00092 #define FT_VALIDATOR( x )  ((FT_Validator)( x ))
00093 
00094 
00095   FT_BASE( void )
00096   ft_validator_init( FT_Validator        valid,
00097                      const FT_Byte*      base,
00098                      const FT_Byte*      limit,
00099                      FT_ValidationLevel  level );
00100 
00101   /* Do not use this. It's broken and will cause your validator to crash */
00102   /* if you run it on an invalid font.                                   */
00103   FT_BASE( FT_Int )
00104   ft_validator_run( FT_Validator  valid );
00105 
00106   /* Sets the error field in a validator, then calls `longjmp' to return */
00107   /* to high-level caller.  Using `setjmp/longjmp' avoids many stupid    */
00108   /* error checks within the validation routines.                        */
00109   /*                                                                     */
00110   FT_BASE( void )
00111   ft_validator_error( FT_Validator  valid,
00112                       FT_Error      error );
00113 
00114 
00115   /* Calls ft_validate_error.  Assumes that the `valid' local variable */
00116   /* holds a pointer to the current validator object.                  */
00117   /*                                                                   */
00118   /* Use preprocessor prescan to pass FT_ERR_PREFIX.                   */
00119   /*                                                                   */
00120 #define FT_INVALID( _prefix, _error )  FT_INVALID_( _prefix, _error )
00121 #define FT_INVALID_( _prefix, _error ) \
00122           ft_validator_error( valid, _prefix ## _error )
00123 
00124   /* called when a broken table is detected */
00125 #define FT_INVALID_TOO_SHORT \
00126           FT_INVALID( FT_ERR_PREFIX, Invalid_Table )
00127 
00128   /* called when an invalid offset is detected */
00129 #define FT_INVALID_OFFSET \
00130           FT_INVALID( FT_ERR_PREFIX, Invalid_Offset )
00131 
00132   /* called when an invalid format/value is detected */
00133 #define FT_INVALID_FORMAT \
00134           FT_INVALID( FT_ERR_PREFIX, Invalid_Table )
00135 
00136   /* called when an invalid glyph index is detected */
00137 #define FT_INVALID_GLYPH_ID \
00138           FT_INVALID( FT_ERR_PREFIX, Invalid_Glyph_Index )
00139 
00140   /* called when an invalid field value is detected */
00141 #define FT_INVALID_DATA \
00142           FT_INVALID( FT_ERR_PREFIX, Invalid_Table )
00143 
00144 
00145 FT_END_HEADER
00146 
00147 #endif /* __FTVALID_H__ */
00148 
00149 
00150 /* END */

Generated on Tue Jul 5 14:13:40 2011 for ROOT_528-00b_version by  doxygen 1.5.1