From 4827e9bd2c8a4c47fcfc5ed81f25a0a8c06e73d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Suzuki=2C=20Toshiya=20=28=E9=88=B4=E6=9C=A8=E4=BF=8A?= =?UTF-8?q?=E5=93=89=29?= Date: Mon, 5 Feb 2007 03:28:29 +0000 Subject: [PATCH] * Add FT_GetFilePath_From_Mac_ATS_Name as replacement for FT_GetFile_From_Mac_ATS_Name --- ChangeLog | 9 +++ builds/mac/ftmac.c | 128 +++++++++++++++++++++++++++++++-------- include/freetype/ftmac.h | 31 ++++++++++ src/base/ftmac.c | 100 ++++++++++++++++++++++++------ 4 files changed, 227 insertions(+), 41 deletions(-) diff --git a/ChangeLog b/ChangeLog index a2d2e93b..8d02b701 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2007-02-05 suzuki toshiya + + * include/freetype/ftmac.h (FT_GetFilePath_From_Mac_ATS_Name): + Introduced as replacement of FT_GetFile_From_Mac_ATS_Name. + * src/base/ftmac.c (FT_GetFilePath_From_Mac_ATS_Name): Ditto. + (FT_GetFile_From_Mac_ATS_Name): Rewritten as wrapper of + FT_GetFilePath_From_Mac_ATS_Name. + * builds/mac/ftmac.c: Ditto. + 2007-02-05 suzuki toshiya * include/freetype/ftmac.h: Fixed wrong comment, FSSpec of diff --git a/builds/mac/ftmac.c b/builds/mac/ftmac.c index 59e99929..484784cf 100644 --- a/builds/mac/ftmac.c +++ b/builds/mac/ftmac.c @@ -243,22 +243,34 @@ #endif /* HAVE_QUICKDRAW_CARBON */ -#if !HAVE_ATS +#if HAVE_ATS - FT_EXPORT_DEF( FT_Error ) - FT_GetFile_From_Mac_ATS_Name( const char* fontName, - FSSpec* pathSpec, - FT_Long* face_index ) + /* Private function. */ + /* The FSSpec type has been discouraged for a long time, */ + /* but for some reason, there is no FSRef version of */ + /* ATSFontGetFileSpecification(), so we made our own. */ + /* Apple will provide one eventually. */ + static OSStatus + FT_ATSFontGetFileReference( ATSFontRef ats_font_id, + FSRef* ats_font_ref ) { - return FT_Err_Unimplemented_Feature; + OSStatus err; + FSSpec spec; + + err = ATSFontGetFileSpecification( ats_font_id, &spec ); + if ( noErr == err ) + { + err = FSpMakeFSRef( &spec, ats_font_ref ); + } + + return err; } -#else - FT_EXPORT_DEF( FT_Error ) - FT_GetFile_From_Mac_ATS_Name( const char* fontName, - FSSpec* pathSpec, - FT_Long* face_index ) + static FT_Error + FT_GetFileRef_From_Mac_ATS_Name( const char* fontName, + FSRef* ats_font_ref, + FT_Long* face_index ) { CFStringRef cf_fontName; ATSFontRef ats_font_id; @@ -274,36 +286,104 @@ if ( ats_font_id == 0 || ats_font_id == 0xFFFFFFFFUL ) return FT_Err_Unknown_File_Format; - if ( 0 != ATSFontGetFileSpecification( ats_font_id, pathSpec ) ) + if ( noErr != FT_ATSFontGetFileReference( ats_font_id, ats_font_ref ) ) return FT_Err_Unknown_File_Format; /* face_index calculation by searching preceding fontIDs */ /* with same FSRef */ { - int i; - FSSpec f; + ATSFontRef id2 = ats_font_id - 1; + FSRef ref2; - for ( i = 1; i < ats_font_id; i++ ) + while ( id2 > 0 ) { - if ( 0 != ATSFontGetFileSpecification( ats_font_id - i, - &f ) || - f.vRefNum != pathSpec->vRefNum || - f.parID != pathSpec->parID || - f.name[0] != pathSpec->name[0] || - 0 != ft_strncmp( (char *)f.name + 1, - (char *)pathSpec->name + 1, - f.name[0] ) ) + if ( noErr != FT_ATSFontGetFileReference( id2, &ref2 ) ) break; + if ( noErr != FSCompareFSRefs( ats_font_ref, &ref2 ) ) + break; + + id2 --; } - *face_index = ( i - 1 ); + *face_index = ats_font_id - ( id2 + 1 ); } + + return FT_Err_Ok; + } + +#endif + +#if !HAVE_ATS + + FT_EXPORT_DEF( FT_Error ) + FT_GetFilePath_From_Mac_ATS_Name( const char* fontName, + UInt8* path, + UInt32 maxPathSize, + FT_Long* face_index ) + { + return FT_Err_Unimplemented_Feature; + } + +#else + + FT_EXPORT_DEF( FT_Error ) + FT_GetFilePath_From_Mac_ATS_Name( const char* fontName, + UInt8* path, + UInt32 maxPathSize, + FT_Long* face_index ) + { + FSRef ref; + FT_Error err; + + + err = FT_GetFileRef_From_Mac_ATS_Name( fontName, &ref, face_index ); + if ( FT_Err_Ok != err ) + return err; + + if ( noErr != FSRefMakePath( &ref, path, maxPathSize ) ) + return FT_Err_Unknown_File_Format; + return FT_Err_Ok; } #endif /* HAVE_ATS */ +#if !HAVE_FSSPEC + + FT_EXPORT_DEF( FT_Error ) + FT_GetFile_From_Mac_ATS_Name( const char* fontName, + FSSpec* pathSpec, + FT_Long* face_index ) + { + return FT_Err_Unimplemented_Feature; + } + +#else + + /* This function is deprecated because FSSpec is deprecated in Mac OS X */ + FT_EXPORT_DEF( FT_Error ) + FT_GetFile_From_Mac_ATS_Name( const char* fontName, + FSSpec* pathSpec, + FT_Long* face_index ) + { + FSRef ref; + FT_Error err; + + err = FT_GetFileRef_From_Mac_ATS_Name( fontName, &ref, face_index ); + if ( FT_Err_Ok != err ) + return err; + + if ( noErr != FSGetCatalogInfo( &ref, kFSCatInfoNone, NULL, NULL, + pathSpec, NULL ) ) + return FT_Err_Unknown_File_Format; + + return FT_Err_Ok; + } + +#endif + + #if defined( __MWERKS__ ) && !TARGET_RT_MAC_MACHO #define STREAM_FILE( stream ) ( (FT_FILE*)stream->descriptor.pointer ) diff --git a/include/freetype/ftmac.h b/include/freetype/ftmac.h index 3b472aa7..4529fe2b 100644 --- a/include/freetype/ftmac.h +++ b/include/freetype/ftmac.h @@ -147,6 +147,37 @@ FT_BEGIN_HEADER FT_Long* face_index ); + /*************************************************************************/ + /* */ + /* */ + /* FT_GetFilePath_From_Mac_ATS_Name */ + /* */ + /* */ + /* Return a pathname of the disk file and face index for given font */ + /* name which is handled by ATS framework. */ + /* */ + /* */ + /* fontName :: Mac OS name of the font in ATS framework. */ + /* */ + /* */ + /* path :: Buffer to store pathname of the file. For passing */ + /* to @FT_New_Face. The client must allocate this */ + /* buffer before calling this function. */ + /* */ + /* maxPathSize :: Lengths of the buffer `path' that client allocated. */ + /* */ + /* face_index :: Index of the face. For passing to @FT_New_Face. */ + /* */ + /* */ + /* FreeType error code. 0 means success. */ + /* */ + FT_EXPORT( FT_Error ) + FT_GetFilePath_From_Mac_ATS_Name( const char* fontName, + UInt8* path, + UInt32 maxPathSize, + FT_Long* face_index ); + + /*************************************************************************/ /* */ /* */ diff --git a/src/base/ftmac.c b/src/base/ftmac.c index 07a2dc7f..c8d06b00 100644 --- a/src/base/ftmac.c +++ b/src/base/ftmac.c @@ -108,10 +108,32 @@ } - FT_EXPORT_DEF( FT_Error ) - FT_GetFile_From_Mac_ATS_Name( const char* fontName, - FSSpec* pathSpec, - FT_Long* face_index ) + /* Private function. */ + /* The FSSpec type has been discouraged for a long time, */ + /* but for some reason, there is no FSRef version of */ + /* ATSFontGetFileSpecification(), so we made our own. */ + /* Apple will provide one eventually. */ + static OSStatus + FT_ATSFontGetFileReference( ATSFontRef ats_font_id, + FSRef* ats_font_ref ) + { + OSStatus err; + FSSpec spec; + + err = ATSFontGetFileSpecification( ats_font_id, &spec ); + if ( noErr == err ) + { + err = FSpMakeFSRef( &spec, ats_font_ref ); + } + + return err; + } + + + static FT_Error + FT_GetFileRef_From_Mac_ATS_Name( const char* fontName, + FSRef* ats_font_ref, + FT_Long* face_index ) { CFStringRef cf_fontName; ATSFontRef ats_font_id; @@ -127,34 +149,78 @@ if ( ats_font_id == 0 || ats_font_id == 0xFFFFFFFFUL ) return FT_Err_Unknown_File_Format; - if ( 0 != ATSFontGetFileSpecification( ats_font_id, pathSpec ) ) + if ( noErr != FT_ATSFontGetFileReference( ats_font_id, ats_font_ref ) ) return FT_Err_Unknown_File_Format; /* face_index calculation by searching preceding fontIDs */ /* with same FSRef */ { - int i; - FSSpec f; + ATSFontRef id2 = ats_font_id - 1; + FSRef ref2; - for ( i = 1; i < ats_font_id; i++ ) + while ( id2 > 0 ) { - if ( 0 != ATSFontGetFileSpecification( ats_font_id - i, - &f ) || - f.vRefNum != pathSpec->vRefNum || - f.parID != pathSpec->parID || - f.name[0] != pathSpec->name[0] || - 0 != ft_strncmp( (char *)f.name + 1, - (char *)pathSpec->name + 1, - f.name[0] ) ) + if ( noErr != FT_ATSFontGetFileReference( id2, &ref2 ) ) break; + if ( noErr != FSCompareFSRefs( ats_font_ref, &ref2 ) ) + break; + + id2 --; } - *face_index = ( i - 1 ); + *face_index = ats_font_id - ( id2 + 1 ); } + return FT_Err_Ok; } + FT_EXPORT_DEF( FT_Error ) + FT_GetFilePath_From_Mac_ATS_Name( const char* fontName, + UInt8* path, + UInt32 maxPathSize, + FT_Long* face_index ) + { + FSRef ref; + FT_Error err; + + + err = FT_GetFileRef_From_Mac_ATS_Name( fontName, &ref, face_index ); + if ( FT_Err_Ok != err ) + return err; + + if ( noErr != FSRefMakePath( &ref, path, maxPathSize ) ) + return FT_Err_Unknown_File_Format; + + return FT_Err_Ok; + } + + + /* This function is deprecated because FSSpec is deprecated in Mac OS X */ + FT_EXPORT_DEF( FT_Error ) + FT_GetFile_From_Mac_ATS_Name( const char* fontName, + FSSpec* pathSpec, + FT_Long* face_index ) + { +#if __LP64__ + return FT_Err_Unimplemented_Feature; +#else + FSRef ref; + FT_Error err; + + err = FT_GetFileRef_From_Mac_ATS_Name( fontName, &ref, face_index ); + if ( FT_Err_Ok != err ) + return err; + + if ( noErr != FSGetCatalogInfo( &ref, kFSCatInfoNone, NULL, NULL, + pathSpec, NULL ) ) + return FT_Err_Unknown_File_Format; + + return FT_Err_Ok; +#endif + } + + static OSErr FT_FSPathMakeRes( const UInt8* pathname, short* res )