OLD | NEW |
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-2002, 2004-2006, 2008-2011 by */ | 7 /* Copyright 2000-2002, 2004-2006, 2008-2011, 2013 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 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 | 61 |
62 | 62 |
63 if ( stream->read ) | 63 if ( stream->read ) |
64 { | 64 { |
65 if ( stream->read( stream, pos, 0, 0 ) ) | 65 if ( stream->read( stream, pos, 0, 0 ) ) |
66 { | 66 { |
67 FT_ERROR(( "FT_Stream_Seek:" | 67 FT_ERROR(( "FT_Stream_Seek:" |
68 " invalid i/o; pos = 0x%lx, size = 0x%lx\n", | 68 " invalid i/o; pos = 0x%lx, size = 0x%lx\n", |
69 pos, stream->size )); | 69 pos, stream->size )); |
70 | 70 |
71 error = FT_Err_Invalid_Stream_Operation; | 71 error = FT_THROW( Invalid_Stream_Operation ); |
72 } | 72 } |
73 } | 73 } |
74 /* note that seeking to the first position after the file is valid */ | 74 /* note that seeking to the first position after the file is valid */ |
75 else if ( pos > stream->size ) | 75 else if ( pos > stream->size ) |
76 { | 76 { |
77 FT_ERROR(( "FT_Stream_Seek:" | 77 FT_ERROR(( "FT_Stream_Seek:" |
78 " invalid i/o; pos = 0x%lx, size = 0x%lx\n", | 78 " invalid i/o; pos = 0x%lx, size = 0x%lx\n", |
79 pos, stream->size )); | 79 pos, stream->size )); |
80 | 80 |
81 error = FT_Err_Invalid_Stream_Operation; | 81 error = FT_THROW( Invalid_Stream_Operation ); |
82 } | 82 } |
83 | 83 |
84 if ( !error ) | 84 if ( !error ) |
85 stream->pos = pos; | 85 stream->pos = pos; |
86 | 86 |
87 return error; | 87 return error; |
88 } | 88 } |
89 | 89 |
90 | 90 |
91 FT_BASE_DEF( FT_Error ) | 91 FT_BASE_DEF( FT_Error ) |
92 FT_Stream_Skip( FT_Stream stream, | 92 FT_Stream_Skip( FT_Stream stream, |
93 FT_Long distance ) | 93 FT_Long distance ) |
94 { | 94 { |
95 if ( distance < 0 ) | 95 if ( distance < 0 ) |
96 return FT_Err_Invalid_Stream_Operation; | 96 return FT_THROW( Invalid_Stream_Operation ); |
97 | 97 |
98 return FT_Stream_Seek( stream, (FT_ULong)( stream->pos + distance ) ); | 98 return FT_Stream_Seek( stream, (FT_ULong)( stream->pos + distance ) ); |
99 } | 99 } |
100 | 100 |
101 | 101 |
102 FT_BASE_DEF( FT_Long ) | 102 FT_BASE_DEF( FT_Long ) |
103 FT_Stream_Pos( FT_Stream stream ) | 103 FT_Stream_Pos( FT_Stream stream ) |
104 { | 104 { |
105 return stream->pos; | 105 return stream->pos; |
106 } | 106 } |
(...skipping 17 matching lines...) Expand all Loading... |
124 FT_Error error = FT_Err_Ok; | 124 FT_Error error = FT_Err_Ok; |
125 FT_ULong read_bytes; | 125 FT_ULong read_bytes; |
126 | 126 |
127 | 127 |
128 if ( pos >= stream->size ) | 128 if ( pos >= stream->size ) |
129 { | 129 { |
130 FT_ERROR(( "FT_Stream_ReadAt:" | 130 FT_ERROR(( "FT_Stream_ReadAt:" |
131 " invalid i/o; pos = 0x%lx, size = 0x%lx\n", | 131 " invalid i/o; pos = 0x%lx, size = 0x%lx\n", |
132 pos, stream->size )); | 132 pos, stream->size )); |
133 | 133 |
134 return FT_Err_Invalid_Stream_Operation; | 134 return FT_THROW( Invalid_Stream_Operation ); |
135 } | 135 } |
136 | 136 |
137 if ( stream->read ) | 137 if ( stream->read ) |
138 read_bytes = stream->read( stream, pos, buffer, count ); | 138 read_bytes = stream->read( stream, pos, buffer, count ); |
139 else | 139 else |
140 { | 140 { |
141 read_bytes = stream->size - pos; | 141 read_bytes = stream->size - pos; |
142 if ( read_bytes > count ) | 142 if ( read_bytes > count ) |
143 read_bytes = count; | 143 read_bytes = count; |
144 | 144 |
145 FT_MEM_COPY( buffer, stream->base + pos, read_bytes ); | 145 FT_MEM_COPY( buffer, stream->base + pos, read_bytes ); |
146 } | 146 } |
147 | 147 |
148 stream->pos = pos + read_bytes; | 148 stream->pos = pos + read_bytes; |
149 | 149 |
150 if ( read_bytes < count ) | 150 if ( read_bytes < count ) |
151 { | 151 { |
152 FT_ERROR(( "FT_Stream_ReadAt:" | 152 FT_ERROR(( "FT_Stream_ReadAt:" |
153 " invalid read; expected %lu bytes, got %lu\n", | 153 " invalid read; expected %lu bytes, got %lu\n", |
154 count, read_bytes )); | 154 count, read_bytes )); |
155 | 155 |
156 error = FT_Err_Invalid_Stream_Operation; | 156 error = FT_THROW( Invalid_Stream_Operation ); |
157 } | 157 } |
158 | 158 |
159 return error; | 159 return error; |
160 } | 160 } |
161 | 161 |
162 | 162 |
163 FT_BASE_DEF( FT_ULong ) | 163 FT_BASE_DEF( FT_ULong ) |
164 FT_Stream_TryRead( FT_Stream stream, | 164 FT_Stream_TryRead( FT_Stream stream, |
165 FT_Byte* buffer, | 165 FT_Byte* buffer, |
166 FT_ULong count ) | 166 FT_ULong count ) |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 FT_Memory memory = stream->memory; | 247 FT_Memory memory = stream->memory; |
248 | 248 |
249 | 249 |
250 /* simple sanity check */ | 250 /* simple sanity check */ |
251 if ( count > stream->size ) | 251 if ( count > stream->size ) |
252 { | 252 { |
253 FT_ERROR(( "FT_Stream_EnterFrame:" | 253 FT_ERROR(( "FT_Stream_EnterFrame:" |
254 " frame size (%lu) larger than stream size (%lu)\n", | 254 " frame size (%lu) larger than stream size (%lu)\n", |
255 count, stream->size )); | 255 count, stream->size )); |
256 | 256 |
257 error = FT_Err_Invalid_Stream_Operation; | 257 error = FT_THROW( Invalid_Stream_Operation ); |
258 goto Exit; | 258 goto Exit; |
259 } | 259 } |
260 | 260 |
261 #ifdef FT_DEBUG_MEMORY | 261 #ifdef FT_DEBUG_MEMORY |
262 /* assume _ft_debug_file and _ft_debug_lineno are already set */ | 262 /* assume _ft_debug_file and _ft_debug_lineno are already set */ |
263 stream->base = (unsigned char*)ft_mem_qalloc( memory, count, &error ); | 263 stream->base = (unsigned char*)ft_mem_qalloc( memory, count, &error ); |
264 if ( error ) | 264 if ( error ) |
265 goto Exit; | 265 goto Exit; |
266 #else | 266 #else |
267 if ( FT_QALLOC( stream->base, count ) ) | 267 if ( FT_QALLOC( stream->base, count ) ) |
268 goto Exit; | 268 goto Exit; |
269 #endif | 269 #endif |
270 /* read it */ | 270 /* read it */ |
271 read_bytes = stream->read( stream, stream->pos, | 271 read_bytes = stream->read( stream, stream->pos, |
272 stream->base, count ); | 272 stream->base, count ); |
273 if ( read_bytes < count ) | 273 if ( read_bytes < count ) |
274 { | 274 { |
275 FT_ERROR(( "FT_Stream_EnterFrame:" | 275 FT_ERROR(( "FT_Stream_EnterFrame:" |
276 " invalid read; expected %lu bytes, got %lu\n", | 276 " invalid read; expected %lu bytes, got %lu\n", |
277 count, read_bytes )); | 277 count, read_bytes )); |
278 | 278 |
279 FT_FREE( stream->base ); | 279 FT_FREE( stream->base ); |
280 error = FT_Err_Invalid_Stream_Operation; | 280 error = FT_THROW( Invalid_Stream_Operation ); |
281 } | 281 } |
282 stream->cursor = stream->base; | 282 stream->cursor = stream->base; |
283 stream->limit = stream->cursor + count; | 283 stream->limit = stream->cursor + count; |
284 stream->pos += read_bytes; | 284 stream->pos += read_bytes; |
285 } | 285 } |
286 else | 286 else |
287 { | 287 { |
288 /* check current and new position */ | 288 /* check current and new position */ |
289 if ( stream->pos >= stream->size || | 289 if ( stream->pos >= stream->size || |
290 stream->size - stream->pos < count ) | 290 stream->size - stream->pos < count ) |
291 { | 291 { |
292 FT_ERROR(( "FT_Stream_EnterFrame:" | 292 FT_ERROR(( "FT_Stream_EnterFrame:" |
293 " invalid i/o; pos = 0x%lx, count = %lu, size = 0x%lx\n", | 293 " invalid i/o; pos = 0x%lx, count = %lu, size = 0x%lx\n", |
294 stream->pos, count, stream->size )); | 294 stream->pos, count, stream->size )); |
295 | 295 |
296 error = FT_Err_Invalid_Stream_Operation; | 296 error = FT_THROW( Invalid_Stream_Operation ); |
297 goto Exit; | 297 goto Exit; |
298 } | 298 } |
299 | 299 |
300 /* set cursor */ | 300 /* set cursor */ |
301 stream->cursor = stream->base + stream->pos; | 301 stream->cursor = stream->base + stream->pos; |
302 stream->limit = stream->cursor + count; | 302 stream->limit = stream->cursor + count; |
303 stream->pos += count; | 303 stream->pos += count; |
304 } | 304 } |
305 | 305 |
306 Exit: | 306 Exit: |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 if ( stream->pos < stream->size ) | 467 if ( stream->pos < stream->size ) |
468 result = stream->base[stream->pos]; | 468 result = stream->base[stream->pos]; |
469 else | 469 else |
470 goto Fail; | 470 goto Fail; |
471 } | 471 } |
472 stream->pos++; | 472 stream->pos++; |
473 | 473 |
474 return result; | 474 return result; |
475 | 475 |
476 Fail: | 476 Fail: |
477 *error = FT_Err_Invalid_Stream_Operation; | 477 *error = FT_THROW( Invalid_Stream_Operation ); |
478 FT_ERROR(( "FT_Stream_ReadChar:" | 478 FT_ERROR(( "FT_Stream_ReadChar:" |
479 " invalid i/o; pos = 0x%lx, size = 0x%lx\n", | 479 " invalid i/o; pos = 0x%lx, size = 0x%lx\n", |
480 stream->pos, stream->size )); | 480 stream->pos, stream->size )); |
481 | 481 |
482 return 0; | 482 return 0; |
483 } | 483 } |
484 | 484 |
485 | 485 |
486 FT_BASE_DEF( FT_UShort ) | 486 FT_BASE_DEF( FT_UShort ) |
487 FT_Stream_ReadUShort( FT_Stream stream, | 487 FT_Stream_ReadUShort( FT_Stream stream, |
(...skipping 26 matching lines...) Expand all Loading... |
514 result = FT_NEXT_USHORT( p ); | 514 result = FT_NEXT_USHORT( p ); |
515 } | 515 } |
516 else | 516 else |
517 goto Fail; | 517 goto Fail; |
518 | 518 |
519 stream->pos += 2; | 519 stream->pos += 2; |
520 | 520 |
521 return result; | 521 return result; |
522 | 522 |
523 Fail: | 523 Fail: |
524 *error = FT_Err_Invalid_Stream_Operation; | 524 *error = FT_THROW( Invalid_Stream_Operation ); |
525 FT_ERROR(( "FT_Stream_ReadUShort:" | 525 FT_ERROR(( "FT_Stream_ReadUShort:" |
526 " invalid i/o; pos = 0x%lx, size = 0x%lx\n", | 526 " invalid i/o; pos = 0x%lx, size = 0x%lx\n", |
527 stream->pos, stream->size )); | 527 stream->pos, stream->size )); |
528 | 528 |
529 return 0; | 529 return 0; |
530 } | 530 } |
531 | 531 |
532 | 532 |
533 FT_BASE_DEF( FT_UShort ) | 533 FT_BASE_DEF( FT_UShort ) |
534 FT_Stream_ReadUShortLE( FT_Stream stream, | 534 FT_Stream_ReadUShortLE( FT_Stream stream, |
(...skipping 26 matching lines...) Expand all Loading... |
561 result = FT_NEXT_USHORT_LE( p ); | 561 result = FT_NEXT_USHORT_LE( p ); |
562 } | 562 } |
563 else | 563 else |
564 goto Fail; | 564 goto Fail; |
565 | 565 |
566 stream->pos += 2; | 566 stream->pos += 2; |
567 | 567 |
568 return result; | 568 return result; |
569 | 569 |
570 Fail: | 570 Fail: |
571 *error = FT_Err_Invalid_Stream_Operation; | 571 *error = FT_THROW( Invalid_Stream_Operation ); |
572 FT_ERROR(( "FT_Stream_ReadUShortLE:" | 572 FT_ERROR(( "FT_Stream_ReadUShortLE:" |
573 " invalid i/o; pos = 0x%lx, size = 0x%lx\n", | 573 " invalid i/o; pos = 0x%lx, size = 0x%lx\n", |
574 stream->pos, stream->size )); | 574 stream->pos, stream->size )); |
575 | 575 |
576 return 0; | 576 return 0; |
577 } | 577 } |
578 | 578 |
579 | 579 |
580 FT_BASE_DEF( FT_ULong ) | 580 FT_BASE_DEF( FT_ULong ) |
581 FT_Stream_ReadUOffset( FT_Stream stream, | 581 FT_Stream_ReadUOffset( FT_Stream stream, |
(...skipping 26 matching lines...) Expand all Loading... |
608 result = FT_NEXT_UOFF3( p ); | 608 result = FT_NEXT_UOFF3( p ); |
609 } | 609 } |
610 else | 610 else |
611 goto Fail; | 611 goto Fail; |
612 | 612 |
613 stream->pos += 3; | 613 stream->pos += 3; |
614 | 614 |
615 return result; | 615 return result; |
616 | 616 |
617 Fail: | 617 Fail: |
618 *error = FT_Err_Invalid_Stream_Operation; | 618 *error = FT_THROW( Invalid_Stream_Operation ); |
619 FT_ERROR(( "FT_Stream_ReadUOffset:" | 619 FT_ERROR(( "FT_Stream_ReadUOffset:" |
620 " invalid i/o; pos = 0x%lx, size = 0x%lx\n", | 620 " invalid i/o; pos = 0x%lx, size = 0x%lx\n", |
621 stream->pos, stream->size )); | 621 stream->pos, stream->size )); |
622 | 622 |
623 return 0; | 623 return 0; |
624 } | 624 } |
625 | 625 |
626 | 626 |
627 FT_BASE_DEF( FT_ULong ) | 627 FT_BASE_DEF( FT_ULong ) |
628 FT_Stream_ReadULong( FT_Stream stream, | 628 FT_Stream_ReadULong( FT_Stream stream, |
(...skipping 26 matching lines...) Expand all Loading... |
655 result = FT_NEXT_ULONG( p ); | 655 result = FT_NEXT_ULONG( p ); |
656 } | 656 } |
657 else | 657 else |
658 goto Fail; | 658 goto Fail; |
659 | 659 |
660 stream->pos += 4; | 660 stream->pos += 4; |
661 | 661 |
662 return result; | 662 return result; |
663 | 663 |
664 Fail: | 664 Fail: |
665 *error = FT_Err_Invalid_Stream_Operation; | 665 *error = FT_THROW( Invalid_Stream_Operation ); |
666 FT_ERROR(( "FT_Stream_ReadULong:" | 666 FT_ERROR(( "FT_Stream_ReadULong:" |
667 " invalid i/o; pos = 0x%lx, size = 0x%lx\n", | 667 " invalid i/o; pos = 0x%lx, size = 0x%lx\n", |
668 stream->pos, stream->size )); | 668 stream->pos, stream->size )); |
669 | 669 |
670 return 0; | 670 return 0; |
671 } | 671 } |
672 | 672 |
673 | 673 |
674 FT_BASE_DEF( FT_ULong ) | 674 FT_BASE_DEF( FT_ULong ) |
675 FT_Stream_ReadULongLE( FT_Stream stream, | 675 FT_Stream_ReadULongLE( FT_Stream stream, |
(...skipping 26 matching lines...) Expand all Loading... |
702 result = FT_NEXT_ULONG_LE( p ); | 702 result = FT_NEXT_ULONG_LE( p ); |
703 } | 703 } |
704 else | 704 else |
705 goto Fail; | 705 goto Fail; |
706 | 706 |
707 stream->pos += 4; | 707 stream->pos += 4; |
708 | 708 |
709 return result; | 709 return result; |
710 | 710 |
711 Fail: | 711 Fail: |
712 *error = FT_Err_Invalid_Stream_Operation; | 712 *error = FT_THROW( Invalid_Stream_Operation ); |
713 FT_ERROR(( "FT_Stream_ReadULongLE:" | 713 FT_ERROR(( "FT_Stream_ReadULongLE:" |
714 " invalid i/o; pos = 0x%lx, size = 0x%lx\n", | 714 " invalid i/o; pos = 0x%lx, size = 0x%lx\n", |
715 stream->pos, stream->size )); | 715 stream->pos, stream->size )); |
716 | 716 |
717 return 0; | 717 return 0; |
718 } | 718 } |
719 | 719 |
720 | 720 |
721 FT_BASE_DEF( FT_Error ) | 721 FT_BASE_DEF( FT_Error ) |
722 FT_Stream_ReadFields( FT_Stream stream, | 722 FT_Stream_ReadFields( FT_Stream stream, |
723 const FT_Frame_Field* fields, | 723 const FT_Frame_Field* fields, |
724 void* structure ) | 724 void* structure ) |
725 { | 725 { |
726 FT_Error error; | 726 FT_Error error; |
727 FT_Bool frame_accessed = 0; | 727 FT_Bool frame_accessed = 0; |
728 FT_Byte* cursor; | 728 FT_Byte* cursor; |
729 | 729 |
| 730 |
730 if ( !fields || !stream ) | 731 if ( !fields || !stream ) |
731 return FT_Err_Invalid_Argument; | 732 return FT_THROW( Invalid_Argument ); |
732 | 733 |
733 cursor = stream->cursor; | 734 cursor = stream->cursor; |
734 | 735 |
735 error = FT_Err_Ok; | 736 error = FT_Err_Ok; |
736 do | 737 do |
737 { | 738 { |
738 FT_ULong value; | 739 FT_ULong value; |
739 FT_Int sign_shift; | 740 FT_Int sign_shift; |
740 FT_Byte* p; | 741 FT_Byte* p; |
741 | 742 |
(...skipping 11 matching lines...) Expand all Loading... |
753 continue; /* loop! */ | 754 continue; /* loop! */ |
754 | 755 |
755 case ft_frame_bytes: /* read a byte sequence */ | 756 case ft_frame_bytes: /* read a byte sequence */ |
756 case ft_frame_skip: /* skip some bytes */ | 757 case ft_frame_skip: /* skip some bytes */ |
757 { | 758 { |
758 FT_UInt len = fields->size; | 759 FT_UInt len = fields->size; |
759 | 760 |
760 | 761 |
761 if ( cursor + len > stream->limit ) | 762 if ( cursor + len > stream->limit ) |
762 { | 763 { |
763 error = FT_Err_Invalid_Stream_Operation; | 764 error = FT_THROW( Invalid_Stream_Operation ); |
764 goto Exit; | 765 goto Exit; |
765 } | 766 } |
766 | 767 |
767 if ( fields->value == ft_frame_bytes ) | 768 if ( fields->value == ft_frame_bytes ) |
768 { | 769 { |
769 p = (FT_Byte*)structure + fields->offset; | 770 p = (FT_Byte*)structure + fields->offset; |
770 FT_MEM_COPY( p, cursor, len ); | 771 FT_MEM_COPY( p, cursor, len ); |
771 } | 772 } |
772 cursor += len; | 773 cursor += len; |
773 fields++; | 774 fields++; |
774 continue; | 775 continue; |
775 } | 776 } |
776 | 777 |
777 case ft_frame_byte: | 778 case ft_frame_byte: |
778 case ft_frame_schar: /* read a single byte */ | 779 case ft_frame_schar: /* read a single byte */ |
779 value = FT_NEXT_BYTE(cursor); | 780 value = FT_NEXT_BYTE( cursor ); |
780 sign_shift = 24; | 781 sign_shift = 24; |
781 break; | 782 break; |
782 | 783 |
783 case ft_frame_short_be: | 784 case ft_frame_short_be: |
784 case ft_frame_ushort_be: /* read a 2-byte big-endian short */ | 785 case ft_frame_ushort_be: /* read a 2-byte big-endian short */ |
785 value = FT_NEXT_USHORT(cursor); | 786 value = FT_NEXT_USHORT( cursor) ; |
786 sign_shift = 16; | 787 sign_shift = 16; |
787 break; | 788 break; |
788 | 789 |
789 case ft_frame_short_le: | 790 case ft_frame_short_le: |
790 case ft_frame_ushort_le: /* read a 2-byte little-endian short */ | 791 case ft_frame_ushort_le: /* read a 2-byte little-endian short */ |
791 value = FT_NEXT_USHORT_LE(cursor); | 792 value = FT_NEXT_USHORT_LE( cursor ); |
792 sign_shift = 16; | 793 sign_shift = 16; |
793 break; | 794 break; |
794 | 795 |
795 case ft_frame_long_be: | 796 case ft_frame_long_be: |
796 case ft_frame_ulong_be: /* read a 4-byte big-endian long */ | 797 case ft_frame_ulong_be: /* read a 4-byte big-endian long */ |
797 value = FT_NEXT_ULONG(cursor); | 798 value = FT_NEXT_ULONG( cursor ); |
798 sign_shift = 0; | 799 sign_shift = 0; |
799 break; | 800 break; |
800 | 801 |
801 case ft_frame_long_le: | 802 case ft_frame_long_le: |
802 case ft_frame_ulong_le: /* read a 4-byte little-endian long */ | 803 case ft_frame_ulong_le: /* read a 4-byte little-endian long */ |
803 value = FT_NEXT_ULONG_LE(cursor); | 804 value = FT_NEXT_ULONG_LE( cursor ); |
804 sign_shift = 0; | 805 sign_shift = 0; |
805 break; | 806 break; |
806 | 807 |
807 case ft_frame_off3_be: | 808 case ft_frame_off3_be: |
808 case ft_frame_uoff3_be: /* read a 3-byte big-endian long */ | 809 case ft_frame_uoff3_be: /* read a 3-byte big-endian long */ |
809 value = FT_NEXT_UOFF3(cursor); | 810 value = FT_NEXT_UOFF3( cursor ); |
810 sign_shift = 8; | 811 sign_shift = 8; |
811 break; | 812 break; |
812 | 813 |
813 case ft_frame_off3_le: | 814 case ft_frame_off3_le: |
814 case ft_frame_uoff3_le: /* read a 3-byte little-endian long */ | 815 case ft_frame_uoff3_le: /* read a 3-byte little-endian long */ |
815 value = FT_NEXT_UOFF3_LE(cursor); | 816 value = FT_NEXT_UOFF3_LE( cursor ); |
816 sign_shift = 8; | 817 sign_shift = 8; |
817 break; | 818 break; |
818 | 819 |
819 default: | 820 default: |
820 /* otherwise, exit the loop */ | 821 /* otherwise, exit the loop */ |
821 stream->cursor = cursor; | 822 stream->cursor = cursor; |
822 goto Exit; | 823 goto Exit; |
823 } | 824 } |
824 | 825 |
825 /* now, compute the signed value is necessary */ | 826 /* now, compute the signed value is necessary */ |
826 if ( fields->value & FT_FRAME_OP_SIGNED ) | 827 if ( fields->value & FT_FRAME_OP_SIGNED ) |
827 value = (FT_ULong)( (FT_Int32)( value << sign_shift ) >> sign_shift ); | 828 value = (FT_ULong)( (FT_Int32)( value << sign_shift ) >> sign_shift ); |
828 | 829 |
829 /* finally, store the value in the object */ | 830 /* finally, store the value in the object */ |
830 | 831 |
831 p = (FT_Byte*)structure + fields->offset; | 832 p = (FT_Byte*)structure + fields->offset; |
832 switch ( fields->size ) | 833 switch ( fields->size ) |
833 { | 834 { |
834 case (8 / FT_CHAR_BIT): | 835 case ( 8 / FT_CHAR_BIT ): |
835 *(FT_Byte*)p = (FT_Byte)value; | 836 *(FT_Byte*)p = (FT_Byte)value; |
836 break; | 837 break; |
837 | 838 |
838 case (16 / FT_CHAR_BIT): | 839 case ( 16 / FT_CHAR_BIT ): |
839 *(FT_UShort*)p = (FT_UShort)value; | 840 *(FT_UShort*)p = (FT_UShort)value; |
840 break; | 841 break; |
841 | 842 |
842 case (32 / FT_CHAR_BIT): | 843 case ( 32 / FT_CHAR_BIT ): |
843 *(FT_UInt32*)p = (FT_UInt32)value; | 844 *(FT_UInt32*)p = (FT_UInt32)value; |
844 break; | 845 break; |
845 | 846 |
846 default: /* for 64-bit systems */ | 847 default: /* for 64-bit systems */ |
847 *(FT_ULong*)p = (FT_ULong)value; | 848 *(FT_ULong*)p = (FT_ULong)value; |
848 } | 849 } |
849 | 850 |
850 /* go to next field */ | 851 /* go to next field */ |
851 fields++; | 852 fields++; |
852 } | 853 } |
853 while ( 1 ); | 854 while ( 1 ); |
854 | 855 |
855 Exit: | 856 Exit: |
856 /* close the frame if it was opened by this read */ | 857 /* close the frame if it was opened by this read */ |
857 if ( frame_accessed ) | 858 if ( frame_accessed ) |
858 FT_Stream_ExitFrame( stream ); | 859 FT_Stream_ExitFrame( stream ); |
859 | 860 |
860 return error; | 861 return error; |
861 } | 862 } |
862 | 863 |
863 | 864 |
864 /* END */ | 865 /* END */ |
OLD | NEW |