ReactOS 0.4.15-dev-7788-g1ad9096
ftrfork.h File Reference
#include <ft2build.h>
Include dependency graph for ftrfork.h:

Go to the source code of this file.

Classes

struct  FT_RFork_Ref_
 

Macros

#define FT_RACCESS_N_RULES   9
 

Typedefs

typedef struct FT_RFork_Ref_ FT_RFork_Ref
 

Functions

 FT_Raccess_Guess (FT_Library library, FT_Stream stream, char *base_name, char **new_names, FT_Long *offsets, FT_Error *errors)
 
 FT_Raccess_Get_HeaderInfo (FT_Library library, FT_Stream stream, FT_Long rfork_offset, FT_Long *map_offset, FT_Long *rdata_pos)
 
 FT_Raccess_Get_DataOffsets (FT_Library library, FT_Stream stream, FT_Long map_offset, FT_Long rdata_pos, FT_Long tag, FT_Bool sort_by_res_id, FT_Long **offsets, FT_Long *count)
 

Macro Definition Documentation

◆ FT_RACCESS_N_RULES

#define FT_RACCESS_N_RULES   9

Definition at line 37 of file ftrfork.h.

Typedef Documentation

◆ FT_RFork_Ref

Function Documentation

◆ FT_Raccess_Get_DataOffsets()

FT_Raccess_Get_DataOffsets ( FT_Library  library,
FT_Stream  stream,
FT_Long  map_offset,
FT_Long  rdata_pos,
FT_Long  tag,
FT_Bool  sort_by_res_id,
FT_Long **  offsets,
FT_Long count 
)

Definition at line 185 of file ftrfork.c.

