69 #include FT_FREETYPE_H 70 #include FT_TRUETYPE_TAGS_H 71 #include FT_INTERNAL_STREAM_H 77 #if !HAVE_ANSI_OS_INLINE 79 #define OS_INLINE static __inline__ 86 #ifndef HAVE_TYPE_RESOURCE_INDEX 87 #if !defined( MAC_OS_X_VERSION_10_5 ) || \ 88 ( MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5 ) 89 #define HAVE_TYPE_RESOURCE_INDEX 0 91 #define HAVE_TYPE_RESOURCE_INDEX 1 95 #if ( HAVE_TYPE_RESOURCE_INDEX == 0 ) 99 #include <CoreServices/CoreServices.h> 100 #include <ApplicationServices/ApplicationServices.h> 101 #include <sys/syslimits.h> 104 #define FT_DEPRECATED_ATTRIBUTE 108 #ifndef kATSOptionFlagsUnRestrictedScope 109 #define kATSOptionFlagsUnRestrictedScope kATSOptionFlagsDefault 117 #define PREFER_LWFN 1 133 return FT_THROW( Unimplemented_Feature );
143 FT_ATSFontGetFileReference( ATSFontRef ats_font_id,
144 FSRef* ats_font_ref )
146 #if defined( MAC_OS_X_VERSION_10_5 ) && \ 147 ( MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 ) 151 err = ATSFontGetFileReference( ats_font_id, ats_font_ref );
165 err = ATSFontGetFileSpecification( ats_font_id, &spec );
167 err = FSpMakeFSRef( &spec, ats_font_ref );
175 FT_GetFileRef_From_Mac_ATS_Name(
const char*
fontName,
179 CFStringRef cf_fontName;
180 ATSFontRef ats_font_id;
185 cf_fontName = CFStringCreateWithCString(
NULL,
fontName,
186 kCFStringEncodingMacRoman );
187 ats_font_id = ATSFontFindFromName( cf_fontName,
189 CFRelease( cf_fontName );
191 if ( ats_font_id == 0 || ats_font_id == 0xFFFFFFFFUL )
192 return FT_THROW( Unknown_File_Format );
194 if ( noErr != FT_ATSFontGetFileReference( ats_font_id, ats_font_ref ) )
195 return FT_THROW( Unknown_File_Format );
200 ATSFontRef id2 = ats_font_id - 1;
206 if ( noErr != FT_ATSFontGetFileReference( id2, &ref2 ) )
208 if ( noErr != FSCompareFSRefs( ats_font_ref, &ref2 ) )
213 *face_index = ats_font_id - ( id2 + 1 );
230 err = FT_GetFileRef_From_Mac_ATS_Name(
fontName, &ref, face_index );
234 if ( noErr != FSRefMakePath( &ref,
path, maxPathSize ) )
235 return FT_THROW( Unknown_File_Format );
247 #if ( __LP64__ ) || ( defined( MAC_OS_X_VERSION_10_5 ) && \ 248 ( MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 ) ) 253 return FT_THROW( Unimplemented_Feature );
259 err = FT_GetFileRef_From_Mac_ATS_Name(
fontName, &ref, face_index );
263 if ( noErr != FSGetCatalogInfo( &ref, kFSCatInfoNone,
NULL,
NULL,
265 return FT_THROW( Unknown_File_Format );
273 FT_FSPathMakeRes(
const UInt8* pathname,
280 if ( noErr != FSPathMakeRef( pathname, &ref,
FALSE ) )
281 return FT_THROW( Cannot_Open_Resource );
284 err = FSOpenResourceFile( &ref, 0,
NULL, fsRdPerm, res );
289 *res = FSOpenResFile( &ref, fsRdPerm );
298 get_file_type_from_path(
const UInt8* pathname )
304 if ( noErr != FSPathMakeRef( pathname, &ref,
FALSE ) )
307 if ( noErr != FSGetCatalogInfo( &ref, kFSCatInfoFinderInfo, &info,
311 return ((FInfo *)(info.finderInfo))->fdType;
317 create_lwfn_name(
char* ps_name,
318 Str255 lwfn_file_name )
325 lwfn_file_name[0] = 0;
347 count_faces_sfnt(
char* fond_data )
352 return EndianS16_BtoN( *( (
short*)( fond_data +
353 sizeof ( FamRec ) ) ) ) + 1;
358 count_faces_scalable(
char* fond_data )
362 short i,
face, face_all;
365 fond = (FamRec*)fond_data;
366 face_all = EndianS16_BtoN( *( (
short *)( fond_data +
367 sizeof ( FamRec ) ) ) ) + 1;
368 assoc = (AsscEntry*)( fond_data +
sizeof ( FamRec ) + 2 );
371 for ( i = 0; i < face_all; i++ )
373 if ( 0 == EndianS16_BtoN( assoc[i].fontSize ) )
389 parse_fond(
char* fond_data,
392 Str255 lwfn_file_name,
396 AsscEntry* base_assoc;
402 lwfn_file_name[0] = 0;
404 fond = (FamRec*)fond_data;
405 assoc = (AsscEntry*)( fond_data +
sizeof ( FamRec ) + 2 );
409 if ( 47 < face_index )
413 if ( face_index < count_faces_sfnt( fond_data ) )
419 if ( EndianS16_BtoN( assoc->fontSize ) == 0 )
422 *sfnt_id = EndianS16_BtoN( assoc->fontID );
424 else if ( base_assoc->fontSize == 0 )
427 *sfnt_id = EndianS16_BtoN( base_assoc->fontID );
431 if ( EndianS32_BtoN( fond->ffStylOff ) )
433 unsigned char*
p = (
unsigned char*)fond_data;
435 unsigned short string_count;
437 unsigned char*
names[64];
441 p += EndianS32_BtoN( fond->ffStylOff );
442 style = (StyleTable*)p;
443 p +=
sizeof ( StyleTable );
444 string_count = EndianS16_BtoN( *(
short*)(p) );
445 p +=
sizeof ( short );
447 for ( i = 0; i < string_count && i < 64; i++ )
455 size_t ps_name_len = (size_t)names[0][0];
458 if ( ps_name_len != 0 )
460 ft_memcpy(ps_name, names[0] + 1, ps_name_len);
461 ps_name[ps_name_len] = 0;
463 if ( style->indexes[face_index] > 1 &&
464 style->indexes[face_index] <=
FT_MIN( string_count, 64 ) )
466 unsigned char* suffixes = names[style->indexes[face_index] - 1];
469 for ( i = 1; i <= suffixes[0]; i++ )
472 size_t j = suffixes[
i] - 1;
475 if ( j < string_count && ( s = names[j] ) !=
NULL )
477 size_t s_len = (size_t)s[0];
480 if ( s_len != 0 && ps_name_len + s_len <
sizeof ( ps_name ) )
482 ft_memcpy( ps_name + ps_name_len, s + 1, s_len );
483 ps_name_len += s_len;
484 ps_name[ps_name_len] = 0;
491 create_lwfn_name( ps_name, lwfn_file_name );
497 lookup_lwfn_by_fond(
const UInt8* path_fond,
498 ConstStr255Param base_lwfn,
509 if ( noErr != FSPathMakeRef( path_fond, &ref,
FALSE ) )
510 return FT_THROW( Invalid_Argument );
512 if ( noErr != FSGetCatalogInfo( &ref, kFSCatInfoNone,
514 return FT_THROW( Invalid_Argument );
516 if ( noErr != FSRefMakePath( &par_ref, path_lwfn, path_size ) )
517 return FT_THROW( Invalid_Argument );
519 if (
ft_strlen( (
char *)path_lwfn ) + 1 + base_lwfn[0] > path_size )
520 return FT_THROW( Invalid_Argument );
524 dirname_len =
ft_strlen( (
char *)path_lwfn );
525 ft_strcat( (
char *)path_lwfn, (
char *)base_lwfn + 1 );
526 path_lwfn[dirname_len + base_lwfn[0]] =
'\0';
528 if ( noErr != FSPathMakeRef( path_lwfn, &ref,
FALSE ) )
529 return FT_THROW( Cannot_Open_Resource );
531 if ( noErr != FSGetCatalogInfo( &ref, kFSCatInfoNone,
533 return FT_THROW( Cannot_Open_Resource );
540 count_faces( Handle fond,
541 const UInt8* pathname )
544 short have_sfnt, have_lwfn;
545 Str255 lwfn_file_name;
551 have_sfnt = have_lwfn = 0;
553 parse_fond( *fond, &have_sfnt, &sfnt_id, lwfn_file_name, 0 );
555 if ( lwfn_file_name[0] )
557 err = lookup_lwfn_by_fond( pathname, lwfn_file_name,
558 buff,
sizeof ( buff ) );
566 num_faces = count_faces_scalable( *fond );
590 char code, last_code;
602 post_data = Get1Resource(
TTAG_POST, res_id++ );
603 if ( post_data ==
NULL )
606 code = (*post_data)[0];
608 if ( code != last_code )
616 total_size += GetHandleSize( post_data ) - 2;
620 if ( total_size < old_total_size )
622 error =
FT_THROW( Array_Too_Large );
626 old_total_size = total_size;
641 post_data = Get1Resource(
TTAG_POST, res_id++ );
642 if ( post_data ==
NULL )
645 post_size = (
FT_ULong)GetHandleSize( post_data ) - 2;
646 code = (*post_data)[0];
648 if ( code != last_code )
650 if ( last_code != -1 )
653 if ( size_p !=
NULL )
655 *size_p++ = (
FT_Byte)( pfb_chunk_size & 0xFF );
656 *size_p++ = (
FT_Byte)( ( pfb_chunk_size >> 8 ) & 0xFF );
657 *size_p++ = (
FT_Byte)( ( pfb_chunk_size >> 16 ) & 0xFF );
658 *size_p++ = (
FT_Byte)( ( pfb_chunk_size >> 24 ) & 0xFF );
666 else if ( code == 2 )
678 ft_memcpy( p, *post_data + 2, post_size );
679 pfb_chunk_size += post_size;
696 const UInt8* pathname,
706 if ( noErr != FT_FSPathMakeRes( pathname, &res ) )
707 return FT_THROW( Cannot_Open_Resource );
711 error = read_lwfn( library->
memory, res, &pfb_data, &pfb_size );
737 int is_cff, is_sfnt_ps;
740 sfnt = GetResource(
TTAG_sfnt, sfnt_id );
744 sfnt_size = (
FT_ULong)GetHandleSize( sfnt );
747 ReleaseResource( sfnt );
751 ft_memcpy( sfnt_data, *sfnt, sfnt_size );
752 ReleaseResource( sfnt );
754 is_cff = sfnt_size > 4 && !
ft_memcmp( sfnt_data,
"OTTO", 4 );
755 is_sfnt_ps = sfnt_size > 4 && !
ft_memcmp( sfnt_data,
"typ1", 4 );
785 is_cff ?
"cff" :
"truetype",
794 FT_New_Face_From_Suitcase(
FT_Library library,
795 const UInt8* pathname,
800 ResFileRefNum res_ref;
803 short num_faces_in_res, num_faces_in_fond;
806 if ( noErr != FT_FSPathMakeRes( pathname, &res_ref ) )
807 return FT_THROW( Cannot_Open_Resource );
809 UseResFile( res_ref );
811 return FT_THROW( Cannot_Open_Resource );
813 num_faces_in_res = 0;
814 for ( res_index = 1; ; ++res_index )
816 fond = Get1IndResource(
TTAG_FOND, res_index );
820 num_faces_in_fond = count_faces( fond, pathname );
821 num_faces_in_res += num_faces_in_fond;
823 if ( 0 <= face_index && face_index < num_faces_in_fond && error )
826 face_index -= num_faces_in_fond;
829 CloseResFile( res_ref );
830 if ( !error && aface && *aface )
831 (*aface)->num_faces = num_faces_in_res;
844 short have_sfnt, have_lwfn = 0;
845 ResID sfnt_id, fond_id;
848 Str255 lwfn_file_name;
854 GetResInfo( fond, &fond_id, &fond_type, fond_name );
855 if ( ResError() != noErr || fond_type !=
TTAG_FOND )
856 return FT_THROW( Invalid_File_Format );
858 parse_fond( *fond, &have_sfnt, &sfnt_id, lwfn_file_name, face_index );
860 if ( lwfn_file_name[0] )
865 res = HomeResFile( fond );
866 if ( noErr != ResError() )
867 goto found_no_lwfn_file;
874 err = FSGetForkCBInfo( res, kFSInvalidVolumeRefNum,
877 goto found_no_lwfn_file;
879 err = FSRefMakePath( &ref, path_fond,
sizeof ( path_fond ) );
881 goto found_no_lwfn_file;
883 error = lookup_lwfn_by_fond( path_fond, lwfn_file_name,
884 path_lwfn,
sizeof ( path_lwfn ) );
891 error = FT_New_Face_From_LWFN( library,
896 error =
FT_THROW( Unknown_File_Format );
899 if ( have_sfnt && error )
900 error = FT_New_Face_From_SFNT( library,
911 FT_New_Face_From_Resource(
FT_Library library,
912 const UInt8* pathname,
921 file_type = get_file_type_from_path( pathname );
923 return FT_New_Face_From_LWFN( library, pathname, face_index, aface );
929 error = FT_New_Face_From_Suitcase( library, pathname, face_index, aface );
953 const char* pathname,
963 return FT_THROW( Invalid_Argument );
969 error = FT_New_Face_From_Resource( library, (UInt8 *)pathname,
971 if ( error != 0 || *aface !=
NULL )
977 return FT_Open_Face( library, &args, face_index, aface );
1005 return FT_THROW( Invalid_Argument );
1007 err = FSRefMakePath(
ref, pathname,
sizeof ( pathname ) );
1009 error =
FT_THROW( Cannot_Open_Resource );
1011 error = FT_New_Face_From_Resource( library, pathname, face_index, aface );
1012 if ( error != 0 || *aface !=
NULL )
1018 return FT_Open_Face( library, &args, face_index, aface );
1038 #if ( __LP64__ ) || ( defined( MAC_OS_X_VERSION_10_5 ) && \ 1039 ( MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 ) ) 1045 return FT_THROW( Unimplemented_Feature );
1050 if ( !spec || FSpMakeFSRef( spec, &ref ) != noErr )
1051 return FT_THROW( Invalid_Argument );
#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
GLdouble GLdouble GLdouble GLdouble q
FT_GetFilePath_From_Mac_ATS_Name(const char *fontName, UInt8 *path, UInt32 maxPathSize, FT_Long *face_index) FT_DEPRECATED_ATTRIBUTE
return FT_THROW(Missing_Property)
#define kATSOptionFlagsUnRestrictedScope
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)
GLenum GLuint GLint GLenum face
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 GLvoid * fontName
GLsizei const GLchar ** path
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
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
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)
GLuint GLuint GLsizei count
FT_New_Face_From_FOND(FT_Library library, Handle fond, FT_Long face_index, FT_Face *aface) FT_DEPRECATED_ATTRIBUTE