Werner Lemberg | ee95b6f | 2004-09-10 14:39:00 +0000 | [diff] [blame] | 1 | /***************************************************************************/ |
| 2 | /* */ |
| 3 | /* otvmod.c */ |
| 4 | /* */ |
| 5 | /* FreeType's OpenType validation module implementation (body). */ |
| 6 | /* */ |
Werner Lemberg | c9114b9 | 2005-02-10 08:18:27 +0000 | [diff] [blame] | 7 | /* Copyright 2004, 2005 by */ |
Werner Lemberg | ee95b6f | 2004-09-10 14:39:00 +0000 | [diff] [blame] | 8 | /* David Turner, Robert Wilhelm, and Werner Lemberg. */ |
| 9 | /* */ |
| 10 | /* This file is part of the FreeType project, and may only be used, */ |
| 11 | /* modified, and distributed under the terms of the FreeType project */ |
| 12 | /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ |
| 13 | /* this file you indicate that you have read the license and */ |
| 14 | /* understand and accept it fully. */ |
| 15 | /* */ |
| 16 | /***************************************************************************/ |
| 17 | |
| 18 | |
| 19 | #include <ft2build.h> |
| 20 | #include FT_TRUETYPE_TABLES_H |
| 21 | #include FT_TRUETYPE_TAGS_H |
| 22 | #include FT_OPENTYPE_VALIDATE_H |
| 23 | #include FT_INTERNAL_OBJECTS_H |
| 24 | #include FT_SERVICE_OPENTYPE_VALIDATE_H |
| 25 | |
| 26 | #include "otvmod.h" |
| 27 | #include "otvalid.h" |
| 28 | #include "otvcommn.h" |
| 29 | |
| 30 | |
| 31 | /*************************************************************************/ |
| 32 | /* */ |
| 33 | /* The macro FT_COMPONENT is used in trace mode. It is an implicit */ |
| 34 | /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */ |
| 35 | /* messages during execution. */ |
| 36 | /* */ |
| 37 | #undef FT_COMPONENT |
| 38 | #define FT_COMPONENT trace_otvmodule |
| 39 | |
| 40 | |
| 41 | static FT_Error |
| 42 | otv_load_table( FT_Face face, |
| 43 | FT_Tag tag, |
| 44 | FT_Byte* *table, |
| 45 | FT_ULong *table_len ) |
| 46 | { |
| 47 | FT_Error error; |
| 48 | FT_Memory memory = FT_FACE_MEMORY( face ); |
| 49 | |
| 50 | |
| 51 | error = FT_Load_Sfnt_Table( face, tag, 0, NULL, table_len ); |
| 52 | if ( error == OTV_Err_Table_Missing ) |
| 53 | return OTV_Err_Ok; |
| 54 | if ( error ) |
| 55 | goto Exit; |
| 56 | |
| 57 | if ( FT_ALLOC( *table, *table_len ) ) |
| 58 | goto Exit; |
| 59 | |
| 60 | error = FT_Load_Sfnt_Table( face, tag, 0, *table, table_len ); |
| 61 | |
| 62 | Exit: |
| 63 | return error; |
| 64 | } |
| 65 | |
| 66 | |
| 67 | static FT_Error |
| 68 | otv_validate( FT_Face face, |
| 69 | FT_UInt ot_flags, |
| 70 | FT_Bytes *ot_base, |
| 71 | FT_Bytes *ot_gdef, |
| 72 | FT_Bytes *ot_gpos, |
| 73 | FT_Bytes *ot_gsub, |
| 74 | FT_Bytes *ot_jstf ) |
| 75 | { |
| 76 | FT_Error error = OTV_Err_Ok; |
| 77 | FT_Byte *base, *gdef, *gpos, *gsub, *jstf; |
| 78 | FT_ULong len_base, len_gdef, len_gpos, len_gsub, len_jstf; |
| 79 | FT_ValidatorRec valid; |
| 80 | |
| 81 | |
| 82 | base = gdef = gpos = gsub = jstf = NULL; |
| 83 | len_base = len_gdef = len_gpos = len_gsub = len_jstf = 0; |
| 84 | |
| 85 | /* load tables */ |
| 86 | |
| 87 | if ( ot_flags & FT_VALIDATE_BASE ) |
| 88 | { |
| 89 | error = otv_load_table( face, TTAG_BASE, &base, &len_base ); |
| 90 | if ( error ) |
| 91 | goto Exit; |
| 92 | } |
| 93 | |
| 94 | if ( ot_flags & FT_VALIDATE_GDEF ) |
| 95 | { |
| 96 | error = otv_load_table( face, TTAG_GDEF, &gdef, &len_gdef ); |
| 97 | if ( error ) |
| 98 | goto Exit; |
| 99 | } |
| 100 | |
| 101 | if ( ot_flags & FT_VALIDATE_GPOS ) |
| 102 | { |
| 103 | error = otv_load_table( face, TTAG_GPOS, &gpos, &len_gpos ); |
| 104 | if ( error ) |
| 105 | goto Exit; |
| 106 | } |
| 107 | |
| 108 | if ( ot_flags & FT_VALIDATE_GSUB ) |
| 109 | { |
| 110 | error = otv_load_table( face, TTAG_GSUB, &gsub, &len_gsub ); |
| 111 | if ( error ) |
| 112 | goto Exit; |
| 113 | } |
| 114 | |
| 115 | if ( ot_flags & FT_VALIDATE_JSTF ) |
| 116 | { |
| 117 | error = otv_load_table( face, TTAG_JSTF, &jstf, &len_jstf ); |
| 118 | if ( error ) |
| 119 | goto Exit; |
| 120 | } |
| 121 | |
| 122 | /* validate tables */ |
| 123 | |
| 124 | if ( base ) |
| 125 | { |
| 126 | ft_validator_init( &valid, base, base + len_base, FT_VALIDATE_DEFAULT ); |
Werner Lemberg | 53ac64e | 2005-08-20 05:33:09 +0000 | [diff] [blame] | 127 | if ( ft_validator_run( &valid ) == 0 ) |
Werner Lemberg | ee95b6f | 2004-09-10 14:39:00 +0000 | [diff] [blame] | 128 | otv_BASE_validate( base, &valid ); |
| 129 | error = valid.error; |
| 130 | if ( error ) |
| 131 | goto Exit; |
| 132 | } |
| 133 | |
| 134 | if ( gpos ) |
| 135 | { |
| 136 | ft_validator_init( &valid, gpos, gpos + len_gpos, FT_VALIDATE_DEFAULT ); |
Werner Lemberg | 53ac64e | 2005-08-20 05:33:09 +0000 | [diff] [blame] | 137 | if ( ft_validator_run( &valid ) == 0 ) |
Werner Lemberg | ee95b6f | 2004-09-10 14:39:00 +0000 | [diff] [blame] | 138 | otv_GPOS_validate( gpos, face->num_glyphs, &valid ); |
| 139 | error = valid.error; |
| 140 | if ( error ) |
| 141 | goto Exit; |
| 142 | } |
| 143 | |
| 144 | if ( gsub ) |
| 145 | { |
| 146 | ft_validator_init( &valid, gsub, gsub + len_gsub, FT_VALIDATE_DEFAULT ); |
Werner Lemberg | 53ac64e | 2005-08-20 05:33:09 +0000 | [diff] [blame] | 147 | if ( ft_validator_run( &valid ) == 0 ) |
Werner Lemberg | ee95b6f | 2004-09-10 14:39:00 +0000 | [diff] [blame] | 148 | otv_GSUB_validate( gsub, face->num_glyphs, &valid ); |
| 149 | error = valid.error; |
| 150 | if ( error ) |
| 151 | goto Exit; |
| 152 | } |
| 153 | |
| 154 | if ( gdef ) |
| 155 | { |
| 156 | ft_validator_init( &valid, gdef, gdef + len_gdef, FT_VALIDATE_DEFAULT ); |
Werner Lemberg | 53ac64e | 2005-08-20 05:33:09 +0000 | [diff] [blame] | 157 | if ( ft_validator_run( &valid ) == 0 ) |
Werner Lemberg | ee95b6f | 2004-09-10 14:39:00 +0000 | [diff] [blame] | 158 | otv_GDEF_validate( gdef, gsub, gpos, &valid ); |
| 159 | error = valid.error; |
| 160 | if ( error ) |
| 161 | goto Exit; |
| 162 | } |
| 163 | |
| 164 | if ( jstf ) |
| 165 | { |
| 166 | ft_validator_init( &valid, jstf, jstf + len_jstf, FT_VALIDATE_DEFAULT ); |
Werner Lemberg | 53ac64e | 2005-08-20 05:33:09 +0000 | [diff] [blame] | 167 | if ( ft_validator_run( &valid ) == 0 ) |
Werner Lemberg | ee95b6f | 2004-09-10 14:39:00 +0000 | [diff] [blame] | 168 | otv_JSTF_validate( jstf, gsub, gpos, face->num_glyphs, &valid ); |
| 169 | error = valid.error; |
| 170 | if ( error ) |
| 171 | goto Exit; |
| 172 | } |
| 173 | |
| 174 | *ot_base = (FT_Bytes)base; |
| 175 | *ot_gdef = (FT_Bytes)gdef; |
| 176 | *ot_gpos = (FT_Bytes)gpos; |
| 177 | *ot_gsub = (FT_Bytes)gsub; |
| 178 | *ot_jstf = (FT_Bytes)jstf; |
| 179 | |
| 180 | Exit: |
Werner Lemberg | c9114b9 | 2005-02-10 08:18:27 +0000 | [diff] [blame] | 181 | if ( error ) { |
| 182 | FT_Memory memory = FT_FACE_MEMORY( face ); |
| 183 | |
| 184 | |
| 185 | FT_FREE( base ); |
| 186 | FT_FREE( gdef ); |
| 187 | FT_FREE( gpos ); |
| 188 | FT_FREE( gsub ); |
| 189 | FT_FREE( jstf ); |
| 190 | } |
| 191 | |
Werner Lemberg | ee95b6f | 2004-09-10 14:39:00 +0000 | [diff] [blame] | 192 | return error; |
| 193 | } |
| 194 | |
| 195 | |
| 196 | static |
| 197 | const FT_Service_OTvalidateRec otvalid_interface = |
| 198 | { |
| 199 | otv_validate |
| 200 | }; |
| 201 | |
| 202 | |
| 203 | static |
| 204 | const FT_ServiceDescRec otvalid_services[] = |
| 205 | { |
| 206 | { FT_SERVICE_ID_OPENTYPE_VALIDATE, &otvalid_interface }, |
| 207 | { NULL, NULL } |
| 208 | }; |
| 209 | |
| 210 | |
| 211 | static FT_Pointer |
| 212 | otvalid_get_service( FT_Module module, |
| 213 | const char* service_id ) |
| 214 | { |
| 215 | FT_UNUSED( module ); |
| 216 | |
| 217 | return ft_service_list_lookup( otvalid_services, service_id ); |
| 218 | } |
| 219 | |
| 220 | |
| 221 | FT_CALLBACK_TABLE_DEF |
| 222 | const FT_Module_Class otv_module_class = |
| 223 | { |
| 224 | 0, |
| 225 | sizeof( FT_ModuleRec ), |
| 226 | "otvalid", |
| 227 | 0x10000L, |
| 228 | 0x20000L, |
| 229 | |
| 230 | 0, /* module-specific interface */ |
| 231 | |
| 232 | (FT_Module_Constructor)0, |
| 233 | (FT_Module_Destructor) 0, |
| 234 | (FT_Module_Requester) otvalid_get_service |
| 235 | }; |
| 236 | |
| 237 | |
| 238 | /* END */ |