1
/***************************************************************************/
5
/* High-level SFNT driver interface (body). */
7
/* Copyright 1996-2001, 2002, 2003, 2004 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_SFNT_H
21
#include FT_INTERNAL_OBJECTS_H
29
#ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
33
#ifdef TT_CONFIG_OPTION_POSTSCRIPT_NAMES
39
#include FT_SERVICE_GLYPH_DICT_H
40
#include FT_SERVICE_POSTSCRIPT_NAME_H
41
#include FT_SERVICE_SFNT_H
42
#include FT_SERVICE_TT_CMAP_H
51
get_sfnt_table( TT_Face face,
60
table = &face->header;
64
table = &face->horizontal;
68
table = face->vertical_info ? &face->vertical : 0;
72
table = face->os2.version == 0xFFFFU ? 0 : &face->os2;
76
table = &face->postscript;
80
table = &face->max_profile;
84
table = face->pclt.Version ? &face->pclt : 0;
95
static const FT_Service_SFNT_TableRec sfnt_service_sfnt_table =
97
(FT_SFNT_TableLoadFunc)tt_face_load_any,
98
(FT_SFNT_TableGetFunc) get_sfnt_table
102
#ifdef TT_CONFIG_OPTION_POSTSCRIPT_NAMES
110
sfnt_get_glyph_name( TT_Face face,
119
error = tt_face_get_ps_name( face, glyph_index, &gname );
120
if ( !error && buffer_max > 0 )
122
FT_UInt len = (FT_UInt)( ft_strlen( gname ) );
125
if ( len >= buffer_max )
126
len = buffer_max - 1;
128
FT_MEM_COPY( buffer, gname, len );
129
((FT_Byte*)buffer)[len] = 0;
136
static const FT_Service_GlyphDictRec sfnt_service_glyph_dict =
138
(FT_GlyphDict_GetNameFunc) sfnt_get_glyph_name,
139
(FT_GlyphDict_NameIndexFunc)NULL
142
#endif /* TT_CONFIG_OPTION_POSTSCRIPT_NAMES */
146
* POSTSCRIPT NAME SERVICE
151
sfnt_get_ps_name( TT_Face face )
153
FT_Int n, found_win, found_apple;
154
const char* result = NULL;
157
/* shouldn't happen, but just in case to avoid memory leaks */
158
if ( face->postscript_name )
159
return face->postscript_name;
161
/* scan the name table to see whether we have a Postscript name here, */
162
/* either in Macintosh or Windows platform encodings */
166
for ( n = 0; n < face->num_names; n++ )
168
TT_NameEntryRec* name = face->name_table.names + n;
171
if ( name->nameID == 6 && name->stringLength > 0 )
173
if ( name->platformID == 3 &&
174
name->encodingID == 1 &&
175
name->languageID == 0x409 )
178
if ( name->platformID == 1 &&
179
name->encodingID == 0 &&
180
name->languageID == 0 )
185
if ( found_win != -1 )
187
FT_Memory memory = face->root.memory;
188
TT_NameEntryRec* name = face->name_table.names + found_win;
189
FT_UInt len = name->stringLength / 2;
190
FT_Error error = SFNT_Err_Ok;
195
if ( !FT_ALLOC( result, name->stringLength + 1 ) )
197
FT_Stream stream = face->name_table.stream;
198
FT_String* r = (FT_String*)result;
199
FT_Byte* p = (FT_Byte*)name->string;
202
if ( FT_STREAM_SEEK( name->stringOffset ) ||
203
FT_FRAME_ENTER( name->stringLength ) )
206
name->stringLength = 0;
207
name->stringOffset = 0;
208
FT_FREE( name->string );
213
p = (FT_Byte*)stream->cursor;
215
for ( ; len > 0; len--, p += 2 )
217
if ( p[0] == 0 && p[1] >= 32 && p[1] < 128 )
227
if ( found_apple != -1 )
229
FT_Memory memory = face->root.memory;
230
TT_NameEntryRec* name = face->name_table.names + found_apple;
231
FT_UInt len = name->stringLength;
232
FT_Error error = SFNT_Err_Ok;
237
if ( !FT_ALLOC( result, len + 1 ) )
239
FT_Stream stream = face->name_table.stream;
242
if ( FT_STREAM_SEEK( name->stringOffset ) ||
243
FT_STREAM_READ( result, len ) )
245
name->stringOffset = 0;
246
name->stringLength = 0;
247
FT_FREE( name->string );
251
((char*)result)[len] = '\0';
256
face->postscript_name = result;
260
static const FT_Service_PsFontNameRec sfnt_service_ps_name =
262
(FT_PsName_GetFunc)sfnt_get_ps_name
270
static const FT_Service_TTCMapsRec tt_service_get_cmap_info =
272
(TT_CMap_Info_GetFunc)tt_get_cmap_info
281
static const FT_ServiceDescRec sfnt_services[] =
283
{ FT_SERVICE_ID_SFNT_TABLE, &sfnt_service_sfnt_table },
284
{ FT_SERVICE_ID_POSTSCRIPT_FONT_NAME, &sfnt_service_ps_name },
285
#ifdef TT_CONFIG_OPTION_POSTSCRIPT_NAMES
286
{ FT_SERVICE_ID_GLYPH_DICT, &sfnt_service_glyph_dict },
288
{ FT_SERVICE_ID_TT_CMAP, &tt_service_get_cmap_info },
294
FT_CALLBACK_DEF( FT_Module_Interface )
295
sfnt_get_interface( FT_Module module,
296
const char* module_interface )
300
if ( ft_strcmp( module_interface, "get_sfnt" ) == 0 )
301
return (FT_Module_Interface)get_sfnt_table;
303
if ( ft_strcmp( module_interface, "load_sfnt" ) == 0 )
304
return (FT_Module_Interface)tt_face_load_any;
306
return ft_service_list_lookup( sfnt_services, module_interface );
311
const SFNT_Interface sfnt_interface =
321
tt_face_load_sfnt_header,
322
tt_face_load_directory,
325
tt_face_load_metrics_header,
327
tt_face_load_max_profile,
329
tt_face_load_postscript,
341
#ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
344
tt_face_load_bitmap_header,
346
/* see `ttsbit.h' and `sfnt.h' */
347
tt_face_set_sbit_strike,
348
tt_face_load_sbit_strikes,
350
tt_load_sbit_metrics,
351
tt_face_load_sbit_image,
352
tt_face_free_sbit_strikes,
354
#else /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */
364
#endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */
366
#ifdef TT_CONFIG_OPTION_POSTSCRIPT_NAMES
370
tt_face_free_ps_names,
372
#else /* TT_CONFIG_OPTION_POSTSCRIPT_NAMES */
377
#endif /* TT_CONFIG_OPTION_POSTSCRIPT_NAMES */
382
FT_CALLBACK_TABLE_DEF
383
const FT_Module_Class sfnt_module_class =
385
0, /* not a font driver or renderer */
386
sizeof( FT_ModuleRec ),
388
"sfnt", /* driver name */
389
0x10000L, /* driver version 1.0 */
390
0x20000L, /* driver requires FreeType 2.0 or higher */
392
(const void*)&sfnt_interface, /* module specific interface */
394
(FT_Module_Constructor)0,
395
(FT_Module_Destructor) 0,
396
(FT_Module_Requester) sfnt_get_interface