1 /***************************************************************************/
5 /* CID objects manager (body). */
7 /* Copyright 1996-2001, 2002 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
26 #include FT_INTERNAL_POSTSCRIPT_HINTS_H
31 /*************************************************************************/
33 /* The macro FT_COMPONENT is used in trace mode. It is an implicit */
34 /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
35 /* messages during execution. */
38 #define FT_COMPONENT trace_cidobjs
41 /*************************************************************************/
45 /*************************************************************************/
48 cid_slot_done( CID_GlyphSlot slot )
50 slot->root.internal->glyph_hints = 0;
54 FT_LOCAL_DEF( FT_Error )
55 cid_slot_init( CID_GlyphSlot slot )
58 PSHinter_Service pshinter;
61 face = (CID_Face)slot->root.face;
62 pshinter = (PSHinter_Service)face->pshinter;
69 module = FT_Get_Module( slot->root.face->driver->root.library,
76 funcs = pshinter->get_t1_funcs( module );
77 slot->root.internal->glyph_hints = (void*)funcs;
85 /*************************************************************************/
89 /*************************************************************************/
92 static PSH_Globals_Funcs
93 cid_size_get_globals_funcs( CID_Size size )
95 CID_Face face = (CID_Face)size->root.face;
96 PSHinter_Service pshinter = (PSHinter_Service)face->pshinter;
100 module = FT_Get_Module( size->root.face->driver->root.library,
102 return ( module && pshinter && pshinter->get_globals_funcs )
103 ? pshinter->get_globals_funcs( module )
109 cid_size_done( CID_Size size )
111 if ( size->root.internal )
113 PSH_Globals_Funcs funcs;
116 funcs = cid_size_get_globals_funcs( size );
118 funcs->destroy( (PSH_Globals)size->root.internal );
120 size->root.internal = 0;
125 FT_LOCAL_DEF( FT_Error )
126 cid_size_init( CID_Size size )
129 PSH_Globals_Funcs funcs = cid_size_get_globals_funcs( size );
135 CID_Face face = (CID_Face)size->root.face;
136 CID_FaceDict dict = face->cid.font_dicts + face->root.face_index;
137 PS_Private priv = &dict->private_dict;
140 error = funcs->create( size->root.face->memory, priv, &globals );
142 size->root.internal = (FT_Size_Internal)(void*)globals;
149 FT_LOCAL_DEF( FT_Error )
150 cid_size_reset( CID_Size size )
152 PSH_Globals_Funcs funcs = cid_size_get_globals_funcs( size );
157 error = funcs->set_scale( (PSH_Globals)size->root.internal,
158 size->root.metrics.x_scale,
159 size->root.metrics.y_scale,
165 /*************************************************************************/
169 /*************************************************************************/
171 /*************************************************************************/
177 /* Finalizes a given face object. */
180 /* face :: A pointer to the face object to destroy. */
183 cid_face_done( CID_Face face )
190 CID_FaceInfo cid = &face->cid;
191 PS_FontInfo info = &cid->font_info;
194 memory = face->root.memory;
202 for ( n = 0; n < cid->num_dicts; n++ )
204 CID_Subrs subr = face->subrs + n;
209 FT_FREE( subr->code[0] );
210 FT_FREE( subr->code );
214 FT_FREE( face->subrs );
217 /* release FontInfo strings */
218 FT_FREE( info->version );
219 FT_FREE( info->notice );
220 FT_FREE( info->full_name );
221 FT_FREE( info->family_name );
222 FT_FREE( info->weight );
224 /* release font dictionaries */
225 FT_FREE( cid->font_dicts );
228 /* release other strings */
229 FT_FREE( cid->cid_font_name );
230 FT_FREE( cid->registry );
231 FT_FREE( cid->ordering );
233 face->root.family_name = 0;
234 face->root.style_name = 0;
239 /*************************************************************************/
245 /* Initializes a given CID face object. */
248 /* stream :: The source font stream. */
250 /* face_index :: The index of the font face in the resource. */
252 /* num_params :: Number of additional generic parameters. Ignored. */
254 /* params :: Additional generic parameters. Ignored. */
257 /* face :: The newly built face object. */
260 /* FreeType error code. 0 means success. */
262 FT_LOCAL_DEF( FT_Error )
263 cid_face_init( FT_Stream stream,
267 FT_Parameter* params )
270 PSNames_Service psnames;
272 PSHinter_Service pshinter;
274 FT_UNUSED( num_params );
276 FT_UNUSED( face_index );
280 face->root.num_faces = 1;
282 psnames = (PSNames_Service)face->psnames;
285 psnames = (PSNames_Service)FT_Get_Module_Interface(
286 FT_FACE_LIBRARY( face ), "psnames" );
288 face->psnames = psnames;
291 psaux = (PSAux_Service)face->psaux;
294 psaux = (PSAux_Service)FT_Get_Module_Interface(
295 FT_FACE_LIBRARY( face ), "psaux" );
300 pshinter = (PSHinter_Service)face->pshinter;
303 pshinter = (PSHinter_Service)FT_Get_Module_Interface(
304 FT_FACE_LIBRARY( face ), "pshinter" );
306 face->pshinter = pshinter;
309 /* open the tokenizer; this will also check the font format */
310 if ( FT_STREAM_SEEK( 0 ) )
313 error = cid_face_open( face );
317 /* if we just wanted to check the format, leave successfully now */
318 if ( face_index < 0 )
321 /* check the face index */
322 if ( face_index != 0 )
324 FT_ERROR(( "cid_face_init: invalid face index\n" ));
325 error = CID_Err_Invalid_Argument;
329 /* Now, load the font program into the face object */
331 /* Init the face object fields */
332 /* Now set up root face fields */
334 FT_Face root = (FT_Face)&face->root;
337 root->num_glyphs = face->cid.cid_count;
338 root->num_charmaps = 0;
340 root->face_index = face_index;
341 root->face_flags = FT_FACE_FLAG_SCALABLE;
343 root->face_flags |= FT_FACE_FLAG_HORIZONTAL;
345 if ( face->cid.font_info.is_fixed_pitch )
346 root->face_flags |= FT_FACE_FLAG_FIXED_WIDTH;
348 /* XXX: TODO: add kerning with .afm support */
350 /* get style name -- be careful, some broken fonts only */
351 /* have a /FontName dictionary entry! */
352 root->family_name = face->cid.font_info.family_name;
353 if ( root->family_name )
355 char* full = face->cid.font_info.full_name;
356 char* family = root->family_name;
358 while ( *family && *full == *family )
364 root->style_name = ( *full == ' ' ) ? full + 1
369 /* do we have a `/FontName'? */
370 if ( face->cid.cid_font_name )
372 root->family_name = face->cid.cid_font_name;
373 root->style_name = (char *)"Regular";
377 /* no embedded bitmap support */
378 root->num_fixed_sizes = 0;
379 root->available_sizes = 0;
381 root->bbox.xMin = face->cid.font_bbox.xMin >> 16;
382 root->bbox.yMin = face->cid.font_bbox.yMin >> 16;
383 root->bbox.xMax = ( face->cid.font_bbox.xMax + 0xFFFFU ) >> 16;
384 root->bbox.yMax = ( face->cid.font_bbox.yMax + 0xFFFFU ) >> 16;
386 if ( !root->units_per_EM )
387 root->units_per_EM = 1000;
389 root->ascender = (FT_Short)( root->bbox.yMax );
390 root->descender = (FT_Short)( root->bbox.yMin );
391 root->height = (FT_Short)(
392 ( ( root->ascender + root->descender ) * 12 ) / 10 );
394 root->underline_position = face->cid.font_info.underline_position;
395 root->underline_thickness = face->cid.font_info.underline_thickness;
397 root->internal->max_points = 0;
398 root->internal->max_contours = 0;
407 /*************************************************************************/
410 /* cid_driver_init */
413 /* Initializes a given CID driver object. */
416 /* driver :: A handle to the target driver object. */
419 /* FreeType error code. 0 means success. */
421 FT_LOCAL_DEF( FT_Error )
422 cid_driver_init( CID_Driver driver )
430 /*************************************************************************/
433 /* cid_driver_done */
436 /* Finalizes a given CID driver. */
439 /* driver :: A handle to the target CID driver. */
442 cid_driver_done( CID_Driver driver )