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