1 /***************************************************************************/
5 /* CID 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
24 #include FT_INTERNAL_POSTSCRIPT_NAMES_H
25 #include FT_INTERNAL_POSTSCRIPT_AUX_H
30 /*************************************************************************/
32 /* The macro FT_COMPONENT is used in trace mode. It is an implicit */
33 /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
34 /* messages during execution. */
37 #define FT_COMPONENT trace_cidobjs
40 /*************************************************************************/
44 /*************************************************************************/
47 /*************************************************************************/
53 /* Finalizes a given face object. */
56 /* face :: A pointer to the face object to destroy. */
59 CID_Done_Face( CID_Face face )
66 CID_Info* cid = &face->cid;
67 T1_FontInfo* info = &cid->font_info;
70 memory = face->root.memory;
72 /* release FontInfo strings */
73 FREE( info->version );
75 FREE( info->full_name );
76 FREE( info->family_name );
79 /* release font dictionaries */
80 FREE( cid->font_dicts );
83 /* release other strings */
84 FREE( cid->cid_font_name );
85 FREE( cid->registry );
86 FREE( cid->ordering );
88 face->root.family_name = 0;
89 face->root.style_name = 0;
94 /*************************************************************************/
100 /* Initializes a given CID face object. */
103 /* stream :: The source font stream. */
105 /* face_index :: The index of the font face in the resource. */
107 /* num_params :: Number of additional generic parameters. Ignored. */
109 /* params :: Additional generic parameters. Ignored. */
112 /* face :: The newly built face object. */
115 /* FreeType error code. 0 means success. */
117 FT_LOCAL_DEF FT_Error
118 CID_Init_Face( FT_Stream stream,
122 FT_Parameter* params )
125 PSNames_Interface* psnames;
126 PSAux_Interface* psaux;
128 FT_UNUSED( num_params );
130 FT_UNUSED( face_index );
134 face->root.num_faces = 1;
136 psnames = (PSNames_Interface*)face->psnames;
139 psnames = (PSNames_Interface*)FT_Get_Module_Interface(
140 FT_FACE_LIBRARY( face ), "psnames" );
142 face->psnames = psnames;
145 psaux = (PSAux_Interface*)face->psaux;
148 psaux = (PSAux_Interface*)FT_Get_Module_Interface(
149 FT_FACE_LIBRARY( face ), "psaux" );
154 /* open the tokenizer; this will also check the font format */
155 if ( FILE_Seek( 0 ) )
158 error = CID_Open_Face( face );
162 /* if we just wanted to check the format, leave successfully now */
163 if ( face_index < 0 )
166 /* check the face index */
167 if ( face_index != 0 )
169 FT_ERROR(( "CID_Init_Face: invalid face index\n" ));
170 error = CID_Err_Invalid_Argument;
174 /* Now, load the font program into the face object */
176 /* Init the face object fields */
177 /* Now set up root face fields */
179 FT_Face root = (FT_Face)&face->root;
182 root->num_glyphs = face->cid.cid_count;
183 root->num_charmaps = 0;
185 root->face_index = face_index;
186 root->face_flags = FT_FACE_FLAG_SCALABLE;
188 root->face_flags |= FT_FACE_FLAG_HORIZONTAL;
190 if ( face->cid.font_info.is_fixed_pitch )
191 root->face_flags |= FT_FACE_FLAG_FIXED_WIDTH;
193 /* XXX: TODO: add kerning with .afm support */
195 /* get style name -- be careful, some broken fonts only */
196 /* have a /FontName dictionary entry! */
197 root->family_name = face->cid.font_info.family_name;
198 if ( root->family_name )
200 char* full = face->cid.font_info.full_name;
201 char* family = root->family_name;
203 while ( *family && *full == *family )
209 root->style_name = ( *full == ' ' ) ? full + 1
214 /* do we have a `/FontName'? */
215 if ( face->cid.cid_font_name )
217 root->family_name = face->cid.cid_font_name;
218 root->style_name = (char *)"Regular";
222 /* no embedded bitmap support */
223 root->num_fixed_sizes = 0;
224 root->available_sizes = 0;
226 root->bbox = face->cid.font_bbox;
227 if ( !root->units_per_EM )
228 root->units_per_EM = 1000;
230 root->ascender = (FT_Short)( face->cid.font_bbox.yMax >> 16 );
231 root->descender = (FT_Short)( face->cid.font_bbox.yMin >> 16 );
232 root->height = (FT_Short)(
233 ( ( root->ascender + root->descender ) * 12 ) / 10 );
238 /* now compute the maximum advance width */
240 root->max_advance_width = face->type1.private_dict.standard_width[0];
242 /* compute max advance width for proportional fonts */
243 if ( !face->type1.font_info.is_fixed_pitch )
248 error = CID_Compute_Max_Advance( face, &max_advance );
250 /* in case of error, keep the standard width */
252 root->max_advance_width = max_advance;
254 error = 0; /* clear error */
257 root->max_advance_height = root->height;
261 root->underline_position = face->cid.font_info.underline_position;
262 root->underline_thickness = face->cid.font_info.underline_thickness;
264 root->internal->max_points = 0;
265 root->internal->max_contours = 0;
271 /* charmap support - synthetize unicode charmap when possible */
273 FT_Face root = &face->root;
274 FT_CharMap charmap = face->charmaprecs;
277 /* synthesize a Unicode charmap if there is support in the `psnames' */
281 PSNames_Interface* psnames = (PSNames_Interface*)face->psnames;
284 if ( psnames->unicode_value )
286 error = psnames->build_unicodes(
288 face->type1.num_glyphs,
289 (const char**)face->type1.glyph_names,
290 &face->unicode_map );
293 root->charmap = charmap;
294 charmap->face = (FT_Face)face;
295 charmap->encoding = ft_encoding_unicode;
296 charmap->platform_id = 3;
297 charmap->encoding_id = 1;
301 /* simply clear the error in case of failure (which really */
302 /* means that out of memory or no unicode glyph names) */
307 /* now, support either the standard, expert, or custom encodings */
308 charmap->face = (FT_Face)face;
309 charmap->platform_id = 7; /* a new platform id for Adobe fonts? */
311 switch ( face->type1.encoding_type )
313 case t1_encoding_standard:
314 charmap->encoding = ft_encoding_adobe_standard;
315 charmap->encoding_id = 0;
318 case t1_encoding_expert:
319 charmap->encoding = ft_encoding_adobe_expert;
320 charmap->encoding_id = 1;
324 charmap->encoding = ft_encoding_adobe_custom;
325 charmap->encoding_id = 2;
329 root->charmaps = face->charmaps;
330 root->num_charmaps = charmap - face->charmaprecs + 1;
331 face->charmaps[0] = &face->charmaprecs[0];
332 face->charmaps[1] = &face->charmaprecs[1];
342 /*************************************************************************/
345 /* CID_Init_Driver */
348 /* Initializes a given CID driver object. */
351 /* driver :: A handle to the target driver object. */
354 /* FreeType error code. 0 means success. */
356 FT_LOCAL_DEF FT_Error
357 CID_Init_Driver( CID_Driver driver )
365 /*************************************************************************/
368 /* CID_Done_Driver */
371 /* Finalizes a given CID driver. */
374 /* driver :: A handle to the target CID driver. */
377 CID_Done_Driver( CID_Driver driver )