1
/***************************************************************************/
5
/* CID objects manager (body). */
7
/* Copyright 1996-2006, 2008, 2010-2011, 2013 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
26
#include FT_SERVICE_POSTSCRIPT_CMAPS_H
27
#include FT_INTERNAL_POSTSCRIPT_AUX_H
28
#include FT_INTERNAL_POSTSCRIPT_HINTS_H
33
/*************************************************************************/
35
/* The macro FT_COMPONENT is used in trace mode. It is an implicit */
36
/* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
37
/* messages during execution. */
40
#define FT_COMPONENT trace_cidobjs
43
/*************************************************************************/
47
/*************************************************************************/
50
cid_slot_done( FT_GlyphSlot slot )
52
slot->internal->glyph_hints = 0;
56
FT_LOCAL_DEF( FT_Error )
57
cid_slot_init( FT_GlyphSlot slot )
60
PSHinter_Service pshinter;
63
face = (CID_Face)slot->face;
64
pshinter = (PSHinter_Service)face->pshinter;
71
module = FT_Get_Module( slot->face->driver->root.library,
78
funcs = pshinter->get_t1_funcs( module );
79
slot->internal->glyph_hints = (void*)funcs;
87
/*************************************************************************/
91
/*************************************************************************/
94
static PSH_Globals_Funcs
95
cid_size_get_globals_funcs( CID_Size size )
97
CID_Face face = (CID_Face)size->root.face;
98
PSHinter_Service pshinter = (PSHinter_Service)face->pshinter;
102
module = FT_Get_Module( size->root.face->driver->root.library,
104
return ( module && pshinter && pshinter->get_globals_funcs )
105
? pshinter->get_globals_funcs( module )
111
cid_size_done( FT_Size cidsize ) /* CID_Size */
113
CID_Size size = (CID_Size)cidsize;
116
if ( cidsize->internal )
118
PSH_Globals_Funcs funcs;
121
funcs = cid_size_get_globals_funcs( size );
123
funcs->destroy( (PSH_Globals)cidsize->internal );
125
cidsize->internal = 0;
130
FT_LOCAL_DEF( FT_Error )
131
cid_size_init( FT_Size cidsize ) /* CID_Size */
133
CID_Size size = (CID_Size)cidsize;
134
FT_Error error = FT_Err_Ok;
135
PSH_Globals_Funcs funcs = cid_size_get_globals_funcs( size );
141
CID_Face face = (CID_Face)cidsize->face;
142
CID_FaceDict dict = face->cid.font_dicts + face->root.face_index;
143
PS_Private priv = &dict->private_dict;
146
error = funcs->create( cidsize->face->memory, priv, &globals );
148
cidsize->internal = (FT_Size_Internal)(void*)globals;
156
cid_size_request( FT_Size size,
157
FT_Size_Request req )
159
PSH_Globals_Funcs funcs;
162
FT_Request_Metrics( size->face, req );
164
funcs = cid_size_get_globals_funcs( (CID_Size)size );
167
funcs->set_scale( (PSH_Globals)size->internal,
168
size->metrics.x_scale,
169
size->metrics.y_scale,
176
/*************************************************************************/
180
/*************************************************************************/
182
/*************************************************************************/
188
/* Finalizes a given face object. */
191
/* face :: A pointer to the face object to destroy. */
194
cid_face_done( FT_Face cidface ) /* CID_Face */
196
CID_Face face = (CID_Face)cidface;
206
info = &cid->font_info;
207
memory = cidface->memory;
215
for ( n = 0; n < cid->num_dicts; n++ )
217
CID_Subrs subr = face->subrs + n;
222
FT_FREE( subr->code[0] );
223
FT_FREE( subr->code );
227
FT_FREE( face->subrs );
230
/* release FontInfo strings */
231
FT_FREE( info->version );
232
FT_FREE( info->notice );
233
FT_FREE( info->full_name );
234
FT_FREE( info->family_name );
235
FT_FREE( info->weight );
237
/* release font dictionaries */
238
FT_FREE( cid->font_dicts );
241
/* release other strings */
242
FT_FREE( cid->cid_font_name );
243
FT_FREE( cid->registry );
244
FT_FREE( cid->ordering );
246
cidface->family_name = 0;
247
cidface->style_name = 0;
249
FT_FREE( face->binary_data );
250
FT_FREE( face->cid_stream );
254
/*************************************************************************/
260
/* Initializes a given CID face object. */
263
/* stream :: The source font stream. */
265
/* face_index :: The index of the font face in the resource. */
267
/* num_params :: Number of additional generic parameters. Ignored. */
269
/* params :: Additional generic parameters. Ignored. */
272
/* face :: The newly built face object. */
275
/* FreeType error code. 0 means success. */
277
FT_LOCAL_DEF( FT_Error )
278
cid_face_init( FT_Stream stream,
279
FT_Face cidface, /* CID_Face */
282
FT_Parameter* params )
284
CID_Face face = (CID_Face)cidface;
287
PSHinter_Service pshinter;
289
FT_UNUSED( num_params );
294
cidface->num_faces = 1;
296
psaux = (PSAux_Service)face->psaux;
299
psaux = (PSAux_Service)FT_Get_Module_Interface(
300
FT_FACE_LIBRARY( face ), "psaux" );
304
FT_ERROR(( "cid_face_init: cannot access `psaux' module\n" ));
305
error = FT_THROW( Missing_Module );
312
pshinter = (PSHinter_Service)face->pshinter;
315
pshinter = (PSHinter_Service)FT_Get_Module_Interface(
316
FT_FACE_LIBRARY( face ), "pshinter" );
318
face->pshinter = pshinter;
321
FT_TRACE2(( "CID driver\n" ));
323
/* open the tokenizer; this will also check the font format */
324
if ( FT_STREAM_SEEK( 0 ) )
327
error = cid_face_open( face, face_index );
331
/* if we just wanted to check the format, leave successfully now */
332
if ( face_index < 0 )
335
/* check the face index */
336
/* XXX: handle CID fonts with more than a single face */
337
if ( face_index != 0 )
339
FT_ERROR(( "cid_face_init: invalid face index\n" ));
340
error = FT_THROW( Invalid_Argument );
344
/* now load the font program into the face object */
346
/* initialize the face object fields */
348
/* set up root face fields */
350
CID_FaceInfo cid = &face->cid;
351
PS_FontInfo info = &cid->font_info;
354
cidface->num_glyphs = cid->cid_count;
355
cidface->num_charmaps = 0;
357
cidface->face_index = face_index;
359
cidface->face_flags |= FT_FACE_FLAG_SCALABLE | /* scalable outlines */
360
FT_FACE_FLAG_HORIZONTAL | /* horizontal data */
361
FT_FACE_FLAG_HINTER; /* has native hinter */
363
if ( info->is_fixed_pitch )
364
cidface->face_flags |= FT_FACE_FLAG_FIXED_WIDTH;
366
/* XXX: TODO: add kerning with .afm support */
368
/* get style name -- be careful, some broken fonts only */
369
/* have a /FontName dictionary entry! */
370
cidface->family_name = info->family_name;
371
/* assume "Regular" style if we don't know better */
372
cidface->style_name = (char *)"Regular";
373
if ( cidface->family_name )
375
char* full = info->full_name;
376
char* family = cidface->family_name;
383
if ( *full == *family )
390
if ( *full == ' ' || *full == '-' )
392
else if ( *family == ' ' || *family == '-' )
397
cidface->style_name = full;
406
/* do we have a `/FontName'? */
407
if ( cid->cid_font_name )
408
cidface->family_name = cid->cid_font_name;
411
/* compute style flags */
412
cidface->style_flags = 0;
413
if ( info->italic_angle )
414
cidface->style_flags |= FT_STYLE_FLAG_ITALIC;
417
if ( !ft_strcmp( info->weight, "Bold" ) ||
418
!ft_strcmp( info->weight, "Black" ) )
419
cidface->style_flags |= FT_STYLE_FLAG_BOLD;
422
/* no embedded bitmap support */
423
cidface->num_fixed_sizes = 0;
424
cidface->available_sizes = 0;
426
cidface->bbox.xMin = cid->font_bbox.xMin >> 16;
427
cidface->bbox.yMin = cid->font_bbox.yMin >> 16;
428
/* no `U' suffix here to 0xFFFF! */
429
cidface->bbox.xMax = ( cid->font_bbox.xMax + 0xFFFF ) >> 16;
430
cidface->bbox.yMax = ( cid->font_bbox.yMax + 0xFFFF ) >> 16;
432
if ( !cidface->units_per_EM )
433
cidface->units_per_EM = 1000;
435
cidface->ascender = (FT_Short)( cidface->bbox.yMax );
436
cidface->descender = (FT_Short)( cidface->bbox.yMin );
438
cidface->height = (FT_Short)( ( cidface->units_per_EM * 12 ) / 10 );
439
if ( cidface->height < cidface->ascender - cidface->descender )
440
cidface->height = (FT_Short)( cidface->ascender - cidface->descender );
442
cidface->underline_position = (FT_Short)info->underline_position;
443
cidface->underline_thickness = (FT_Short)info->underline_thickness;
451
/*************************************************************************/
454
/* cid_driver_init */
457
/* Initializes a given CID driver object. */
460
/* driver :: A handle to the target driver object. */
463
/* FreeType error code. 0 means success. */
465
FT_LOCAL_DEF( FT_Error )
466
cid_driver_init( FT_Module driver )
474
/*************************************************************************/
477
/* cid_driver_done */
480
/* Finalizes a given CID driver. */
483
/* driver :: A handle to the target CID driver. */
486
cid_driver_done( FT_Module driver )