Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenotvmod.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 { 00219 FT_Memory memory = FT_FACE_MEMORY( face ); 00220 00221 00222 FT_FREE( base ); 00223 FT_FREE( gdef ); 00224 FT_FREE( gpos ); 00225 FT_FREE( gsub ); 00226 FT_FREE( jstf ); 00227 } 00228 00229 { 00230 FT_Memory memory = FT_FACE_MEMORY( face ); 00231 00232 00233 FT_FREE( math ); /* Can't return this as API is frozen */ 00234 } 00235 00236 return error; 00237 } 00238 00239 00240 static 00241 const FT_Service_OTvalidateRec otvalid_interface = 00242 { 00243 otv_validate 00244 }; 00245 00246 00247 static 00248 const FT_ServiceDescRec otvalid_services[] = 00249 { 00250 { FT_SERVICE_ID_OPENTYPE_VALIDATE, &otvalid_interface }, 00251 { NULL, NULL } 00252 }; 00253 00254 00255 static FT_Pointer 00256 otvalid_get_service( FT_Module module, 00257 const char* service_id ) 00258 { 00259 FT_UNUSED( module ); 00260 00261 return ft_service_list_lookup( otvalid_services, service_id ); 00262 } 00263 00264 00265 FT_CALLBACK_TABLE_DEF 00266 const FT_Module_Class otv_module_class = 00267 { 00268 0, 00269 sizeof( FT_ModuleRec ), 00270 "otvalid", 00271 0x10000L, 00272 0x20000L, 00273 00274 0, /* module-specific interface */ 00275 00276 (FT_Module_Constructor)0, 00277 (FT_Module_Destructor) 0, 00278 (FT_Module_Requester) otvalid_get_service 00279 }; 00280 00281 00282 /* END */ Generated on Sat May 26 2012 04:32:46 for ReactOS by
1.7.6.1
|