193 {
195 int i, j, cnt, subcnt;
196 FT_Long tag_internal, rpos;
199 FT_Long *offsets_internal = NULL;
201
202
203 FT_TRACE3(( "\n" ));
204 error = FT_Stream_Seek( stream, (FT_ULong)map_offset );
205 if ( error )
206 return error;
207
208 if ( FT_READ_SHORT( cnt ) )
209 return error;
210 cnt++;
211
212 /* `rpos' is a signed 16bit integer offset to resource records; the */
213 /* size of a resource record is 12 bytes. The map header is 28 bytes, */
214 /* and a type list needs 10 bytes or more. If we assume that the name */
215 /* list is empty and we have only a single entry in the type list, */
216 /* there can be at most */
217 /* */
218 /* (32768 - 28 - 10) / 12 = 2727 */
219 /* */
220 /* resources. */
221 /* */
222 /* A type list starts with a two-byte counter, followed by 10-byte */
223 /* type records. Assuming that there are no resources, the number of */
224 /* type records can be at most */
225 /* */
226 /* (32768 - 28 - 2) / 8 = 4079 */
227 /* */
228 if ( cnt > 4079 )
229 return FT_THROW( Invalid_Table );
230
231 for ( i = 0; i < cnt; i++ )
232 {
233 if ( FT_READ_LONG( tag_internal ) ||
234 FT_READ_SHORT( subcnt ) ||
235 FT_READ_SHORT( rpos ) )
236 return error;
237
238 FT_TRACE2(( "Resource tags: %c%c%c%c\n",
239 (char)( 0xFF & ( tag_internal >> 24 ) ),
240 (char)( 0xFF & ( tag_internal >> 16 ) ),
241 (char)( 0xFF & ( tag_internal >> 8 ) ),
242 (char)( 0xFF & ( tag_internal >> 0 ) ) ));
243 FT_TRACE3(( " : subcount=%d, suboffset=0x%04x\n",
244 subcnt, rpos ));
245
246 if ( tag_internal == tag )
247 {
248 *count = subcnt + 1;
249 rpos += map_offset;
250
251 /* a zero count might be valid in the resource specification, */
252 /* however, it is completely useless to us */
253 if ( *count < 1 || *count > 2727 )
254 return FT_THROW( Invalid_Table );
255
257 if ( error )
258 return error;
259
260 if ( FT_NEW_ARRAY( ref, *count ) )
261 return error;
262
263 for ( j = 0; j < *count; j++ )
264 {
265 if ( FT_READ_SHORT( ref[j].res_id ) )
266 goto Exit;
267 if ( FT_STREAM_SKIP( 2 ) ) /* resource name offset */
268 goto Exit;
269 if ( FT_READ_LONG( temp ) ) /* attributes (8bit), offset (24bit) */
270 goto Exit;
271 if ( FT_STREAM_SKIP( 4 ) ) /* mbz */
272 goto Exit;
273
274 /*
275 * According to Inside Macintosh: More Macintosh Toolbox,
276 * "Resource IDs" (1-46), there are some reserved IDs.
277 * However, FreeType2 is not a font synthesizer, no need
278 * to check the acceptable resource ID.
279 */
280 if ( temp < 0 )
281 {
282 error = FT_THROW( Invalid_Table );
283 goto Exit;
284 }
285
286 ref[j].offset = temp & 0xFFFFFFL;
287
288 FT_TRACE3(( " [%d]:"
289 " resource_id=0x%04x, offset=0x%08x\n",
290 j, (FT_UShort)ref[j].res_id, ref[j].offset ));
291 }
292
293 if ( sort_by_res_id )
294 {
295 ft_qsort( ref,
296 (size_t)*count,
297 sizeof ( FT_RFork_Ref ),
298 ( int(*)(const void*,
299 const void*) )ft_raccess_sort_ref_by_id );
300
301 FT_TRACE3(( " -- sort resources by their ids --\n" ));
302
303 for ( j = 0; j < *count; j++ )
304 FT_TRACE3(( " [%d]:"
305 " resource_id=0x%04x, offset=0x%08x\n",
306 j, ref[j].res_id, ref[j].offset ));
307 }
308
309 if ( FT_NEW_ARRAY( offsets_internal, *count ) )
310 goto Exit;
311
312 /* XXX: duplicated reference ID,
313 * gap between reference IDs are acceptable?
314 * further investigation on Apple implementation is needed.
315 */
316 for ( j = 0; j < *count; j++ )
317 offsets_internal[j] = rdata_pos + ref[j].offset;
318
319 *offsets = offsets_internal;
321
322 Exit:
323 FT_FREE( ref );
324 return error;
325 }
326 }
327
328 return FT_THROW( Cannot_Open_Resource );
329 }
FT_Library library
Definition: cffdrivr.c:654
#define NULL
Definition: types.h:112
return FT_Err_Ok
Definition: ftbbox.c:511
#define FT_TRACE3(varformat)
Definition: ftdebug.h:160
#define FT_THROW(e)
Definition: ftdebug.h:213
#define FT_TRACE2(varformat)
Definition: ftdebug.h:159
#define FT_NEW_ARRAY(ptr, count)
Definition: ftmemory.h:333
#define FT_FREE(ptr)
Definition: ftmemory.h:329
static int ft_raccess_sort_ref_by_id(FT_RFork_Ref *a, FT_RFork_Ref *b)
Definition: ftrfork.c:172
#define ft_qsort
Definition: ftstdlib.h:122
#define FT_READ_LONG(var)
Definition: ftstream.h:312
#define FT_STREAM_SKIP(distance)
Definition: ftstream.h:493
FT_Stream_Seek(FT_Stream stream, FT_ULong pos)
Definition: ftstream.c:57
#define FT_READ_SHORT(var)
Definition: ftstream.h:308
typedefFT_BEGIN_HEADER struct FT_MemoryRec_ * FT_Memory
Definition: ftsystem.h:66
unsigned long FT_ULong
Definition: fttypes.h:253
int FT_Error
Definition: fttypes.h:300
signed long FT_Long
Definition: fttypes.h:242
unsigned short FT_UShort
Definition: fttypes.h:209
static const FxOffsetAndName offsets[]
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLintptr offset
Definition: glext.h:5920
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
#define error(str)
Definition: mkdosfs.c:1605
static char memory[1024 *256]
Definition: process.c:116
static calc_node_t temp
Definition: rpn_ieee.c:38
static void Exit(void)
Definition: sock.c:1330
FT_Memory memory
Definition: ftobjs.h:918
Definition: send.c:48
Definition: parse.h:23
Definition: ecma_167.h:138

◆ FT_Raccess_Get_HeaderInfo()

FT_Raccess_Get_HeaderInfo ( FT_Library  library,
FT_Stream  stream,
FT_Long  rfork_offset,
FT_Long map_offset,
FT_Long rdata_pos 
)

Definition at line 51 of file ftrfork.c.

