Disabling auto-refresh of game list by default, as it is causing bugs sometimes
[open-ps2-loader.git] / thirdparty / freetype-2.3.12 / src / cid / cidobjs.c
blob82678af0d4b908335065c28dcda6b334bc826390
1 /***************************************************************************/
2 /* */
3 /* cidobjs.c */
4 /* */
5 /* CID objects manager (body). */
6 /* */
7 /* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2008 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_STREAM_H
23 #include "cidgload.h"
24 #include "cidload.h"
26 #include FT_SERVICE_POSTSCRIPT_CMAPS_H
27 #include FT_INTERNAL_POSTSCRIPT_AUX_H
28 #include FT_INTERNAL_POSTSCRIPT_HINTS_H
30 #include "ciderrs.h"
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_cidobjs
43 /*************************************************************************/
44 /* */
45 /* SLOT FUNCTIONS */
46 /* */
47 /*************************************************************************/
49 FT_LOCAL_DEF( void )
50 cid_slot_done( FT_GlyphSlot slot )
52 slot->internal->glyph_hints = 0;
56 FT_LOCAL_DEF( FT_Error )
57 cid_slot_init( FT_GlyphSlot slot )
59 CID_Face face;
60 PSHinter_Service pshinter;
63 face = (CID_Face)slot->face;
64 pshinter = (PSHinter_Service)face->pshinter;
66 if ( pshinter )
68 FT_Module module;
71 module = FT_Get_Module( slot->face->driver->root.library,
72 "pshinter" );
73 if ( module )
75 T1_Hints_Funcs funcs;
78 funcs = pshinter->get_t1_funcs( module );
79 slot->internal->glyph_hints = (void*)funcs;
83 return 0;
87 /*************************************************************************/
88 /* */
89 /* SIZE FUNCTIONS */
90 /* */
91 /*************************************************************************/
94 static PSH_Globals_Funcs
95 cid_size_get_globals_funcs( CID_Size size )
97 CID_Face face = (CID_Face)size->root.face;
98 PSHinter_Service pshinter = (PSHinter_Service)face->pshinter;
99 FT_Module module;
102 module = FT_Get_Module( size->root.face->driver->root.library,
103 "pshinter" );
104 return ( module && pshinter && pshinter->get_globals_funcs )
105 ? pshinter->get_globals_funcs( module )
106 : 0;
110 FT_LOCAL_DEF( void )
111 cid_size_done( FT_Size cidsize ) /* CID_Size */
113 CID_Size size = (CID_Size)cidsize;
116 if ( cidsize->internal )
118 PSH_Globals_Funcs funcs;
121 funcs = cid_size_get_globals_funcs( size );
122 if ( funcs )
123 funcs->destroy( (PSH_Globals)cidsize->internal );
125 cidsize->internal = 0;
130 FT_LOCAL_DEF( FT_Error )
131 cid_size_init( FT_Size cidsize ) /* CID_Size */
133 CID_Size size = (CID_Size)cidsize;
134 FT_Error error = 0;
135 PSH_Globals_Funcs funcs = cid_size_get_globals_funcs( size );
138 if ( funcs )
140 PSH_Globals globals;
141 CID_Face face = (CID_Face)cidsize->face;
142 CID_FaceDict dict = face->cid.font_dicts + face->root.face_index;
143 PS_Private priv = &dict->private_dict;
146 error = funcs->create( cidsize->face->memory, priv, &globals );
147 if ( !error )
148 cidsize->internal = (FT_Size_Internal)(void*)globals;
151 return error;
155 FT_LOCAL( FT_Error )
156 cid_size_request( FT_Size size,
157 FT_Size_Request req )
159 PSH_Globals_Funcs funcs;
162 FT_Request_Metrics( size->face, req );
164 funcs = cid_size_get_globals_funcs( (CID_Size)size );
166 if ( funcs )
167 funcs->set_scale( (PSH_Globals)size->internal,
168 size->metrics.x_scale,
169 size->metrics.y_scale,
170 0, 0 );
172 return CID_Err_Ok;
176 /*************************************************************************/
177 /* */
178 /* FACE FUNCTIONS */
179 /* */
180 /*************************************************************************/
182 /*************************************************************************/
183 /* */
184 /* <Function> */
185 /* cid_face_done */
186 /* */
187 /* <Description> */
188 /* Finalizes a given face object. */
189 /* */
190 /* <Input> */
191 /* face :: A pointer to the face object to destroy. */
192 /* */
193 FT_LOCAL_DEF( void )
194 cid_face_done( FT_Face cidface ) /* CID_Face */
196 CID_Face face = (CID_Face)cidface;
197 FT_Memory memory;
198 CID_FaceInfo cid;
199 PS_FontInfo info;
202 if ( !face )
203 return;
205 cid = &face->cid;
206 info = &cid->font_info;
207 memory = cidface->memory;
209 /* release subrs */
210 if ( face->subrs )
212 FT_Int n;
215 for ( n = 0; n < cid->num_dicts; n++ )
217 CID_Subrs subr = face->subrs + n;
220 if ( subr->code )
222 FT_FREE( subr->code[0] );
223 FT_FREE( subr->code );
227 FT_FREE( face->subrs );
230 /* release FontInfo strings */
231 FT_FREE( info->version );
232 FT_FREE( info->notice );
233 FT_FREE( info->full_name );
234 FT_FREE( info->family_name );
235 FT_FREE( info->weight );
237 /* release font dictionaries */
238 FT_FREE( cid->font_dicts );
239 cid->num_dicts = 0;
241 /* release other strings */
242 FT_FREE( cid->cid_font_name );
243 FT_FREE( cid->registry );
244 FT_FREE( cid->ordering );
246 cidface->family_name = 0;
247 cidface->style_name = 0;
249 FT_FREE( face->binary_data );
250 FT_FREE( face->cid_stream );
254 /*************************************************************************/
255 /* */
256 /* <Function> */
257 /* cid_face_init */
258 /* */
259 /* <Description> */
260 /* Initializes a given CID face object. */
261 /* */
262 /* <Input> */
263 /* stream :: The source font stream. */
264 /* */
265 /* face_index :: The index of the font face in the resource. */
266 /* */
267 /* num_params :: Number of additional generic parameters. Ignored. */
268 /* */
269 /* params :: Additional generic parameters. Ignored. */
270 /* */
271 /* <InOut> */
272 /* face :: The newly built face object. */
273 /* */
274 /* <Return> */
275 /* FreeType error code. 0 means success. */
276 /* */
277 FT_LOCAL_DEF( FT_Error )
278 cid_face_init( FT_Stream stream,
279 FT_Face cidface, /* CID_Face */
280 FT_Int face_index,
281 FT_Int num_params,
282 FT_Parameter* params )
284 CID_Face face = (CID_Face)cidface;
285 FT_Error error;
286 PSAux_Service psaux;
287 PSHinter_Service pshinter;
289 FT_UNUSED( num_params );
290 FT_UNUSED( params );
291 FT_UNUSED( stream );
294 cidface->num_faces = 1;
296 psaux = (PSAux_Service)face->psaux;
297 if ( !psaux )
299 psaux = (PSAux_Service)FT_Get_Module_Interface(
300 FT_FACE_LIBRARY( face ), "psaux" );
302 face->psaux = psaux;
305 pshinter = (PSHinter_Service)face->pshinter;
306 if ( !pshinter )
308 pshinter = (PSHinter_Service)FT_Get_Module_Interface(
309 FT_FACE_LIBRARY( face ), "pshinter" );
311 face->pshinter = pshinter;
314 /* open the tokenizer; this will also check the font format */
315 if ( FT_STREAM_SEEK( 0 ) )
316 goto Exit;
318 error = cid_face_open( face, face_index );
319 if ( error )
320 goto Exit;
322 /* if we just wanted to check the format, leave successfully now */
323 if ( face_index < 0 )
324 goto Exit;
326 /* check the face index */
327 /* XXX: handle CID fonts with more than a single face */
328 if ( face_index != 0 )
330 FT_ERROR(( "cid_face_init: invalid face index\n" ));
331 error = CID_Err_Invalid_Argument;
332 goto Exit;
335 /* now load the font program into the face object */
337 /* initialize the face object fields */
339 /* set up root face fields */
341 CID_FaceInfo cid = &face->cid;
342 PS_FontInfo info = &cid->font_info;
345 cidface->num_glyphs = cid->cid_count;
346 cidface->num_charmaps = 0;
348 cidface->face_index = face_index;
349 cidface->face_flags = FT_FACE_FLAG_SCALABLE | /* scalable outlines */
350 FT_FACE_FLAG_HORIZONTAL | /* horizontal data */
351 FT_FACE_FLAG_HINTER; /* has native hinter */
353 if ( info->is_fixed_pitch )
354 cidface->face_flags |= FT_FACE_FLAG_FIXED_WIDTH;
356 /* XXX: TODO: add kerning with .afm support */
358 /* get style name -- be careful, some broken fonts only */
359 /* have a /FontName dictionary entry! */
360 cidface->family_name = info->family_name;
361 /* assume "Regular" style if we don't know better */
362 cidface->style_name = (char *)"Regular";
363 if ( cidface->family_name )
365 char* full = info->full_name;
366 char* family = cidface->family_name;
369 if ( full )
371 while ( *full )
373 if ( *full == *family )
375 family++;
376 full++;
378 else
380 if ( *full == ' ' || *full == '-' )
381 full++;
382 else if ( *family == ' ' || *family == '-' )
383 family++;
384 else
386 if ( !*family )
387 cidface->style_name = full;
388 break;
394 else
396 /* do we have a `/FontName'? */
397 if ( cid->cid_font_name )
398 cidface->family_name = cid->cid_font_name;
401 /* compute style flags */
402 cidface->style_flags = 0;
403 if ( info->italic_angle )
404 cidface->style_flags |= FT_STYLE_FLAG_ITALIC;
405 if ( info->weight )
407 if ( !ft_strcmp( info->weight, "Bold" ) ||
408 !ft_strcmp( info->weight, "Black" ) )
409 cidface->style_flags |= FT_STYLE_FLAG_BOLD;
412 /* no embedded bitmap support */
413 cidface->num_fixed_sizes = 0;
414 cidface->available_sizes = 0;
416 cidface->bbox.xMin = cid->font_bbox.xMin >> 16;
417 cidface->bbox.yMin = cid->font_bbox.yMin >> 16;
418 /* no `U' suffix here to 0xFFFF! */
419 cidface->bbox.xMax = ( cid->font_bbox.xMax + 0xFFFF ) >> 16;
420 cidface->bbox.yMax = ( cid->font_bbox.yMax + 0xFFFF ) >> 16;
422 if ( !cidface->units_per_EM )
423 cidface->units_per_EM = 1000;
425 cidface->ascender = (FT_Short)( cidface->bbox.yMax );
426 cidface->descender = (FT_Short)( cidface->bbox.yMin );
428 cidface->height = (FT_Short)( ( cidface->units_per_EM * 12 ) / 10 );
429 if ( cidface->height < cidface->ascender - cidface->descender )
430 cidface->height = (FT_Short)( cidface->ascender - cidface->descender );
432 cidface->underline_position = (FT_Short)info->underline_position;
433 cidface->underline_thickness = (FT_Short)info->underline_thickness;
436 Exit:
437 return error;
441 /*************************************************************************/
442 /* */
443 /* <Function> */
444 /* cid_driver_init */
445 /* */
446 /* <Description> */
447 /* Initializes a given CID driver object. */
448 /* */
449 /* <Input> */
450 /* driver :: A handle to the target driver object. */
451 /* */
452 /* <Return> */
453 /* FreeType error code. 0 means success. */
454 /* */
455 FT_LOCAL_DEF( FT_Error )
456 cid_driver_init( FT_Module driver )
458 FT_UNUSED( driver );
460 return CID_Err_Ok;
464 /*************************************************************************/
465 /* */
466 /* <Function> */
467 /* cid_driver_done */
468 /* */
469 /* <Description> */
470 /* Finalizes a given CID driver. */
471 /* */
472 /* <Input> */
473 /* driver :: A handle to the target CID driver. */
474 /* */
475 FT_LOCAL_DEF( void )
476 cid_driver_done( FT_Module driver )
478 FT_UNUSED( driver );
482 /* END */