1 /***************************************************************************/ |
1 /**************************************************************************** |
2 /* */ |
2 * |
3 /* ftstream.c */ |
3 * ftstream.c |
4 /* */ |
4 * |
5 /* I/O stream support (body). */ |
5 * I/O stream support (body). |
6 /* */ |
6 * |
7 /* Copyright 2000-2018 by */ |
7 * Copyright (C) 2000-2019 by |
8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */ |
8 * David Turner, Robert Wilhelm, and Werner Lemberg. |
9 /* */ |
9 * |
10 /* This file is part of the FreeType project, and may only be used, */ |
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 */ |
11 * modified, and distributed under the terms of the FreeType project |
12 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ |
12 * license, LICENSE.TXT. By continuing to use, modify, or distribute |
13 /* this file you indicate that you have read the license and */ |
13 * this file you indicate that you have read the license and |
14 /* understand and accept it fully. */ |
14 * understand and accept it fully. |
15 /* */ |
15 * |
16 /***************************************************************************/ |
16 */ |
17 |
17 |
18 |
18 |
19 #include <ft2build.h> |
19 #include <ft2build.h> |
20 #include FT_INTERNAL_STREAM_H |
20 #include FT_INTERNAL_STREAM_H |
21 #include FT_INTERNAL_DEBUG_H |
21 #include FT_INTERNAL_DEBUG_H |
22 |
22 |
23 |
23 |
24 /*************************************************************************/ |
24 /************************************************************************** |
25 /* */ |
25 * |
26 /* The macro FT_COMPONENT is used in trace mode. It is an implicit */ |
26 * The macro FT_COMPONENT is used in trace mode. It is an implicit |
27 /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */ |
27 * parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log |
28 /* messages during execution. */ |
28 * messages during execution. |
29 /* */ |
29 */ |
30 #undef FT_COMPONENT |
30 #undef FT_COMPONENT |
31 #define FT_COMPONENT trace_stream |
31 #define FT_COMPONENT stream |
32 |
32 |
33 |
33 |
34 FT_BASE_DEF( void ) |
34 FT_BASE_DEF( void ) |
35 FT_Stream_OpenMemory( FT_Stream stream, |
35 FT_Stream_OpenMemory( FT_Stream stream, |
36 const FT_Byte* base, |
36 const FT_Byte* base, |
279 count, read_bytes )); |
282 count, read_bytes )); |
280 |
283 |
281 FT_FREE( stream->base ); |
284 FT_FREE( stream->base ); |
282 error = FT_THROW( Invalid_Stream_Operation ); |
285 error = FT_THROW( Invalid_Stream_Operation ); |
283 } |
286 } |
|
287 |
284 stream->cursor = stream->base; |
288 stream->cursor = stream->base; |
285 stream->limit = stream->cursor + count; |
289 stream->limit = stream->cursor + count; |
286 stream->pos += read_bytes; |
290 stream->pos += read_bytes; |
287 } |
291 } |
288 else |
292 else |
319 /* 0 records, like in some strange kern tables). */ |
323 /* 0 records, like in some strange kern tables). */ |
320 /* */ |
324 /* */ |
321 /* In this case, the loader code handles the 0-length table */ |
325 /* In this case, the loader code handles the 0-length table */ |
322 /* gracefully; however, stream.cursor is really set to 0 by the */ |
326 /* gracefully; however, stream.cursor is really set to 0 by the */ |
323 /* FT_Stream_EnterFrame() call, and this is not an error. */ |
327 /* FT_Stream_EnterFrame() call, and this is not an error. */ |
324 /* */ |
328 |
|
329 FT_TRACE7(( "FT_Stream_ExitFrame\n" )); |
|
330 |
325 FT_ASSERT( stream ); |
331 FT_ASSERT( stream ); |
326 |
332 |
327 if ( stream->read ) |
333 if ( stream->read ) |
328 { |
334 { |
329 FT_Memory memory = stream->memory; |
335 FT_Memory memory = stream->memory; |
|
336 |
330 |
337 |
331 #ifdef FT_DEBUG_MEMORY |
338 #ifdef FT_DEBUG_MEMORY |
332 ft_mem_free( memory, stream->base ); |
339 ft_mem_free( memory, stream->base ); |
333 stream->base = NULL; |
340 stream->base = NULL; |
334 #else |
341 #else |
335 FT_FREE( stream->base ); |
342 FT_FREE( stream->base ); |
336 #endif |
343 #endif |
337 } |
344 } |
|
345 |
338 stream->cursor = NULL; |
346 stream->cursor = NULL; |
339 stream->limit = NULL; |
347 stream->limit = NULL; |
340 } |
348 } |
341 |
349 |
342 |
350 |