1 /***************************************************************************/ 2 /* */ 3 /* ftmac.c */ 4 /* */ 5 /* Mac FOND support. Written by just@letterror.com. */ 6 /* Heavily modified by mpsuzuki, George Williams, and Sean McBride. */ 7 /* */ 8 /* This file is for Mac OS X only; see builds/mac/ftoldmac.c for */ 9 /* classic platforms built by MPW. */ 10 /* */ 11 /* Copyright 1996-2018 by */ 12 /* Just van Rossum, David Turner, Robert Wilhelm, and Werner Lemberg. */ 13 /* */ 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 */ 16 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ 17 /* this file you indicate that you have read the license and */ 18 /* understand and accept it fully. */ 19 /* */ 20 /***************************************************************************/ 21 22 23 /* 24 Notes 25 26 Mac suitcase files can (and often do!) contain multiple fonts. To 27 support this I use the face_index argument of FT_(Open|New)_Face() 28 functions, and pretend the suitcase file is a collection. 29 30 Warning: fbit and NFNT bitmap resources are not supported yet. In old 31 sfnt fonts, bitmap glyph data for each size is stored in each `NFNT' 32 resources instead of the `bdat' table in the sfnt resource. Therefore, 33 face->num_fixed_sizes is set to 0, because bitmap data in `NFNT' 34 resource is unavailable at present. 35 36 The Mac FOND support works roughly like this: 37 38 - Check whether the offered stream points to a Mac suitcase file. This 39 is done by checking the file type: it has to be 'FFIL' or 'tfil'. The 40 stream that gets passed to our init_face() routine is a stdio stream, 937 file_type = get_file_type_from_path( pathname ); 938 if ( file_type == TTAG_LWFN ) 939 return FT_New_Face_From_LWFN( library, pathname, face_index, aface ); 940 941 /* Otherwise the file type doesn't matter (there are more than */ 942 /* `FFIL' and `tfil'). Just try opening it as a font suitcase; */ 943 /* if it works, fine. */ 944 945 error = FT_New_Face_From_Suitcase( library, pathname, face_index, aface ); 946 if ( error ) 947 { 948 /* let it fall through to normal loader (.ttf, .otf, etc.); */ 949 /* we signal this by returning no error and no FT_Face */ 950 *aface = NULL; 951 } 952 953 return FT_Err_Ok; 954 } 955 956 957 /*************************************************************************/ 958 /* */ 959 /* <Function> */ 960 /* FT_New_Face */ 961 /* */ 962 /* <Description> */ 963 /* This is the Mac-specific implementation of FT_New_Face. In */ 964 /* addition to the standard FT_New_Face() functionality, it also */ 965 /* accepts pathnames to Mac suitcase files. For further */ 966 /* documentation see the original FT_New_Face() in freetype.h. */ 967 /* */ 968 FT_EXPORT_DEF( FT_Error ) 969 FT_New_Face( FT_Library library, 970 const char* pathname, 971 FT_Long face_index, 972 FT_Face* aface ) 973 { 974 FT_Open_Args args; 975 FT_Error error; 976 977 978 /* test for valid `library' and `aface' delayed to FT_Open_Face() */ 979 if ( !pathname ) 980 return FT_THROW( Invalid_Argument ); 981 982 *aface = NULL; 983 984 /* try resourcefork based font: LWFN, FFIL */ 985 error = FT_New_Face_From_Resource( library, (UInt8 *)pathname, 986 face_index, aface ); 987 if ( error || *aface ) 988 return error; 989 990 /* let it fall through to normal loader (.ttf, .otf, etc.) */ 991 args.flags = FT_OPEN_PATHNAME; 992 args.pathname = (char*)pathname; 993 994 return FT_Open_Face( library, &args, face_index, aface ); 995 } 996 997 998 /*************************************************************************/ 999 /* */ 1000 /* <Function> */ 1001 /* FT_New_Face_From_FSRef */ 1002 /* */ 1003 /* <Description> */ 1004 /* FT_New_Face_From_FSRef is identical to FT_New_Face except it */ 1005 /* accepts an FSRef instead of a path. */ 1006 /* */ 1007 /* This function is deprecated because Carbon data types (FSRef) */ 1008 /* are not cross-platform, and thus not suitable for the FreeType API. */ 1009 FT_EXPORT_DEF( FT_Error ) 1010 FT_New_Face_From_FSRef( FT_Library library, 1011 const FSRef* ref, 1012 FT_Long face_index, 1013 FT_Face* aface ) 1014 { 1015 FT_Error error; 1016 FT_Open_Args args; 1017 1018 OSErr err; 1019 UInt8 pathname[PATH_MAX]; 1020 1021 1022 /* check of `library' and `aface' delayed to */ 1023 /* `FT_New_Face_From_Resource' */ 1024 1025 if ( !ref ) 1026 return FT_THROW( Invalid_Argument ); 1027 1028 err = FSRefMakePath( ref, pathname, sizeof ( pathname ) ); 1029 if ( err ) 1030 error = FT_THROW( Cannot_Open_Resource ); 1031 1032 error = FT_New_Face_From_Resource( library, pathname, face_index, aface ); 1033 if ( error || *aface ) 1034 return error; 1035 1036 /* fallback to datafork font */ 1037 args.flags = FT_OPEN_PATHNAME; 1038 args.pathname = (char*)pathname; 1039 return FT_Open_Face( library, &args, face_index, aface ); 1040 } 1041 1042 1043 /*************************************************************************/ 1044 /* */ 1045 /* <Function> */ 1046 /* FT_New_Face_From_FSSpec */ 1047 /* */ 1048 /* <Description> */ 1049 /* FT_New_Face_From_FSSpec is identical to FT_New_Face except it */ 1050 /* accepts an FSSpec instead of a path. */ 1051 /* */ 1052 /* This function is deprecated because FSSpec is deprecated in Mac OS X */ 1053 FT_EXPORT_DEF( FT_Error ) 1054 FT_New_Face_From_FSSpec( FT_Library library, 1055 const FSSpec* spec, 1056 FT_Long face_index, 1057 FT_Face* aface ) 1058 { 1059 #if ( __LP64__ ) || ( defined( MAC_OS_X_VERSION_10_5 ) && \ 1060 ( MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 ) ) 1061 FT_UNUSED( library ); 1062 FT_UNUSED( spec ); 1063 FT_UNUSED( face_index ); 1064 FT_UNUSED( aface ); 1065 1066 return FT_THROW( Unimplemented_Feature ); 1067 #else 1068 FSRef ref; 1069 1070 1071 /* check of `library' and `aface' delayed to `FT_New_Face_From_FSRef' */ 1072 | 1 /**************************************************************************** 2 * 3 * ftmac.c 4 * 5 * Mac FOND support. Written by just@letterror.com. 6 * Heavily modified by mpsuzuki, George Williams, and Sean McBride. 7 * 8 * This file is for Mac OS X only; see builds/mac/ftoldmac.c for 9 * classic platforms built by MPW. 10 * 11 * Copyright (C) 1996-2019 by 12 * Just van Rossum, David Turner, Robert Wilhelm, and Werner Lemberg. 13 * 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 16 * license, LICENSE.TXT. By continuing to use, modify, or distribute 17 * this file you indicate that you have read the license and 18 * understand and accept it fully. 19 * 20 */ 21 22 23 /* 24 Notes 25 26 Mac suitcase files can (and often do!) contain multiple fonts. To 27 support this I use the face_index argument of FT_(Open|New)_Face() 28 functions, and pretend the suitcase file is a collection. 29 30 Warning: fbit and NFNT bitmap resources are not supported yet. In old 31 sfnt fonts, bitmap glyph data for each size is stored in each `NFNT' 32 resources instead of the `bdat' table in the sfnt resource. Therefore, 33 face->num_fixed_sizes is set to 0, because bitmap data in `NFNT' 34 resource is unavailable at present. 35 36 The Mac FOND support works roughly like this: 37 38 - Check whether the offered stream points to a Mac suitcase file. This 39 is done by checking the file type: it has to be 'FFIL' or 'tfil'. The 40 stream that gets passed to our init_face() routine is a stdio stream, 937 file_type = get_file_type_from_path( pathname ); 938 if ( file_type == TTAG_LWFN ) 939 return FT_New_Face_From_LWFN( library, pathname, face_index, aface ); 940 941 /* Otherwise the file type doesn't matter (there are more than */ 942 /* `FFIL' and `tfil'). Just try opening it as a font suitcase; */ 943 /* if it works, fine. */ 944 945 error = FT_New_Face_From_Suitcase( library, pathname, face_index, aface ); 946 if ( error ) 947 { 948 /* let it fall through to normal loader (.ttf, .otf, etc.); */ 949 /* we signal this by returning no error and no FT_Face */ 950 *aface = NULL; 951 } 952 953 return FT_Err_Ok; 954 } 955 956 957 /************************************************************************** 958 * 959 * @Function: 960 * FT_New_Face 961 * 962 * @Description: 963 * This is the Mac-specific implementation of FT_New_Face. In 964 * addition to the standard FT_New_Face() functionality, it also 965 * accepts pathnames to Mac suitcase files. For further 966 * documentation see the original FT_New_Face() in freetype.h. 967 */ 968 FT_EXPORT_DEF( FT_Error ) 969 FT_New_Face( FT_Library library, 970 const char* pathname, 971 FT_Long face_index, 972 FT_Face* aface ) 973 { 974 FT_Open_Args args; 975 FT_Error error; 976 977 978 /* test for valid `library' and `aface' delayed to FT_Open_Face() */ 979 if ( !pathname ) 980 return FT_THROW( Invalid_Argument ); 981 982 *aface = NULL; 983 984 /* try resourcefork based font: LWFN, FFIL */ 985 error = FT_New_Face_From_Resource( library, (UInt8 *)pathname, 986 face_index, aface ); 987 if ( error || *aface ) 988 return error; 989 990 /* let it fall through to normal loader (.ttf, .otf, etc.) */ 991 args.flags = FT_OPEN_PATHNAME; 992 args.pathname = (char*)pathname; 993 994 return FT_Open_Face( library, &args, face_index, aface ); 995 } 996 997 998 /************************************************************************** 999 * 1000 * @Function: 1001 * FT_New_Face_From_FSRef 1002 * 1003 * @Description: 1004 * FT_New_Face_From_FSRef is identical to FT_New_Face except it 1005 * accepts an FSRef instead of a path. 1006 * 1007 * This function is deprecated because Carbon data types (FSRef) 1008 * are not cross-platform, and thus not suitable for the FreeType API. 1009 */ 1010 FT_EXPORT_DEF( FT_Error ) 1011 FT_New_Face_From_FSRef( FT_Library library, 1012 const FSRef* ref, 1013 FT_Long face_index, 1014 FT_Face* aface ) 1015 { 1016 FT_Error error; 1017 FT_Open_Args args; 1018 1019 OSErr err; 1020 UInt8 pathname[PATH_MAX]; 1021 1022 1023 /* check of `library' and `aface' delayed to */ 1024 /* `FT_New_Face_From_Resource' */ 1025 1026 if ( !ref ) 1027 return FT_THROW( Invalid_Argument ); 1028 1029 err = FSRefMakePath( ref, pathname, sizeof ( pathname ) ); 1030 if ( err ) 1031 error = FT_THROW( Cannot_Open_Resource ); 1032 1033 error = FT_New_Face_From_Resource( library, pathname, face_index, aface ); 1034 if ( error || *aface ) 1035 return error; 1036 1037 /* fallback to datafork font */ 1038 args.flags = FT_OPEN_PATHNAME; 1039 args.pathname = (char*)pathname; 1040 return FT_Open_Face( library, &args, face_index, aface ); 1041 } 1042 1043 1044 /************************************************************************** 1045 * 1046 * @Function: 1047 * FT_New_Face_From_FSSpec 1048 * 1049 * @Description: 1050 * FT_New_Face_From_FSSpec is identical to FT_New_Face except it 1051 * accepts an FSSpec instead of a path. 1052 * 1053 * This function is deprecated because FSSpec is deprecated in Mac OS X 1054 */ 1055 FT_EXPORT_DEF( FT_Error ) 1056 FT_New_Face_From_FSSpec( FT_Library library, 1057 const FSSpec* spec, 1058 FT_Long face_index, 1059 FT_Face* aface ) 1060 { 1061 #if ( __LP64__ ) || ( defined( MAC_OS_X_VERSION_10_5 ) && \ 1062 ( MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 ) ) 1063 FT_UNUSED( library ); 1064 FT_UNUSED( spec ); 1065 FT_UNUSED( face_index ); 1066 FT_UNUSED( aface ); 1067 1068 return FT_THROW( Unimplemented_Feature ); 1069 #else 1070 FSRef ref; 1071 1072 1073 /* check of `library' and `aface' delayed to `FT_New_Face_From_FSRef' */ 1074 |