/* Common function to load a new FT_Face from a resource file. */ static FT_Error FT_New_Face_From_Resource( FT_Library library, const UInt8* pathname, FT_Long face_index, FT_Face* aface ) { OSType file_type; FT_Error error; /* LWFN is a (very) specific file format, check for it explicitly */ file_type = get_file_type_from_path( pathname ); if ( file_type == TTAG_LWFN ) return FT_New_Face_From_LWFN( library, pathname, face_index, aface ); /* Otherwise the file type doesn't matter (there are more than */ /* `FFIL' and `tfil'). Just try opening it as a font suitcase; */ /* if it works, fine. */ error = FT_New_Face_From_Suitcase( library, pathname, face_index, aface ); if ( error == 0 ) return error; /* let it fall through to normal loader (.ttf, .otf, etc.); */ /* we signal this by returning no error and no FT_Face */ *aface = NULL; return 0; }
FT_EXPORT_DEF( FT_Error ) FT_New_Face( FT_Library library, const char* pathname, FT_Long face_index, FT_Face *aface ) { FT_Open_Args args; FSSpec spec; OSType file_type; /* test for valid `library' and `aface' delayed to FT_Open_Face() */ if ( !pathname ) return FT_Err_Invalid_Argument; if ( file_spec_from_path( pathname, &spec ) ) return FT_Err_Invalid_Argument; file_type = get_file_type( &spec ); if ( file_type == 'FFIL' || file_type == 'tfil' ) return FT_New_Face_From_Suitcase( library, &spec, face_index, aface ); else if ( file_type == 'LWFN' ) return FT_New_Face_From_LWFN( library, &spec, face_index, aface ); else { args.flags = ft_open_pathname; args.pathname = (char*)pathname; return FT_Open_Face( library, &args, face_index, aface ); } }
FT_New_Face( FT_Library library, const char* pathname, FT_Long face_index, FT_Face *aface ) { FT_Open_Args args; FSSpec spec; OSType file_type; /* test for valid `library' and `aface' delayed to FT_Open_Face() */ if ( !pathname ) return FT_Err_Invalid_Argument; if ( file_spec_from_path( pathname, &spec ) ) return FT_Err_Invalid_Argument; /* Regardless of type, don't try to use the resource fork if it is */ /* empty. Some TTF fonts have type `FFIL', for example, but they */ /* only have data forks. */ if ( ResourceForkSize( &spec ) != 0 ) { file_type = get_file_type( &spec ); if ( file_type == 'FFIL' || file_type == 'tfil' ) return FT_New_Face_From_Suitcase( library, &spec, face_index, aface ); if ( file_type == 'LWFN' ) return FT_New_Face_From_LWFN( library, &spec, face_index, aface ); } #if TARGET_API_MAC_CARBON if ( is_dfont( &spec ) ) return FT_New_Face_From_dfont( library, &spec, face_index, aface ); #endif /* let it fall through to normal loader (.ttf, .otf, etc.) */ args.flags = ft_open_pathname; args.pathname = (char*)pathname; return FT_Open_Face( library, &args, face_index, aface ); }
FT_EXPORT_DEF( FT_Error ) FT_New_Face_From_FOND( FT_Library library, Handle fond, FT_Long face_index, FT_Face *aface ) { short sfnt_id, have_sfnt, have_lwfn = 0; Str255 lwfn_file_name; short fond_id; OSType fond_type; Str255 fond_name; FSSpec lwfn_spec; FT_Error error = FT_Err_Unknown_File_Format; GetResInfo(fond, &fond_id, &fond_type, fond_name); if ( ResError() != noErr || fond_type != 'FOND' ) return FT_Err_Invalid_File_Format; HLock( fond ); parse_fond( *fond, &have_sfnt, &sfnt_id, lwfn_file_name ); HUnlock( fond ); if ( lwfn_file_name[0] ) { if ( make_lwfn_spec( fond, lwfn_file_name, &lwfn_spec ) == FT_Err_Ok ) have_lwfn = 1; /* yeah, we got one! */ else have_lwfn = 0; /* no LWFN file found */ } if ( have_lwfn && ( !have_sfnt || PREFER_LWFN ) ) return FT_New_Face_From_LWFN( library, &lwfn_spec, face_index, aface ); else if ( have_sfnt ) return FT_New_Face_From_SFNT( library, sfnt_id, face_index, aface ); return FT_Err_Unknown_File_Format; }
FT_New_Face_From_FOND( FT_Library library, Handle fond, FT_Long face_index, FT_Face* aface ) { short have_sfnt, have_lwfn = 0; ResID sfnt_id, fond_id; OSType fond_type; Str255 fond_name; Str255 lwfn_file_name; UInt8 path_lwfn[PATH_MAX]; OSErr err; FT_Error error = FT_Err_Ok; GetResInfo( fond, &fond_id, &fond_type, fond_name ); if ( ResError() != noErr || fond_type != TTAG_FOND ) return FT_Err_Invalid_File_Format; parse_fond( *fond, &have_sfnt, &sfnt_id, lwfn_file_name, face_index ); if ( lwfn_file_name[0] ) { ResFileRefNum res; res = HomeResFile( fond ); if ( noErr != ResError() ) goto found_no_lwfn_file; { UInt8 path_fond[PATH_MAX]; FSRef ref; err = FSGetForkCBInfo( res, kFSInvalidVolumeRefNum, NULL, NULL, NULL, &ref, NULL ); if ( noErr != err ) goto found_no_lwfn_file; err = FSRefMakePath( &ref, path_fond, sizeof ( path_fond ) ); if ( noErr != err ) goto found_no_lwfn_file; error = lookup_lwfn_by_fond( path_fond, lwfn_file_name, path_lwfn, sizeof ( path_lwfn ) ); if ( FT_Err_Ok == error ) have_lwfn = 1; } } if ( have_lwfn && ( !have_sfnt || PREFER_LWFN ) ) error = FT_New_Face_From_LWFN( library, path_lwfn, face_index, aface ); else error = FT_Err_Unknown_File_Format; found_no_lwfn_file: if ( have_sfnt && FT_Err_Ok != error ) error = FT_New_Face_From_SFNT( library, sfnt_id, face_index, aface ); return error; }
FT_New_Face_From_FOND( FT_Library library, Handle fond, FT_Long face_index, FT_Face* aface ) { short have_sfnt, have_lwfn = 0; ResID sfnt_id, fond_id; OSType fond_type; Str255 fond_name; Str255 lwfn_file_name; UInt8 path_lwfn[PATH_MAX]; OSErr err; FT_Error error = FT_Err_Ok; /* test for valid `aface' and `library' delayed to */ /* `FT_New_Face_From_XXX' */ GetResInfo( fond, &fond_id, &fond_type, fond_name ); if ( ResError() != noErr || fond_type != TTAG_FOND ) return FT_THROW( Invalid_File_Format ); HLock( fond ); parse_fond( *fond, &have_sfnt, &sfnt_id, lwfn_file_name, face_index ); HUnlock( fond ); if ( lwfn_file_name[0] ) { ResFileRefNum res; res = HomeResFile( fond ); if ( noErr != ResError() ) goto found_no_lwfn_file; #if HAVE_FSREF { UInt8 path_fond[PATH_MAX]; FSRef ref; err = FSGetForkCBInfo( res, kFSInvalidVolumeRefNum, NULL, NULL, NULL, &ref, NULL ); if ( noErr != err ) goto found_no_lwfn_file; err = FSRefMakePath( &ref, path_fond, sizeof ( path_fond ) ); if ( noErr != err ) goto found_no_lwfn_file; error = lookup_lwfn_by_fond( path_fond, lwfn_file_name, path_lwfn, sizeof ( path_lwfn ) ); if ( !error ) have_lwfn = 1; } #elif HAVE_FSSPEC { UInt8 path_fond[PATH_MAX]; FCBPBRec pb; Str255 fond_file_name; FSSpec spec; FT_MEM_SET( &spec, 0, sizeof ( FSSpec ) ); FT_MEM_SET( &pb, 0, sizeof ( FCBPBRec ) ); pb.ioNamePtr = fond_file_name; pb.ioVRefNum = 0; pb.ioRefNum = res; pb.ioFCBIndx = 0; err = PBGetFCBInfoSync( &pb ); if ( noErr != err ) goto found_no_lwfn_file; err = FSMakeFSSpec( pb.ioFCBVRefNum, pb.ioFCBParID, fond_file_name, &spec ); if ( noErr != err ) goto found_no_lwfn_file; err = FT_FSpMakePath( &spec, path_fond, sizeof ( path_fond ) ); if ( noErr != err ) goto found_no_lwfn_file; error = lookup_lwfn_by_fond( path_fond, lwfn_file_name, path_lwfn, sizeof ( path_lwfn ) ); if ( !error ) have_lwfn = 1; } #endif /* HAVE_FSREF, HAVE_FSSPEC */ } if ( have_lwfn && ( !have_sfnt || PREFER_LWFN ) ) error = FT_New_Face_From_LWFN( library, path_lwfn, face_index, aface ); else error = FT_ERR( Unknown_File_Format ); found_no_lwfn_file: if ( have_sfnt && error ) error = FT_New_Face_From_SFNT( library, sfnt_id, face_index, aface ); return error; }