56 {
58 unsigned char head[16], head2[16];
59 FT_Long map_pos, map_len, rdata_len;
60 int allzeros, allmatch, i;
61 FT_Long type_list;
62
64
65
66 error = FT_Stream_Seek( stream, (FT_ULong)rfork_offset );
67 if ( error )
68 return error;
69
71 if ( error )
72 return error;
73
74 /* ensure positive values */
75 if ( head[0] >= 0x80 ||
76 head[4] >= 0x80 ||
77 head[8] >= 0x80 ||
78 head[12] >= 0x80 )
79 return FT_THROW( Unknown_File_Format );
80
81 *rdata_pos = ( head[ 0] << 24 ) |
82 ( head[ 1] << 16 ) |
83 ( head[ 2] << 8 ) |
84 head[ 3];
85 map_pos = ( head[ 4] << 24 ) |
86 ( head[ 5] << 16 ) |
87 ( head[ 6] << 8 ) |
88 head[ 7];
89 rdata_len = ( head[ 8] << 24 ) |
90 ( head[ 9] << 16 ) |
91 ( head[10] << 8 ) |
92 head[11];
93 map_len = ( head[12] << 24 ) |
94 ( head[13] << 16 ) |
95 ( head[14] << 8 ) |
96 head[15];
97
98 /* the map must not be empty */
99 if ( !map_pos )
100 return FT_THROW( Unknown_File_Format );
101
102 /* check whether rdata and map overlap */
103 if ( *rdata_pos < map_pos )
104 {
105 if ( *rdata_pos > map_pos - rdata_len )
106 return FT_THROW( Unknown_File_Format );
107 }
108 else
109 {
110 if ( map_pos > *rdata_pos - map_len )
111 return FT_THROW( Unknown_File_Format );
112 }
113
114 /* check whether end of rdata or map exceeds stream size */
115 if ( FT_LONG_MAX - rdata_len < *rdata_pos ||
116 FT_LONG_MAX - map_len < map_pos ||
117
118 FT_LONG_MAX - ( *rdata_pos + rdata_len ) < rfork_offset ||
119 FT_LONG_MAX - ( map_pos + map_len ) < rfork_offset ||
120
121 (FT_ULong)( rfork_offset + *rdata_pos + rdata_len ) > stream->size ||
122 (FT_ULong)( rfork_offset + map_pos + map_len ) > stream->size )
123 return FT_THROW( Unknown_File_Format );
124
125 *rdata_pos += rfork_offset;
126 map_pos += rfork_offset;
127
128 error = FT_Stream_Seek( stream, (FT_ULong)map_pos );
129 if ( error )
130 return error;
131
132 head2[15] = (FT_Byte)( head[15] + 1 ); /* make it be different */
133
134 error = FT_Stream_Read( stream, (FT_Byte*)head2, 16 );
135 if ( error )
136 return error;
137
138 allzeros = 1;
139 allmatch = 1;
140 for ( i = 0; i < 16; i++ )
141 {
142 if ( head2[i] != 0 )
143 allzeros = 0;
144 if ( head2[i] != head[i] )
145 allmatch = 0;
146 }
147 if ( !allzeros && !allmatch )
148 return FT_THROW( Unknown_File_Format );
149
150 /* If we have reached this point then it is probably a mac resource */
151 /* file. Now, does it contain any interesting resources? */
152
153 (void)FT_STREAM_SKIP( 4 /* skip handle to next resource map */
154 + 2 /* skip file resource number */
155 + 2 ); /* skip attributes */
156
157 if ( FT_READ_SHORT( type_list ) )
158 return error;
159 if ( type_list < 0 )
160 return FT_THROW( Unknown_File_Format );
161
162 error = FT_Stream_Seek( stream, (FT_ULong)( map_pos + type_list ) );
163 if ( error )
164 return error;
165
166 *map_offset = map_pos + type_list;
167 return FT_Err_Ok;
168 }
struct outqueuenode * head
Definition: adnsresfilter.c:66
#define FT_UNUSED(arg)
Definition: ftconfig.h:101
#define FT_LONG_MAX
Definition: ftstdlib.h:67
FT_Stream_Read(FT_Stream stream, FT_Byte *buffer, FT_ULong count)
Definition: ftstream.c:110
unsigned char FT_Byte
Definition: fttypes.h:154
unsigned int size
Definition: parse.h:27

◆ FT_Raccess_Guess()

FT_Raccess_Guess ( FT_Library  library,
FT_Stream  stream,
char base_name,
char **  new_names,
FT_Long offsets,
FT_Error errors 
)

Definition at line 917 of file ftrfork.c.

923 {
924 FT_Int i;
925
927 FT_UNUSED( stream );
928 FT_UNUSED( base_name );
929
930
931 for ( i = 0; i < FT_RACCESS_N_RULES; i++ )
932 {
933 new_names[i] = NULL;
934 offsets[i] = 0;
935 errors[i] = FT_ERR( Unimplemented_Feature );
936 }
937 }
#define FT_RACCESS_N_RULES
Definition: ftrfork.h:37
#define FT_ERR(e)
Definition: fttypes.h:586
signed int FT_Int
Definition: fttypes.h:220