OLD | NEW |
1 /***************************************************************************/ | 1 /***************************************************************************/ |
2 /* */ | 2 /* */ |
3 /* ftrfork.c */ | 3 /* ftrfork.c */ |
4 /* */ | 4 /* */ |
5 /* Embedded resource forks accessor (body). */ | 5 /* Embedded resource forks accessor (body). */ |
6 /* */ | 6 /* */ |
7 /* Copyright 2004-2010, 2013 by */ | 7 /* Copyright 2004-2010, 2013, 2014 by */ |
8 /* Masatake YAMATO and Redhat K.K. */ | 8 /* Masatake YAMATO and Redhat K.K. */ |
9 /* */ | 9 /* */ |
10 /* FT_Raccess_Get_HeaderInfo() and raccess_guess_darwin_hfsplus() are */ | 10 /* FT_Raccess_Get_HeaderInfo() and raccess_guess_darwin_hfsplus() are */ |
11 /* derived from ftobjs.c. */ | 11 /* derived from ftobjs.c. */ |
12 /* */ | 12 /* */ |
13 /* This file is part of the FreeType project, and may only be used, */ | 13 /* This file is part of the FreeType project, and may only be used, */ |
14 /* modified, and distributed under the terms of the FreeType project */ | 14 /* modified, and distributed under the terms of the FreeType project */ |
15 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ | 15 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ |
16 /* this file you indicate that you have read the license and */ | 16 /* this file you indicate that you have read the license and */ |
17 /* understand and accept it fully. */ | 17 /* understand and accept it fully. */ |
18 /* */ | 18 /* */ |
19 /***************************************************************************/ | 19 /***************************************************************************/ |
20 | 20 |
21 /***************************************************************************/ | 21 /***************************************************************************/ |
22 /* Development of the code in this file is support of */ | 22 /* Development of the code in this file is support of */ |
23 /* Information-technology Promotion Agency, Japan. */ | 23 /* Information-technology Promotion Agency, Japan. */ |
24 /***************************************************************************/ | 24 /***************************************************************************/ |
25 | 25 |
26 | 26 |
27 #include "../../include/ft2build.h" | 27 #include <ft2build.h> |
28 #include "../../include/freetype/internal/ftdebug.h" | 28 #include FT_INTERNAL_DEBUG_H |
29 #include "../../include/freetype/internal/ftstream.h" | 29 #include FT_INTERNAL_STREAM_H |
30 #include "../../include/freetype/internal/ftrfork.h" | 30 #include FT_INTERNAL_RFORK_H |
31 #include "basepic.h" | 31 #include "basepic.h" |
| 32 #include "ftbase.h" |
32 | 33 |
33 #undef FT_COMPONENT | 34 #undef FT_COMPONENT |
34 #define FT_COMPONENT trace_raccess | 35 #define FT_COMPONENT trace_raccess |
35 | 36 |
36 | 37 |
37 /*************************************************************************/ | 38 /*************************************************************************/ |
38 /*************************************************************************/ | 39 /*************************************************************************/ |
39 /*************************************************************************/ | 40 /*************************************************************************/ |
40 /**** ****/ | 41 /**** ****/ |
41 /**** ****/ | 42 /**** ****/ |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 return 0; | 145 return 0; |
145 } | 146 } |
146 | 147 |
147 | 148 |
148 FT_BASE_DEF( FT_Error ) | 149 FT_BASE_DEF( FT_Error ) |
149 FT_Raccess_Get_DataOffsets( FT_Library library, | 150 FT_Raccess_Get_DataOffsets( FT_Library library, |
150 FT_Stream stream, | 151 FT_Stream stream, |
151 FT_Long map_offset, | 152 FT_Long map_offset, |
152 FT_Long rdata_pos, | 153 FT_Long rdata_pos, |
153 FT_Long tag, | 154 FT_Long tag, |
| 155 FT_Bool sort_by_res_id, |
154 FT_Long **offsets, | 156 FT_Long **offsets, |
155 FT_Long *count ) | 157 FT_Long *count ) |
156 { | 158 { |
157 FT_Error error; | 159 FT_Error error; |
158 int i, j, cnt, subcnt; | 160 int i, j, cnt, subcnt; |
159 FT_Long tag_internal, rpos; | 161 FT_Long tag_internal, rpos; |
160 FT_Memory memory = library->memory; | 162 FT_Memory memory = library->memory; |
161 FT_Long temp; | 163 FT_Long temp; |
162 FT_Long *offsets_internal = NULL; | 164 FT_Long *offsets_internal = NULL; |
163 FT_RFork_Ref *ref = NULL; | 165 FT_RFork_Ref *ref = NULL; |
164 | 166 |
165 | 167 |
| 168 FT_TRACE3(( "\n" )); |
166 error = FT_Stream_Seek( stream, map_offset ); | 169 error = FT_Stream_Seek( stream, map_offset ); |
167 if ( error ) | 170 if ( error ) |
168 return error; | 171 return error; |
169 | 172 |
170 if ( FT_READ_USHORT( cnt ) ) | 173 if ( FT_READ_USHORT( cnt ) ) |
171 return error; | 174 return error; |
172 cnt++; | 175 cnt++; |
173 | 176 |
174 for ( i = 0; i < cnt; ++i ) | 177 for ( i = 0; i < cnt; ++i ) |
175 { | 178 { |
176 if ( FT_READ_LONG( tag_internal ) || | 179 if ( FT_READ_LONG( tag_internal ) || |
177 FT_READ_USHORT( subcnt ) || | 180 FT_READ_USHORT( subcnt ) || |
178 FT_READ_USHORT( rpos ) ) | 181 FT_READ_USHORT( rpos ) ) |
179 return error; | 182 return error; |
180 | 183 |
181 FT_TRACE2(( "Resource tags: %c%c%c%c\n", | 184 FT_TRACE2(( "Resource tags: %c%c%c%c\n", |
182 (char)( 0xff & ( tag_internal >> 24 ) ), | 185 (char)( 0xff & ( tag_internal >> 24 ) ), |
183 (char)( 0xff & ( tag_internal >> 16 ) ), | 186 (char)( 0xff & ( tag_internal >> 16 ) ), |
184 (char)( 0xff & ( tag_internal >> 8 ) ), | 187 (char)( 0xff & ( tag_internal >> 8 ) ), |
185 (char)( 0xff & ( tag_internal >> 0 ) ) )); | 188 (char)( 0xff & ( tag_internal >> 0 ) ) )); |
| 189 FT_TRACE3(( " : subcount=%d, suboffset=0x%04x\n", |
| 190 subcnt, rpos )); |
186 | 191 |
187 if ( tag_internal == tag ) | 192 if ( tag_internal == tag ) |
188 { | 193 { |
189 *count = subcnt + 1; | 194 *count = subcnt + 1; |
190 rpos += map_offset; | 195 rpos += map_offset; |
191 | 196 |
192 error = FT_Stream_Seek( stream, rpos ); | 197 error = FT_Stream_Seek( stream, rpos ); |
193 if ( error ) | 198 if ( error ) |
194 return error; | 199 return error; |
195 | 200 |
196 if ( FT_NEW_ARRAY( ref, *count ) ) | 201 if ( FT_NEW_ARRAY( ref, *count ) ) |
197 return error; | 202 return error; |
198 | 203 |
199 for ( j = 0; j < *count; ++j ) | 204 for ( j = 0; j < *count; ++j ) |
200 { | 205 { |
201 if ( FT_READ_USHORT( ref[j].res_id ) ) | 206 if ( FT_READ_USHORT( ref[j].res_id ) ) |
202 goto Exit; | 207 goto Exit; |
203 if ( FT_STREAM_SKIP( 2 ) ) /* resource name */ | 208 if ( FT_STREAM_SKIP( 2 ) ) /* resource name */ |
204 goto Exit; | 209 goto Exit; |
205 if ( FT_READ_LONG( temp ) ) | 210 if ( FT_READ_LONG( temp ) ) |
206 goto Exit; | 211 goto Exit; |
207 if ( FT_STREAM_SKIP( 4 ) ) /* mbz */ | 212 if ( FT_STREAM_SKIP( 4 ) ) /* mbz */ |
208 goto Exit; | 213 goto Exit; |
209 | 214 |
210 ref[j].offset = temp & 0xFFFFFFL; | 215 ref[j].offset = temp & 0xFFFFFFL; |
| 216 FT_TRACE3(( " [%d]:" |
| 217 " resource_id=0x%04x, offset=0x%08x\n", |
| 218 j, ref[j].res_id, ref[j].offset )); |
211 } | 219 } |
212 | 220 |
213 ft_qsort( ref, *count, sizeof ( FT_RFork_Ref ), | 221 if (sort_by_res_id) |
214 ( int(*)(const void*, const void*) ) | 222 { |
215 ft_raccess_sort_ref_by_id ); | 223 ft_qsort( ref, *count, sizeof ( FT_RFork_Ref ), |
| 224 ( int(*)(const void*, const void*) ) |
| 225 ft_raccess_sort_ref_by_id ); |
| 226 |
| 227 FT_TRACE3(( " -- sort resources by their ids --\n" )); |
| 228 for ( j = 0; j < *count; ++ j ) { |
| 229 FT_TRACE3(( " [%d]:" |
| 230 " resource_id=0x%04x, offset=0x%08x\n", |
| 231 j, ref[j].res_id, ref[j].offset )); |
| 232 } |
| 233 } |
216 | 234 |
217 if ( FT_NEW_ARRAY( offsets_internal, *count ) ) | 235 if ( FT_NEW_ARRAY( offsets_internal, *count ) ) |
218 goto Exit; | 236 goto Exit; |
219 | 237 |
220 /* XXX: duplicated reference ID, | 238 /* XXX: duplicated reference ID, |
221 * gap between reference IDs are acceptable? | 239 * gap between reference IDs are acceptable? |
222 * further investigation on Apple implementation is needed. | 240 * further investigation on Apple implementation is needed. |
223 */ | 241 */ |
224 for ( j = 0; j < *count; ++j ) | 242 for ( j = 0; j < *count; ++j ) |
225 offsets_internal[j] = rdata_pos + ref[j].offset; | 243 offsets_internal[j] = rdata_pos + ref[j].offset; |
(...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
840 offsets[i] = 0; | 858 offsets[i] = 0; |
841 errors[i] = FT_ERR( Unimplemented_Feature ); | 859 errors[i] = FT_ERR( Unimplemented_Feature ); |
842 } | 860 } |
843 } | 861 } |
844 | 862 |
845 | 863 |
846 #endif /* !FT_CONFIG_OPTION_GUESSING_EMBEDDED_RFORK */ | 864 #endif /* !FT_CONFIG_OPTION_GUESSING_EMBEDDED_RFORK */ |
847 | 865 |
848 | 866 |
849 /* END */ | 867 /* END */ |
OLD | NEW |