1 /***************************************************************************/
2 /* */
3 /* ttpload.c */
4 /* */
5 /* TrueType glyph data/program tables loader (body). */
6 /* */
7 /* Copyright 1996-2001 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 )
60 {
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 )
72 {
73 error = TT_Err_Locations_Missing;
74 goto Exit;
75 }
77 if ( LongOffsets != 0 )
78 {
79 face->num_locations = (FT_UShort)( table_len >> 2 );
81 FT_TRACE2(( "(32bit offsets): %12d ", face->num_locations ));
83 if ( ALLOC_ARRAY( face->glyph_locations,
84 face->num_locations,
85 FT_Long ) )
86 goto Exit;
88 if ( ACCESS_Frame( face->num_locations * 4L ) )
89 goto Exit;
91 {
92 FT_Long* loc = face->glyph_locations;
93 FT_Long* limit = loc + face->num_locations;
96 for ( ; loc < limit; loc++ )
97 *loc = GET_Long();
98 }
100 FORGET_Frame();
101 }
102 else
103 {
104 face->num_locations = (FT_UShort)( table_len >> 1 );
106 FT_TRACE2(( "(16bit offsets): %12d ", face->num_locations ));
108 if ( ALLOC_ARRAY( face->glyph_locations,
109 face->num_locations,
110 FT_Long ) )
111 goto Exit;
113 if ( ACCESS_Frame( face->num_locations * 2L ) )
114 goto Exit;
115 {
116 FT_Long* loc = face->glyph_locations;
117 FT_Long* limit = loc + face->num_locations;
120 for ( ; loc < limit; loc++ )
121 *loc = (FT_Long)( (FT_ULong)GET_UShort() * 2 );
122 }
123 FORGET_Frame();
124 }
126 FT_TRACE2(( "loaded\n" ));
128 Exit:
129 return error;
130 }
133 /*************************************************************************/
134 /* */
135 /* <Function> */
136 /* TT_Load_CVT */
137 /* */
138 /* <Description> */
139 /* Loads the control value table into a face object. */
140 /* */
141 /* <InOut> */
142 /* face :: A handle to the target face object. */
143 /* */
144 /* <Input> */
145 /* stream :: A handle to the input stream. */
146 /* */
147 /* <Return> */
148 /* FreeType error code. 0 means success. */
149 /* */
150 FT_LOCAL_DEF FT_Error
151 TT_Load_CVT( TT_Face face,
152 FT_Stream stream )
153 {
154 FT_Error error;
155 FT_Memory memory = stream->memory;
156 FT_ULong table_len;
159 FT_TRACE2(( "CVT " ));
161 error = face->goto_table( face, TTAG_cvt, stream, &table_len );
162 if ( error )
163 {
164 FT_TRACE2(( "is missing!\n" ));
166 face->cvt_size = 0;
167 face->cvt = NULL;
168 error = TT_Err_Ok;
170 goto Exit;
171 }
173 face->cvt_size = table_len / 2;
175 if ( ALLOC_ARRAY( face->cvt,
176 face->cvt_size,
177 FT_Short ) )
178 goto Exit;
180 if ( ACCESS_Frame( face->cvt_size * 2L ) )
181 goto Exit;
183 {
184 FT_Short* cur = face->cvt;
185 FT_Short* limit = cur + face->cvt_size;
188 for ( ; cur < limit; cur++ )
189 *cur = GET_Short();
190 }
192 FORGET_Frame();
193 FT_TRACE2(( "loaded\n" ));
195 Exit:
196 return error;
197 }
200 /*************************************************************************/
201 /* */
202 /* <Function> */
203 /* TT_Load_Progams */
204 /* */
205 /* <Description> */
206 /* Loads the font program and the cvt program. */
207 /* */
208 /* <InOut> */
209 /* face :: A handle to the target face object. */
210 /* */
211 /* <Input> */
212 /* stream :: A handle to the input stream. */
213 /* */
214 /* <Return> */
215 /* FreeType error code. 0 means success. */
216 /* */
217 FT_LOCAL_DEF FT_Error
218 TT_Load_Programs( TT_Face face,
219 FT_Stream stream )
220 {
221 FT_Error error;
222 FT_ULong table_len;
225 FT_TRACE2(( "Font program " ));
227 /* The font program is optional */
228 error = face->goto_table( face, TTAG_fpgm, stream, &table_len );
229 if ( error )
230 {
231 face->font_program = NULL;
232 face->font_program_size = 0;
234 FT_TRACE2(( "is missing!\n" ));
235 }
236 else
237 {
238 face->font_program_size = table_len;
239 if ( EXTRACT_Frame( table_len, face->font_program ) )
240 goto Exit;
242 FT_TRACE2(( "loaded, %12d bytes\n", face->font_program_size ));
243 }
245 FT_TRACE2(( "Prep program " ));
247 error = face->goto_table( face, TTAG_prep, stream, &table_len );
248 if ( error )
249 {
250 face->cvt_program = NULL;
251 face->cvt_program_size = 0;
252 error = TT_Err_Ok;
254 FT_TRACE2(( "is missing!\n" ));
255 }
256 else
257 {
258 face->cvt_program_size = table_len;
259 if ( EXTRACT_Frame( table_len, face->cvt_program ) )
260 goto Exit;
262 FT_TRACE2(( "loaded, %12d bytes\n", face->cvt_program_size ));
263 }
265 Exit:
266 return error;
267 }
270 /* END */