Disabling auto-refresh of game list by default, as it is causing bugs sometimes
[open-ps2-loader.git] / thirdparty / freetype-2.3.12 / src / base / ftgloadr.c
blobac0010ddd8807de939ddbdc09939c1861b3797de
1 /***************************************************************************/
2 /* */
3 /* ftgloadr.c */
4 /* */
5 /* The FreeType glyph loader (body). */
6 /* */
7 /* Copyright 2002, 2003, 2004, 2005, 2006 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_GLYPH_LOADER_H
21 #include FT_INTERNAL_MEMORY_H
22 #include FT_INTERNAL_OBJECTS_H
24 #undef FT_COMPONENT
25 #define FT_COMPONENT trace_gloader
28 /*************************************************************************/
29 /*************************************************************************/
30 /*************************************************************************/
31 /***** *****/
32 /***** *****/
33 /***** G L Y P H L O A D E R *****/
34 /***** *****/
35 /***** *****/
36 /*************************************************************************/
37 /*************************************************************************/
38 /*************************************************************************/
40 /*************************************************************************/
41 /* */
42 /* The glyph loader is a simple object which is used to load a set of */
43 /* glyphs easily. It is critical for the correct loading of composites. */
44 /* */
45 /* Ideally, one can see it as a stack of abstract `glyph' objects. */
46 /* */
47 /* loader.base Is really the bottom of the stack. It describes a */
48 /* single glyph image made of the juxtaposition of */
49 /* several glyphs (those `in the stack'). */
50 /* */
51 /* loader.current Describes the top of the stack, on which a new */
52 /* glyph can be loaded. */
53 /* */
54 /* Rewind Clears the stack. */
55 /* Prepare Set up `loader.current' for addition of a new glyph */
56 /* image. */
57 /* Add Add the `current' glyph image to the `base' one, */
58 /* and prepare for another one. */
59 /* */
60 /* The glyph loader is now a base object. Each driver used to */
61 /* re-implement it in one way or the other, which wasted code and */
62 /* energy. */
63 /* */
64 /*************************************************************************/
67 /* create a new glyph loader */
68 FT_BASE_DEF( FT_Error )
69 FT_GlyphLoader_New( FT_Memory memory,
70 FT_GlyphLoader *aloader )
72 FT_GlyphLoader loader;
73 FT_Error error;
76 if ( !FT_NEW( loader ) )
78 loader->memory = memory;
79 *aloader = loader;
81 return error;
85 /* rewind the glyph loader - reset counters to 0 */
86 FT_BASE_DEF( void )
87 FT_GlyphLoader_Rewind( FT_GlyphLoader loader )
89 FT_GlyphLoad base = &loader->base;
90 FT_GlyphLoad current = &loader->current;
93 base->outline.n_points = 0;
94 base->outline.n_contours = 0;
95 base->num_subglyphs = 0;
97 *current = *base;
101 /* reset the glyph loader, frees all allocated tables */
102 /* and starts from zero */
103 FT_BASE_DEF( void )
104 FT_GlyphLoader_Reset( FT_GlyphLoader loader )
106 FT_Memory memory = loader->memory;
109 FT_FREE( loader->base.outline.points );
110 FT_FREE( loader->base.outline.tags );
111 FT_FREE( loader->base.outline.contours );
112 FT_FREE( loader->base.extra_points );
113 FT_FREE( loader->base.subglyphs );
115 loader->base.extra_points2 = NULL;
117 loader->max_points = 0;
118 loader->max_contours = 0;
119 loader->max_subglyphs = 0;
121 FT_GlyphLoader_Rewind( loader );
125 /* delete a glyph loader */
126 FT_BASE_DEF( void )
127 FT_GlyphLoader_Done( FT_GlyphLoader loader )
129 if ( loader )
131 FT_Memory memory = loader->memory;
134 FT_GlyphLoader_Reset( loader );
135 FT_FREE( loader );
140 /* re-adjust the `current' outline fields */
141 static void
142 FT_GlyphLoader_Adjust_Points( FT_GlyphLoader loader )
144 FT_Outline* base = &loader->base.outline;
145 FT_Outline* current = &loader->current.outline;
148 current->points = base->points + base->n_points;
149 current->tags = base->tags + base->n_points;
150 current->contours = base->contours + base->n_contours;
152 /* handle extra points table - if any */
153 if ( loader->use_extra )
155 loader->current.extra_points = loader->base.extra_points +
156 base->n_points;
158 loader->current.extra_points2 = loader->base.extra_points2 +
159 base->n_points;
164 FT_BASE_DEF( FT_Error )
165 FT_GlyphLoader_CreateExtra( FT_GlyphLoader loader )
167 FT_Error error;
168 FT_Memory memory = loader->memory;
171 if ( !FT_NEW_ARRAY( loader->base.extra_points, 2 * loader->max_points ) )
173 loader->use_extra = 1;
174 loader->base.extra_points2 = loader->base.extra_points +
175 loader->max_points;
177 FT_GlyphLoader_Adjust_Points( loader );
179 return error;
183 /* re-adjust the `current' subglyphs field */
184 static void
185 FT_GlyphLoader_Adjust_Subglyphs( FT_GlyphLoader loader )
187 FT_GlyphLoad base = &loader->base;
188 FT_GlyphLoad current = &loader->current;
191 current->subglyphs = base->subglyphs + base->num_subglyphs;
195 /* Ensure that we can add `n_points' and `n_contours' to our glyph. */
196 /* This function reallocates its outline tables if necessary. Note that */
197 /* it DOESN'T change the number of points within the loader! */
198 /* */
199 FT_BASE_DEF( FT_Error )
200 FT_GlyphLoader_CheckPoints( FT_GlyphLoader loader,
201 FT_UInt n_points,
202 FT_UInt n_contours )
204 FT_Memory memory = loader->memory;
205 FT_Error error = FT_Err_Ok;
206 FT_Outline* base = &loader->base.outline;
207 FT_Outline* current = &loader->current.outline;
208 FT_Bool adjust = 0;
210 FT_UInt new_max, old_max;
213 /* check points & tags */
214 new_max = base->n_points + current->n_points + n_points;
215 old_max = loader->max_points;
217 if ( new_max > old_max )
219 new_max = FT_PAD_CEIL( new_max, 8 );
221 if ( new_max > FT_OUTLINE_POINTS_MAX )
222 return FT_Err_Array_Too_Large;
224 if ( FT_RENEW_ARRAY( base->points, old_max, new_max ) ||
225 FT_RENEW_ARRAY( base->tags, old_max, new_max ) )
226 goto Exit;
228 if ( loader->use_extra )
230 if ( FT_RENEW_ARRAY( loader->base.extra_points,
231 old_max * 2, new_max * 2 ) )
232 goto Exit;
234 FT_ARRAY_MOVE( loader->base.extra_points + new_max,
235 loader->base.extra_points + old_max,
236 old_max );
238 loader->base.extra_points2 = loader->base.extra_points + new_max;
241 adjust = 1;
242 loader->max_points = new_max;
245 /* check contours */
246 old_max = loader->max_contours;
247 new_max = base->n_contours + current->n_contours +
248 n_contours;
249 if ( new_max > old_max )
251 new_max = FT_PAD_CEIL( new_max, 4 );
253 if ( new_max > FT_OUTLINE_CONTOURS_MAX )
254 return FT_Err_Array_Too_Large;
256 if ( FT_RENEW_ARRAY( base->contours, old_max, new_max ) )
257 goto Exit;
259 adjust = 1;
260 loader->max_contours = new_max;
263 if ( adjust )
264 FT_GlyphLoader_Adjust_Points( loader );
266 Exit:
267 return error;
271 /* Ensure that we can add `n_subglyphs' to our glyph. this function */
272 /* reallocates its subglyphs table if necessary. Note that it DOES */
273 /* NOT change the number of subglyphs within the loader! */
274 /* */
275 FT_BASE_DEF( FT_Error )
276 FT_GlyphLoader_CheckSubGlyphs( FT_GlyphLoader loader,
277 FT_UInt n_subs )
279 FT_Memory memory = loader->memory;
280 FT_Error error = FT_Err_Ok;
281 FT_UInt new_max, old_max;
283 FT_GlyphLoad base = &loader->base;
284 FT_GlyphLoad current = &loader->current;
287 new_max = base->num_subglyphs + current->num_subglyphs + n_subs;
288 old_max = loader->max_subglyphs;
289 if ( new_max > old_max )
291 new_max = FT_PAD_CEIL( new_max, 2 );
292 if ( FT_RENEW_ARRAY( base->subglyphs, old_max, new_max ) )
293 goto Exit;
295 loader->max_subglyphs = new_max;
297 FT_GlyphLoader_Adjust_Subglyphs( loader );
300 Exit:
301 return error;
305 /* prepare loader for the addition of a new glyph on top of the base one */
306 FT_BASE_DEF( void )
307 FT_GlyphLoader_Prepare( FT_GlyphLoader loader )
309 FT_GlyphLoad current = &loader->current;
312 current->outline.n_points = 0;
313 current->outline.n_contours = 0;
314 current->num_subglyphs = 0;
316 FT_GlyphLoader_Adjust_Points ( loader );
317 FT_GlyphLoader_Adjust_Subglyphs( loader );
321 /* add current glyph to the base image - and prepare for another */
322 FT_BASE_DEF( void )
323 FT_GlyphLoader_Add( FT_GlyphLoader loader )
325 FT_GlyphLoad base;
326 FT_GlyphLoad current;
328 FT_UInt n_curr_contours;
329 FT_UInt n_base_points;
330 FT_UInt n;
333 if ( !loader )
334 return;
336 base = &loader->base;
337 current = &loader->current;
339 n_curr_contours = current->outline.n_contours;
340 n_base_points = base->outline.n_points;
342 base->outline.n_points =
343 (short)( base->outline.n_points + current->outline.n_points );
344 base->outline.n_contours =
345 (short)( base->outline.n_contours + current->outline.n_contours );
347 base->num_subglyphs += current->num_subglyphs;
349 /* adjust contours count in newest outline */
350 for ( n = 0; n < n_curr_contours; n++ )
351 current->outline.contours[n] =
352 (short)( current->outline.contours[n] + n_base_points );
354 /* prepare for another new glyph image */
355 FT_GlyphLoader_Prepare( loader );
359 FT_BASE_DEF( FT_Error )
360 FT_GlyphLoader_CopyPoints( FT_GlyphLoader target,
361 FT_GlyphLoader source )
363 FT_Error error;
364 FT_UInt num_points = source->base.outline.n_points;
365 FT_UInt num_contours = source->base.outline.n_contours;
368 error = FT_GlyphLoader_CheckPoints( target, num_points, num_contours );
369 if ( !error )
371 FT_Outline* out = &target->base.outline;
372 FT_Outline* in = &source->base.outline;
375 FT_ARRAY_COPY( out->points, in->points,
376 num_points );
377 FT_ARRAY_COPY( out->tags, in->tags,
378 num_points );
379 FT_ARRAY_COPY( out->contours, in->contours,
380 num_contours );
382 /* do we need to copy the extra points? */
383 if ( target->use_extra && source->use_extra )
385 FT_ARRAY_COPY( target->base.extra_points, source->base.extra_points,
386 num_points );
387 FT_ARRAY_COPY( target->base.extra_points2, source->base.extra_points2,
388 num_points );
391 out->n_points = (short)num_points;
392 out->n_contours = (short)num_contours;
394 FT_GlyphLoader_Adjust_Points( target );
397 return error;
401 /* END */