1 /***************************************************************************/ 2 /* */ 3 /* ftrfork.h */ 4 /* */ 5 /* Embedded resource forks accessor (specification). */ 6 /* */ 7 /* Copyright 2004, 2006, 2007 by */ 8 /* Masatake YAMATO and Redhat K.K. */ 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 /* Development of the code in this file is support of */ 20 /* Information-technology Promotion Agency, Japan. */ 21 /***************************************************************************/ 22 23 24 #ifndef __FTRFORK_H__ 25 #define __FTRFORK_H__ 26 27 28 #include <ft2build.h> 29 #include FT_INTERNAL_OBJECTS_H 30 31 32 FT_BEGIN_HEADER 33 34 35 /* Number of guessing rules supported in `FT_Raccess_Guess'. */ 36 /* Don't forget to increment the number if you add a new guessing rule. */ 37 #define FT_RACCESS_N_RULES 9 38 39 40 /* A structure to describe a reference in a resource by its resource ID */ 41 /* and internal offset. The `POST' resource expects to be concatenated */ 42 /* by the order of resource IDs instead of its appearance in the file. */ 43 44 typedef struct FT_RFork_Ref_ 45 { 46 FT_UShort res_id; 47 FT_ULong offset; 48 49 } FT_RFork_Ref; 50 51 #ifdef FT_CONFIG_OPTION_GUESSING_EMBEDDED_RFORK 52 typedef FT_Error 53 (*ft_raccess_guess_func)( FT_Library library, 54 FT_Stream stream, 55 char *base_file_name, 56 char **result_file_name, 57 FT_Long *result_offset ); 58 59 typedef enum FT_RFork_Rule_ { 60 FT_RFork_Rule_invalid = -2, 61 FT_RFork_Rule_uknown, /* -1 */ 62 FT_RFork_Rule_apple_double, 63 FT_RFork_Rule_apple_single, 64 FT_RFork_Rule_darwin_ufs_export, 65 FT_RFork_Rule_darwin_newvfs, 66 FT_RFork_Rule_darwin_hfsplus, 67 FT_RFork_Rule_vfat, 68 FT_RFork_Rule_linux_cap, 69 FT_RFork_Rule_linux_double, 70 FT_RFork_Rule_linux_netatalk 71 } FT_RFork_Rule; 72 73 /* For fast translation between rule index and rule type, 74 * the macros FT_RFORK_xxx should be kept consistent with 75 * the raccess_guess_funcs table 76 */ 77 typedef struct ft_raccess_guess_rec_ { 78 ft_raccess_guess_func func; 79 FT_RFork_Rule type; 80 } ft_raccess_guess_rec; 81 82 #ifndef FT_CONFIG_OPTION_PIC 83 /* this array is a storage in non-PIC mode, so ; is needed in END */ 84 #define CONST_FT_RFORK_RULE_ARRAY_BEGIN( name, type ) \ 85 const type name[] = { 86 #define CONST_FT_RFORK_RULE_ARRAY_ENTRY( func_suffix, type_suffix ) \ 87 { raccess_guess_##func_suffix, FT_RFork_Rule_##type_suffix }, 88 #define CONST_FT_RFORK_RULE_ARRAY_END }; 89 #else /* FT_CONFIG_OPTION_PIC */ 90 /* this array is a function in PIC mode, so no ; is needed in END */ 91 #define CONST_FT_RFORK_RULE_ARRAY_BEGIN( name, type ) \ 92 void FT_Init_##name ( type* storage ) { \ 93 type *local = storage; \ 94 int i = 0; 95 #define CONST_FT_RFORK_RULE_ARRAY_ENTRY( func_suffix, type_suffix ) \ 96 local[i].func = raccess_guess_##func_suffix; \ 97 local[i].type = FT_RFork_Rule_##type_suffix; \ 98 i++; 99 #define CONST_FT_RFORK_RULE_ARRAY_END } 100 #endif /* FT_CONFIG_OPTION_PIC */ 101 #endif /* FT_CONFIG_OPTION_GUESSING_EMBEDDED_RFORK */ 102 103 /*************************************************************************/ 104 /* */ 105 /* <Function> */ 106 /* FT_Raccess_Guess */ 107 /* */ 108 /* <Description> */ 109 /* Guess a file name and offset where the actual resource fork is */ 110 /* stored. The macro FT_RACCESS_N_RULES holds the number of */ 111 /* guessing rules; the guessed result for the Nth rule is */ 112 /* represented as a triplet: a new file name (new_names[N]), a file */ 113 /* offset (offsets[N]), and an error code (errors[N]). */ 114 /* */ 115 /* <Input> */ 116 /* library :: */ 117 /* A FreeType library instance. */ 118 /* */ 119 /* stream :: */ 120 /* A file stream containing the resource fork. */ 121 /* */ 122 /* base_name :: */ 123 /* The (base) file name of the resource fork used for some */ 124 /* guessing rules. */ 125 /* */ 126 /* <Output> */ 127 /* new_names :: */ 128 /* An array of guessed file names in which the resource forks may */ 129 /* exist. If `new_names[N]' is NULL, the guessed file name is */ 130 /* equal to `base_name'. */ 131 /* */ 132 /* offsets :: */ 133 /* An array of guessed file offsets. `offsets[N]' holds the file */ 134 /* offset of the possible start of the resource fork in file */ 135 /* `new_names[N]'. */ 136 /* */ 137 /* errors :: */ 138 /* An array of FreeType error codes. `errors[N]' is the error */ 139 /* code of Nth guessing rule function. If `errors[N]' is not */ 140 /* FT_Err_Ok, `new_names[N]' and `offsets[N]' are meaningless. */ 141 /* */ 142 FT_BASE( void ) 143 FT_Raccess_Guess( FT_Library library, 144 FT_Stream stream, 145 char* base_name, 146 char** new_names, 147 FT_Long* offsets, 148 FT_Error* errors ); 149 150 151 /*************************************************************************/ 152 /* */ 153 /* <Function> */ 154 /* FT_Raccess_Get_HeaderInfo */ 155 /* */ 156 /* <Description> */ 157 /* Get the information from the header of resource fork. The */ 158 /* information includes the file offset where the resource map */ 159 /* starts, and the file offset where the resource data starts. */ 160 /* `FT_Raccess_Get_DataOffsets' requires these two data. */ 161 /* */ 162 /* <Input> */ 163 /* library :: */ 164 /* A FreeType library instance. */ 165 /* */ 166 /* stream :: */ 167 /* A file stream containing the resource fork. */ 168 /* */ 169 /* rfork_offset :: */ 170 /* The file offset where the resource fork starts. */ 171 /* */ 172 /* <Output> */ 173 /* map_offset :: */ 174 /* The file offset where the resource map starts. */ 175 /* */ 176 /* rdata_pos :: */ 177 /* The file offset where the resource data starts. */ 178 /* */ 179 /* <Return> */ 180 /* FreeType error code. FT_Err_Ok means success. */ 181 /* */ 182 FT_BASE( FT_Error ) 183 FT_Raccess_Get_HeaderInfo( FT_Library library, 184 FT_Stream stream, 185 FT_Long rfork_offset, 186 FT_Long *map_offset, 187 FT_Long *rdata_pos ); 188 189 190 /*************************************************************************/ 191 /* */ 192 /* <Function> */ 193 /* FT_Raccess_Get_DataOffsets */ 194 /* */ 195 /* <Description> */ 196 /* Get the data offsets for a tag in a resource fork. Offsets are */ 197 /* stored in an array because, in some cases, resources in a resource */ 198 /* fork have the same tag. */ 199 /* */ 200 /* <Input> */ 201 /* library :: */ 202 /* A FreeType library instance. */ 203 /* */ 204 /* stream :: */ 205 /* A file stream containing the resource fork. */ 206 /* */ 207 /* map_offset :: */ 208 /* The file offset where the resource map starts. */ 209 /* */ 210 /* rdata_pos :: */ 211 /* The file offset where the resource data starts. */ 212 /* */ 213 /* tag :: */ 214 /* The resource tag. */ 215 /* */ 216 /* <Output> */ 217 /* offsets :: */ 218 /* The stream offsets for the resource data specified by `tag'. */ 219 /* This array is allocated by the function, so you have to call */ 220 /* @ft_mem_free after use. */ 221 /* */ 222 /* count :: */ 223 /* The length of offsets array. */ 224 /* */ 225 /* <Return> */ 226 /* FreeType error code. FT_Err_Ok means success. */ 227 /* */ 228 /* <Note> */ 229 /* Normally you should use `FT_Raccess_Get_HeaderInfo' to get the */ 230 /* value for `map_offset' and `rdata_pos'. */ 231 /* */ 232 FT_BASE( FT_Error ) 233 FT_Raccess_Get_DataOffsets( FT_Library library, 234 FT_Stream stream, 235 FT_Long map_offset, 236 FT_Long rdata_pos, 237 FT_Long tag, 238 FT_Long **offsets, 239 FT_Long *count ); 240 241 242 FT_END_HEADER 243 244 #endif /* __FTRFORK_H__ */ 245 246 247 /* END */ 248