Disabling auto-refresh of game list by default, as it is causing bugs sometimes
[open-ps2-loader.git] / thirdparty / freetype-2.3.12 / src / type1 / t1objs.c
blobb1de6871967873f298c8bce3c938c500b23cba75
1 /***************************************************************************/
2 /* */
3 /* t1objs.c */
4 /* */
5 /* Type 1 objects manager (body). */
6 /* */
7 /* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 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_CALC_H
21 #include FT_INTERNAL_DEBUG_H
22 #include FT_INTERNAL_STREAM_H
23 #include FT_TRUETYPE_IDS_H
25 #include "t1gload.h"
26 #include "t1load.h"
28 #include "t1errors.h"
30 #ifndef T1_CONFIG_OPTION_NO_AFM
31 #include "t1afm.h"
32 #endif
34 #include FT_SERVICE_POSTSCRIPT_CMAPS_H
35 #include FT_INTERNAL_POSTSCRIPT_AUX_H
38 /*************************************************************************/
39 /* */
40 /* The macro FT_COMPONENT is used in trace mode. It is an implicit */
41 /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
42 /* messages during execution. */
43 /* */
44 #undef FT_COMPONENT
45 #define FT_COMPONENT trace_t1objs
48 /*************************************************************************/
49 /* */
50 /* SIZE FUNCTIONS */
51 /* */
52 /* note that we store the global hints in the size's "internal" root */
53 /* field */
54 /* */
55 /*************************************************************************/
58 static PSH_Globals_Funcs
59 T1_Size_Get_Globals_Funcs( T1_Size size )
61 T1_Face face = (T1_Face)size->root.face;
62 PSHinter_Service pshinter = (PSHinter_Service)face->pshinter;
63 FT_Module module;
66 module = FT_Get_Module( size->root.face->driver->root.library,
67 "pshinter" );
68 return ( module && pshinter && pshinter->get_globals_funcs )
69 ? pshinter->get_globals_funcs( module )
70 : 0 ;
74 FT_LOCAL_DEF( void )
75 T1_Size_Done( T1_Size size )
77 if ( size->root.internal )
79 PSH_Globals_Funcs funcs;
82 funcs = T1_Size_Get_Globals_Funcs( size );
83 if ( funcs )
84 funcs->destroy( (PSH_Globals)size->root.internal );
86 size->root.internal = 0;
91 FT_LOCAL_DEF( FT_Error )
92 T1_Size_Init( T1_Size size )
94 FT_Error error = T1_Err_Ok;
95 PSH_Globals_Funcs funcs = T1_Size_Get_Globals_Funcs( size );
98 if ( funcs )
100 PSH_Globals globals;
101 T1_Face face = (T1_Face)size->root.face;
104 error = funcs->create( size->root.face->memory,
105 &face->type1.private_dict, &globals );
106 if ( !error )
107 size->root.internal = (FT_Size_Internal)(void*)globals;
110 return error;
114 FT_LOCAL_DEF( FT_Error )
115 T1_Size_Request( T1_Size size,
116 FT_Size_Request req )
118 PSH_Globals_Funcs funcs = T1_Size_Get_Globals_Funcs( size );
121 FT_Request_Metrics( size->root.face, req );
123 if ( funcs )
124 funcs->set_scale( (PSH_Globals)size->root.internal,
125 size->root.metrics.x_scale,
126 size->root.metrics.y_scale,
127 0, 0 );
129 return T1_Err_Ok;
133 /*************************************************************************/
134 /* */
135 /* SLOT FUNCTIONS */
136 /* */
137 /*************************************************************************/
139 FT_LOCAL_DEF( void )
140 T1_GlyphSlot_Done( T1_GlyphSlot slot )
142 slot->root.internal->glyph_hints = 0;
146 FT_LOCAL_DEF( FT_Error )
147 T1_GlyphSlot_Init( T1_GlyphSlot slot )
149 T1_Face face;
150 PSHinter_Service pshinter;
153 face = (T1_Face)slot->root.face;
154 pshinter = (PSHinter_Service)face->pshinter;
156 if ( pshinter )
158 FT_Module module;
161 module = FT_Get_Module( slot->root.face->driver->root.library, "pshinter" );
162 if (module)
164 T1_Hints_Funcs funcs;
166 funcs = pshinter->get_t1_funcs( module );
167 slot->root.internal->glyph_hints = (void*)funcs;
170 return 0;
174 /*************************************************************************/
175 /* */
176 /* FACE FUNCTIONS */
177 /* */
178 /*************************************************************************/
181 /*************************************************************************/
182 /* */
183 /* <Function> */
184 /* T1_Face_Done */
185 /* */
186 /* <Description> */
187 /* The face object destructor. */
188 /* */
189 /* <Input> */
190 /* face :: A typeless pointer to the face object to destroy. */
191 /* */
192 FT_LOCAL_DEF( void )
193 T1_Face_Done( T1_Face face )
195 FT_Memory memory;
196 T1_Font type1;
199 if ( !face )
200 return;
202 memory = face->root.memory;
203 type1 = &face->type1;
205 #ifndef T1_CONFIG_OPTION_NO_MM_SUPPORT
206 /* release multiple masters information */
207 FT_ASSERT( ( face->len_buildchar == 0 ) == ( face->buildchar == NULL ) );
209 if ( face->buildchar )
211 FT_FREE( face->buildchar );
213 face->buildchar = NULL;
214 face->len_buildchar = 0;
217 T1_Done_Blend( face );
218 face->blend = 0;
219 #endif
221 /* release font info strings */
223 PS_FontInfo info = &type1->font_info;
226 FT_FREE( info->version );
227 FT_FREE( info->notice );
228 FT_FREE( info->full_name );
229 FT_FREE( info->family_name );
230 FT_FREE( info->weight );
233 /* release top dictionary */
234 FT_FREE( type1->charstrings_len );
235 FT_FREE( type1->charstrings );
236 FT_FREE( type1->glyph_names );
238 FT_FREE( type1->subrs );
239 FT_FREE( type1->subrs_len );
241 FT_FREE( type1->subrs_block );
242 FT_FREE( type1->charstrings_block );
243 FT_FREE( type1->glyph_names_block );
245 FT_FREE( type1->encoding.char_index );
246 FT_FREE( type1->encoding.char_name );
247 FT_FREE( type1->font_name );
249 #ifndef T1_CONFIG_OPTION_NO_AFM
250 /* release afm data if present */
251 if ( face->afm_data )
252 T1_Done_Metrics( memory, (AFM_FontInfo)face->afm_data );
253 #endif
255 /* release unicode map, if any */
256 #if 0
257 FT_FREE( face->unicode_map_rec.maps );
258 face->unicode_map_rec.num_maps = 0;
259 face->unicode_map = NULL;
260 #endif
262 face->root.family_name = NULL;
263 face->root.style_name = NULL;
267 /*************************************************************************/
268 /* */
269 /* <Function> */
270 /* T1_Face_Init */
271 /* */
272 /* <Description> */
273 /* The face object constructor. */
274 /* */
275 /* <Input> */
276 /* stream :: input stream where to load font data. */
277 /* */
278 /* face_index :: The index of the font face in the resource. */
279 /* */
280 /* num_params :: Number of additional generic parameters. Ignored. */
281 /* */
282 /* params :: Additional generic parameters. Ignored. */
283 /* */
284 /* <InOut> */
285 /* face :: The face record to build. */
286 /* */
287 /* <Return> */
288 /* FreeType error code. 0 means success. */
289 /* */
290 FT_LOCAL_DEF( FT_Error )
291 T1_Face_Init( FT_Stream stream,
292 T1_Face face,
293 FT_Int face_index,
294 FT_Int num_params,
295 FT_Parameter* params )
297 FT_Error error;
298 FT_Service_PsCMaps psnames;
299 PSAux_Service psaux;
300 T1_Font type1 = &face->type1;
301 PS_FontInfo info = &type1->font_info;
303 FT_UNUSED( num_params );
304 FT_UNUSED( params );
305 FT_UNUSED( stream );
308 face->root.num_faces = 1;
310 FT_FACE_FIND_GLOBAL_SERVICE( face, psnames, POSTSCRIPT_CMAPS );
311 face->psnames = psnames;
313 face->psaux = FT_Get_Module_Interface( FT_FACE_LIBRARY( face ),
314 "psaux" );
315 psaux = (PSAux_Service)face->psaux;
317 face->pshinter = FT_Get_Module_Interface( FT_FACE_LIBRARY( face ),
318 "pshinter" );
320 /* open the tokenizer; this will also check the font format */
321 error = T1_Open_Face( face );
322 if ( error )
323 goto Exit;
325 /* if we just wanted to check the format, leave successfully now */
326 if ( face_index < 0 )
327 goto Exit;
329 /* check the face index */
330 if ( face_index > 0 )
332 FT_ERROR(( "T1_Face_Init: invalid face index\n" ));
333 error = T1_Err_Invalid_Argument;
334 goto Exit;
337 /* now load the font program into the face object */
339 /* initialize the face object fields */
341 /* set up root face fields */
343 FT_Face root = (FT_Face)&face->root;
346 root->num_glyphs = type1->num_glyphs;
347 root->face_index = 0;
349 root->face_flags = FT_FACE_FLAG_SCALABLE |
350 FT_FACE_FLAG_HORIZONTAL |
351 FT_FACE_FLAG_GLYPH_NAMES |
352 FT_FACE_FLAG_HINTER;
354 if ( info->is_fixed_pitch )
355 root->face_flags |= FT_FACE_FLAG_FIXED_WIDTH;
357 if ( face->blend )
358 root->face_flags |= FT_FACE_FLAG_MULTIPLE_MASTERS;
360 /* XXX: TODO -- add kerning with .afm support */
363 /* The following code to extract the family and the style is very */
364 /* simplistic and might get some things wrong. For a full-featured */
365 /* algorithm you might have a look at the whitepaper given at */
366 /* */
367 /* http://blogs.msdn.com/text/archive/2007/04/23/wpf-font-selection-model.aspx */
369 /* get style name -- be careful, some broken fonts only */
370 /* have a `/FontName' dictionary entry! */
371 root->family_name = info->family_name;
372 root->style_name = NULL;
374 if ( root->family_name )
376 char* full = info->full_name;
377 char* family = root->family_name;
380 if ( full )
382 FT_Bool the_same = TRUE;
385 while ( *full )
387 if ( *full == *family )
389 family++;
390 full++;
392 else
394 if ( *full == ' ' || *full == '-' )
395 full++;
396 else if ( *family == ' ' || *family == '-' )
397 family++;
398 else
400 the_same = FALSE;
402 if ( !*family )
403 root->style_name = full;
404 break;
409 if ( the_same )
410 root->style_name = (char *)"Regular";
413 else
415 /* do we have a `/FontName'? */
416 if ( type1->font_name )
417 root->family_name = type1->font_name;
420 if ( !root->style_name )
422 if ( info->weight )
423 root->style_name = info->weight;
424 else
425 /* assume `Regular' style because we don't know better */
426 root->style_name = (char *)"Regular";
429 /* compute style flags */
430 root->style_flags = 0;
431 if ( info->italic_angle )
432 root->style_flags |= FT_STYLE_FLAG_ITALIC;
433 if ( info->weight )
435 if ( !ft_strcmp( info->weight, "Bold" ) ||
436 !ft_strcmp( info->weight, "Black" ) )
437 root->style_flags |= FT_STYLE_FLAG_BOLD;
440 /* no embedded bitmap support */
441 root->num_fixed_sizes = 0;
442 root->available_sizes = 0;
444 root->bbox.xMin = type1->font_bbox.xMin >> 16;
445 root->bbox.yMin = type1->font_bbox.yMin >> 16;
446 /* no `U' suffix here to 0xFFFF! */
447 root->bbox.xMax = ( type1->font_bbox.xMax + 0xFFFF ) >> 16;
448 root->bbox.yMax = ( type1->font_bbox.yMax + 0xFFFF ) >> 16;
450 /* Set units_per_EM if we didn't set it in parse_font_matrix. */
451 if ( !root->units_per_EM )
452 root->units_per_EM = 1000;
454 root->ascender = (FT_Short)( root->bbox.yMax );
455 root->descender = (FT_Short)( root->bbox.yMin );
457 root->height = (FT_Short)( ( root->units_per_EM * 12 ) / 10 );
458 if ( root->height < root->ascender - root->descender )
459 root->height = (FT_Short)( root->ascender - root->descender );
461 /* now compute the maximum advance width */
462 root->max_advance_width =
463 (FT_Short)( root->bbox.xMax );
465 FT_Pos max_advance;
468 error = T1_Compute_Max_Advance( face, &max_advance );
470 /* in case of error, keep the standard width */
471 if ( !error )
472 root->max_advance_width = (FT_Short)FIXED_TO_INT( max_advance );
473 else
474 error = T1_Err_Ok; /* clear error */
477 root->max_advance_height = root->height;
479 root->underline_position = (FT_Short)info->underline_position;
480 root->underline_thickness = (FT_Short)info->underline_thickness;
484 FT_Face root = &face->root;
487 if ( psnames && psaux )
489 FT_CharMapRec charmap;
490 T1_CMap_Classes cmap_classes = psaux->t1_cmap_classes;
491 FT_CMap_Class clazz;
494 charmap.face = root;
496 /* first of all, try to synthesize a Unicode charmap */
497 charmap.platform_id = 3;
498 charmap.encoding_id = 1;
499 charmap.encoding = FT_ENCODING_UNICODE;
501 FT_CMap_New( cmap_classes->unicode, NULL, &charmap, NULL );
503 /* now, generate an Adobe Standard encoding when appropriate */
504 charmap.platform_id = 7;
505 clazz = NULL;
507 switch ( type1->encoding_type )
509 case T1_ENCODING_TYPE_STANDARD:
510 charmap.encoding = FT_ENCODING_ADOBE_STANDARD;
511 charmap.encoding_id = TT_ADOBE_ID_STANDARD;
512 clazz = cmap_classes->standard;
513 break;
515 case T1_ENCODING_TYPE_EXPERT:
516 charmap.encoding = FT_ENCODING_ADOBE_EXPERT;
517 charmap.encoding_id = TT_ADOBE_ID_EXPERT;
518 clazz = cmap_classes->expert;
519 break;
521 case T1_ENCODING_TYPE_ARRAY:
522 charmap.encoding = FT_ENCODING_ADOBE_CUSTOM;
523 charmap.encoding_id = TT_ADOBE_ID_CUSTOM;
524 clazz = cmap_classes->custom;
525 break;
527 case T1_ENCODING_TYPE_ISOLATIN1:
528 charmap.encoding = FT_ENCODING_ADOBE_LATIN_1;
529 charmap.encoding_id = TT_ADOBE_ID_LATIN_1;
530 clazz = cmap_classes->unicode;
531 break;
533 default:
537 if ( clazz )
538 FT_CMap_New( clazz, NULL, &charmap, NULL );
540 #if 0
541 /* Select default charmap */
542 if (root->num_charmaps)
543 root->charmap = root->charmaps[0];
544 #endif
548 Exit:
549 return error;
553 /*************************************************************************/
554 /* */
555 /* <Function> */
556 /* T1_Driver_Init */
557 /* */
558 /* <Description> */
559 /* Initializes a given Type 1 driver object. */
560 /* */
561 /* <Input> */
562 /* driver :: A handle to the target driver object. */
563 /* */
564 /* <Return> */
565 /* FreeType error code. 0 means success. */
566 /* */
567 FT_LOCAL_DEF( FT_Error )
568 T1_Driver_Init( T1_Driver driver )
570 FT_UNUSED( driver );
572 return T1_Err_Ok;
576 /*************************************************************************/
577 /* */
578 /* <Function> */
579 /* T1_Driver_Done */
580 /* */
581 /* <Description> */
582 /* Finalizes a given Type 1 driver. */
583 /* */
584 /* <Input> */
585 /* driver :: A handle to the target Type 1 driver. */
586 /* */
587 FT_LOCAL_DEF( void )
588 T1_Driver_Done( T1_Driver driver )
590 FT_UNUSED( driver );
594 /* END */