70 #include FT_FREETYPE_H
71 #include FT_TRUETYPE_TAGS_H
72 #include FT_INTERNAL_STREAM_H
78 #if !HAVE_ANSI_OS_INLINE
80 #define OS_INLINE static __inline__
87 #ifndef HAVE_TYPE_RESOURCE_INDEX
88 #if !defined( MAC_OS_X_VERSION_10_5 ) || \
89 ( MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5 )
90 #define HAVE_TYPE_RESOURCE_INDEX 0
92 #define HAVE_TYPE_RESOURCE_INDEX 1
96 #if ( HAVE_TYPE_RESOURCE_INDEX == 0 )
100 #include <CoreServices/CoreServices.h>
101 #include <ApplicationServices/ApplicationServices.h>
102 #include <sys/syslimits.h>
105 #define FT_DEPRECATED_ATTRIBUTE
109 #ifndef kATSOptionFlagsUnRestrictedScope
110 #define kATSOptionFlagsUnRestrictedScope kATSOptionFlagsDefault
118 #define PREFER_LWFN 1
134 return FT_Err_Unimplemented_Feature;
144 FT_ATSFontGetFileReference( ATSFontRef ats_font_id,
145 FSRef* ats_font_ref )
147 #if defined( MAC_OS_X_VERSION_10_5 ) && \
148 ( MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 )
152 err = ATSFontGetFileReference( ats_font_id, ats_font_ref );
166 err = ATSFontGetFileSpecification( ats_font_id, &spec );
168 err = FSpMakeFSRef( &spec, ats_font_ref );
176 FT_GetFileRef_From_Mac_ATS_Name(
const char*
fontName,
180 CFStringRef cf_fontName;
181 ATSFontRef ats_font_id;
186 cf_fontName = CFStringCreateWithCString(
NULL, fontName,
187 kCFStringEncodingMacRoman );
188 ats_font_id = ATSFontFindFromName( cf_fontName,
190 CFRelease( cf_fontName );
192 if ( ats_font_id == 0 || ats_font_id == 0xFFFFFFFFUL )
193 return FT_Err_Unknown_File_Format;
195 if ( noErr != FT_ATSFontGetFileReference( ats_font_id, ats_font_ref ) )
196 return FT_Err_Unknown_File_Format;
201 ATSFontRef id2 = ats_font_id - 1;
207 if ( noErr != FT_ATSFontGetFileReference( id2, &ref2 ) )
209 if ( noErr != FSCompareFSRefs( ats_font_ref, &ref2 ) )
214 *face_index = ats_font_id - ( id2 + 1 );
231 err = FT_GetFileRef_From_Mac_ATS_Name( fontName, &ref, face_index );
235 if ( noErr != FSRefMakePath( &ref, path, maxPathSize ) )
236 return FT_Err_Unknown_File_Format;
248 #if ( __LP64__ ) || ( defined( MAC_OS_X_VERSION_10_5 ) && \
249 ( MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 ) )
254 return FT_Err_Unimplemented_Feature;
260 err = FT_GetFileRef_From_Mac_ATS_Name( fontName, &ref, face_index );
264 if ( noErr != FSGetCatalogInfo( &ref, kFSCatInfoNone,
NULL,
NULL,
266 return FT_Err_Unknown_File_Format;
274 FT_FSPathMakeRes(
const UInt8* pathname,
281 if ( noErr != FSPathMakeRef( pathname, &ref,
FALSE ) )
282 return FT_Err_Cannot_Open_Resource;
285 err = FSOpenResourceFile( &ref, 0,
NULL, fsRdPerm, res );
290 *res = FSOpenResFile( &ref, fsRdPerm );
299 get_file_type_from_path(
const UInt8* pathname )
305 if ( noErr != FSPathMakeRef( pathname, &ref,
FALSE ) )
308 if ( noErr != FSGetCatalogInfo( &ref, kFSCatInfoFinderInfo, &info,
312 return ((FInfo *)(info.finderInfo))->fdType;
318 create_lwfn_name(
char* ps_name,
319 Str255 lwfn_file_name )
326 lwfn_file_name[0] = 0;
348 count_faces_sfnt(
char* fond_data )
353 return EndianS16_BtoN( *( (
short*)( fond_data +
354 sizeof ( FamRec ) ) ) ) + 1;
359 count_faces_scalable(
char* fond_data )
363 short i,
face, face_all;
366 fond = (FamRec*)fond_data;
367 face_all = EndianS16_BtoN( *( (
short *)( fond_data +
368 sizeof ( FamRec ) ) ) ) + 1;
369 assoc = (AsscEntry*)( fond_data +
sizeof ( FamRec ) + 2 );
372 for ( i = 0; i < face_all; i++ )
374 if ( 0 == EndianS16_BtoN( assoc[i].fontSize ) )
390 parse_fond(
char* fond_data,
393 Str255 lwfn_file_name,
397 AsscEntry* base_assoc;
403 lwfn_file_name[0] = 0;
405 fond = (FamRec*)fond_data;
406 assoc = (AsscEntry*)( fond_data +
sizeof ( FamRec ) + 2 );
410 if ( 47 < face_index )
414 if ( face_index < count_faces_sfnt( fond_data ) )
420 if ( EndianS16_BtoN( assoc->fontSize ) == 0 )
423 *sfnt_id = EndianS16_BtoN( assoc->fontID );
425 else if ( base_assoc->fontSize == 0 )
428 *sfnt_id = EndianS16_BtoN( base_assoc->fontID );
432 if ( EndianS32_BtoN( fond->ffStylOff ) )
434 unsigned char* p = (
unsigned char*)fond_data;
436 unsigned short string_count;
438 unsigned char*
names[64];
442 p += EndianS32_BtoN( fond->ffStylOff );
443 style = (StyleTable*)p;
444 p +=
sizeof ( StyleTable );
445 string_count = EndianS16_BtoN( *(
short*)(p) );
446 p +=
sizeof ( short );
448 for ( i = 0; i < string_count && i < 64; i++ )
456 size_t ps_name_len = (
size_t)names[0][0];
459 if ( ps_name_len != 0 )
461 ft_memcpy(ps_name, names[0] + 1, ps_name_len);
462 ps_name[ps_name_len] = 0;
464 if ( style->indexes[face_index] > 1 &&
465 style->indexes[face_index] <=
FT_MIN( string_count, 64 ) )
467 unsigned char* suffixes = names[style->indexes[face_index] - 1];
470 for ( i = 1; i <= suffixes[0]; i++ )
473 size_t j = suffixes[
i] - 1;
476 if ( j < string_count && ( s = names[j] ) !=
NULL )
478 size_t s_len = (
size_t)s[0];
481 if ( s_len != 0 && ps_name_len + s_len <
sizeof ( ps_name ) )
483 ft_memcpy( ps_name + ps_name_len, s + 1, s_len );
484 ps_name_len += s_len;
485 ps_name[ps_name_len] = 0;
492 create_lwfn_name( ps_name, lwfn_file_name );
498 lookup_lwfn_by_fond(
const UInt8* path_fond,
499 ConstStr255Param base_lwfn,
510 if ( noErr != FSPathMakeRef( path_fond, &ref,
FALSE ) )
513 if ( noErr != FSGetCatalogInfo( &ref, kFSCatInfoNone,
517 if ( noErr != FSRefMakePath( &par_ref, path_lwfn, path_size ) )
520 if (
ft_strlen( (
char *)path_lwfn ) + 1 + base_lwfn[0] > path_size )
525 dirname_len =
ft_strlen( (
char *)path_lwfn );
526 ft_strcat( (
char *)path_lwfn, (
char *)base_lwfn + 1 );
527 path_lwfn[dirname_len + base_lwfn[0]] =
'\0';
529 if ( noErr != FSPathMakeRef( path_lwfn, &ref,
FALSE ) )
530 return FT_Err_Cannot_Open_Resource;
532 if ( noErr != FSGetCatalogInfo( &ref, kFSCatInfoNone,
534 return FT_Err_Cannot_Open_Resource;
541 count_faces( Handle fond,
542 const UInt8* pathname )
545 short have_sfnt, have_lwfn;
546 Str255 lwfn_file_name;
552 have_sfnt = have_lwfn = 0;
554 parse_fond( *fond, &have_sfnt, &sfnt_id, lwfn_file_name, 0 );
556 if ( lwfn_file_name[0] )
558 err = lookup_lwfn_by_fond( pathname, lwfn_file_name,
559 buff,
sizeof ( buff ) );
567 num_faces = count_faces_scalable( *fond );
591 char code, last_code;
603 post_data = Get1Resource(
TTAG_POST, res_id++ );
604 if ( post_data ==
NULL )
607 code = (*post_data)[0];
609 if ( code != last_code )
617 total_size += GetHandleSize( post_data ) - 2;
621 if ( total_size < old_total_size )
623 error = FT_Err_Array_Too_Large;
627 old_total_size = total_size;
642 post_data = Get1Resource(
TTAG_POST, res_id++ );
643 if ( post_data ==
NULL )
646 post_size = (
FT_ULong)GetHandleSize( post_data ) - 2;
647 code = (*post_data)[0];
649 if ( code != last_code )
651 if ( last_code != -1 )
654 if ( size_p !=
NULL )
656 *size_p++ = (
FT_Byte)( pfb_chunk_size & 0xFF );
657 *size_p++ = (
FT_Byte)( ( pfb_chunk_size >> 8 ) & 0xFF );
658 *size_p++ = (
FT_Byte)( ( pfb_chunk_size >> 16 ) & 0xFF );
659 *size_p++ = (
FT_Byte)( ( pfb_chunk_size >> 24 ) & 0xFF );
667 else if ( code == 2 )
679 ft_memcpy( p, *post_data + 2, post_size );
680 pfb_chunk_size += post_size;
697 const UInt8* pathname,
707 if ( noErr != FT_FSPathMakeRes( pathname, &res ) )
708 return FT_Err_Cannot_Open_Resource;
712 error = read_lwfn( library->
memory, res, &pfb_data, &pfb_size );
738 int is_cff, is_sfnt_ps;
741 sfnt = GetResource(
TTAG_sfnt, sfnt_id );
743 return FT_Err_Invalid_Handle;
745 sfnt_size = (
FT_ULong)GetHandleSize( sfnt );
748 ReleaseResource( sfnt );
752 ft_memcpy( sfnt_data, *sfnt, sfnt_size );
753 ReleaseResource( sfnt );
755 is_cff = sfnt_size > 4 && !
ft_memcmp( sfnt_data,
"OTTO", 4 );
756 is_sfnt_ps = sfnt_size > 4 && !
ft_memcmp( sfnt_data,
"typ1", 4 );
786 is_cff ?
"cff" :
"truetype",
795 FT_New_Face_From_Suitcase(
FT_Library library,
796 const UInt8* pathname,
800 FT_Error error = FT_Err_Cannot_Open_Resource;
801 ResFileRefNum res_ref;
804 short num_faces_in_res, num_faces_in_fond;
807 if ( noErr != FT_FSPathMakeRes( pathname, &res_ref ) )
808 return FT_Err_Cannot_Open_Resource;
810 UseResFile( res_ref );
812 return FT_Err_Cannot_Open_Resource;
814 num_faces_in_res = 0;
815 for ( res_index = 1; ; ++res_index )
817 fond = Get1IndResource(
TTAG_FOND, res_index );
821 num_faces_in_fond = count_faces( fond, pathname );
822 num_faces_in_res += num_faces_in_fond;
824 if ( 0 <= face_index && face_index < num_faces_in_fond && error )
827 face_index -= num_faces_in_fond;
830 CloseResFile( res_ref );
832 (*aface)->num_faces = num_faces_in_res;
845 short have_sfnt, have_lwfn = 0;
846 ResID sfnt_id, fond_id;
849 Str255 lwfn_file_name;
855 GetResInfo( fond, &fond_id, &fond_type, fond_name );
856 if ( ResError() != noErr || fond_type !=
TTAG_FOND )
857 return FT_Err_Invalid_File_Format;
859 parse_fond( *fond, &have_sfnt, &sfnt_id, lwfn_file_name, face_index );
861 if ( lwfn_file_name[0] )
866 res = HomeResFile( fond );
867 if ( noErr != ResError() )
868 goto found_no_lwfn_file;
875 err = FSGetForkCBInfo( res, kFSInvalidVolumeRefNum,
878 goto found_no_lwfn_file;
880 err = FSRefMakePath( &ref, path_fond,
sizeof ( path_fond ) );
882 goto found_no_lwfn_file;
884 error = lookup_lwfn_by_fond( path_fond, lwfn_file_name,
885 path_lwfn,
sizeof ( path_lwfn ) );
892 error = FT_New_Face_From_LWFN( library,
897 error = FT_Err_Unknown_File_Format;
901 error = FT_New_Face_From_SFNT( library,
912 FT_New_Face_From_Resource(
FT_Library library,
913 const UInt8* pathname,
922 file_type = get_file_type_from_path( pathname );
924 return FT_New_Face_From_LWFN( library, pathname, face_index, aface );
930 error = FT_New_Face_From_Suitcase( library, pathname, face_index, aface );
954 const char* pathname,
970 error = FT_New_Face_From_Resource( library, (UInt8 *)pathname,
972 if ( error != 0 || *aface !=
NULL )
978 return FT_Open_Face( library, &args, face_index, aface );
1008 err = FSRefMakePath( ref, pathname,
sizeof ( pathname ) );
1010 error = FT_Err_Cannot_Open_Resource;
1012 error = FT_New_Face_From_Resource( library, pathname, face_index, aface );
1013 if ( error != 0 || *aface !=
NULL )
1019 return FT_Open_Face( library, &args, face_index, aface );
1039 #if ( __LP64__ ) || ( defined( MAC_OS_X_VERSION_10_5 ) && \
1040 ( MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 ) )
1046 return FT_Err_Unimplemented_Feature;
1051 if ( !spec || FSpMakeFSRef( spec, &ref ) != noErr )
#define FT_ALLOC(ptr, size)
FT_New_Face_From_FSRef(FT_Library library, const FSRef *ref, FT_Long face_index, FT_Face *aface) FT_DEPRECATED_ATTRIBUTE
FT_GetFilePath_From_Mac_ATS_Name(const char *fontName, UInt8 *path, UInt32 maxPathSize, FT_Long *face_index) FT_DEPRECATED_ATTRIBUTE
return FT_Err_Invalid_Argument
GLuint const GLuint * names
FT_Stream_Close(FT_Stream stream)
FT_BEGIN_HEADER open_face_PS_from_sfnt_stream(FT_Library library, FT_Stream stream, FT_Long face_index, FT_Int num_params, FT_Parameter *params, FT_Face *aface)
GLsizei const GLchar *const * path
open_face_from_buffer(FT_Library library, FT_Byte *base, FT_ULong size, FT_Long face_index, const char *driver_name, FT_Face *aface)
GLenum const void * fontName
EGLContext EGLenum EGLClientBuffer buffer
FT_GetFile_From_Mac_Name(const char *fontName, FSSpec *pathSpec, FT_Long *face_index) FT_DEPRECATED_ATTRIBUTE
FT_GetFile_From_Mac_ATS_Name(const char *fontName, FSSpec *pathSpec, FT_Long *face_index) FT_DEPRECATED_ATTRIBUTE
#define kATSOptionFlagsUnRestrictedScope
typedefFT_BEGIN_HEADER struct FT_MemoryRec_ * FT_Memory
FT_New_Face_From_FSSpec(FT_Library library, const FSSpec *spec, FT_Long face_index, FT_Face *aface) FT_DEPRECATED_ATTRIBUTE
GLdouble GLdouble GLdouble GLdouble q
FT_Open_Face(FT_Library library, const FT_Open_Args *args, FT_Long face_index, FT_Face *aface)
FT_New_Face(FT_Library library, const char *filepathname, FT_Long face_index, FT_Face *aface)
FT_Stream_OpenMemory(FT_Stream stream, const FT_Byte *base, FT_ULong size)
FT_New_Face_From_FOND(FT_Library library, Handle fond, FT_Long face_index, FT_Face *aface) FT_DEPRECATED_ATTRIBUTE