]> git.saurik.com Git - wxWidgets.git/blob - src/freetype/freetype/internal/ftstream.h
Added a couple more numeric character references
[wxWidgets.git] / src / freetype / freetype / internal / ftstream.h
1 /***************************************************************************/
2 /* */
3 /* ftstream.h */
4 /* */
5 /* Stream handling(specification). */
6 /* */
7 /* Copyright 1996-2000 by */
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 #ifndef FTSTREAM_H
20 #define FTSTREAM_H
21
22 #include <freetype/internal/ftobjs.h>
23
24
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28
29
30 /* format of an 8-bit frame_op value = [ xxxxx | e | s ] */
31 /* s is set to 1 if the value is signed, */
32 /* e is set to 1 if the value is little-endian */
33 /* xxxxx is a command */
34
35 #define FT_FRAME_OP_SHIFT 2
36 #define FT_FRAME_OP_SIGNED 1
37 #define FT_FRAME_OP_LITTLE 2
38 #define FT_FRAME_OP_COMMAND( x ) ( x >> FT_FRAME_OP_SHIFT )
39
40 #define FT_MAKE_FRAME_OP( command, little, sign ) \
41 ( ( command << FT_FRAME_OP_SHIFT ) | ( little << 1 ) | sign )
42
43 #define FT_FRAME_OP_END 0
44 #define FT_FRAME_OP_START 1 /* start a new frame */
45 #define FT_FRAME_OP_BYTE 2 /* read 1-byte value */
46 #define FT_FRAME_OP_SHORT 3 /* read 2-byte value */
47 #define FT_FRAME_OP_LONG 4 /* read 4-byte value */
48 #define FT_FRAME_OP_OFF3 5 /* read 3-byte value */
49 #define FT_FRAME_OP_BYTES 6 /* read a bytes sequence */
50
51
52 typedef enum FT_Frame_Op_
53 {
54 ft_frame_end = 0,
55 ft_frame_start = FT_MAKE_FRAME_OP( FT_FRAME_OP_START, 0, 0 ),
56
57 ft_frame_byte = FT_MAKE_FRAME_OP( FT_FRAME_OP_BYTE, 0, 0 ),
58 ft_frame_schar = FT_MAKE_FRAME_OP( FT_FRAME_OP_BYTE, 0, 1 ),
59
60 ft_frame_ushort_be = FT_MAKE_FRAME_OP( FT_FRAME_OP_SHORT, 0, 0 ),
61 ft_frame_short_be = FT_MAKE_FRAME_OP( FT_FRAME_OP_SHORT, 0, 1 ),
62 ft_frame_ushort_le = FT_MAKE_FRAME_OP( FT_FRAME_OP_SHORT, 1, 0 ),
63 ft_frame_short_le = FT_MAKE_FRAME_OP( FT_FRAME_OP_SHORT, 1, 1 ),
64
65 ft_frame_ulong_be = FT_MAKE_FRAME_OP( FT_FRAME_OP_LONG, 0, 0 ),
66 ft_frame_ulong_le = FT_MAKE_FRAME_OP( FT_FRAME_OP_LONG, 0, 1 ),
67 ft_frame_long_be = FT_MAKE_FRAME_OP( FT_FRAME_OP_LONG, 1, 0 ),
68 ft_frame_long_le = FT_MAKE_FRAME_OP( FT_FRAME_OP_LONG, 1, 1 ),
69
70 ft_frame_uoff3_be = FT_MAKE_FRAME_OP( FT_FRAME_OP_OFF3, 0, 0 ),
71 ft_frame_uoff3_le = FT_MAKE_FRAME_OP( FT_FRAME_OP_OFF3, 0, 1 ),
72 ft_frame_off3_be = FT_MAKE_FRAME_OP( FT_FRAME_OP_OFF3, 1, 0 ),
73 ft_frame_off3_le = FT_MAKE_FRAME_OP( FT_FRAME_OP_OFF3, 1, 1 ),
74
75 ft_frame_bytes = FT_MAKE_FRAME_OP( FT_FRAME_OP_BYTES, 0, 0 ),
76 ft_frame_skip = FT_MAKE_FRAME_OP( FT_FRAME_OP_BYTES, 0, 1 )
77
78 } FT_Frame_Op;
79
80
81 typedef struct FT_Frame_Field_
82 {
83 FT_Frame_Op value;
84 char size;
85 FT_UShort offset;
86
87 } FT_Frame_Field;
88
89
90 /* make-up a FT_Frame_Field out of a structure type and a field name */
91 #define FT_FIELD_REF( s, f ) (((s*)0)->f)
92
93 #define FT_FRAME_FIELD( frame_op, struct_type, field ) \
94 { \
95 frame_op, \
96 sizeof ( FT_FIELD_REF( struct_type,field ) ), \
97 (FT_UShort)(char*)&FT_FIELD_REF( struct_type, field ) \
98 }
99
100 #define FT_MAKE_EMPTY_FIELD( frame_op ) { frame_op, 0, 0 }
101
102 #define FT_FRAME_START( s ) { ft_frame_start, 0, s }
103 #define FT_FRAME_END { ft_frame_end, 0, 0 }
104
105 #define FT_FRAME_LONG( s, f ) FT_FRAME_FIELD( ft_frame_long_be, s, f )
106 #define FT_FRAME_ULONG( s, f ) FT_FRAME_FIELD( ft_frame_ulong_be, s, f )
107 #define FT_FRAME_SHORT( s, f ) FT_FRAME_FIELD( ft_frame_short_be, s, f )
108 #define FT_FRAME_USHORT( s, f ) FT_FRAME_FIELD( ft_frame_ushort_be, s, f )
109 #define FT_FRAME_BYTE( s, f ) FT_FRAME_FIELD( ft_frame_byte, s, f )
110 #define FT_FRAME_CHAR( s, f ) FT_FRAME_FIELD( ft_frame_schar, s, f )
111
112 #define FT_FRAME_LONG_LE( s, f ) FT_FRAME_FIELD( ft_frame_long_le, s, f )
113 #define FT_FRAME_ULONG_LE( s, f ) FT_FRAME_FIELD( ft_frame_ulong_le, s, f )
114 #define FT_FRAME_SHORT_LE( s, f ) FT_FRAME_FIELD( ft_frame_short_le, s, f )
115 #define FT_FRAME_USHORT_LE( s, f ) FT_FRAME_FIELD( ft_frame_ushort_le, s, f )
116
117 #define FT_FRAME_SKIP_LONG { ft_frame_long_be, 0, 0 }
118 #define FT_FRAME_SKIP_SHORT { ft_frame_short_be, 0, 0 }
119 #define FT_FRAME_SKIP_BYTE { ft_frame_byte, 0, 0 }
120
121 #define FT_FRAME_BYTES( struct_type, field, count ) \
122 { \
123 ft_frame_bytes, \
124 count, \
125 (FT_UShort)(char*)&FT_FIELD_REF( struct_type, field ) \
126 }
127 #define FT_FRAME_SKIP_BYTES( count ) { ft_frame_skip, count, 0 }
128
129
130
131 /*************************************************************************/
132 /* */
133 /* integer extraction macros -- the `buffer' parameter must ALWAYS be of */
134 /* type `char*' or equivalent (1-byte elements). */
135 /* */
136 #define NEXT_Char( buffer ) \
137 ( (signed char)*buffer++ )
138 #define NEXT_Byte( buffer ) \
139 ( (unsigned char)*buffer++ )
140
141 #define NEXT_Short( buffer ) \
142 ( buffer += 2, \
143 ( (short)( (signed char)buffer[-2] << 8 ) | \
144 (unsigned char)buffer[-1] ) )
145
146 #define NEXT_UShort( buffer ) \
147 ( (unsigned short)NEXT_Short( buffer ) )
148
149 #define NEXT_Offset( buffer ) \
150 ( buffer += 3, \
151 ( ( (long)(signed char)buffer[-3] << 16 ) | \
152 ( (long)(unsigned char)buffer[-2] << 8 ) | \
153 (long)(unsigned char)buffer[-1] ) )
154
155 #define NEXT_UOffset( buffer ) \
156 ( (unsigned long)NEXT_Offset( buffer ) )
157
158 #define NEXT_Long( buffer ) \
159 ( buffer += 4, \
160 ( ( (long)(signed char)buffer[-4] << 24 ) | \
161 ( (long)(unsigned char)buffer[-3] << 16 ) | \
162 ( (long)(unsigned char)buffer[-2] << 8 ) | \
163 (long)(unsigned char)buffer[-1] ) )
164
165 #define NEXT_ULong( buffer ) \
166 ( (unsigned long)NEXT_Long( buffer ) )
167
168
169 #define NEXT_ShortLE( buffer ) \
170 ( buffer += 2, \
171 ( (short)( (signed char)buffer[-1] << 8 ) | \
172 (unsigned char)buffer[-2] ) )
173
174 #define NEXT_UShortLE( buffer ) \
175 ( (unsigned short)NEXT_ShortLE( buffer ) )
176
177 #define NEXT_OffsetLE( buffer ) \
178 ( buffer += 3, \
179 ( ( (long)(signed char)buffer[-1] << 16 ) | \
180 ( (long)(unsigned char)buffer[-2] << 8 ) | \
181 (long)(unsigned char)buffer[-3] ) )
182
183 #define NEXT_UOffsetLE( buffer ) \
184 ( (unsigned long)NEXT_OffsetLE( buffer ) )
185
186
187 #define NEXT_LongLE( buffer ) \
188 ( buffer += 4, \
189 ( ( (long)(signed char)buffer[-1] << 24 ) | \
190 ( (long)(unsigned char)buffer[-2] << 16 ) | \
191 ( (long)(unsigned char)buffer[-3] << 8 ) | \
192 (long)(unsigned char)buffer[-4] ) )
193
194 #define NEXT_ULongLE( buffer ) \
195 ( (unsigned long)NEXT_LongLE( buffer ) )
196
197
198 /*************************************************************************/
199 /* */
200 /* Each GET_xxxx() macro uses an implicit `stream' variable. */
201 /* */
202 #define FT_GET_MACRO( func, type ) ( (type)func( stream ) )
203
204 #define GET_Char() FT_GET_MACRO( FT_Get_Char, FT_Char )
205 #define GET_Byte() FT_GET_MACRO( FT_Get_Char, FT_Byte )
206 #define GET_Short() FT_GET_MACRO( FT_Get_Short, FT_Short )
207 #define GET_UShort() FT_GET_MACRO( FT_Get_Short, FT_UShort )
208 #define GET_Offset() FT_GET_MACRO( FT_Get_Offset, FT_Long )
209 #define GET_UOffset() FT_GET_MACRO( FT_Get_Offset, FT_ULong )
210 #define GET_Long() FT_GET_MACRO( FT_Get_Long, FT_Long )
211 #define GET_ULong() FT_GET_MACRO( FT_Get_Long, FT_ULong )
212 #define GET_Tag4() FT_GET_MACRO( FT_Get_Long, FT_ULong )
213
214 #define GET_ShortLE() FT_GET_MACRO( FT_Get_ShortLE, FT_Short )
215 #define GET_UShortLE() FT_GET_MACRO( FT_Get_ShortLE, FT_UShort )
216 #define GET_LongLE() FT_GET_MACRO( FT_Get_LongLE, FT_Short )
217 #define GET_ULongLE() FT_GET_MACRO( FT_Get_LongLE, FT_Short )
218
219 #define FT_READ_MACRO( func, type, var ) \
220 ( var = (type)func( stream, &error ), \
221 error != FT_Err_Ok )
222
223 #define READ_Byte( var ) FT_READ_MACRO( FT_Read_Char, FT_Byte, var )
224 #define READ_Char( var ) FT_READ_MACRO( FT_Read_Char, FT_Char, var )
225 #define READ_Short( var ) FT_READ_MACRO( FT_Read_Short, FT_Short, var )
226 #define READ_UShort( var ) FT_READ_MACRO( FT_Read_Short, FT_UShort, var )
227 #define READ_Offset( var ) FT_READ_MACRO( FT_Read_Offset, FT_Long, var )
228 #define READ_UOffset( var ) FT_READ_MACRO( FT_Read_Offset, FT_ULong, var )
229 #define READ_Long( var ) FT_READ_MACRO( FT_Read_Long, FT_Long, var )
230 #define READ_ULong( var ) FT_READ_MACRO( FT_Read_Long, FT_ULong, var )
231
232 #define READ_ShortLE( var ) FT_READ_MACRO( FT_Read_ShortLE, FT_Short, var )
233 #define READ_UShortLE( var ) FT_READ_MACRO( FT_Read_ShortLE, FT_UShort, var )
234 #define READ_LongLE( var ) FT_READ_MACRO( FT_Read_LongLE, FT_Long, var )
235 #define READ_ULongLE( var ) FT_READ_MACRO( FT_Read_LongLE, FT_ULong, var )
236
237
238 BASE_DEF( void ) FT_New_Memory_Stream( FT_Library library,
239 FT_Byte* base,
240 FT_ULong size,
241 FT_Stream stream );
242
243 BASE_DEF( FT_Error ) FT_Seek_Stream( FT_Stream stream,
244 FT_ULong pos );
245
246 BASE_DEF( FT_Error ) FT_Skip_Stream( FT_Stream stream,
247 FT_Long distance );
248
249 BASE_DEF( FT_Long ) FT_Stream_Pos( FT_Stream stream );
250
251
252 BASE_DEF( FT_Error ) FT_Read_Stream( FT_Stream stream,
253 FT_Byte* buffer,
254 FT_ULong count );
255
256 BASE_DEF( FT_Error ) FT_Read_Stream_At( FT_Stream stream,
257 FT_ULong pos,
258 FT_Byte* buffer,
259 FT_ULong count );
260
261 BASE_DEF( FT_Error ) FT_Access_Frame( FT_Stream stream,
262 FT_ULong count );
263
264 BASE_DEF( void ) FT_Forget_Frame( FT_Stream stream );
265
266 BASE_DEF( FT_Error ) FT_Extract_Frame( FT_Stream stream,
267 FT_ULong count,
268 FT_Byte** pbytes );
269
270 BASE_DEF( void ) FT_Release_Frame( FT_Stream stream,
271 FT_Byte** pbytes );
272
273 BASE_DEF( FT_Char ) FT_Get_Char( FT_Stream stream );
274
275 BASE_DEF( FT_Short ) FT_Get_Short( FT_Stream stream );
276
277 BASE_DEF( FT_Long ) FT_Get_Offset( FT_Stream stream );
278
279 BASE_DEF( FT_Long ) FT_Get_Long( FT_Stream stream );
280
281 BASE_DEF( FT_Short ) FT_Get_ShortLE( FT_Stream stream );
282
283 BASE_DEF( FT_Long ) FT_Get_LongLE( FT_Stream stream );
284
285
286 BASE_DEF( FT_Char ) FT_Read_Char( FT_Stream stream,
287 FT_Error* error );
288
289 BASE_DEF( FT_Short ) FT_Read_Short( FT_Stream stream,
290 FT_Error* error );
291
292 BASE_DEF( FT_Long ) FT_Read_Offset( FT_Stream stream,
293 FT_Error* error );
294
295 BASE_DEF( FT_Long ) FT_Read_Long( FT_Stream stream,
296 FT_Error* error );
297
298 BASE_DEF( FT_Short ) FT_Read_ShortLE( FT_Stream stream,
299 FT_Error* error );
300
301 BASE_DEF( FT_Long ) FT_Read_LongLE( FT_Stream stream,
302 FT_Error* error );
303
304 BASE_DEF( FT_Error ) FT_Read_Fields( FT_Stream stream,
305 const FT_Frame_Field* fields,
306 void* structure );
307
308
309 #define USE_Stream( resource, stream ) \
310 FT_SET_ERROR( FT_Open_Stream( resource, stream ) )
311
312 #define DONE_Stream( stream ) \
313 FT_Done_Stream( stream )
314
315
316 #define ACCESS_Frame( size ) \
317 FT_SET_ERROR( FT_Access_Frame( stream, size ) )
318
319 #define FORGET_Frame() \
320 FT_Forget_Frame( stream )
321
322 #define EXTRACT_Frame( size, bytes ) \
323 FT_SET_ERROR( FT_Extract_Frame( stream, size, \
324 (FT_Byte**)&(bytes) ) )
325
326 #define RELEASE_Frame( bytes ) \
327 FT_Release_Frame( stream, (FT_Byte**)&(bytes) )
328
329 #define FILE_Seek( position ) \
330 FT_SET_ERROR( FT_Seek_Stream( stream, position ) )
331
332 #define FILE_Skip( distance ) \
333 FT_SET_ERROR( FT_Skip_Stream( stream, distance ) )
334
335 #define FILE_Pos() \
336 FT_Stream_Pos( stream )
337
338 #define FILE_Read( buffer, count ) \
339 FT_SET_ERROR( FT_Read_Stream( stream, \
340 (FT_Byte*)buffer, \
341 count ) )
342
343 #define FILE_Read_At( position, buffer, count ) \
344 FT_SET_ERROR( FT_Read_Stream_At( stream, \
345 position, \
346 (FT_Byte*)buffer, \
347 count ) )
348
349 #define READ_Fields( fields, object ) \
350 ( ( error = FT_Read_Fields( stream, fields, object ) ) != FT_Err_Ok )
351
352
353 #ifdef __cplusplus
354 }
355 #endif
356
357
358 #endif /* FTSTREAM_H */
359
360
361 /* END */