1 /***************************************************************************/
5 /* Type 1 objects manager (body). */
7 /* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007 by */
8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */
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. */
16 /***************************************************************************/
20 #include FT_INTERNAL_DEBUG_H
21 #include FT_INTERNAL_STREAM_H
22 #include FT_TRUETYPE_IDS_H
29 #ifndef T1_CONFIG_OPTION_NO_AFM
33 #include FT_SERVICE_POSTSCRIPT_CMAPS_H
34 #include FT_INTERNAL_POSTSCRIPT_AUX_H
37 /*************************************************************************/
39 /* The macro FT_COMPONENT is used in trace mode. It is an implicit */
40 /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
41 /* messages during execution. */
44 #define FT_COMPONENT trace_t1objs
47 /*************************************************************************/
51 /* note that we store the global hints in the size's "internal" root */
54 /*************************************************************************/
57 static PSH_Globals_Funcs
58 T1_Size_Get_Globals_Funcs( T1_Size size
)
60 T1_Face face
= (T1_Face
)size
->root
.face
;
61 PSHinter_Service pshinter
= (PSHinter_Service
)face
->pshinter
;
65 module
= FT_Get_Module( size
->root
.face
->driver
->root
.library
,
67 return ( module
&& pshinter
&& pshinter
->get_globals_funcs
)
68 ? pshinter
->get_globals_funcs( module
)
74 T1_Size_Done( T1_Size size
)
76 if ( size
->root
.internal
)
78 PSH_Globals_Funcs funcs
;
81 funcs
= T1_Size_Get_Globals_Funcs( size
);
83 funcs
->destroy( (PSH_Globals
)size
->root
.internal
);
85 size
->root
.internal
= 0;
90 FT_LOCAL_DEF( FT_Error
)
91 T1_Size_Init( T1_Size size
)
94 PSH_Globals_Funcs funcs
= T1_Size_Get_Globals_Funcs( size
);
100 T1_Face face
= (T1_Face
)size
->root
.face
;
103 error
= funcs
->create( size
->root
.face
->memory
,
104 &face
->type1
.private_dict
, &globals
);
106 size
->root
.internal
= (FT_Size_Internal
)(void*)globals
;
113 FT_LOCAL_DEF( FT_Error
)
114 T1_Size_Request( T1_Size size
,
115 FT_Size_Request req
)
117 PSH_Globals_Funcs funcs
= T1_Size_Get_Globals_Funcs( size
);
120 FT_Request_Metrics( size
->root
.face
, req
);
123 funcs
->set_scale( (PSH_Globals
)size
->root
.internal
,
124 size
->root
.metrics
.x_scale
,
125 size
->root
.metrics
.y_scale
,
132 /*************************************************************************/
136 /*************************************************************************/
139 T1_GlyphSlot_Done( T1_GlyphSlot slot
)
141 slot
->root
.internal
->glyph_hints
= 0;
145 FT_LOCAL_DEF( FT_Error
)
146 T1_GlyphSlot_Init( T1_GlyphSlot slot
)
149 PSHinter_Service pshinter
;
152 face
= (T1_Face
)slot
->root
.face
;
153 pshinter
= (PSHinter_Service
)face
->pshinter
;
160 module
= FT_Get_Module( slot
->root
.face
->driver
->root
.library
, "pshinter" );
163 T1_Hints_Funcs funcs
;
165 funcs
= pshinter
->get_t1_funcs( module
);
166 slot
->root
.internal
->glyph_hints
= (void*)funcs
;
173 /*************************************************************************/
177 /*************************************************************************/
180 /*************************************************************************/
186 /* The face object destructor. */
189 /* face :: A typeless pointer to the face object to destroy. */
192 T1_Face_Done( T1_Face face
)
196 FT_Memory memory
= face
->root
.memory
;
197 T1_Font type1
= &face
->type1
;
200 #ifndef T1_CONFIG_OPTION_NO_MM_SUPPORT
201 /* release multiple masters information */
202 FT_ASSERT( ( face
->len_buildchar
== 0 ) == ( face
->buildchar
== NULL
) );
204 if ( face
->buildchar
)
206 FT_FREE( face
->buildchar
);
208 face
->buildchar
= NULL
;
209 face
->len_buildchar
= 0;
212 T1_Done_Blend( face
);
216 /* release font info strings */
218 PS_FontInfo info
= &type1
->font_info
;
221 FT_FREE( info
->version
);
222 FT_FREE( info
->notice
);
223 FT_FREE( info
->full_name
);
224 FT_FREE( info
->family_name
);
225 FT_FREE( info
->weight
);
228 /* release top dictionary */
229 FT_FREE( type1
->charstrings_len
);
230 FT_FREE( type1
->charstrings
);
231 FT_FREE( type1
->glyph_names
);
233 FT_FREE( type1
->subrs
);
234 FT_FREE( type1
->subrs_len
);
236 FT_FREE( type1
->subrs_block
);
237 FT_FREE( type1
->charstrings_block
);
238 FT_FREE( type1
->glyph_names_block
);
240 FT_FREE( type1
->encoding
.char_index
);
241 FT_FREE( type1
->encoding
.char_name
);
242 FT_FREE( type1
->font_name
);
244 #ifndef T1_CONFIG_OPTION_NO_AFM
245 /* release afm data if present */
246 if ( face
->afm_data
)
247 T1_Done_Metrics( memory
, (AFM_FontInfo
)face
->afm_data
);
250 /* release unicode map, if any */
252 FT_FREE( face
->unicode_map_rec
.maps
);
253 face
->unicode_map_rec
.num_maps
= 0;
254 face
->unicode_map
= NULL
;
257 face
->root
.family_name
= 0;
258 face
->root
.style_name
= 0;
263 /*************************************************************************/
269 /* The face object constructor. */
272 /* stream :: input stream where to load font data. */
274 /* face_index :: The index of the font face in the resource. */
276 /* num_params :: Number of additional generic parameters. Ignored. */
278 /* params :: Additional generic parameters. Ignored. */
281 /* face :: The face record to build. */
284 /* FreeType error code. 0 means success. */
286 FT_LOCAL_DEF( FT_Error
)
287 T1_Face_Init( FT_Stream stream
,
291 FT_Parameter
* params
)
294 FT_Service_PsCMaps psnames
;
296 T1_Font type1
= &face
->type1
;
297 PS_FontInfo info
= &type1
->font_info
;
299 FT_UNUSED( num_params
);
301 FT_UNUSED( face_index
);
305 face
->root
.num_faces
= 1;
307 FT_FACE_FIND_GLOBAL_SERVICE( face
, psnames
, POSTSCRIPT_CMAPS
);
308 face
->psnames
= psnames
;
310 face
->psaux
= FT_Get_Module_Interface( FT_FACE_LIBRARY( face
),
312 psaux
= (PSAux_Service
)face
->psaux
;
314 face
->pshinter
= FT_Get_Module_Interface( FT_FACE_LIBRARY( face
),
317 /* open the tokenizer; this will also check the font format */
318 error
= T1_Open_Face( face
);
322 /* if we just wanted to check the format, leave successfully now */
323 if ( face_index
< 0 )
326 /* check the face index */
327 if ( face_index
!= 0 )
329 FT_ERROR(( "T1_Face_Init: invalid face index\n" ));
330 error
= T1_Err_Invalid_Argument
;
334 /* now load the font program into the face object */
336 /* initialize the face object fields */
338 /* set up root face fields */
340 FT_Face root
= (FT_Face
)&face
->root
;
343 root
->num_glyphs
= type1
->num_glyphs
;
344 root
->face_index
= face_index
;
346 root
->face_flags
= FT_FACE_FLAG_SCALABLE
|
347 FT_FACE_FLAG_HORIZONTAL
|
348 FT_FACE_FLAG_GLYPH_NAMES
|
351 if ( info
->is_fixed_pitch
)
352 root
->face_flags
|= FT_FACE_FLAG_FIXED_WIDTH
;
355 root
->face_flags
|= FT_FACE_FLAG_MULTIPLE_MASTERS
;
357 /* XXX: TODO -- add kerning with .afm support */
359 /* get style name -- be careful, some broken fonts only */
360 /* have a `/FontName' dictionary entry! */
361 root
->family_name
= info
->family_name
;
362 /* assume "Regular" style if we don't know better */
363 root
->style_name
= (char *)"Regular";
364 if ( root
->family_name
)
366 char* full
= info
->full_name
;
367 char* family
= root
->family_name
;
374 if ( *full
== *family
)
381 if ( *full
== ' ' || *full
== '-' )
383 else if ( *family
== ' ' || *family
== '-' )
388 root
->style_name
= full
;
397 /* do we have a `/FontName'? */
398 if ( type1
->font_name
)
399 root
->family_name
= type1
->font_name
;
402 /* compute style flags */
403 root
->style_flags
= 0;
404 if ( info
->italic_angle
)
405 root
->style_flags
|= FT_STYLE_FLAG_ITALIC
;
408 if ( !ft_strcmp( info
->weight
, "Bold" ) ||
409 !ft_strcmp( info
->weight
, "Black" ) )
410 root
->style_flags
|= FT_STYLE_FLAG_BOLD
;
413 /* no embedded bitmap support */
414 root
->num_fixed_sizes
= 0;
415 root
->available_sizes
= 0;
417 root
->bbox
.xMin
= type1
->font_bbox
.xMin
>> 16;
418 root
->bbox
.yMin
= type1
->font_bbox
.yMin
>> 16;
419 root
->bbox
.xMax
= ( type1
->font_bbox
.xMax
+ 0xFFFFU
) >> 16;
420 root
->bbox
.yMax
= ( type1
->font_bbox
.yMax
+ 0xFFFFU
) >> 16;
422 /* Set units_per_EM if we didn't set it in parse_font_matrix. */
423 if ( !root
->units_per_EM
)
424 root
->units_per_EM
= 1000;
426 root
->ascender
= (FT_Short
)( root
->bbox
.yMax
);
427 root
->descender
= (FT_Short
)( root
->bbox
.yMin
);
429 root
->height
= (FT_Short
)( ( root
->units_per_EM
* 12 ) / 10 );
430 if ( root
->height
< root
->ascender
- root
->descender
)
431 root
->height
= (FT_Short
)( root
->ascender
- root
->descender
);
433 /* now compute the maximum advance width */
434 root
->max_advance_width
=
435 (FT_Short
)( root
->bbox
.xMax
);
440 error
= T1_Compute_Max_Advance( face
, &max_advance
);
442 /* in case of error, keep the standard width */
444 root
->max_advance_width
= (FT_Short
)max_advance
;
446 error
= 0; /* clear error */
449 root
->max_advance_height
= root
->height
;
451 root
->underline_position
= (FT_Short
)info
->underline_position
;
452 root
->underline_thickness
= (FT_Short
)info
->underline_thickness
;
456 FT_Face root
= &face
->root
;
459 if ( psnames
&& psaux
)
461 FT_CharMapRec charmap
;
462 T1_CMap_Classes cmap_classes
= psaux
->t1_cmap_classes
;
468 /* first of all, try to synthetize a Unicode charmap */
469 charmap
.platform_id
= 3;
470 charmap
.encoding_id
= 1;
471 charmap
.encoding
= FT_ENCODING_UNICODE
;
473 FT_CMap_New( cmap_classes
->unicode
, NULL
, &charmap
, NULL
);
475 /* now, generate an Adobe Standard encoding when appropriate */
476 charmap
.platform_id
= 7;
479 switch ( type1
->encoding_type
)
481 case T1_ENCODING_TYPE_STANDARD
:
482 charmap
.encoding
= FT_ENCODING_ADOBE_STANDARD
;
483 charmap
.encoding_id
= TT_ADOBE_ID_STANDARD
;
484 clazz
= cmap_classes
->standard
;
487 case T1_ENCODING_TYPE_EXPERT
:
488 charmap
.encoding
= FT_ENCODING_ADOBE_EXPERT
;
489 charmap
.encoding_id
= TT_ADOBE_ID_EXPERT
;
490 clazz
= cmap_classes
->expert
;
493 case T1_ENCODING_TYPE_ARRAY
:
494 charmap
.encoding
= FT_ENCODING_ADOBE_CUSTOM
;
495 charmap
.encoding_id
= TT_ADOBE_ID_CUSTOM
;
496 clazz
= cmap_classes
->custom
;
499 case T1_ENCODING_TYPE_ISOLATIN1
:
500 charmap
.encoding
= FT_ENCODING_ADOBE_LATIN_1
;
501 charmap
.encoding_id
= TT_ADOBE_ID_LATIN_1
;
502 clazz
= cmap_classes
->unicode
;
510 FT_CMap_New( clazz
, NULL
, &charmap
, NULL
);
513 /* Select default charmap */
514 if (root
->num_charmaps
)
515 root
->charmap
= root
->charmaps
[0];
525 /*************************************************************************/
531 /* Initializes a given Type 1 driver object. */
534 /* driver :: A handle to the target driver object. */
537 /* FreeType error code. 0 means success. */
539 FT_LOCAL_DEF( FT_Error
)
540 T1_Driver_Init( T1_Driver driver
)
548 /*************************************************************************/
554 /* Finalizes a given Type 1 driver. */
557 /* driver :: A handle to the target Type 1 driver. */
560 T1_Driver_Done( T1_Driver driver
)