| OLD | NEW |
| 1 /***************************************************************************/ | 1 /***************************************************************************/ |
| 2 /* */ | 2 /* */ |
| 3 /* ftmac.c */ | 3 /* ftmac.c */ |
| 4 /* */ | 4 /* */ |
| 5 /* Mac FOND support. Written by just@letterror.com. */ | 5 /* Mac FOND support. Written by just@letterror.com. */ |
| 6 /* Heavily modified by mpsuzuki, George Williams, and Sean McBride. */ | 6 /* Heavily modified by mpsuzuki, George Williams, and Sean McBride. */ |
| 7 /* */ | 7 /* */ |
| 8 /* This file is for Mac OS X only; see builds/mac/ftoldmac.c for */ | 8 /* This file is for Mac OS X only; see builds/mac/ftoldmac.c for */ |
| 9 /* classic platforms built by MPW. */ | 9 /* classic platforms built by MPW. */ |
| 10 /* */ | 10 /* */ |
| 11 /* Copyright 1996-2009, 2013 by */ | 11 /* Copyright 1996-2009, 2013, 2014 by */ |
| 12 /* Just van Rossum, David Turner, Robert Wilhelm, and Werner Lemberg. */ | 12 /* Just van Rossum, David Turner, Robert Wilhelm, and Werner Lemberg. */ |
| 13 /* */ | 13 /* */ |
| 14 /* This file is part of the FreeType project, and may only be used, */ | 14 /* This file is part of the FreeType project, and may only be used, */ |
| 15 /* modified, and distributed under the terms of the FreeType project */ | 15 /* modified, and distributed under the terms of the FreeType project */ |
| 16 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ | 16 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ |
| 17 /* this file you indicate that you have read the license and */ | 17 /* this file you indicate that you have read the license and */ |
| 18 /* understand and accept it fully. */ | 18 /* understand and accept it fully. */ |
| 19 /* */ | 19 /* */ |
| 20 /***************************************************************************/ | 20 /***************************************************************************/ |
| 21 | 21 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 the rest of the work to it, by calling FT_Open_Face(). | 58 the rest of the work to it, by calling FT_Open_Face(). |
| 59 | 59 |
| 60 - Some suitcase fonts (notably Onyx) might point the `LWFN' file to | 60 - Some suitcase fonts (notably Onyx) might point the `LWFN' file to |
| 61 itself, even though it doesn't contains `POST' resources. To handle | 61 itself, even though it doesn't contains `POST' resources. To handle |
| 62 this special case without opening the file an extra time, we just | 62 this special case without opening the file an extra time, we just |
| 63 ignore errors from the `LWFN' and fallback to the `sfnt' if both are | 63 ignore errors from the `LWFN' and fallback to the `sfnt' if both are |
| 64 available. | 64 available. |
| 65 */ | 65 */ |
| 66 | 66 |
| 67 | 67 |
| 68 #include "../../include/ft2build.h" | 68 #include <ft2build.h> |
| 69 #include "../../include/freetype/freetype.h" | 69 #include FT_FREETYPE_H |
| 70 #include "../../include/freetype/tttags.h" | 70 #include FT_TRUETYPE_TAGS_H |
| 71 #include "../../include/freetype/internal/ftstream.h" | 71 #include FT_INTERNAL_STREAM_H |
| 72 #include "ftbase.h" | 72 #include "ftbase.h" |
| 73 | 73 |
| 74 /* This is for Mac OS X. Without redefinition, OS_INLINE */ | 74 /* This is for Mac OS X. Without redefinition, OS_INLINE */ |
| 75 /* expands to `static inline' which doesn't survive the */ | 75 /* expands to `static inline' which doesn't survive the */ |
| 76 /* -ansi compilation flag of GCC. */ | 76 /* -ansi compilation flag of GCC. */ |
| 77 #if !HAVE_ANSI_OS_INLINE | 77 #if !HAVE_ANSI_OS_INLINE |
| 78 #undef OS_INLINE | 78 #undef OS_INLINE |
| 79 #define OS_INLINE static __inline__ | 79 #define OS_INLINE static __inline__ |
| 80 #endif | 80 #endif |
| 81 | 81 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 96 typedef short ResourceIndex; | 96 typedef short ResourceIndex; |
| 97 #endif | 97 #endif |
| 98 | 98 |
| 99 #include <CoreServices/CoreServices.h> | 99 #include <CoreServices/CoreServices.h> |
| 100 #include <ApplicationServices/ApplicationServices.h> | 100 #include <ApplicationServices/ApplicationServices.h> |
| 101 #include <sys/syslimits.h> /* PATH_MAX */ | 101 #include <sys/syslimits.h> /* PATH_MAX */ |
| 102 | 102 |
| 103 /* Don't want warnings about our own use of deprecated functions. */ | 103 /* Don't want warnings about our own use of deprecated functions. */ |
| 104 #define FT_DEPRECATED_ATTRIBUTE | 104 #define FT_DEPRECATED_ATTRIBUTE |
| 105 | 105 |
| 106 #include "../../include/freetype/ftmac.h" | 106 #include FT_MAC_H |
| 107 | 107 |
| 108 #ifndef kATSOptionFlagsUnRestrictedScope /* since Mac OS X 10.1 */ | 108 #ifndef kATSOptionFlagsUnRestrictedScope /* since Mac OS X 10.1 */ |
| 109 #define kATSOptionFlagsUnRestrictedScope kATSOptionFlagsDefault | 109 #define kATSOptionFlagsUnRestrictedScope kATSOptionFlagsDefault |
| 110 #endif | 110 #endif |
| 111 | 111 |
| 112 | 112 |
| 113 /* Set PREFER_LWFN to 1 if LWFN (Type 1) is preferred over | 113 /* Set PREFER_LWFN to 1 if LWFN (Type 1) is preferred over |
| 114 TrueType in case *both* are available (this is not common, | 114 TrueType in case *both* are available (this is not common, |
| 115 but it *is* possible). */ | 115 but it *is* possible). */ |
| 116 #ifndef PREFER_LWFN | 116 #ifndef PREFER_LWFN |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 FT_EXPORT_DEF( FT_Error ) | 220 FT_EXPORT_DEF( FT_Error ) |
| 221 FT_GetFilePath_From_Mac_ATS_Name( const char* fontName, | 221 FT_GetFilePath_From_Mac_ATS_Name( const char* fontName, |
| 222 UInt8* path, | 222 UInt8* path, |
| 223 UInt32 maxPathSize, | 223 UInt32 maxPathSize, |
| 224 FT_Long* face_index ) | 224 FT_Long* face_index ) |
| 225 { | 225 { |
| 226 FSRef ref; | 226 FSRef ref; |
| 227 FT_Error err; | 227 FT_Error err; |
| 228 | 228 |
| 229 | 229 |
| 230 if ( !fontName || !face_index ) |
| 231 return FT_THROW( Invalid_Argument) ; |
| 232 |
| 230 err = FT_GetFileRef_From_Mac_ATS_Name( fontName, &ref, face_index ); | 233 err = FT_GetFileRef_From_Mac_ATS_Name( fontName, &ref, face_index ); |
| 231 if ( err ) | 234 if ( err ) |
| 232 return err; | 235 return err; |
| 233 | 236 |
| 234 if ( noErr != FSRefMakePath( &ref, path, maxPathSize ) ) | 237 if ( noErr != FSRefMakePath( &ref, path, maxPathSize ) ) |
| 235 return FT_THROW( Unknown_File_Format ); | 238 return FT_THROW( Unknown_File_Format ); |
| 236 | 239 |
| 237 return FT_Err_Ok; | 240 return FT_Err_Ok; |
| 238 } | 241 } |
| 239 | 242 |
| 240 | 243 |
| 241 /* This function is deprecated because FSSpec is deprecated in Mac OS X */ | 244 /* This function is deprecated because FSSpec is deprecated in Mac OS X */ |
| 242 FT_EXPORT_DEF( FT_Error ) | 245 FT_EXPORT_DEF( FT_Error ) |
| 243 FT_GetFile_From_Mac_ATS_Name( const char* fontName, | 246 FT_GetFile_From_Mac_ATS_Name( const char* fontName, |
| 244 FSSpec* pathSpec, | 247 FSSpec* pathSpec, |
| 245 FT_Long* face_index ) | 248 FT_Long* face_index ) |
| 246 { | 249 { |
| 247 #if ( __LP64__ ) || ( defined( MAC_OS_X_VERSION_10_5 ) && \ | 250 #if ( __LP64__ ) || ( defined( MAC_OS_X_VERSION_10_5 ) && \ |
| 248 ( MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 ) ) | 251 ( MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 ) ) |
| 249 FT_UNUSED( fontName ); | 252 FT_UNUSED( fontName ); |
| 250 FT_UNUSED( pathSpec ); | 253 FT_UNUSED( pathSpec ); |
| 251 FT_UNUSED( face_index ); | 254 FT_UNUSED( face_index ); |
| 252 | 255 |
| 253 return FT_THROW( Unimplemented_Feature ); | 256 return FT_THROW( Unimplemented_Feature ); |
| 254 #else | 257 #else |
| 255 FSRef ref; | 258 FSRef ref; |
| 256 FT_Error err; | 259 FT_Error err; |
| 257 | 260 |
| 258 | 261 |
| 262 if ( !fontName || !face_index ) |
| 263 return FT_THROW( Invalid_Argument ); |
| 264 |
| 259 err = FT_GetFileRef_From_Mac_ATS_Name( fontName, &ref, face_index ); | 265 err = FT_GetFileRef_From_Mac_ATS_Name( fontName, &ref, face_index ); |
| 260 if ( err ) | 266 if ( err ) |
| 261 return err; | 267 return err; |
| 262 | 268 |
| 263 if ( noErr != FSGetCatalogInfo( &ref, kFSCatInfoNone, NULL, NULL, | 269 if ( noErr != FSGetCatalogInfo( &ref, kFSCatInfoNone, NULL, NULL, |
| 264 pathSpec, NULL ) ) | 270 pathSpec, NULL ) ) |
| 265 return FT_THROW( Unknown_File_Format ); | 271 return FT_THROW( Unknown_File_Format ); |
| 266 | 272 |
| 267 return FT_Err_Ok; | 273 return FT_Err_Ok; |
| 268 #endif | 274 #endif |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 unsigned short string_count; | 439 unsigned short string_count; |
| 434 char ps_name[256]; | 440 char ps_name[256]; |
| 435 unsigned char* names[64]; | 441 unsigned char* names[64]; |
| 436 int i; | 442 int i; |
| 437 | 443 |
| 438 | 444 |
| 439 p += EndianS32_BtoN( fond->ffStylOff ); | 445 p += EndianS32_BtoN( fond->ffStylOff ); |
| 440 style = (StyleTable*)p; | 446 style = (StyleTable*)p; |
| 441 p += sizeof ( StyleTable ); | 447 p += sizeof ( StyleTable ); |
| 442 string_count = EndianS16_BtoN( *(short*)(p) ); | 448 string_count = EndianS16_BtoN( *(short*)(p) ); |
| 449 string_count = FT_MIN( 64, string_count ); |
| 443 p += sizeof ( short ); | 450 p += sizeof ( short ); |
| 444 | 451 |
| 445 for ( i = 0; i < string_count && i < 64; i++ ) | 452 for ( i = 0; i < string_count; i++ ) |
| 446 { | 453 { |
| 447 names[i] = p; | 454 names[i] = p; |
| 448 p += names[i][0]; | 455 p += names[i][0]; |
| 449 p++; | 456 p++; |
| 450 } | 457 } |
| 451 | 458 |
| 452 { | 459 { |
| 453 size_t ps_name_len = (size_t)names[0][0]; | 460 size_t ps_name_len = (size_t)names[0][0]; |
| 454 | 461 |
| 455 | 462 |
| 456 if ( ps_name_len != 0 ) | 463 if ( ps_name_len != 0 ) |
| 457 { | 464 { |
| 458 ft_memcpy(ps_name, names[0] + 1, ps_name_len); | 465 ft_memcpy(ps_name, names[0] + 1, ps_name_len); |
| 459 ps_name[ps_name_len] = 0; | 466 ps_name[ps_name_len] = 0; |
| 460 } | 467 } |
| 461 if ( style->indexes[face_index] > 1 && | 468 if ( style->indexes[face_index] > 1 && |
| 462 style->indexes[face_index] <= FT_MIN( string_count, 64 ) ) | 469 style->indexes[face_index] <= string_count ) |
| 463 { | 470 { |
| 464 unsigned char* suffixes = names[style->indexes[face_index] - 1]; | 471 unsigned char* suffixes = names[style->indexes[face_index] - 1]; |
| 465 | 472 |
| 466 | 473 |
| 467 for ( i = 1; i <= suffixes[0]; i++ ) | 474 for ( i = 1; i <= suffixes[0]; i++ ) |
| 468 { | 475 { |
| 469 unsigned char* s; | 476 unsigned char* s; |
| 470 size_t j = suffixes[i] - 1; | 477 size_t j = suffixes[i] - 1; |
| 471 | 478 |
| 472 | 479 |
| (...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 845 short have_sfnt, have_lwfn = 0; | 852 short have_sfnt, have_lwfn = 0; |
| 846 ResID sfnt_id, fond_id; | 853 ResID sfnt_id, fond_id; |
| 847 OSType fond_type; | 854 OSType fond_type; |
| 848 Str255 fond_name; | 855 Str255 fond_name; |
| 849 Str255 lwfn_file_name; | 856 Str255 lwfn_file_name; |
| 850 UInt8 path_lwfn[PATH_MAX]; | 857 UInt8 path_lwfn[PATH_MAX]; |
| 851 OSErr err; | 858 OSErr err; |
| 852 FT_Error error = FT_Err_Ok; | 859 FT_Error error = FT_Err_Ok; |
| 853 | 860 |
| 854 | 861 |
| 862 /* check of `library' and `aface' delayed to `FT_New_Face_From_XXX' */ |
| 863 |
| 855 GetResInfo( fond, &fond_id, &fond_type, fond_name ); | 864 GetResInfo( fond, &fond_id, &fond_type, fond_name ); |
| 856 if ( ResError() != noErr || fond_type != TTAG_FOND ) | 865 if ( ResError() != noErr || fond_type != TTAG_FOND ) |
| 857 return FT_THROW( Invalid_File_Format ); | 866 return FT_THROW( Invalid_File_Format ); |
| 858 | 867 |
| 859 parse_fond( *fond, &have_sfnt, &sfnt_id, lwfn_file_name, face_index ); | 868 parse_fond( *fond, &have_sfnt, &sfnt_id, lwfn_file_name, face_index ); |
| 860 | 869 |
| 861 if ( lwfn_file_name[0] ) | 870 if ( lwfn_file_name[0] ) |
| 862 { | 871 { |
| 863 ResFileRefNum res; | 872 ResFileRefNum res; |
| 864 | 873 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 956 FT_Face* aface ) | 965 FT_Face* aface ) |
| 957 { | 966 { |
| 958 FT_Open_Args args; | 967 FT_Open_Args args; |
| 959 FT_Error error; | 968 FT_Error error; |
| 960 | 969 |
| 961 | 970 |
| 962 /* test for valid `library' and `aface' delayed to FT_Open_Face() */ | 971 /* test for valid `library' and `aface' delayed to FT_Open_Face() */ |
| 963 if ( !pathname ) | 972 if ( !pathname ) |
| 964 return FT_THROW( Invalid_Argument ); | 973 return FT_THROW( Invalid_Argument ); |
| 965 | 974 |
| 966 error = FT_Err_Ok; | |
| 967 *aface = NULL; | 975 *aface = NULL; |
| 968 | 976 |
| 969 /* try resourcefork based font: LWFN, FFIL */ | 977 /* try resourcefork based font: LWFN, FFIL */ |
| 970 error = FT_New_Face_From_Resource( library, (UInt8 *)pathname, | 978 error = FT_New_Face_From_Resource( library, (UInt8 *)pathname, |
| 971 face_index, aface ); | 979 face_index, aface ); |
| 972 if ( error != 0 || *aface != NULL ) | 980 if ( error != 0 || *aface != NULL ) |
| 973 return error; | 981 return error; |
| 974 | 982 |
| 975 /* let it fall through to normal loader (.ttf, .otf, etc.) */ | 983 /* let it fall through to normal loader (.ttf, .otf, etc.) */ |
| 976 args.flags = FT_OPEN_PATHNAME; | 984 args.flags = FT_OPEN_PATHNAME; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 991 /* This function is deprecated because Carbon data types (FSRef) */ | 999 /* This function is deprecated because Carbon data types (FSRef) */ |
| 992 /* are not cross-platform, and thus not suitable for the freetype API. */ | 1000 /* are not cross-platform, and thus not suitable for the freetype API. */ |
| 993 FT_EXPORT_DEF( FT_Error ) | 1001 FT_EXPORT_DEF( FT_Error ) |
| 994 FT_New_Face_From_FSRef( FT_Library library, | 1002 FT_New_Face_From_FSRef( FT_Library library, |
| 995 const FSRef* ref, | 1003 const FSRef* ref, |
| 996 FT_Long face_index, | 1004 FT_Long face_index, |
| 997 FT_Face* aface ) | 1005 FT_Face* aface ) |
| 998 { | 1006 { |
| 999 FT_Error error; | 1007 FT_Error error; |
| 1000 FT_Open_Args args; | 1008 FT_Open_Args args; |
| 1001 OSErr err; | |
| 1002 UInt8 pathname[PATH_MAX]; | |
| 1003 | 1009 |
| 1010 OSErr err; |
| 1011 UInt8 pathname[PATH_MAX]; |
| 1012 |
| 1013 |
| 1014 /* check of `library' and `aface' delayed to */ |
| 1015 /* `FT_New_Face_From_Resource' */ |
| 1004 | 1016 |
| 1005 if ( !ref ) | 1017 if ( !ref ) |
| 1006 return FT_THROW( Invalid_Argument ); | 1018 return FT_THROW( Invalid_Argument ); |
| 1007 | 1019 |
| 1008 err = FSRefMakePath( ref, pathname, sizeof ( pathname ) ); | 1020 err = FSRefMakePath( ref, pathname, sizeof ( pathname ) ); |
| 1009 if ( err ) | 1021 if ( err ) |
| 1010 error = FT_THROW( Cannot_Open_Resource ); | 1022 error = FT_THROW( Cannot_Open_Resource ); |
| 1011 | 1023 |
| 1012 error = FT_New_Face_From_Resource( library, pathname, face_index, aface ); | 1024 error = FT_New_Face_From_Resource( library, pathname, face_index, aface ); |
| 1013 if ( error != 0 || *aface != NULL ) | 1025 if ( error != 0 || *aface != NULL ) |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1041 FT_UNUSED( library ); | 1053 FT_UNUSED( library ); |
| 1042 FT_UNUSED( spec ); | 1054 FT_UNUSED( spec ); |
| 1043 FT_UNUSED( face_index ); | 1055 FT_UNUSED( face_index ); |
| 1044 FT_UNUSED( aface ); | 1056 FT_UNUSED( aface ); |
| 1045 | 1057 |
| 1046 return FT_THROW( Unimplemented_Feature ); | 1058 return FT_THROW( Unimplemented_Feature ); |
| 1047 #else | 1059 #else |
| 1048 FSRef ref; | 1060 FSRef ref; |
| 1049 | 1061 |
| 1050 | 1062 |
| 1063 /* check of `library' and `aface' delayed to `FT_New_Face_From_FSRef' */ |
| 1064 |
| 1051 if ( !spec || FSpMakeFSRef( spec, &ref ) != noErr ) | 1065 if ( !spec || FSpMakeFSRef( spec, &ref ) != noErr ) |
| 1052 return FT_THROW( Invalid_Argument ); | 1066 return FT_THROW( Invalid_Argument ); |
| 1053 else | 1067 else |
| 1054 return FT_New_Face_From_FSRef( library, &ref, face_index, aface ); | 1068 return FT_New_Face_From_FSRef( library, &ref, face_index, aface ); |
| 1055 #endif | 1069 #endif |
| 1056 } | 1070 } |
| 1057 | 1071 |
| 1058 #endif /* FT_MACINTOSH */ | 1072 #endif /* FT_MACINTOSH */ |
| 1059 | 1073 |
| 1060 | 1074 |
| 1061 /* END */ | 1075 /* END */ |
| OLD | NEW |