Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygengxvmort2.c
Go to the documentation of this file.
00001 /***************************************************************************/ 00002 /* */ 00003 /* gxvmort2.c */ 00004 /* */ 00005 /* TrueTypeGX/AAT mort table validation */ 00006 /* body for type2 (Ligature Substitution) subtable. */ 00007 /* */ 00008 /* Copyright 2005 by suzuki toshiya, Masatake YAMATO, Red Hat K.K., */ 00009 /* David Turner, Robert Wilhelm, and Werner Lemberg. */ 00010 /* */ 00011 /* This file is part of the FreeType project, and may only be used, */ 00012 /* modified, and distributed under the terms of the FreeType project */ 00013 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ 00014 /* this file you indicate that you have read the license and */ 00015 /* understand and accept it fully. */ 00016 /* */ 00017 /***************************************************************************/ 00018 00019 /***************************************************************************/ 00020 /* */ 00021 /* gxvalid is derived from both gxlayout module and otvalid module. */ 00022 /* Development of gxlayout is supported by the Information-technology */ 00023 /* Promotion Agency(IPA), Japan. */ 00024 /* */ 00025 /***************************************************************************/ 00026 00027 00028 #include "gxvmort.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_gxvmort 00039 00040 00041 typedef struct GXV_mort_subtable_type2_StateOptRec_ 00042 { 00043 FT_UShort ligActionTable; 00044 FT_UShort componentTable; 00045 FT_UShort ligatureTable; 00046 FT_UShort ligActionTable_length; 00047 FT_UShort componentTable_length; 00048 FT_UShort ligatureTable_length; 00049 00050 } GXV_mort_subtable_type2_StateOptRec, 00051 *GXV_mort_subtable_type2_StateOptRecData; 00052 00053 #define GXV_MORT_SUBTABLE_TYPE2_HEADER_SIZE \ 00054 ( GXV_STATETABLE_HEADER_SIZE + 2 + 2 + 2 ) 00055 00056 00057 static void 00058 gxv_mort_subtable_type2_opttable_load( FT_Bytes table, 00059 FT_Bytes limit, 00060 GXV_Validator valid ) 00061 { 00062 FT_Bytes p = table; 00063 GXV_mort_subtable_type2_StateOptRecData optdata = 00064 (GXV_mort_subtable_type2_StateOptRecData)valid->statetable.optdata; 00065 00066 00067 GXV_LIMIT_CHECK( 2 + 2 + 2 ); 00068 optdata->ligActionTable = FT_NEXT_USHORT( p ); 00069 optdata->componentTable = FT_NEXT_USHORT( p ); 00070 optdata->ligatureTable = FT_NEXT_USHORT( p ); 00071 00072 GXV_TRACE(( "offset to ligActionTable=0x%04x\n", 00073 optdata->ligActionTable )); 00074 GXV_TRACE(( "offset to componentTable=0x%04x\n", 00075 optdata->componentTable )); 00076 GXV_TRACE(( "offset to ligatureTable=0x%04x\n", 00077 optdata->ligatureTable )); 00078 } 00079 00080 00081 static void 00082 gxv_mort_subtable_type2_subtable_setup( FT_UShort table_size, 00083 FT_UShort classTable, 00084 FT_UShort stateArray, 00085 FT_UShort entryTable, 00086 FT_UShort *classTable_length_p, 00087 FT_UShort *stateArray_length_p, 00088 FT_UShort *entryTable_length_p, 00089 GXV_Validator valid ) 00090 { 00091 FT_UShort o[6]; 00092 FT_UShort *l[6]; 00093 FT_UShort buff[7]; 00094 00095 GXV_mort_subtable_type2_StateOptRecData optdata = 00096 (GXV_mort_subtable_type2_StateOptRecData)valid->statetable.optdata; 00097 00098 00099 GXV_NAME_ENTER( "subtable boundaries setup" ); 00100 00101 o[0] = classTable; 00102 o[1] = stateArray; 00103 o[2] = entryTable; 00104 o[3] = optdata->ligActionTable; 00105 o[4] = optdata->componentTable; 00106 o[5] = optdata->ligatureTable; 00107 l[0] = classTable_length_p; 00108 l[1] = stateArray_length_p; 00109 l[2] = entryTable_length_p; 00110 l[3] = &(optdata->ligActionTable_length); 00111 l[4] = &(optdata->componentTable_length); 00112 l[5] = &(optdata->ligatureTable_length); 00113 00114 gxv_set_length_by_ushort_offset( o, l, buff, 6, table_size, valid ); 00115 00116 GXV_TRACE(( "classTable: offset=0x%04x length=0x%04x\n", 00117 classTable, *classTable_length_p )); 00118 GXV_TRACE(( "stateArray: offset=0x%04x length=0x%04x\n", 00119 stateArray, *stateArray_length_p )); 00120 GXV_TRACE(( "entryTable: offset=0x%04x length=0x%04x\n", 00121 entryTable, *entryTable_length_p )); 00122 GXV_TRACE(( "ligActionTable: offset=0x%04x length=0x%04x\n", 00123 optdata->ligActionTable, 00124 optdata->ligActionTable_length )); 00125 GXV_TRACE(( "componentTable: offset=0x%04x length=0x%04x\n", 00126 optdata->componentTable, 00127 optdata->componentTable_length )); 00128 GXV_TRACE(( "ligatureTable: offset=0x%04x length=0x%04x\n", 00129 optdata->ligatureTable, 00130 optdata->ligatureTable_length )); 00131 00132 GXV_EXIT; 00133 } 00134 00135 00136 static void 00137 gxv_mort_subtable_type2_ligActionOffset_validate( 00138 FT_Bytes table, 00139 FT_UShort ligActionOffset, 00140 GXV_Validator valid ) 00141 { 00142 /* access ligActionTable */ 00143 GXV_mort_subtable_type2_StateOptRecData optdata = 00144 (GXV_mort_subtable_type2_StateOptRecData)valid->statetable.optdata; 00145 00146 FT_Bytes lat_base = table + optdata->ligActionTable; 00147 FT_Bytes p = table + ligActionOffset; 00148 FT_Bytes lat_limit = lat_base + optdata->ligActionTable; 00149 00150 00151 GXV_32BIT_ALIGNMENT_VALIDATE( ligActionOffset ); 00152 if ( p < lat_base ) 00153 { 00154 GXV_TRACE(( "too short offset 0x%04x: p < lat_base (%d byte rewind)\n", 00155 ligActionOffset, lat_base - p )); 00156 00157 /* FontValidator, ftxvalidator, ftxdumperfuser warn but continue */ 00158 if ( valid->root->level >= FT_VALIDATE_PARANOID ) 00159 FT_INVALID_OFFSET; 00160 } 00161 else if ( lat_limit < p ) 00162 { 00163 GXV_TRACE(( "too large offset 0x%04x: lat_limit < p (%d byte overrun)\n", 00164 ligActionOffset, p - lat_limit )); 00165 00166 /* FontValidator, ftxvalidator, ftxdumperfuser warn but continue */ 00167 if ( valid->root->level >= FT_VALIDATE_PARANOID ) 00168 FT_INVALID_OFFSET; 00169 } 00170 else 00171 { 00172 /* validate entry in ligActionTable */ 00173 FT_ULong lig_action; 00174 FT_UShort last; 00175 FT_UShort store; 00176 FT_ULong offset; 00177 00178 00179 lig_action = FT_NEXT_ULONG( p ); 00180 last = (FT_UShort)( ( lig_action >> 31 ) & 1 ); 00181 store = (FT_UShort)( ( lig_action >> 30 ) & 1 ); 00182 00183 offset = lig_action & 0x3FFFFFFFUL; 00184 } 00185 } 00186 00187 00188 static void 00189 gxv_mort_subtable_type2_entry_validate( 00190 FT_Byte state, 00191 FT_UShort flags, 00192 GXV_StateTable_GlyphOffsetCPtr glyphOffset_p, 00193 FT_Bytes table, 00194 FT_Bytes limit, 00195 GXV_Validator valid ) 00196 { 00197 FT_UShort setComponent; 00198 FT_UShort dontAdvance; 00199 FT_UShort offset; 00200 00201 FT_UNUSED( state ); 00202 FT_UNUSED( glyphOffset_p ); 00203 FT_UNUSED( limit ); 00204 00205 00206 setComponent = (FT_UShort)( ( flags >> 15 ) & 1 ); 00207 dontAdvance = (FT_UShort)( ( flags >> 14 ) & 1 ); 00208 00209 offset = (FT_UShort)( flags & 0x3FFFU ); 00210 00211 if ( 0 < offset ) 00212 gxv_mort_subtable_type2_ligActionOffset_validate( table, offset, 00213 valid ); 00214 } 00215 00216 00217 static void 00218 gxv_mort_subtable_type2_ligatureTable_validate( FT_Bytes table, 00219 GXV_Validator valid ) 00220 { 00221 GXV_mort_subtable_type2_StateOptRecData optdata = 00222 (GXV_mort_subtable_type2_StateOptRecData)valid->statetable.optdata; 00223 00224 FT_Bytes p = table + optdata->ligatureTable; 00225 FT_Bytes limit = table + optdata->ligatureTable 00226 + optdata->ligatureTable_length; 00227 00228 00229 GXV_NAME_ENTER( "mort chain subtable type2 - substitutionTable" ); 00230 if ( 0 != optdata->ligatureTable ) 00231 { 00232 /* Apple does not give specification of ligatureTable format */ 00233 while ( p < limit ) 00234 { 00235 FT_UShort lig_gid; 00236 00237 00238 GXV_LIMIT_CHECK( 2 ); 00239 lig_gid = FT_NEXT_USHORT( p ); 00240 } 00241 } 00242 GXV_EXIT; 00243 } 00244 00245 00246 FT_LOCAL_DEF( void ) 00247 gxv_mort_subtable_type2_validate( FT_Bytes table, 00248 FT_Bytes limit, 00249 GXV_Validator valid ) 00250 { 00251 FT_Bytes p = table; 00252 00253 GXV_mort_subtable_type2_StateOptRec lig_rec; 00254 00255 00256 GXV_NAME_ENTER( "mort chain subtable type2 (Ligature Substitution)" ); 00257 00258 GXV_LIMIT_CHECK( GXV_MORT_SUBTABLE_TYPE2_HEADER_SIZE ); 00259 00260 valid->statetable.optdata = 00261 &lig_rec; 00262 valid->statetable.optdata_load_func = 00263 gxv_mort_subtable_type2_opttable_load; 00264 valid->statetable.subtable_setup_func = 00265 gxv_mort_subtable_type2_subtable_setup; 00266 valid->statetable.entry_glyphoffset_fmt = 00267 GXV_GLYPHOFFSET_NONE; 00268 valid->statetable.entry_validate_func = 00269 gxv_mort_subtable_type2_entry_validate; 00270 00271 gxv_StateTable_validate( p, limit, valid ); 00272 00273 p += valid->subtable_length; 00274 gxv_mort_subtable_type2_ligatureTable_validate( table, valid ); 00275 00276 valid->subtable_length = p - table; 00277 00278 GXV_EXIT; 00279 } 00280 00281 00282 /* END */ Generated on Sat May 26 2012 04:32:44 for ReactOS by
1.7.6.1
|