66 #include FT_FREETYPE_H 67 #include FT_TRUETYPE_TAGS_H 68 #include FT_INTERNAL_STREAM_H 71 #if defined( __GNUC__ ) || defined( __IBMC__ ) 75 #if !HAVE_ANSI_OS_INLINE 77 #define OS_INLINE static __inline__ 79 #include <CoreServices/CoreServices.h> 80 #include <ApplicationServices/ApplicationServices.h> 81 #include <sys/syslimits.h> 83 #include <Resources.h> 88 #include <TextUtils.h> 95 #if defined( __MWERKS__ ) && !TARGET_RT_MAC_MACHO 96 #include <FSp_fopen.h> 99 #define FT_DEPRECATED_ATTRIBUTE 104 #undef FT_GetFile_From_Mac_Name 105 #undef FT_GetFile_From_Mac_ATS_Name 106 #undef FT_New_Face_From_FOND 107 #undef FT_New_Face_From_FSSpec 108 #undef FT_New_Face_From_FSRef 113 #if TARGET_API_MAC_OS8 || TARGET_API_MAC_CARBON 114 #define HAVE_FSSPEC 1 116 #define HAVE_FSSPEC 0 122 #if TARGET_API_MAC_OSX 130 #ifndef HAVE_QUICKDRAW_CARBON 131 #if TARGET_API_MAC_OS8 || TARGET_API_MAC_CARBON 132 #define HAVE_QUICKDRAW_CARBON 1 134 #define HAVE_QUICKDRAW_CARBON 0 140 #if TARGET_API_MAC_OSX 142 #ifndef kATSOptionFlagsUnRestrictedScope 143 #define kATSOptionFlagsUnRestrictedScope kATSOptionFlagsDefault 154 #ifndef HAVE_TYPE_RESOURCE_INDEX 155 #if !defined( MAC_OS_X_VERSION_10_5 ) || \ 156 ( MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5 ) 157 #define HAVE_TYPE_RESOURCE_INDEX 0 159 #define HAVE_TYPE_RESOURCE_INDEX 1 163 #if ( HAVE_TYPE_RESOURCE_INDEX == 0 ) 171 #define PREFER_LWFN 1 176 #if !HAVE_QUICKDRAW_CARBON 187 return FT_Err_Unimplemented_Feature;
197 OptionBits options = kFMUseGlobalScopeOption;
199 FMFontFamilyIterator famIter;
200 OSStatus status = FMCreateFontFamilyIterator(
NULL,
NULL,
204 FMFontFamily family = 0;
208 while ( status == 0 && !the_font )
210 status = FMGetNextFontFamily( &famIter, &family );
214 FMFontFamilyInstanceIterator instIter;
220 FMGetFontFamilyName( family, famNameStr );
221 CopyPascalStringToC( famNameStr, famName );
224 FMCreateFontFamilyInstanceIterator( family, &instIter );
229 while ( stat2 == 0 && !the_font )
236 stat2 = FMGetNextFontFamilyInstance( &instIter, &font,
238 if ( stat2 == 0 && size == 0 )
247 if ( style & italic )
261 FMDisposeFontFamilyInstanceIterator( &instIter );
265 FMDisposeFontFamilyIterator( &famIter );
269 FMGetFontContainer( the_font, pathSpec );
273 return FT_Err_Unknown_File_Format;
287 FT_ATSFontGetFileReference( ATSFontRef ats_font_id,
288 FSRef* ats_font_ref )
292 #if !defined( MAC_OS_X_VERSION_10_5 ) || \ 293 MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5 297 err = ATSFontGetFileSpecification( ats_font_id, &spec );
299 err = FSpMakeFSRef( &spec, ats_font_ref );
301 err = ATSFontGetFileReference( ats_font_id, ats_font_ref );
309 FT_GetFileRef_From_Mac_ATS_Name(
const char*
fontName,
313 CFStringRef cf_fontName;
314 ATSFontRef ats_font_id;
319 cf_fontName = CFStringCreateWithCString(
NULL,
fontName,
320 kCFStringEncodingMacRoman );
321 ats_font_id = ATSFontFindFromName( cf_fontName,
323 CFRelease( cf_fontName );
325 if ( ats_font_id == 0 || ats_font_id == 0xFFFFFFFFUL )
326 return FT_Err_Unknown_File_Format;
328 if ( noErr != FT_ATSFontGetFileReference( ats_font_id, ats_font_ref ) )
329 return FT_Err_Unknown_File_Format;
334 ATSFontRef id2 = ats_font_id - 1;
340 if ( noErr != FT_ATSFontGetFileReference( id2, &ref2 ) )
342 if ( noErr != FSCompareFSRefs( ats_font_ref, &ref2 ) )
347 *face_index = ats_font_id - ( id2 + 1 );
368 return FT_Err_Unimplemented_Feature;
383 err = FT_GetFileRef_From_Mac_ATS_Name(
fontName, &ref, face_index );
387 if ( noErr != FSRefMakePath( &ref,
path, maxPathSize ) )
388 return FT_Err_Unknown_File_Format;
396 #if !HAVE_FSSPEC || !HAVE_ATS 407 return FT_Err_Unimplemented_Feature;
422 err = FT_GetFileRef_From_Mac_ATS_Name(
fontName, &ref, face_index );
426 if ( noErr != FSGetCatalogInfo( &ref, kFSCatInfoNone,
NULL,
NULL,
428 return FT_Err_Unknown_File_Format;
436 #if defined( __MWERKS__ ) && !TARGET_RT_MAC_MACHO 438 #define STREAM_FILE( stream ) ( (FT_FILE*)stream->descriptor.pointer ) 456 unsigned long count )
471 #if HAVE_FSSPEC && !HAVE_FSREF 475 FT_FSPathMakeSpec(
const UInt8* pathname,
477 Boolean isDirectory )
487 p = q = (
const char *)pathname;
504 if ( 255 <
ft_strlen( (
char *)pathname ) )
506 while ( p < q && *q !=
':' )
511 *(
char *)nodeName = q - p;
515 return errFSNameTooLong;
517 ft_strncpy( (
char *)nodeName + 1, (
char *)p, *(
char *)nodeName );
518 err = FSMakeFSSpec( vRefNum, dirID, nodeName, spec_p );
519 if ( err ||
'\0' == *q )
522 vRefNum = spec_p->vRefNum;
523 dirID = spec_p->parID;
531 FT_FSpMakePath(
const FSSpec* spec_p,
536 FSSpec spec = *spec_p;
546 unsigned char node_namelen = spec.name[0];
547 unsigned char* node_name = spec.name + 1;
550 if ( node_namelen + child_namelen > maxPathSize )
551 return errFSNameTooLong;
553 FT_MEM_MOVE( path + node_namelen + 1, path, child_namelen );
555 if ( child_namelen > 0 )
556 path[node_namelen] =
':';
558 vRefNum = spec.vRefNum;
560 parDir_name[0] =
'\0';
561 err = FSMakeFSSpec( vRefNum, dirID, parDir_name, &spec );
562 if ( noErr != err || dirID == spec.parID )
572 FT_FSPathMakeRes(
const UInt8* pathname,
582 if ( noErr != FSPathMakeRef( pathname, &ref,
FALSE ) )
583 return FT_Err_Cannot_Open_Resource;
586 err = FSOpenResourceFile( &ref, 0,
NULL, fsRdPerm, res );
591 *res = FSOpenResFile( &ref, fsRdPerm );
600 if ( noErr != FT_FSPathMakeSpec( pathname, &spec,
FALSE ) )
601 return FT_Err_Cannot_Open_Resource;
605 *res = FSpOpenResFile( &spec, fsRdPerm );
616 get_file_type_from_path(
const UInt8* pathname )
625 if ( noErr != FSPathMakeRef( pathname, &ref,
FALSE ) )
628 if ( noErr != FSGetCatalogInfo( &ref, kFSCatInfoFinderInfo, &info,
632 return ((FInfo *)(info.finderInfo))->fdType;
640 if ( noErr != FT_FSPathMakeSpec( pathname, &spec,
FALSE ) )
643 if ( noErr != FSpGetFInfo( &spec, &finfo ) )
655 create_lwfn_name(
char* ps_name,
656 Str255 lwfn_file_name )
663 lwfn_file_name[0] = 0;
685 count_faces_sfnt(
char* fond_data )
690 return EndianS16_BtoN( *( (
short*)( fond_data +
691 sizeof ( FamRec ) ) ) ) + 1;
696 count_faces_scalable(
char* fond_data )
700 short i,
face, face_all;
703 fond = (FamRec*)fond_data;
704 face_all = EndianS16_BtoN( *( (
short *)( fond_data +
705 sizeof ( FamRec ) ) ) ) + 1;
706 assoc = (AsscEntry*)( fond_data +
sizeof ( FamRec ) + 2 );
709 for ( i = 0; i < face_all; i++ )
711 if ( 0 == EndianS16_BtoN( assoc[i].fontSize ) )
726 parse_fond(
char* fond_data,
729 Str255 lwfn_file_name,
733 AsscEntry* base_assoc;
739 lwfn_file_name[0] = 0;
741 fond = (FamRec*)fond_data;
742 assoc = (AsscEntry*)( fond_data +
sizeof ( FamRec ) + 2 );
746 if ( 47 < face_index )
750 if ( face_index < count_faces_sfnt( fond_data ) )
756 if ( EndianS16_BtoN( assoc->fontSize ) == 0 )
759 *sfnt_id = EndianS16_BtoN( assoc->fontID );
761 else if ( base_assoc->fontSize == 0 )
764 *sfnt_id = EndianS16_BtoN( base_assoc->fontID );
768 if ( EndianS32_BtoN( fond->ffStylOff ) )
770 unsigned char*
p = (
unsigned char*)fond_data;
772 unsigned short string_count;
774 unsigned char*
names[64];
778 p += EndianS32_BtoN( fond->ffStylOff );
779 style = (StyleTable*)p;
780 p +=
sizeof ( StyleTable );
781 string_count = EndianS16_BtoN( *(
short*)(p) );
782 p +=
sizeof ( short );
784 for ( i = 0; i < string_count && i < 64; i++ )
792 size_t ps_name_len = (size_t)names[0][0];
795 if ( ps_name_len != 0 )
797 ft_memcpy(ps_name, names[0] + 1, ps_name_len);
798 ps_name[ps_name_len] = 0;
800 if ( style->indexes[face_index] > 1 &&
801 style->indexes[face_index] <=
FT_MIN( string_count, 64 ) )
803 unsigned char* suffixes = names[style->indexes[face_index] - 1];
806 for ( i = 1; i <= suffixes[0]; i++ )
809 size_t j = suffixes[
i] - 1;
812 if ( j < string_count && ( s = names[j] ) !=
NULL )
814 size_t s_len = (size_t)s[0];
817 if ( s_len != 0 && ps_name_len + s_len <
sizeof ( ps_name ) )
819 ft_memcpy( ps_name + ps_name_len, s + 1, s_len );
820 ps_name_len += s_len;
821 ps_name[ps_name_len] = 0;
828 create_lwfn_name( ps_name, lwfn_file_name );
834 lookup_lwfn_by_fond(
const UInt8* path_fond,
835 ConstStr255Param base_lwfn,
849 if ( noErr != FSPathMakeRef( path_fond, &ref,
FALSE ) )
850 return FT_Err_Invalid_Argument;
852 if ( noErr != FSGetCatalogInfo( &ref, kFSCatInfoNone,
854 return FT_Err_Invalid_Argument;
856 if ( noErr != FSRefMakePath( &par_ref, path_lwfn, path_size ) )
857 return FT_Err_Invalid_Argument;
859 if (
ft_strlen( (
char *)path_lwfn ) + 1 + base_lwfn[0] > path_size )
860 return FT_Err_Invalid_Argument;
863 if ( path_lwfn[0] ==
'/' )
868 dirname_len =
ft_strlen( (
char *)path_lwfn );
869 ft_strcat( (
char *)path_lwfn, (
char *)base_lwfn + 1 );
870 path_lwfn[dirname_len + base_lwfn[0]] =
'\0';
872 if ( noErr != FSPathMakeRef( path_lwfn, &ref,
FALSE ) )
873 return FT_Err_Cannot_Open_Resource;
875 if ( noErr != FSGetCatalogInfo( &ref, kFSCatInfoNone,
877 return FT_Err_Cannot_Open_Resource;
888 if (
ft_strlen( (
char *)path_fond ) > path_size )
889 return FT_Err_Invalid_Argument;
891 ft_strcpy( (
char *)path_lwfn, (
char *)path_fond );
894 while ( i > 0 &&
':' != path_lwfn[i] )
897 if ( i + 1 + base_lwfn[0] > path_size )
898 return FT_Err_Invalid_Argument;
900 if (
':' == path_lwfn[i] )
902 ft_strcpy( (
char *)path_lwfn + i + 1, (
char *)base_lwfn + 1 );
903 path_lwfn[i + 1 + base_lwfn[0]] =
'\0';
907 ft_strcpy( (
char *)path_lwfn, (
char *)base_lwfn + 1 );
908 path_lwfn[base_lwfn[0]] =
'\0';
911 if ( noErr != FT_FSPathMakeSpec( path_lwfn, &spec,
FALSE ) )
912 return FT_Err_Cannot_Open_Resource;
922 count_faces( Handle fond,
923 const UInt8* pathname )
926 short have_sfnt, have_lwfn;
927 Str255 lwfn_file_name;
933 have_sfnt = have_lwfn = 0;
936 parse_fond( *fond, &have_sfnt, &sfnt_id, lwfn_file_name, 0 );
938 if ( lwfn_file_name[0] )
940 err = lookup_lwfn_by_fond( pathname, lwfn_file_name,
941 buff,
sizeof ( buff ) );
949 num_faces = count_faces_scalable( *fond );
974 char code, last_code;
986 post_data = Get1Resource(
TTAG_POST, res_id++ );
987 if ( post_data ==
NULL )
990 code = (*post_data)[0];
992 if ( code != last_code )
1000 total_size += GetHandleSize( post_data ) - 2;
1004 if ( total_size < old_total_size )
1006 error = FT_Err_Array_Too_Large;
1010 old_total_size = total_size;
1025 post_data = Get1Resource(
TTAG_POST, res_id++ );
1026 if ( post_data ==
NULL )
1029 post_size = (
FT_ULong)GetHandleSize( post_data ) - 2;
1030 code = (*post_data)[0];
1032 if ( code != last_code )
1034 if ( last_code != -1 )
1037 if ( size_p !=
NULL )
1039 *size_p++ = (
FT_Byte)( pfb_chunk_size & 0xFF );
1040 *size_p++ = (
FT_Byte)( ( pfb_chunk_size >> 8 ) & 0xFF );
1041 *size_p++ = (
FT_Byte)( ( pfb_chunk_size >> 16 ) & 0xFF );
1042 *size_p++ = (
FT_Byte)( ( pfb_chunk_size >> 24 ) & 0xFF );
1050 else if ( code == 2 )
1062 ft_memcpy( p, *post_data + 2, post_size );
1063 pfb_chunk_size += post_size;
1072 CloseResFile(
res );
1080 const UInt8* pathname,
1090 if ( noErr != FT_FSPathMakeRes( pathname, &res ) )
1091 return FT_Err_Cannot_Open_Resource;
1095 error = read_lwfn( library->
memory, res, &pfb_data, &pfb_size );
1096 CloseResFile( res );
1121 int is_cff, is_sfnt_ps;
1124 sfnt = GetResource(
TTAG_sfnt, sfnt_id );
1126 return FT_Err_Invalid_Handle;
1128 sfnt_size = (
FT_ULong)GetHandleSize( sfnt );
1131 ReleaseResource( sfnt );
1136 ft_memcpy( sfnt_data, *sfnt, sfnt_size );
1138 ReleaseResource( sfnt );
1140 is_cff = sfnt_size > 4 && !
ft_memcmp( sfnt_data,
"OTTO", 4 );
1141 is_sfnt_ps = sfnt_size > 4 && !
ft_memcmp( sfnt_data,
"typ1", 4 );
1171 is_cff ?
"cff" :
"truetype",
1180 FT_New_Face_From_Suitcase(
FT_Library library,
1181 const UInt8* pathname,
1186 ResFileRefNum res_ref;
1189 short num_faces_in_res, num_faces_in_fond;
1192 if ( noErr != FT_FSPathMakeRes( pathname, &res_ref ) )
1193 return FT_Err_Cannot_Open_Resource;
1195 UseResFile( res_ref );
1197 return FT_Err_Cannot_Open_Resource;
1199 num_faces_in_res = 0;
1200 for ( res_index = 1; ; ++res_index )
1202 fond = Get1IndResource(
TTAG_FOND, res_index );
1206 num_faces_in_fond = count_faces( fond, pathname );
1207 num_faces_in_res += num_faces_in_fond;
1209 if ( 0 <= face_index && face_index < num_faces_in_fond && error )
1212 face_index -= num_faces_in_fond;
1215 CloseResFile( res_ref );
1217 (*aface)->num_faces = num_faces_in_res;
1230 short have_sfnt, have_lwfn = 0;
1231 ResID sfnt_id, fond_id;
1234 Str255 lwfn_file_name;
1240 GetResInfo( fond, &fond_id, &fond_type, fond_name );
1241 if ( ResError() != noErr || fond_type !=
TTAG_FOND )
1242 return FT_Err_Invalid_File_Format;
1245 parse_fond( *fond, &have_sfnt, &sfnt_id, lwfn_file_name, face_index );
1248 if ( lwfn_file_name[0] )
1253 res = HomeResFile( fond );
1254 if ( noErr != ResError() )
1255 goto found_no_lwfn_file;
1264 err = FSGetForkCBInfo( res, kFSInvalidVolumeRefNum,
1267 goto found_no_lwfn_file;
1269 err = FSRefMakePath( &ref, path_fond,
sizeof ( path_fond ) );
1271 goto found_no_lwfn_file;
1273 error = lookup_lwfn_by_fond( path_fond, lwfn_file_name,
1274 path_lwfn,
sizeof ( path_lwfn ) );
1284 Str255 fond_file_name;
1291 pb.ioNamePtr = fond_file_name;
1296 err = PBGetFCBInfoSync( &pb );
1298 goto found_no_lwfn_file;
1300 err = FSMakeFSSpec( pb.ioFCBVRefNum, pb.ioFCBParID,
1301 fond_file_name, &spec );
1303 goto found_no_lwfn_file;
1305 err = FT_FSpMakePath( &spec, path_fond,
sizeof ( path_fond ) );
1307 goto found_no_lwfn_file;
1309 error = lookup_lwfn_by_fond( path_fond, lwfn_file_name,
1310 path_lwfn,
sizeof ( path_lwfn ) );
1320 error = FT_New_Face_From_LWFN( library,
1325 error = FT_Err_Unknown_File_Format;
1329 error = FT_New_Face_From_SFNT( library,
1340 FT_New_Face_From_Resource(
FT_Library library,
1341 const UInt8* pathname,
1350 file_type = get_file_type_from_path( pathname );
1352 return FT_New_Face_From_LWFN( library, pathname, face_index, aface );
1358 error = FT_New_Face_From_Suitcase( library, pathname, face_index, aface );
1382 const char* pathname,
1392 return FT_Err_Invalid_Argument;
1398 error = FT_New_Face_From_Resource( library, (UInt8 *)pathname,
1399 face_index, aface );
1400 if ( error != 0 || *aface !=
NULL )
1406 return FT_Open_Face( library, &args, face_index, aface );
1435 return FT_Err_Unimplemented_Feature;
1446 return FT_Err_Invalid_Argument;
1448 err = FSRefMakePath(
ref, pathname,
sizeof ( pathname ) );
1450 error = FT_Err_Cannot_Open_Resource;
1452 error = FT_New_Face_From_Resource( library, pathname, face_index, aface );
1453 if ( error != 0 || *aface !=
NULL )
1459 return FT_Open_Face( library, &args, face_index, aface );
1489 if ( !spec || FSpMakeFSRef( spec, &ref ) != noErr )
1490 return FT_Err_Invalid_Argument;
1503 return FT_Err_Invalid_Argument;
1505 err = FT_FSpMakePath( spec, pathname,
sizeof ( pathname ) );
1507 error = FT_Err_Cannot_Open_Resource;
1509 error = FT_New_Face_From_Resource( library, pathname, face_index, aface );
1510 if ( error != 0 || *aface !=
NULL )
1516 return FT_Open_Face( library, &args, face_index, aface );
1525 return FT_Err_Unimplemented_Feature;
#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
#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
#define FT_CALLBACK_DEF(x)
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
#define FT_MEM_COPY(dest, source, count)
#define FT_MEM_SET(dest, byte, count)
#define FT_MEM_MOVE(dest, source, count)
#define STREAM_FILE(stream)
FT_New_Face_From_FOND(FT_Library library, Handle fond, FT_Long face_index, FT_Face *aface) FT_DEPRECATED_ATTRIBUTE