Bringing apdf from vendor into main branch.
[AROS-Contrib.git] / apdf / freetype2 / truetype / ttpload.c
blob19bd0f87c285e0ce8108f6940cb2152fc51a6e70
1 /***************************************************************************/
2 /* */
3 /* ttpload.c */
4 /* */
5 /* TrueType glyph data/program tables loader (body). */
6 /* */
7 /* Copyright 1996-2001, 2002 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 /***************************************************************************/
19 #include <ft2build.h>
20 #include FT_INTERNAL_DEBUG_H
21 #include FT_INTERNAL_OBJECTS_H
22 #include FT_INTERNAL_STREAM_H
23 #include FT_TRUETYPE_TAGS_H
25 #include "ttpload.h"
27 #include "tterrors.h"
30 /*************************************************************************/
31 /* */
32 /* The macro FT_COMPONENT is used in trace mode. It is an implicit */
33 /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
34 /* messages during execution. */
35 /* */
36 #undef FT_COMPONENT
37 #define FT_COMPONENT trace_ttpload
40 /*************************************************************************/
41 /* */
42 /* <Function> */
43 /* TT_Load_Locations */
44 /* */
45 /* <Description> */
46 /* Loads the locations table. */
47 /* */
48 /* <InOut> */
49 /* face :: A handle to the target face object. */
50 /* */
51 /* <Input> */
52 /* stream :: The input stream. */
53 /* */
54 /* <Return> */
55 /* FreeType error code. 0 means success. */
56 /* */
57 FT_LOCAL_DEF( FT_Error )
58 TT_Load_Locations( TT_Face face,
59 FT_Stream stream )
61 FT_Error error;
62 FT_Memory memory = stream->memory;
63 FT_Short LongOffsets;
64 FT_ULong table_len;
67 FT_TRACE2(( "Locations " ));
68 LongOffsets = face->header.Index_To_Loc_Format;
70 error = face->goto_table( face, TTAG_loca, stream, &table_len );
71 if ( error )
73 error = TT_Err_Locations_Missing;
74 goto Exit;
77 if ( LongOffsets != 0 )
79 face->num_locations = (FT_UShort)( table_len >> 2 );
81 FT_TRACE2(( "(32bit offsets): %12d ", face->num_locations ));
83 if ( FT_NEW_ARRAY( face->glyph_locations, face->num_locations ) )
84 goto Exit;
86 if ( FT_FRAME_ENTER( face->num_locations * 4L ) )
87 goto Exit;
90 FT_Long* loc = face->glyph_locations;
91 FT_Long* limit = loc + face->num_locations;
94 for ( ; loc < limit; loc++ )
95 *loc = FT_GET_LONG();
98 FT_FRAME_EXIT();
100 else
102 face->num_locations = (FT_UShort)( table_len >> 1 );
104 FT_TRACE2(( "(16bit offsets): %12d ", face->num_locations ));
106 if ( FT_NEW_ARRAY( face->glyph_locations, face->num_locations ) )
107 goto Exit;
109 if ( FT_FRAME_ENTER( face->num_locations * 2L ) )
110 goto Exit;
112 FT_Long* loc = face->glyph_locations;
113 FT_Long* limit = loc + face->num_locations;
116 for ( ; loc < limit; loc++ )
117 *loc = (FT_Long)( (FT_ULong)FT_GET_USHORT() * 2 );
119 FT_FRAME_EXIT();
122 FT_TRACE2(( "loaded\n" ));
124 Exit:
125 return error;
129 /*************************************************************************/
130 /* */
131 /* <Function> */
132 /* TT_Load_CVT */
133 /* */
134 /* <Description> */
135 /* Loads the control value table into a face object. */
136 /* */
137 /* <InOut> */
138 /* face :: A handle to the target face object. */
139 /* */
140 /* <Input> */
141 /* stream :: A handle to the input stream. */
142 /* */
143 /* <Return> */
144 /* FreeType error code. 0 means success. */
145 /* */
146 FT_LOCAL_DEF( FT_Error )
147 TT_Load_CVT( TT_Face face,
148 FT_Stream stream )
150 FT_Error error;
151 FT_Memory memory = stream->memory;
152 FT_ULong table_len;
155 FT_TRACE2(( "CVT " ));
157 error = face->goto_table( face, TTAG_cvt, stream, &table_len );
158 if ( error )
160 FT_TRACE2(( "is missing!\n" ));
162 face->cvt_size = 0;
163 face->cvt = NULL;
164 error = TT_Err_Ok;
166 goto Exit;
169 face->cvt_size = table_len / 2;
171 if ( FT_NEW_ARRAY( face->cvt, face->cvt_size ) )
172 goto Exit;
174 if ( FT_FRAME_ENTER( face->cvt_size * 2L ) )
175 goto Exit;
178 FT_Short* cur = face->cvt;
179 FT_Short* limit = cur + face->cvt_size;
182 for ( ; cur < limit; cur++ )
183 *cur = FT_GET_SHORT();
186 FT_FRAME_EXIT();
187 FT_TRACE2(( "loaded\n" ));
189 Exit:
190 return error;
194 /*************************************************************************/
195 /* */
196 /* <Function> */
197 /* TT_Load_Progams */
198 /* */
199 /* <Description> */
200 /* Loads the font program and the cvt program. */
201 /* */
202 /* <InOut> */
203 /* face :: A handle to the target face object. */
204 /* */
205 /* <Input> */
206 /* stream :: A handle to the input stream. */
207 /* */
208 /* <Return> */
209 /* FreeType error code. 0 means success. */
210 /* */
211 FT_LOCAL_DEF( FT_Error )
212 TT_Load_Programs( TT_Face face,
213 FT_Stream stream )
215 FT_Error error;
216 FT_ULong table_len;
219 FT_TRACE2(( "Font program " ));
221 /* The font program is optional */
222 error = face->goto_table( face, TTAG_fpgm, stream, &table_len );
223 if ( error )
225 face->font_program = NULL;
226 face->font_program_size = 0;
228 FT_TRACE2(( "is missing!\n" ));
230 else
232 face->font_program_size = table_len;
233 if ( FT_FRAME_EXTRACT( table_len, face->font_program ) )
234 goto Exit;
236 FT_TRACE2(( "loaded, %12d bytes\n", face->font_program_size ));
239 FT_TRACE2(( "Prep program " ));
241 error = face->goto_table( face, TTAG_prep, stream, &table_len );
242 if ( error )
244 face->cvt_program = NULL;
245 face->cvt_program_size = 0;
246 error = TT_Err_Ok;
248 FT_TRACE2(( "is missing!\n" ));
250 else
252 face->cvt_program_size = table_len;
253 if ( FT_FRAME_EXTRACT( table_len, face->cvt_program ) )
254 goto Exit;
256 FT_TRACE2(( "loaded, %12d bytes\n", face->cvt_program_size ));
259 Exit:
260 return error;
264 /* END */