ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

gxvbsln.c
Go to the documentation of this file.
00001 /***************************************************************************/
00002 /*                                                                         */
00003 /*  gxvbsln.c                                                              */
00004 /*                                                                         */
00005 /*    TrueTypeGX/AAT bsln table validation (body).                         */
00006 /*                                                                         */
00007 /*  Copyright 2004, 2005 by suzuki toshiya, Masatake YAMATO, Red Hat K.K., */
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 /*                                                                         */
00020 /* gxvalid is derived from both gxlayout module and otvalid module.        */
00021 /* Development of gxlayout is supported by the Information-technology      */
00022 /* Promotion Agency(IPA), Japan.                                           */
00023 /*                                                                         */
00024 /***************************************************************************/
00025 
00026 
00027 #include "gxvalid.h"
00028 #include "gxvcommn.h"
00029 
00030 
00031   /*************************************************************************/
00032   /*                                                                       */
00033   /* The macro FT_COMPONENT is used in trace mode.  It is an implicit      */
00034   /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log  */
00035   /* messages during execution.                                            */
00036   /*                                                                       */
00037 #undef  FT_COMPONENT
00038 #define FT_COMPONENT  trace_gxvbsln
00039 
00040 
00041   /*************************************************************************/
00042   /*************************************************************************/
00043   /*****                                                               *****/
00044   /*****                      Data and Types                           *****/
00045   /*****                                                               *****/
00046   /*************************************************************************/
00047   /*************************************************************************/
00048 
00049 #define GXV_BSLN_VALUE_COUNT  32
00050 #define GXV_BSLN_VALUE_EMPTY  0xFFFFU
00051 
00052 
00053   typedef struct  GXV_bsln_DataRec_
00054   {
00055     FT_Bytes   ctlPoints_p;
00056     FT_UShort  defaultBaseline;
00057 
00058   } GXV_bsln_DataRec, *GXV_bsln_Data;
00059 
00060 
00061 #define GXV_BSLN_DATA( field )  GXV_TABLE_DATA( bsln, field )
00062 
00063 
00064   /*************************************************************************/
00065   /*************************************************************************/
00066   /*****                                                               *****/
00067   /*****                      UTILITY FUNCTIONS                        *****/
00068   /*****                                                               *****/
00069   /*************************************************************************/
00070   /*************************************************************************/
00071 
00072   static void
00073   gxv_bsln_LookupValue_validate( FT_UShort            glyph,
00074                                  GXV_LookupValueCPtr  value_p,
00075                                  GXV_Validator        valid )
00076   {
00077     FT_UShort   v = value_p->u;
00078     FT_UShort*  ctlPoints;
00079 
00080     FT_UNUSED( glyph );
00081 
00082 
00083     GXV_NAME_ENTER( "lookup value" );
00084 
00085     if ( v >= GXV_BSLN_VALUE_COUNT )
00086       FT_INVALID_DATA;
00087 
00088     ctlPoints = (FT_UShort*)GXV_BSLN_DATA( ctlPoints_p );
00089     if ( ctlPoints && ctlPoints[v] == GXV_BSLN_VALUE_EMPTY )
00090       FT_INVALID_DATA;
00091 
00092     GXV_EXIT;
00093   }
00094 
00095 
00096   /*
00097     +===============+ --------+
00098     | lookup header |         |
00099     +===============+         |
00100     | BinSrchHeader |         |
00101     +===============+         |
00102     | lastGlyph[0]  |         |
00103     +---------------+         |
00104     | firstGlyph[0] |         |    head of lookup table
00105     +---------------+         |             +
00106     | offset[0]     |    ->   |          offset            [byte]
00107     +===============+         |             +
00108     | lastGlyph[1]  |         | (glyphID - firstGlyph) * 2 [byte]
00109     +---------------+         |
00110     | firstGlyph[1] |         |
00111     +---------------+         |
00112     | offset[1]     |         |
00113     +===============+         |
00114                               |
00115     ...                       |
00116                               |
00117     16bit value array         |
00118     +===============+         |
00119     |     value     | <-------+
00120     ...
00121   */
00122 
00123   static GXV_LookupValueDesc
00124   gxv_bsln_LookupFmt4_transit( FT_UShort            relative_gindex,
00125                                GXV_LookupValueCPtr  base_value_p,
00126                                FT_Bytes             lookuptbl_limit,
00127                                GXV_Validator        valid )
00128   {
00129     FT_Bytes             p;
00130     FT_Bytes             limit;
00131     FT_UShort            offset;
00132     GXV_LookupValueDesc  value;
00133 
00134     /* XXX: check range ? */
00135     offset = (FT_UShort)( base_value_p->u +
00136                           ( relative_gindex * sizeof ( FT_UShort ) ) );
00137 
00138     p     = valid->lookuptbl_head + offset;
00139     limit = lookuptbl_limit;
00140     GXV_LIMIT_CHECK( 2 );
00141 
00142     value.u = FT_NEXT_USHORT( p );
00143 
00144     return value;
00145   }
00146 
00147 
00148   static void
00149   gxv_bsln_parts_fmt0_validate( FT_Bytes       tables,
00150                                 FT_Bytes       limit,
00151                                 GXV_Validator  valid )
00152   {
00153     FT_Bytes  p = tables;
00154 
00155 
00156     GXV_NAME_ENTER( "parts format 0" );
00157 
00158     /* deltas */
00159     GXV_LIMIT_CHECK( 2 * GXV_BSLN_VALUE_COUNT );
00160 
00161     valid->table_data = NULL;      /* No ctlPoints here. */
00162 
00163     GXV_EXIT;
00164   }
00165 
00166 
00167   static void
00168   gxv_bsln_parts_fmt1_validate( FT_Bytes       tables,
00169                                 FT_Bytes       limit,
00170                                 GXV_Validator  valid )
00171   {
00172     FT_Bytes  p = tables;
00173 
00174 
00175     GXV_NAME_ENTER( "parts format 1" );
00176 
00177     /* deltas */
00178     gxv_bsln_parts_fmt0_validate( p, limit, valid );
00179 
00180     /* mappingData */
00181     valid->lookupval_sign   = GXV_LOOKUPVALUE_UNSIGNED;
00182     valid->lookupval_func   = gxv_bsln_LookupValue_validate;
00183     valid->lookupfmt4_trans = gxv_bsln_LookupFmt4_transit;
00184     gxv_LookupTable_validate( p + 2 * GXV_BSLN_VALUE_COUNT,
00185                               limit,
00186                               valid );
00187 
00188     GXV_EXIT;
00189   }
00190 
00191 
00192   static void
00193   gxv_bsln_parts_fmt2_validate( FT_Bytes       tables,
00194                                 FT_Bytes       limit,
00195                                 GXV_Validator  valid )
00196   {
00197     FT_Bytes   p = tables;
00198 
00199     FT_UShort  stdGlyph;
00200     FT_UShort  ctlPoint;
00201     FT_Int     i;
00202 
00203     FT_UShort  defaultBaseline = GXV_BSLN_DATA( defaultBaseline );
00204 
00205 
00206     GXV_NAME_ENTER( "parts format 2" );
00207 
00208     GXV_LIMIT_CHECK( 2 + ( 2 * GXV_BSLN_VALUE_COUNT ) );
00209 
00210     /* stdGlyph */
00211     stdGlyph = FT_NEXT_USHORT( p );
00212     GXV_TRACE(( " (stdGlyph = %u)\n", stdGlyph ));
00213 
00214     gxv_glyphid_validate( stdGlyph, valid );
00215 
00216     /* Record the position of ctlPoints */
00217     GXV_BSLN_DATA( ctlPoints_p ) = p;
00218 
00219     /* ctlPoints */
00220     for ( i = 0; i < GXV_BSLN_VALUE_COUNT; i++ )
00221     {
00222       ctlPoint = FT_NEXT_USHORT( p );
00223       if ( ctlPoint == GXV_BSLN_VALUE_EMPTY )
00224       {
00225         if ( i == defaultBaseline )
00226           FT_INVALID_DATA;
00227       }
00228       else
00229         gxv_ctlPoint_validate( stdGlyph, (FT_Short)ctlPoint, valid );
00230     }
00231 
00232     GXV_EXIT;
00233   }
00234 
00235 
00236   static void
00237   gxv_bsln_parts_fmt3_validate( FT_Bytes       tables,
00238                                 FT_Bytes       limit,
00239                                 GXV_Validator  valid)
00240   {
00241     FT_Bytes  p = tables;
00242 
00243 
00244     GXV_NAME_ENTER( "parts format 3" );
00245 
00246     /* stdGlyph + ctlPoints */
00247     gxv_bsln_parts_fmt2_validate( p, limit, valid );
00248 
00249     /* mappingData */
00250     valid->lookupval_sign   = GXV_LOOKUPVALUE_UNSIGNED;
00251     valid->lookupval_func   = gxv_bsln_LookupValue_validate;
00252     valid->lookupfmt4_trans = gxv_bsln_LookupFmt4_transit;
00253     gxv_LookupTable_validate( p + ( 2 + 2 * GXV_BSLN_VALUE_COUNT ),
00254                               limit,
00255                               valid );
00256 
00257     GXV_EXIT;
00258   }
00259 
00260 
00261   /*************************************************************************/
00262   /*************************************************************************/
00263   /*****                                                               *****/
00264   /*****                         bsln TABLE                            *****/
00265   /*****                                                               *****/
00266   /*************************************************************************/
00267   /*************************************************************************/
00268 
00269   FT_LOCAL_DEF( void )
00270   gxv_bsln_validate( FT_Bytes      table,
00271                      FT_Face       face,
00272                      FT_Validator  ftvalid )
00273   {
00274     GXV_ValidatorRec  validrec;
00275     GXV_Validator     valid = &validrec;
00276 
00277     GXV_bsln_DataRec  bslnrec;
00278     GXV_bsln_Data     bsln = &bslnrec;
00279 
00280     FT_Bytes  p     = table;
00281     FT_Bytes  limit = 0;
00282 
00283     FT_ULong   version;
00284     FT_UShort  format;
00285     FT_UShort  defaultBaseline;
00286 
00287     GXV_Validate_Func  fmt_funcs_table [] =
00288     {
00289       gxv_bsln_parts_fmt0_validate,
00290       gxv_bsln_parts_fmt1_validate,
00291       gxv_bsln_parts_fmt2_validate,
00292       gxv_bsln_parts_fmt3_validate,
00293     };
00294 
00295 
00296     valid->root       = ftvalid;
00297     valid->table_data = bsln;
00298     valid->face       = face;
00299 
00300     FT_TRACE3(( "validating `bsln' table\n" ));
00301     GXV_INIT;
00302 
00303 
00304     GXV_LIMIT_CHECK( 4 + 2 + 2 );
00305     version         = FT_NEXT_ULONG( p );
00306     format          = FT_NEXT_USHORT( p );
00307     defaultBaseline = FT_NEXT_USHORT( p );
00308 
00309     /* only version 1.0 is defined (1996) */
00310     if ( version != 0x00010000UL )
00311       FT_INVALID_FORMAT;
00312 
00313     /* only format 1, 2, 3 are defined (1996) */
00314     GXV_TRACE(( " (format = %d)\n", format ));
00315     if ( format > 3 )
00316       FT_INVALID_FORMAT;
00317 
00318     if ( defaultBaseline > 31 )
00319       FT_INVALID_FORMAT;
00320 
00321     bsln->defaultBaseline = defaultBaseline;
00322 
00323     fmt_funcs_table[format]( p, limit, valid );
00324 
00325     FT_TRACE4(( "\n" ));
00326   }
00327 
00328 
00329 /* arch-tag: ebe81143-fdaa-4c68-a4d1-b57227daa3bc
00330    (do not change this comment) */
00331 
00332 
00333 /* END */

Generated on Sun May 27 2012 04:33:50 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.