1 /****************************************************************************
5 * Embedded resource forks accessor (specification).
7 * Copyright (C) 2004-2020 by
8 * Masatake YAMATO and Redhat K.K.
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.
18 /****************************************************************************
19 * Development of the code in this file is support of
20 * Information-technology Promotion Agency, Japan.
28 #include <freetype/internal/ftobjs.h>
34 /* Number of guessing rules supported in `FT_Raccess_Guess'. */
35 /* Don't forget to increment the number if you add a new guessing rule. */
36 #define FT_RACCESS_N_RULES 9
39 /* A structure to describe a reference in a resource by its resource ID */
40 /* and internal offset. The `POST' resource expects to be concatenated */
41 /* by the order of resource IDs instead of its appearance in the file. */
43 typedef struct FT_RFork_Ref_
51 #ifdef FT_CONFIG_OPTION_GUESSING_EMBEDDED_RFORK
53 (*ft_raccess_guess_func)( FT_Library library,
56 char **result_file_name,
57 FT_Long *result_offset );
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,
68 FT_RFork_Rule_linux_cap,
69 FT_RFork_Rule_linux_double,
70 FT_RFork_Rule_linux_netatalk
73 /* For fast translation between rule index and rule type,
74 * the macros FT_RFORK_xxx should be kept consistent with the
75 * raccess_guess_funcs table
77 typedef struct ft_raccess_guess_rec_ {
78 ft_raccess_guess_func func;
80 } ft_raccess_guess_rec;
83 #define CONST_FT_RFORK_RULE_ARRAY_BEGIN( name, type ) \
84 static const type name[] = {
85 #define CONST_FT_RFORK_RULE_ARRAY_ENTRY( func_suffix, type_suffix ) \
86 { raccess_guess_ ## func_suffix, \
87 FT_RFork_Rule_ ## type_suffix },
88 /* this array is a storage, thus a final `;' is needed */
89 #define CONST_FT_RFORK_RULE_ARRAY_END };
91 #endif /* FT_CONFIG_OPTION_GUESSING_EMBEDDED_RFORK */
94 /**************************************************************************
100 * Guess a file name and offset where the actual resource fork is stored.
101 * The macro FT_RACCESS_N_RULES holds the number of guessing rules; the
102 * guessed result for the Nth rule is represented as a triplet: a new
103 * file name (new_names[N]), a file offset (offsets[N]), and an error
108 * A FreeType library instance.
111 * A file stream containing the resource fork.
114 * The (base) file name of the resource fork used for some guessing
119 * An array of guessed file names in which the resource forks may
120 * exist. If 'new_names[N]' is `NULL`, the guessed file name is equal
124 * An array of guessed file offsets. 'offsets[N]' holds the file
125 * offset of the possible start of the resource fork in file
129 * An array of FreeType error codes. 'errors[N]' is the error code of
130 * Nth guessing rule function. If 'errors[N]' is not FT_Err_Ok,
131 * 'new_names[N]' and 'offsets[N]' are meaningless.
134 FT_Raccess_Guess( FT_Library library,
142 /**************************************************************************
145 * FT_Raccess_Get_HeaderInfo
148 * Get the information from the header of resource fork. The information
149 * includes the file offset where the resource map starts, and the file
150 * offset where the resource data starts. `FT_Raccess_Get_DataOffsets`
151 * requires these two data.
155 * A FreeType library instance.
158 * A file stream containing the resource fork.
161 * The file offset where the resource fork starts.
165 * The file offset where the resource map starts.
168 * The file offset where the resource data starts.
171 * FreeType error code. FT_Err_Ok means success.
174 FT_Raccess_Get_HeaderInfo( FT_Library library,
176 FT_Long rfork_offset,
178 FT_Long *rdata_pos );
181 /**************************************************************************
184 * FT_Raccess_Get_DataOffsets
187 * Get the data offsets for a tag in a resource fork. Offsets are stored
188 * in an array because, in some cases, resources in a resource fork have
193 * A FreeType library instance.
196 * A file stream containing the resource fork.
199 * The file offset where the resource map starts.
202 * The file offset where the resource data starts.
208 * A Boolean to sort the fragmented resource by their ids. The
209 * fragmented resources for 'POST' resource should be sorted to restore
210 * Type1 font properly. For 'sfnt' resources, sorting may induce a
211 * different order of the faces in comparison to that by QuickDraw API.
215 * The stream offsets for the resource data specified by 'tag'. This
216 * array is allocated by the function, so you have to call @ft_mem_free
220 * The length of offsets array.
223 * FreeType error code. FT_Err_Ok means success.
226 * Normally you should use `FT_Raccess_Get_HeaderInfo` to get the value
227 * for `map_offset` and `rdata_pos`.
230 FT_Raccess_Get_DataOffsets( FT_Library library,
235 FT_Bool sort_by_res_id,
242 #endif /* FTRFORK_H_ */