1
/***************************************************************************/
5
/* OpenType font driver implementation (body). */
7
/* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 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_FREETYPE_H
21
#include FT_INTERNAL_DEBUG_H
22
#include FT_INTERNAL_STREAM_H
23
#include FT_INTERNAL_SFNT_H
24
#include FT_TRUETYPE_IDS_H
25
#include FT_SERVICE_CID_H
26
#include FT_SERVICE_POSTSCRIPT_CMAPS_H
27
#include FT_SERVICE_POSTSCRIPT_INFO_H
28
#include FT_SERVICE_POSTSCRIPT_NAME_H
29
#include FT_SERVICE_TT_CMAP_H
38
#include FT_SERVICE_XFREE86_NAME_H
39
#include FT_SERVICE_GLYPH_DICT_H
42
/*************************************************************************/
44
/* The macro FT_COMPONENT is used in trace mode. It is an implicit */
45
/* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
46
/* messages during execution. */
49
#define FT_COMPONENT trace_cffdriver
52
/*************************************************************************/
53
/*************************************************************************/
54
/*************************************************************************/
60
/*************************************************************************/
61
/*************************************************************************/
62
/*************************************************************************/
66
#define PAIR_TAG( left, right ) ( ( (FT_ULong)left << 16 ) | \
70
/*************************************************************************/
76
/* A driver method used to return the kerning vector between two */
77
/* glyphs of the same face. */
80
/* face :: A handle to the source face object. */
82
/* left_glyph :: The index of the left glyph in the kern pair. */
84
/* right_glyph :: The index of the right glyph in the kern pair. */
87
/* kerning :: The kerning vector. This is in font units for */
88
/* scalable formats, and in pixels for fixed-sizes */
92
/* FreeType error code. 0 means success. */
95
/* Only horizontal layouts (left-to-right & right-to-left) are */
96
/* supported by this function. Other layouts, or more sophisticated */
97
/* kernings, are out of scope of this method (the basic driver */
98
/* interface is meant to be simple). */
100
/* They can be implemented by format-specific interfaces. */
102
FT_CALLBACK_DEF( FT_Error )
103
cff_get_kerning( FT_Face ttface, /* TT_Face */
108
TT_Face face = (TT_Face)ttface;
109
SFNT_Service sfnt = (SFNT_Service)face->sfnt;
116
kerning->x = sfnt->get_kerning( face, left_glyph, right_glyph );
125
/*************************************************************************/
131
/* A driver method used to load a glyph within a given glyph slot. */
134
/* slot :: A handle to the target slot object where the glyph */
135
/* will be loaded. */
137
/* size :: A handle to the source face size at which the glyph */
138
/* must be scaled, loaded, etc. */
140
/* glyph_index :: The index of the glyph in the font file. */
142
/* load_flags :: A flag indicating what to load for this glyph. The */
143
/* FT_LOAD_??? constants can be used to control the */
144
/* glyph loading process (e.g., whether the outline */
145
/* should be scaled, whether to load bitmaps or not, */
146
/* whether to hint the outline, etc). */
149
/* FreeType error code. 0 means success. */
151
FT_CALLBACK_DEF( FT_Error )
152
Load_Glyph( FT_GlyphSlot cffslot, /* CFF_GlyphSlot */
153
FT_Size cffsize, /* CFF_Size */
155
FT_Int32 load_flags )
158
CFF_GlyphSlot slot = (CFF_GlyphSlot)cffslot;
159
CFF_Size size = (CFF_Size)cffsize;
163
return CFF_Err_Invalid_Slot_Handle;
165
/* check whether we want a scaled outline or bitmap */
167
load_flags |= FT_LOAD_NO_SCALE | FT_LOAD_NO_HINTING;
169
/* reset the size object if necessary */
170
if ( load_flags & FT_LOAD_NO_SCALE )
175
/* these two objects must have the same parent */
176
if ( cffsize->face != cffslot->face )
177
return CFF_Err_Invalid_Face_Handle;
180
/* now load the glyph outline if necessary */
181
error = cff_slot_load( slot, size, glyph_index, load_flags );
183
/* force drop-out mode to 2 - irrelevant now */
184
/* slot->outline.dropout_mode = 2; */
190
FT_CALLBACK_DEF( FT_Error )
191
cff_get_advances( FT_Face face,
198
FT_Error error = CFF_Err_Ok;
199
FT_GlyphSlot slot = face->glyph;
202
flags |= FT_LOAD_ADVANCE_ONLY;
204
for ( nn = 0; nn < count; nn++ )
206
error = Load_Glyph( slot, face->size, start + nn, flags );
210
advances[nn] = ( flags & FT_LOAD_VERTICAL_LAYOUT )
211
? slot->linearVertAdvance
212
: slot->linearHoriAdvance;
225
cff_get_glyph_name( CFF_Face face,
230
CFF_Font font = (CFF_Font)face->extra.data;
231
FT_Memory memory = FT_FACE_MEMORY( face );
234
FT_Service_PsCMaps psnames;
238
FT_FACE_FIND_GLOBAL_SERVICE( face, psnames, POSTSCRIPT_CMAPS );
241
FT_ERROR(( "cff_get_glyph_name:" ));
242
FT_ERROR(( " cannot get glyph name from CFF & CEF fonts\n" ));
244
FT_ERROR(( " without the `PSNames' module\n" ));
245
error = CFF_Err_Unknown_File_Format;
249
/* first, locate the sid in the charset table */
250
sid = font->charset.sids[glyph_index];
252
/* now, lookup the name itself */
253
gname = cff_index_get_sid_string( &font->string_index, sid, psnames );
256
FT_STRCPYN( buffer, gname, buffer_max );
267
cff_get_name_index( CFF_Face face,
268
FT_String* glyph_name )
272
FT_Service_PsCMaps psnames;
273
FT_Memory memory = FT_FACE_MEMORY( face );
280
cff = (CFF_FontRec *)face->extra.data;
281
charset = &cff->charset;
283
FT_FACE_FIND_GLOBAL_SERVICE( face, psnames, POSTSCRIPT_CMAPS );
287
for ( i = 0; i < cff->num_glyphs; i++ )
289
sid = charset->sids[i];
292
name = cff_index_get_name( &cff->string_index, sid - 391 );
294
name = (FT_String *)psnames->adobe_std_strings( sid );
299
result = ft_strcmp( glyph_name, name );
312
static const FT_Service_GlyphDictRec cff_service_glyph_dict =
314
(FT_GlyphDict_GetNameFunc) cff_get_glyph_name,
315
(FT_GlyphDict_NameIndexFunc)cff_get_name_index,
320
* POSTSCRIPT INFO SERVICE
325
cff_ps_has_glyph_names( FT_Face face )
327
return ( face->face_flags & FT_FACE_FLAG_GLYPH_NAMES ) > 0;
332
cff_ps_get_font_info( CFF_Face face,
333
PS_FontInfoRec* afont_info )
335
CFF_Font cff = (CFF_Font)face->extra.data;
336
FT_Error error = FT_Err_Ok;
339
if ( cff && cff->font_info == NULL )
341
CFF_FontRecDict dict = &cff->top_font.font_dict;
342
PS_FontInfoRec *font_info;
343
FT_Memory memory = face->root.memory;
344
FT_Service_PsCMaps psnames = (FT_Service_PsCMaps)cff->psnames;
347
if ( FT_ALLOC( font_info, sizeof ( *font_info ) ) )
350
font_info->version = cff_index_get_sid_string( &cff->string_index,
353
font_info->notice = cff_index_get_sid_string( &cff->string_index,
356
font_info->full_name = cff_index_get_sid_string( &cff->string_index,
359
font_info->family_name = cff_index_get_sid_string( &cff->string_index,
362
font_info->weight = cff_index_get_sid_string( &cff->string_index,
365
font_info->italic_angle = dict->italic_angle;
366
font_info->is_fixed_pitch = dict->is_fixed_pitch;
367
font_info->underline_position = (FT_Short)dict->underline_position;
368
font_info->underline_thickness = (FT_Short)dict->underline_thickness;
370
cff->font_info = font_info;
374
*afont_info = *cff->font_info;
381
static const FT_Service_PsInfoRec cff_service_ps_info =
383
(PS_GetFontInfoFunc) cff_ps_get_font_info,
384
(PS_GetFontExtraFunc) NULL,
385
(PS_HasGlyphNamesFunc) cff_ps_has_glyph_names,
386
(PS_GetFontPrivateFunc)NULL /* unsupported with CFF fonts */
391
* POSTSCRIPT NAME SERVICE
396
cff_get_ps_name( CFF_Face face )
398
CFF_Font cff = (CFF_Font)face->extra.data;
401
return (const char*)cff->font_name;
405
static const FT_Service_PsFontNameRec cff_service_ps_name =
407
(FT_PsName_GetFunc)cff_get_ps_name
414
* If the charmap is a synthetic Unicode encoding cmap or
415
* a Type 1 standard (or expert) encoding cmap, hide TT CMAP INFO
416
* service defined in SFNT module.
418
* Otherwise call the service function in the sfnt module.
422
cff_get_cmap_info( FT_CharMap charmap,
423
TT_CMapInfo *cmap_info )
425
FT_CMap cmap = FT_CMAP( charmap );
426
FT_Error error = CFF_Err_Ok;
429
cmap_info->language = 0;
430
cmap_info->format = 0;
432
if ( cmap->clazz != &cff_cmap_encoding_class_rec &&
433
cmap->clazz != &cff_cmap_unicode_class_rec )
435
FT_Face face = FT_CMAP_FACE( cmap );
436
FT_Library library = FT_FACE_LIBRARY( face );
437
FT_Module sfnt = FT_Get_Module( library, "sfnt" );
438
FT_Service_TTCMaps service =
439
(FT_Service_TTCMaps)ft_module_get_service( sfnt,
440
FT_SERVICE_ID_TT_CMAP );
443
if ( service && service->get_cmap_info )
444
error = service->get_cmap_info( charmap, cmap_info );
451
static const FT_Service_TTCMapsRec cff_service_get_cmap_info =
453
(TT_CMap_Info_GetFunc)cff_get_cmap_info
462
cff_get_ros( CFF_Face face,
463
const char* *registry,
464
const char* *ordering,
467
FT_Error error = CFF_Err_Ok;
468
CFF_Font cff = (CFF_Font)face->extra.data;
473
CFF_FontRecDict dict = &cff->top_font.font_dict;
474
FT_Service_PsCMaps psnames = (FT_Service_PsCMaps)cff->psnames;
477
if ( dict->cid_registry == 0xFFFFU )
479
error = CFF_Err_Invalid_Argument;
485
if ( cff->registry == NULL )
486
cff->registry = cff_index_get_sid_string( &cff->string_index,
489
*registry = cff->registry;
494
if ( cff->ordering == NULL )
495
cff->ordering = cff_index_get_sid_string( &cff->string_index,
498
*ordering = cff->ordering;
502
*supplement = dict->cid_supplement;
511
cff_get_is_cid( CFF_Face face,
514
FT_Error error = CFF_Err_Ok;
515
CFF_Font cff = (CFF_Font)face->extra.data;
522
CFF_FontRecDict dict = &cff->top_font.font_dict;
525
if ( dict->cid_registry != 0xFFFFU )
534
cff_get_cid_from_glyph_index( CFF_Face face,
538
FT_Error error = CFF_Err_Ok;
542
cff = (CFF_Font)face->extra.data;
547
CFF_FontRecDict dict = &cff->top_font.font_dict;
550
if ( dict->cid_registry == 0xFFFFU )
552
error = CFF_Err_Invalid_Argument;
556
if ( glyph_index > cff->num_glyphs )
558
error = CFF_Err_Invalid_Argument;
562
c = cff->charset.sids[glyph_index];
573
static const FT_Service_CIDRec cff_service_cid_info =
575
(FT_CID_GetRegistryOrderingSupplementFunc)cff_get_ros,
576
(FT_CID_GetIsInternallyCIDKeyedFunc) cff_get_is_cid,
577
(FT_CID_GetCIDFromGlyphIndexFunc) cff_get_cid_from_glyph_index
581
/*************************************************************************/
582
/*************************************************************************/
583
/*************************************************************************/
586
/**** D R I V E R I N T E R F A C E ****/
589
/*************************************************************************/
590
/*************************************************************************/
591
/*************************************************************************/
593
static const FT_ServiceDescRec cff_services[] =
595
{ FT_SERVICE_ID_XF86_NAME, FT_XF86_FORMAT_CFF },
596
{ FT_SERVICE_ID_POSTSCRIPT_INFO, &cff_service_ps_info },
597
{ FT_SERVICE_ID_POSTSCRIPT_FONT_NAME, &cff_service_ps_name },
598
#ifndef FT_CONFIG_OPTION_NO_GLYPH_NAMES
599
{ FT_SERVICE_ID_GLYPH_DICT, &cff_service_glyph_dict },
601
{ FT_SERVICE_ID_TT_CMAP, &cff_service_get_cmap_info },
602
{ FT_SERVICE_ID_CID, &cff_service_cid_info },
607
FT_CALLBACK_DEF( FT_Module_Interface )
608
cff_get_interface( FT_Module driver, /* CFF_Driver */
609
const char* module_interface )
612
FT_Module_Interface result;
615
result = ft_service_list_lookup( cff_services, module_interface );
616
if ( result != NULL )
619
/* we pass our request to the `sfnt' module */
620
sfnt = FT_Get_Module( driver->library, "sfnt" );
622
return sfnt ? sfnt->clazz->get_interface( sfnt, module_interface ) : 0;
626
/* The FT_DriverInterface structure is defined in ftdriver.h. */
628
FT_CALLBACK_TABLE_DEF
629
const FT_Driver_ClassRec cff_driver_class =
631
/* begin with the FT_Module_Class fields */
633
FT_MODULE_FONT_DRIVER |
634
FT_MODULE_DRIVER_SCALABLE |
635
FT_MODULE_DRIVER_HAS_HINTER,
637
sizeof( CFF_DriverRec ),
642
0, /* module-specific interface */
649
/* now the specific driver fields */
650
sizeof( TT_FaceRec ),
651
sizeof( CFF_SizeRec ),
652
sizeof( CFF_GlyphSlotRec ),
661
#ifdef FT_CONFIG_OPTION_OLD_INTERNALS
662
ft_stub_set_char_sizes,
663
ft_stub_set_pixel_sizes,
669
0, /* FT_Face_AttachFunc */
670
cff_get_advances, /* FT_Face_GetAdvancesFunc */
674
#ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
677
0 /* FT_Size_SelectFunc */