otvmod.c

Go to the documentation of this file.
00001 /***************************************************************************/
00002 /*                                                                         */
00003 /*  otvmod.c                                                               */
00004 /*                                                                         */
00005 /*    FreeType's OpenType validation module implementation (body).         */
00006 /*                                                                         */
00007 /*  Copyright 2004, 2005, 2006, 2007, 2008 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 #include <ft2build.h>
00020 #include FT_TRUETYPE_TABLES_H
00021 #include FT_TRUETYPE_TAGS_H
00022 #include FT_OPENTYPE_VALIDATE_H
00023 #include FT_INTERNAL_OBJECTS_H
00024 #include FT_SERVICE_OPENTYPE_VALIDATE_H
00025 
00026 #include "otvmod.h"
00027 #include "otvalid.h"
00028 #include "otvcommn.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_otvmodule
00039 
00040 
00041   static FT_Error
00042   otv_load_table( FT_Face             face,
00043                   FT_Tag              tag,
00044                   FT_Byte* volatile*  table,
00045                   FT_ULong*           table_len )
00046   {
00047     FT_Error   error;
00048     FT_Memory  memory = FT_FACE_MEMORY( face );
00049 
00050 
00051     error = FT_Load_Sfnt_Table( face, tag, 0, NULL, table_len );
00052     if ( error == OTV_Err_Table_Missing )
00053       return OTV_Err_Ok;
00054     if ( error )
00055       goto Exit;
00056 
00057     if ( FT_ALLOC( *table, *table_len ) )
00058       goto Exit;
00059 
00060     error = FT_Load_Sfnt_Table( face, tag, 0, *table, table_len );
00061 
00062   Exit:
00063     return error;
00064   }
00065 
00066 
00067   static FT_Error
00068   otv_validate( FT_Face volatile   face,
00069                 FT_UInt            ot_flags,
00070                 FT_Bytes          *ot_base,
00071                 FT_Bytes          *ot_gdef,
00072                 FT_Bytes          *ot_gpos,
00073                 FT_Bytes          *ot_gsub,
00074                 FT_Bytes          *ot_jstf )
00075   {
00076     FT_Error                  error = OTV_Err_Ok;
00077     FT_Byte* volatile         base;
00078     FT_Byte* volatile         gdef;
00079     FT_Byte* volatile         gpos;
00080     FT_Byte* volatile         gsub;
00081     FT_Byte* volatile         jstf;
00082     FT_Byte* volatile         math;
00083     FT_ULong                  len_base, len_gdef, len_gpos, len_gsub, len_jstf;
00084     FT_ULong                  len_math;
00085     FT_UInt                   num_glyphs = (FT_UInt)face->num_glyphs;
00086     FT_ValidatorRec volatile  valid;
00087 
00088 
00089     base     = gdef     = gpos     = gsub     = jstf     = math     = NULL;
00090     len_base = len_gdef = len_gpos = len_gsub = len_jstf = len_math = 0;
00091 
00092     /*
00093      * XXX: OpenType tables cannot handle 32-bit glyph index,
00094      *      although broken TrueType can have 32-bit glyph index.
00095      */
00096     if ( face->num_glyphs > 0xFFFFL )
00097     {
00098       FT_TRACE1(( "otv_validate: Invalid glyphs index (0x0000FFFF - 0x%08x) ",
00099                   face->num_glyphs ));
00100       FT_TRACE1(( "are not handled by OpenType tables\n" ));
00101       num_glyphs = 0xFFFF;
00102     }
00103 
00104     /* load tables */
00105 
00106     if ( ot_flags & FT_VALIDATE_BASE )
00107     {
00108       error = otv_load_table( face, TTAG_BASE, &base, &len_base );
00109       if ( error )
00110         goto Exit;
00111     }
00112 
00113     if ( ot_flags & FT_VALIDATE_GDEF )
00114     {
00115       error = otv_load_table( face, TTAG_GDEF, &gdef, &len_gdef );
00116       if ( error )
00117         goto Exit;
00118     }
00119 
00120     if ( ot_flags & FT_VALIDATE_GPOS )
00121     {
00122       error = otv_load_table( face, TTAG_GPOS, &gpos, &len_gpos );
00123       if ( error )
00124         goto Exit;
00125     }
00126 
00127     if ( ot_flags & FT_VALIDATE_GSUB )
00128     {
00129       error = otv_load_table( face, TTAG_GSUB, &gsub, &len_gsub );
00130       if ( error )
00131         goto Exit;
00132     }
00133 
00134     if ( ot_flags & FT_VALIDATE_JSTF )
00135     {
00136       error = otv_load_table( face, TTAG_JSTF, &jstf, &len_jstf );
00137       if ( error )
00138         goto Exit;
00139     }
00140 
00141     if ( ot_flags & FT_VALIDATE_MATH )
00142     {
00143       error = otv_load_table( face, TTAG_MATH, &math, &len_math );
00144       if ( error )
00145         goto Exit;
00146     }
00147 
00148     /* validate tables */
00149 
00150     if ( base )
00151     {
00152       ft_validator_init( &valid, base, base + len_base, FT_VALIDATE_DEFAULT );
00153       if ( ft_setjmp( valid.jump_buffer ) == 0 )
00154         otv_BASE_validate( base, &valid );
00155       error = valid.error;
00156       if ( error )
00157         goto Exit;
00158     }
00159 
00160     if ( gpos )
00161     {
00162       ft_validator_init( &valid, gpos, gpos + len_gpos, FT_VALIDATE_DEFAULT );
00163       if ( ft_setjmp( valid.jump_buffer ) == 0 )
00164         otv_GPOS_validate( gpos, num_glyphs, &valid );
00165       error = valid.error;
00166       if ( error )
00167         goto Exit;
00168     }
00169 
00170     if ( gsub )
00171     {
00172       ft_validator_init( &valid, gsub, gsub + len_gsub, FT_VALIDATE_DEFAULT );
00173       if ( ft_setjmp( valid.jump_buffer ) == 0 )
00174         otv_GSUB_validate( gsub, num_glyphs, &valid );
00175       error = valid.error;
00176       if ( error )
00177         goto Exit;
00178     }
00179 
00180     if ( gdef )
00181     {
00182       ft_validator_init( &valid, gdef, gdef + len_gdef, FT_VALIDATE_DEFAULT );
00183       if ( ft_setjmp( valid.jump_buffer ) == 0 )
00184         otv_GDEF_validate( gdef, gsub, gpos, num_glyphs, &valid );
00185       error = valid.error;
00186       if ( error )
00187         goto Exit;
00188     }
00189 
00190     if ( jstf )
00191     {
00192       ft_validator_init( &valid, jstf, jstf + len_jstf, FT_VALIDATE_DEFAULT );
00193       if ( ft_setjmp( valid.jump_buffer ) == 0 )
00194         otv_JSTF_validate( jstf, gsub, gpos, num_glyphs, &valid );
00195       error = valid.error;
00196       if ( error )
00197         goto Exit;
00198     }
00199 
00200     if ( math )
00201     {
00202       ft_validator_init( &valid, math, math + len_math, FT_VALIDATE_DEFAULT );
00203       if ( ft_setjmp( valid.jump_buffer ) == 0 )
00204         otv_MATH_validate( math, num_glyphs, &valid );
00205       error = valid.error;
00206       if ( error )
00207         goto Exit;
00208     }
00209 
00210     *ot_base = (FT_Bytes)base;
00211     *ot_gdef = (FT_Bytes)gdef;
00212     *ot_gpos = (FT_Bytes)gpos;
00213     *ot_gsub = (FT_Bytes)gsub;
00214     *ot_jstf = (FT_Bytes)jstf;
00215 
00216   Exit:
00217     if ( error ) {
00218       FT_Memory  memory = FT_FACE_MEMORY( face );
00219 
00220 
00221       FT_FREE( base );
00222       FT_FREE( gdef );
00223       FT_FREE( gpos );
00224       FT_FREE( gsub );
00225       FT_FREE( jstf );
00226     }
00227     {
00228       FT_Memory  memory = FT_FACE_MEMORY( face );
00229 
00230 
00231       FT_FREE( math );                 /* Can't return this as API is frozen */
00232     }
00233 
00234     return error;
00235   }
00236 
00237 
00238   static
00239   const FT_Service_OTvalidateRec  otvalid_interface =
00240   {
00241     otv_validate
00242   };
00243 
00244 
00245   static
00246   const FT_ServiceDescRec  otvalid_services[] =
00247   {
00248     { FT_SERVICE_ID_OPENTYPE_VALIDATE, &otvalid_interface },
00249     { NULL, NULL }
00250   };
00251 
00252 
00253   static FT_Pointer
00254   otvalid_get_service( FT_Module    module,
00255                        const char*  service_id )
00256   {
00257     FT_UNUSED( module );
00258 
00259     return ft_service_list_lookup( otvalid_services, service_id );
00260   }
00261 
00262 
00263   FT_CALLBACK_TABLE_DEF
00264   const FT_Module_Class  otv_module_class =
00265   {
00266     0,
00267     sizeof( FT_ModuleRec ),
00268     "otvalid",
00269     0x10000L,
00270     0x20000L,
00271 
00272     0,              /* module-specific interface */
00273 
00274     (FT_Module_Constructor)0,
00275     (FT_Module_Destructor) 0,
00276     (FT_Module_Requester)  otvalid_get_service
00277   };
00278 
00279 
00280 /* END */

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