1 /***************************************************************************/
5 /* Type 1 objects manager (body). */
7 /* Copyright 1996-2001 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
23 #include <string.h> /* strcmp() */
30 #ifndef T1_CONFIG_OPTION_NO_AFM
34 #include FT_INTERNAL_POSTSCRIPT_NAMES_H
35 #include FT_INTERNAL_POSTSCRIPT_AUX_H
38 /*************************************************************************/
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. */
45 #define FT_COMPONENT trace_t1objs
48 /*************************************************************************/
52 /*************************************************************************/
55 /*************************************************************************/
61 /* The face object destructor. */
64 /* face :: A typeless pointer to the face object to destroy. */
67 T1_Done_Face( T1_Face face )
70 T1_Font* type1 = &face->type1;
75 memory = face->root.memory;
77 #ifndef T1_CONFIG_OPTION_NO_MM_SUPPORT
78 /* release multiple masters information */
79 T1_Done_Blend( face );
83 /* release font info strings */
85 T1_FontInfo* info = &type1->font_info;
88 FREE( info->version );
90 FREE( info->full_name );
91 FREE( info->family_name );
95 /* release top dictionary */
96 FREE( type1->charstrings_len );
97 FREE( type1->charstrings );
98 FREE( type1->glyph_names );
100 FREE( type1->subrs );
101 FREE( type1->subrs_len );
103 FREE( type1->subrs_block );
104 FREE( type1->charstrings_block );
105 FREE( type1->glyph_names_block );
107 FREE( type1->encoding.char_index );
108 FREE( type1->encoding.char_name );
109 FREE( type1->font_name );
111 #ifndef T1_CONFIG_OPTION_NO_AFM
112 /* release afm data if present */
113 if ( face->afm_data )
114 T1_Done_AFM( memory, (T1_AFM*)face->afm_data );
117 /* release unicode map, if any */
118 FREE( face->unicode_map.maps );
119 face->unicode_map.num_maps = 0;
121 face->root.family_name = 0;
122 face->root.style_name = 0;
127 /*************************************************************************/
133 /* The face object constructor. */
136 /* stream :: input stream where to load font data. */
138 /* face_index :: The index of the font face in the resource. */
140 /* num_params :: Number of additional generic parameters. Ignored. */
142 /* params :: Additional generic parameters. Ignored. */
145 /* face :: The face record to build. */
148 /* FreeType error code. 0 means success. */
150 FT_LOCAL_DEF FT_Error
151 T1_Init_Face( FT_Stream stream,
155 FT_Parameter* params )
158 PSNames_Interface* psnames;
159 PSAux_Interface* psaux;
161 FT_UNUSED( num_params );
163 FT_UNUSED( face_index );
167 face->root.num_faces = 1;
169 psnames = (PSNames_Interface*)face->psnames;
172 psnames = (PSNames_Interface*)
173 FT_Get_Module_Interface( FT_FACE_LIBRARY( face ), "psnames" );
175 face->psnames = psnames;
178 psaux = (PSAux_Interface*)face->psaux;
181 psaux = (PSAux_Interface*)
182 FT_Get_Module_Interface( FT_FACE_LIBRARY( face ), "psaux" );
187 /* open the tokenizer, this will also check the font format */
188 error = T1_Open_Face( face );
192 /* if we just wanted to check the format, leave successfully now */
193 if ( face_index < 0 )
196 /* check the face index */
197 if ( face_index != 0 )
199 FT_ERROR(( "T1_Init_Face: invalid face index\n" ));
200 error = T1_Err_Invalid_Argument;
204 /* Now, load the font program into the face object */
206 /* Init the face object fields */
207 /* Now set up root face fields */
209 FT_Face root = (FT_Face)&face->root;
212 root->num_glyphs = face->type1.num_glyphs;
213 root->num_charmaps = 1;
215 root->face_index = face_index;
216 root->face_flags = FT_FACE_FLAG_SCALABLE;
218 root->face_flags |= FT_FACE_FLAG_HORIZONTAL;
220 root->face_flags |= FT_FACE_FLAG_GLYPH_NAMES;
222 if ( face->type1.font_info.is_fixed_pitch )
223 root->face_flags |= FT_FACE_FLAG_FIXED_WIDTH;
226 root->face_flags |= FT_FACE_FLAG_MULTIPLE_MASTERS;
228 /* XXX: TODO -- add kerning with .afm support */
230 /* get style name -- be careful, some broken fonts only */
231 /* have a `/FontName' dictionary entry! */
232 root->family_name = face->type1.font_info.family_name;
233 if ( root->family_name )
235 char* full = face->type1.font_info.full_name;
236 char* family = root->family_name;
239 while ( *family && *full == *family )
245 root->style_name = ( *full == ' ' ? full + 1
246 : (char *)"Regular" );
250 /* do we have a `/FontName'? */
251 if ( face->type1.font_name )
253 root->family_name = face->type1.font_name;
254 root->style_name = (char *)"Regular";
258 /* compute style flags */
259 root->style_flags = 0;
260 if ( face->type1.font_info.italic_angle )
261 root->style_flags |= FT_STYLE_FLAG_ITALIC;
262 if ( face->type1.font_info.weight )
264 if ( !strcmp( face->type1.font_info.weight, "Bold" ) ||
265 !strcmp( face->type1.font_info.weight, "Black" ) )
266 root->style_flags |= FT_STYLE_FLAG_BOLD;
269 /* no embedded bitmap support */
270 root->num_fixed_sizes = 0;
271 root->available_sizes = 0;
273 root->bbox = face->type1.font_bbox;
275 /* Set units_per_EM if we didn't set it in parse_font_matrix. */
276 if ( !root->units_per_EM )
277 root->units_per_EM = 1000;
279 root->ascender = (FT_Short)( face->type1.font_bbox.yMax >> 16 );
280 root->descender = (FT_Short)( face->type1.font_bbox.yMin >> 16 );
281 root->height = (FT_Short)(
282 ( ( root->ascender - root->descender ) * 12 ) / 10 );
284 /* now compute the maximum advance width */
285 root->max_advance_width =
286 (FT_Short)( face->type1.font_bbox.xMax >> 16 );
291 error = T1_Compute_Max_Advance( face, &max_advance );
293 /* in case of error, keep the standard width */
295 root->max_advance_width = (FT_Short)max_advance;
297 error = 0; /* clear error */
300 root->max_advance_height = root->height;
302 root->underline_position = face->type1.font_info.underline_position;
303 root->underline_thickness = face->type1.font_info.underline_thickness;
305 root->internal->max_points = 0;
306 root->internal->max_contours = 0;
309 /* charmap support -- synthetize unicode charmap if possible */
311 FT_Face root = &face->root;
312 FT_CharMap charmap = face->charmaprecs;
315 /* synthesize a Unicode charmap if there is support in the `PSNames' */
319 if ( psnames->unicode_value )
321 error = psnames->build_unicodes(
323 face->type1.num_glyphs,
324 (const char**)face->type1.glyph_names,
325 &face->unicode_map );
328 root->charmap = charmap;
329 charmap->face = (FT_Face)face;
330 charmap->encoding = ft_encoding_unicode;
331 charmap->platform_id = 3;
332 charmap->encoding_id = 1;
336 /* simply clear the error in case of failure (which really) */
337 /* means that out of memory or no unicode glyph names */
342 /* now, support either the standard, expert, or custom encoding */
343 charmap->face = (FT_Face)face;
344 charmap->platform_id = 7; /* a new platform id for Adobe fonts? */
346 switch ( face->type1.encoding_type )
348 case t1_encoding_standard:
349 charmap->encoding = ft_encoding_adobe_standard;
350 charmap->encoding_id = 0;
353 case t1_encoding_expert:
354 charmap->encoding = ft_encoding_adobe_expert;
355 charmap->encoding_id = 1;
359 charmap->encoding = ft_encoding_adobe_custom;
360 charmap->encoding_id = 2;
364 root->charmaps = face->charmaps;
365 root->num_charmaps = charmap - face->charmaprecs + 1;
366 face->charmaps[0] = &face->charmaprecs[0];
367 face->charmaps[1] = &face->charmaprecs[1];
375 /*************************************************************************/
381 /* Initializes a given Type 1 driver object. */
384 /* driver :: A handle to the target driver object. */
387 /* FreeType error code. 0 means success. */
389 FT_LOCAL_DEF FT_Error
390 T1_Init_Driver( T1_Driver driver )
398 /*************************************************************************/
404 /* Finalizes a given Type 1 driver. */
407 /* driver :: A handle to the target Type 1 driver. */
410 T1_Done_Driver( T1_Driver driver )