]>
Commit | Line | Data |
---|---|---|
1 | /***************************************************************************/ | |
2 | /* */ | |
3 | /* ttpload.h */ | |
4 | /* */ | |
5 | /* TrueType glyph data/program tables loader (body). */ | |
6 | /* */ | |
7 | /* Copyright 1996-2000 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 | /***************************************************************************/ | |
17 | ||
18 | ||
19 | #include <freetype/internal/ftdebug.h> | |
20 | #include <freetype/internal/ftobjs.h> | |
21 | #include <freetype/internal/ftstream.h> | |
22 | #include <freetype/tttags.h> | |
23 | ||
24 | #ifdef FT_FLAT_COMPILE | |
25 | #include "ttpload.h" | |
26 | #else | |
27 | #include <truetype/ttpload.h> | |
28 | #endif | |
29 | ||
30 | #include <freetype/internal/tterrors.h> | |
31 | ||
32 | ||
33 | /*************************************************************************/ | |
34 | /* */ | |
35 | /* The macro FT_COMPONENT is used in trace mode. It is an implicit */ | |
36 | /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */ | |
37 | /* messages during execution. */ | |
38 | /* */ | |
39 | #undef FT_COMPONENT | |
40 | #define FT_COMPONENT trace_ttpload | |
41 | ||
42 | ||
43 | /*************************************************************************/ | |
44 | /* */ | |
45 | /* <Function> */ | |
46 | /* TT_Load_Locations */ | |
47 | /* */ | |
48 | /* <Description> */ | |
49 | /* Loads the locations table. */ | |
50 | /* */ | |
51 | /* <InOut> */ | |
52 | /* face :: A handle to the target face object. */ | |
53 | /* */ | |
54 | /* <Input> */ | |
55 | /* stream :: The input stream. */ | |
56 | /* */ | |
57 | /* <Return> */ | |
58 | /* FreeType error code. 0 means success. */ | |
59 | /* */ | |
60 | LOCAL_FUNC | |
61 | FT_Error TT_Load_Locations( TT_Face face, | |
62 | FT_Stream stream ) | |
63 | { | |
64 | FT_Error error; | |
65 | FT_Memory memory = stream->memory; | |
66 | FT_Short LongOffsets; | |
67 | FT_ULong table_len; | |
68 | ||
69 | ||
70 | FT_TRACE2(( "Locations " )); | |
71 | LongOffsets = face->header.Index_To_Loc_Format; | |
72 | ||
73 | error = face->goto_table( face, TTAG_loca, stream, &table_len ); | |
74 | if ( error ) | |
75 | { | |
76 | error = TT_Err_Locations_Missing; | |
77 | goto Exit; | |
78 | } | |
79 | ||
80 | if ( LongOffsets != 0 ) | |
81 | { | |
82 | face->num_locations = (FT_UShort)( table_len >> 2 ); | |
83 | ||
84 | FT_TRACE2(( "(32bit offsets): %12d ", face->num_locations )); | |
85 | ||
86 | if ( ALLOC_ARRAY( face->glyph_locations, | |
87 | face->num_locations, | |
88 | FT_Long ) ) | |
89 | goto Exit; | |
90 | ||
91 | if ( ACCESS_Frame( face->num_locations * 4L ) ) | |
92 | goto Exit; | |
93 | ||
94 | { | |
95 | FT_Long* loc = face->glyph_locations; | |
96 | FT_Long* limit = loc + face->num_locations; | |
97 | ||
98 | ||
99 | for ( ; loc < limit; loc++ ) | |
100 | *loc = GET_Long(); | |
101 | } | |
102 | ||
103 | FORGET_Frame(); | |
104 | } | |
105 | else | |
106 | { | |
107 | face->num_locations = (FT_UShort)( table_len >> 1 ); | |
108 | ||
109 | FT_TRACE2(( "(16bit offsets): %12d ", face->num_locations )); | |
110 | ||
111 | if ( ALLOC_ARRAY( face->glyph_locations, | |
112 | face->num_locations, | |
113 | FT_Long ) ) | |
114 | goto Exit; | |
115 | ||
116 | if ( ACCESS_Frame( face->num_locations * 2L ) ) | |
117 | goto Exit; | |
118 | { | |
119 | FT_Long* loc = face->glyph_locations; | |
120 | FT_Long* limit = loc + face->num_locations; | |
121 | ||
122 | ||
123 | for ( ; loc < limit; loc++ ) | |
124 | *loc = (FT_Long)( (FT_ULong)GET_UShort() * 2 ); | |
125 | } | |
126 | FORGET_Frame(); | |
127 | } | |
128 | ||
129 | FT_TRACE2(( "loaded\n" )); | |
130 | ||
131 | Exit: | |
132 | return error; | |
133 | } | |
134 | ||
135 | ||
136 | /*************************************************************************/ | |
137 | /* */ | |
138 | /* <Function> */ | |
139 | /* TT_Load_CVT */ | |
140 | /* */ | |
141 | /* <Description> */ | |
142 | /* Loads the control value table into a face object. */ | |
143 | /* */ | |
144 | /* <InOut> */ | |
145 | /* face :: A handle to the target face object. */ | |
146 | /* */ | |
147 | /* <Input> */ | |
148 | /* stream :: A handle to the input stream. */ | |
149 | /* */ | |
150 | /* <Return> */ | |
151 | /* FreeType error code. 0 means success. */ | |
152 | /* */ | |
153 | LOCAL_FUNC | |
154 | FT_Error TT_Load_CVT( TT_Face face, | |
155 | FT_Stream stream ) | |
156 | { | |
157 | FT_Error error; | |
158 | FT_Memory memory = stream->memory; | |
159 | FT_ULong table_len; | |
160 | ||
161 | ||
162 | FT_TRACE2(( "CVT " )); | |
163 | ||
164 | error = face->goto_table( face, TTAG_cvt, stream, &table_len ); | |
165 | if ( error ) | |
166 | { | |
167 | FT_TRACE2(( "is missing!\n" )); | |
168 | ||
169 | face->cvt_size = 0; | |
170 | face->cvt = NULL; | |
171 | error = TT_Err_Ok; | |
172 | ||
173 | goto Exit; | |
174 | } | |
175 | ||
176 | face->cvt_size = table_len / 2; | |
177 | ||
178 | if ( ALLOC_ARRAY( face->cvt, | |
179 | face->cvt_size, | |
180 | FT_Short ) ) | |
181 | goto Exit; | |
182 | ||
183 | if ( ACCESS_Frame( face->cvt_size * 2L ) ) | |
184 | goto Exit; | |
185 | ||
186 | { | |
187 | FT_Short* cur = face->cvt; | |
188 | FT_Short* limit = cur + face->cvt_size; | |
189 | ||
190 | ||
191 | for ( ; cur < limit; cur++ ) | |
192 | *cur = GET_Short(); | |
193 | } | |
194 | ||
195 | FORGET_Frame(); | |
196 | FT_TRACE2(( "loaded\n" )); | |
197 | ||
198 | Exit: | |
199 | return error; | |
200 | } | |
201 | ||
202 | ||
203 | /*************************************************************************/ | |
204 | /* */ | |
205 | /* <Function> */ | |
206 | /* TT_Load_Progams */ | |
207 | /* */ | |
208 | /* <Description> */ | |
209 | /* Loads the font program and the cvt program. */ | |
210 | /* */ | |
211 | /* <InOut> */ | |
212 | /* face :: A handle to the target face object. */ | |
213 | /* */ | |
214 | /* <Input> */ | |
215 | /* stream :: A handle to the input stream. */ | |
216 | /* */ | |
217 | /* <Return> */ | |
218 | /* FreeType error code. 0 means success. */ | |
219 | /* */ | |
220 | LOCAL_FUNC | |
221 | FT_Error TT_Load_Programs( TT_Face face, | |
222 | FT_Stream stream ) | |
223 | { | |
224 | FT_Error error; | |
225 | FT_ULong table_len; | |
226 | ||
227 | ||
228 | FT_TRACE2(( "Font program " )); | |
229 | ||
230 | /* The font program is optional */ | |
231 | error = face->goto_table( face, TTAG_fpgm, stream, &table_len ); | |
232 | if ( error ) | |
233 | { | |
234 | face->font_program = NULL; | |
235 | face->font_program_size = 0; | |
236 | ||
237 | FT_TRACE2(( "is missing!\n" )); | |
238 | } | |
239 | else | |
240 | { | |
241 | face->font_program_size = table_len; | |
242 | if ( EXTRACT_Frame( table_len, face->font_program ) ) | |
243 | goto Exit; | |
244 | ||
245 | FT_TRACE2(( "loaded, %12d bytes\n", face->font_program_size )); | |
246 | } | |
247 | ||
248 | FT_TRACE2(( "Prep program " )); | |
249 | ||
250 | error = face->goto_table( face, TTAG_prep, stream, &table_len ); | |
251 | if ( error ) | |
252 | { | |
253 | face->cvt_program = NULL; | |
254 | face->cvt_program_size = 0; | |
255 | error = TT_Err_Ok; | |
256 | ||
257 | FT_TRACE2(( "is missing!\n" )); | |
258 | } | |
259 | else | |
260 | { | |
261 | face->cvt_program_size = table_len; | |
262 | if ( EXTRACT_Frame( table_len, face->cvt_program ) ) | |
263 | goto Exit; | |
264 | ||
265 | FT_TRACE2(( "loaded, %12d bytes\n", face->cvt_program_size )); | |
266 | } | |
267 | ||
268 | Exit: | |
269 | return error; | |
270 | } | |
271 | ||
272 | ||
273 | /* END */ |