1 /***************************************************************************/
5 /* High-level SFNT driver interface (body). */
7 /* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007 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
37 #ifdef TT_CONFIG_OPTION_BDF
39 #include FT_SERVICE_BDF_H
46 #include FT_SERVICE_GLYPH_DICT_H
47 #include FT_SERVICE_POSTSCRIPT_NAME_H
48 #include FT_SERVICE_SFNT_H
49 #include FT_SERVICE_TT_CMAP_H
58 get_sfnt_table( TT_Face face
,
67 table
= &face
->header
;
71 table
= &face
->horizontal
;
75 table
= face
->vertical_info
? &face
->vertical
: 0;
79 table
= face
->os2
.version
== 0xFFFFU
? 0 : &face
->os2
;
83 table
= &face
->postscript
;
87 table
= &face
->max_profile
;
91 table
= face
->pclt
.Version
? &face
->pclt
: 0;
103 sfnt_table_info( TT_Face face
,
108 if ( !tag
|| !length
)
109 return SFNT_Err_Invalid_Argument
;
111 if ( idx
>= face
->num_tables
)
112 return SFNT_Err_Table_Missing
;
114 *tag
= face
->dir_tables
[idx
].Tag
;
115 *length
= face
->dir_tables
[idx
].Length
;
121 static const FT_Service_SFNT_TableRec sfnt_service_sfnt_table
=
123 (FT_SFNT_TableLoadFunc
)tt_face_load_any
,
124 (FT_SFNT_TableGetFunc
) get_sfnt_table
,
125 (FT_SFNT_TableInfoFunc
)sfnt_table_info
129 #ifdef TT_CONFIG_OPTION_POSTSCRIPT_NAMES
137 sfnt_get_glyph_name( TT_Face face
,
146 error
= tt_face_get_ps_name( face
, glyph_index
, &gname
);
148 FT_STRCPYN( buffer
, gname
, buffer_max
);
154 static const FT_Service_GlyphDictRec sfnt_service_glyph_dict
=
156 (FT_GlyphDict_GetNameFunc
) sfnt_get_glyph_name
,
157 (FT_GlyphDict_NameIndexFunc
)NULL
160 #endif /* TT_CONFIG_OPTION_POSTSCRIPT_NAMES */
164 * POSTSCRIPT NAME SERVICE
169 sfnt_get_ps_name( TT_Face face
)
171 FT_Int n
, found_win
, found_apple
;
172 const char* result
= NULL
;
175 /* shouldn't happen, but just in case to avoid memory leaks */
176 if ( face
->postscript_name
)
177 return face
->postscript_name
;
179 /* scan the name table to see whether we have a Postscript name here, */
180 /* either in Macintosh or Windows platform encodings */
184 for ( n
= 0; n
< face
->num_names
; n
++ )
186 TT_NameEntryRec
* name
= face
->name_table
.names
+ n
;
189 if ( name
->nameID
== 6 && name
->stringLength
> 0 )
191 if ( name
->platformID
== 3 &&
192 name
->encodingID
== 1 &&
193 name
->languageID
== 0x409 )
196 if ( name
->platformID
== 1 &&
197 name
->encodingID
== 0 &&
198 name
->languageID
== 0 )
203 if ( found_win
!= -1 )
205 FT_Memory memory
= face
->root
.memory
;
206 TT_NameEntryRec
* name
= face
->name_table
.names
+ found_win
;
207 FT_UInt len
= name
->stringLength
/ 2;
208 FT_Error error
= SFNT_Err_Ok
;
213 if ( !FT_ALLOC( result
, name
->stringLength
+ 1 ) )
215 FT_Stream stream
= face
->name_table
.stream
;
216 FT_String
* r
= (FT_String
*)result
;
217 FT_Byte
* p
= (FT_Byte
*)name
->string
;
220 if ( FT_STREAM_SEEK( name
->stringOffset
) ||
221 FT_FRAME_ENTER( name
->stringLength
) )
224 name
->stringLength
= 0;
225 name
->stringOffset
= 0;
226 FT_FREE( name
->string
);
231 p
= (FT_Byte
*)stream
->cursor
;
233 for ( ; len
> 0; len
--, p
+= 2 )
235 if ( p
[0] == 0 && p
[1] >= 32 && p
[1] < 128 )
245 if ( found_apple
!= -1 )
247 FT_Memory memory
= face
->root
.memory
;
248 TT_NameEntryRec
* name
= face
->name_table
.names
+ found_apple
;
249 FT_UInt len
= name
->stringLength
;
250 FT_Error error
= SFNT_Err_Ok
;
255 if ( !FT_ALLOC( result
, len
+ 1 ) )
257 FT_Stream stream
= face
->name_table
.stream
;
260 if ( FT_STREAM_SEEK( name
->stringOffset
) ||
261 FT_STREAM_READ( result
, len
) )
263 name
->stringOffset
= 0;
264 name
->stringLength
= 0;
265 FT_FREE( name
->string
);
269 ((char*)result
)[len
] = '\0';
274 face
->postscript_name
= result
;
278 static const FT_Service_PsFontNameRec sfnt_service_ps_name
=
280 (FT_PsName_GetFunc
)sfnt_get_ps_name
287 static const FT_Service_TTCMapsRec tt_service_get_cmap_info
=
289 (TT_CMap_Info_GetFunc
)tt_get_cmap_info
293 #ifdef TT_CONFIG_OPTION_BDF
296 sfnt_get_charset_id( TT_Face face
,
297 const char* *acharset_encoding
,
298 const char* *acharset_registry
)
300 BDF_PropertyRec encoding
, registry
;
304 /* XXX: I don't know whether this is correct, since
305 * tt_face_find_bdf_prop only returns something correct if we have
306 * previously selected a size that is listed in the BDF table.
307 * Should we change the BDF table format to include single offsets
308 * for `CHARSET_REGISTRY' and `CHARSET_ENCODING'?
310 error
= tt_face_find_bdf_prop( face
, "CHARSET_REGISTRY", ®istry
);
313 error
= tt_face_find_bdf_prop( face
, "CHARSET_ENCODING", &encoding
);
316 if ( registry
.type
== BDF_PROPERTY_TYPE_ATOM
&&
317 encoding
.type
== BDF_PROPERTY_TYPE_ATOM
)
319 *acharset_encoding
= encoding
.u
.atom
;
320 *acharset_registry
= registry
.u
.atom
;
323 error
= FT_Err_Invalid_Argument
;
331 static const FT_Service_BDFRec sfnt_service_bdf
=
333 (FT_BDF_GetCharsetIdFunc
) sfnt_get_charset_id
,
334 (FT_BDF_GetPropertyFunc
) tt_face_find_bdf_prop
,
337 #endif /* TT_CONFIG_OPTION_BDF */
344 static const FT_ServiceDescRec sfnt_services
[] =
346 { FT_SERVICE_ID_SFNT_TABLE
, &sfnt_service_sfnt_table
},
347 { FT_SERVICE_ID_POSTSCRIPT_FONT_NAME
, &sfnt_service_ps_name
},
348 #ifdef TT_CONFIG_OPTION_POSTSCRIPT_NAMES
349 { FT_SERVICE_ID_GLYPH_DICT
, &sfnt_service_glyph_dict
},
351 #ifdef TT_CONFIG_OPTION_BDF
352 { FT_SERVICE_ID_BDF
, &sfnt_service_bdf
},
354 { FT_SERVICE_ID_TT_CMAP
, &tt_service_get_cmap_info
},
360 FT_CALLBACK_DEF( FT_Module_Interface
)
361 sfnt_get_interface( FT_Module module
,
362 const char* module_interface
)
366 return ft_service_list_lookup( sfnt_services
, module_interface
);
370 #ifdef FT_CONFIG_OPTION_OLD_INTERNALS
372 FT_CALLBACK_DEF( FT_Error
)
373 tt_face_load_sfnt_header_stub( TT_Face face
,
380 FT_UNUSED( face_index
);
383 return FT_Err_Unimplemented_Feature
;
387 FT_CALLBACK_DEF( FT_Error
)
388 tt_face_load_directory_stub( TT_Face face
,
396 return FT_Err_Unimplemented_Feature
;
400 FT_CALLBACK_DEF( FT_Error
)
401 tt_face_load_hdmx_stub( TT_Face face
,
407 return FT_Err_Unimplemented_Feature
;
411 FT_CALLBACK_DEF( void )
412 tt_face_free_hdmx_stub( TT_Face face
)
418 FT_CALLBACK_DEF( FT_Error
)
419 tt_face_set_sbit_strike_stub( TT_Face face
,
422 FT_ULong
* astrike_index
)
425 * We simply forge a FT_Size_Request and call the real function
426 * that does all the work.
428 * This stub might be called by libXfont in the X.Org Xserver,
429 * compiled against version 2.1.8 or newer.
432 FT_Size_RequestRec req
;
435 req
.type
= FT_SIZE_REQUEST_TYPE_NOMINAL
;
436 req
.width
= (FT_F26Dot6
)x_ppem
;
437 req
.height
= (FT_F26Dot6
)y_ppem
;
438 req
.horiResolution
= 0;
439 req
.vertResolution
= 0;
441 *astrike_index
= 0x7FFFFFFFUL
;
443 return tt_face_set_sbit_strike( face
, &req
, astrike_index
);
447 FT_CALLBACK_DEF( FT_Error
)
448 tt_face_load_sbit_stub( TT_Face face
,
455 * This function was originally implemented to load the sbit table.
456 * However, it has been replaced by `tt_face_load_eblc', and this stub
457 * is only there for some rogue clients which would want to call it
458 * directly (which doesn't make much sense).
460 return FT_Err_Unimplemented_Feature
;
464 FT_CALLBACK_DEF( void )
465 tt_face_free_sbit_stub( TT_Face face
)
467 /* nothing to do in this stub */
472 FT_CALLBACK_DEF( FT_Error
)
473 tt_face_load_charmap_stub( TT_Face face
,
481 return FT_Err_Unimplemented_Feature
;
485 FT_CALLBACK_DEF( FT_Error
)
486 tt_face_free_charmap_stub( TT_Face face
,
495 #endif /* FT_CONFIG_OPTION_OLD_INTERNALS */
499 const SFNT_Interface sfnt_interface
=
510 #ifdef FT_CONFIG_OPTION_OLD_INTERNALS
511 tt_face_load_sfnt_header_stub
,
512 tt_face_load_directory_stub
,
525 #ifdef FT_CONFIG_OPTION_OLD_INTERNALS
526 tt_face_load_hdmx_stub
,
527 tt_face_free_hdmx_stub
,
534 #ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
541 #ifdef FT_CONFIG_OPTION_OLD_INTERNALS
542 tt_face_set_sbit_strike_stub
,
543 tt_face_load_sbit_stub
,
546 tt_load_sbit_metrics
,
549 #ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
550 tt_face_load_sbit_image
,
555 #ifdef FT_CONFIG_OPTION_OLD_INTERNALS
556 tt_face_free_sbit_stub
,
559 #ifdef TT_CONFIG_OPTION_POSTSCRIPT_NAMES
562 tt_face_free_ps_names
,
568 #ifdef FT_CONFIG_OPTION_OLD_INTERNALS
569 tt_face_load_charmap_stub
,
570 tt_face_free_charmap_stub
,
573 /* since version 2.1.8 */
577 /* since version 2.2 */
579 tt_face_load_font_dir
,
582 #ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
583 /* see `ttsbit.h' and `sfnt.h' */
587 tt_face_set_sbit_strike
,
588 tt_face_load_strike_metrics
,
600 FT_CALLBACK_TABLE_DEF
601 const FT_Module_Class sfnt_module_class
=
603 0, /* not a font driver or renderer */
604 sizeof( FT_ModuleRec
),
606 "sfnt", /* driver name */
607 0x10000L
, /* driver version 1.0 */
608 0x20000L
, /* driver requires FreeType 2.0 or higher */
610 (const void*)&sfnt_interface
, /* module specific interface */
612 (FT_Module_Constructor
)0,
613 (FT_Module_Destructor
) 0,
614 (FT_Module_Requester
) sfnt_get_interface