📄 ftmac.c
字号:
sfnt_data[3] == 'O'; return open_face_from_buffer( library, sfnt_data, sfnt_size, face_index, is_cff ? "cff" : "truetype", aface ); } /* Create a new FT_Face from a file spec to a suitcase file. */ static FT_Error FT_New_Face_From_Suitcase( FT_Library library, short res_ref, FT_Long face_index, FT_Face *aface ) { FT_Error error = FT_Err_Ok; short res_index; Handle fond; short num_faces; UseResFile( res_ref ); for ( res_index = 1; ; ++res_index ) { fond = Get1IndResource( 'FOND', res_index ); if ( ResError() ) { error = FT_Err_Cannot_Open_Resource; goto Error; } if ( face_index < 0 ) break; num_faces = count_faces( fond ); if ( face_index < num_faces ) break; face_index -= num_faces; } error = FT_New_Face_From_FOND( library, fond, face_index, aface ); Error: CloseResFile( res_ref ); return error; } /* documentation is in ftmac.h */ 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; 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, face_index ); 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; } /* documentation is in ftmac.h */ FT_EXPORT_DEF( FT_Error ) FT_GetFile_From_Mac_Name( const char* fontName, FSSpec* pathSpec, FT_Long* face_index ) { OptionBits options = kFMUseGlobalScopeOption; FMFontFamilyIterator famIter; OSStatus status = FMCreateFontFamilyIterator( NULL, NULL, options, &famIter ); FMFont the_font = NULL; FMFontFamily family = NULL; *face_index = 0; while ( status == 0 && !the_font ) { status = FMGetNextFontFamily( &famIter, &family ); if ( status == 0 ) { int stat2; FMFontFamilyInstanceIterator instIter; Str255 famNameStr; char famName[256]; /* get the family name */ FMGetFontFamilyName( family, famNameStr ); CopyPascalStringToC( famNameStr, famName ); /* iterate through the styles */ FMCreateFontFamilyInstanceIterator( family, &instIter ); *face_index = 0; stat2 = 0; while ( stat2 == 0 && !the_font ) { FMFontStyle style; FMFontSize size; FMFont font; stat2 = FMGetNextFontFamilyInstance( &instIter, &font, &style, &size ); if ( stat2 == 0 && size == 0 ) { char fullName[256]; /* build up a complete face name */ ft_strcpy( fullName, famName ); if ( style & bold ) strcat( fullName, " Bold" ); if ( style & italic ) strcat( fullName, " Italic" ); /* compare with the name we are looking for */ if ( ft_strcmp( fullName, fontName ) == 0 ) { /* found it! */ the_font = font; } else ++(*face_index); } } FMDisposeFontFamilyInstanceIterator( &instIter ); } } FMDisposeFontFamilyIterator( &famIter ); if ( the_font ) { FMGetFontContainer( the_font, pathSpec ); return FT_Err_Ok; } else return FT_Err_Unknown_File_Format; } /* Common function to load a new FT_Face from a resource file. */ static FT_Error FT_New_Face_From_Resource( FT_Library library, const FSSpec *spec, FT_Long face_index, FT_Face *aface ) { OSType file_type; short res_ref; FT_Error error; if ( OpenFileAsResource( spec, &res_ref ) == FT_Err_Ok ) { /* LWFN is a (very) specific file format, check for it explicitly */ file_type = get_file_type( spec ); if ( file_type == 'LWFN' ) return FT_New_Face_From_LWFN( library, spec, 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, res_ref, face_index, aface ); if ( error == 0 ) return error; /* else forget about the resource fork and fall through to */ /* data fork formats */ CloseResFile( res_ref ); } /* 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; } /*************************************************************************/ /* */ /* <Function> */ /* FT_New_Face */ /* */ /* <Description> */ /* This is the Mac-specific implementation of FT_New_Face. In */ /* addition to the standard FT_New_Face() functionality, it also */ /* accepts pathnames to Mac suitcase files. For further */ /* documentation see the original FT_New_Face() in freetype.h. */ /* */ 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; FT_Error error; /* 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; error = FT_New_Face_From_Resource( library, &spec, face_index, aface ); if ( error != 0 || *aface != NULL ) return error; /* 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 ); } /*************************************************************************/ /* */ /* <Function> */ /* FT_New_Face_From_FSSpec */ /* */ /* <Description> */ /* FT_New_Face_From_FSSpec is identical to FT_New_Face except it */ /* accepts an FSSpec instead of a path. */ /* */ FT_EXPORT_DEF( FT_Error ) FT_New_Face_From_FSSpec( FT_Library library, const FSSpec *spec, FT_Long face_index, FT_Face *aface ) {#if defined( __MWERKS__ ) && !TARGET_RT_MAC_MACHO FT_Open_Args args; FT_Stream stream; FILE* file; FT_Memory memory;#endif FT_Error error; /* test for valid `library' and `aface' delayed to FT_Open_Face() */ if ( !spec ) return FT_Err_Invalid_Argument; error = FT_New_Face_From_Resource( library, spec, face_index, aface ); if ( error != 0 || *aface != NULL ) return error; /* let it fall through to normal loader (.ttf, .otf, etc.) */#if defined( __MWERKS__ ) && !TARGET_RT_MAC_MACHO /* Codewarrior's C library can open a FILE from a FSSpec */ /* but we must compile with FSp_fopen.c in addition to */ /* runtime libraries. */ memory = library->memory; if ( FT_NEW( stream ) ) return error; stream->memory = memory; file = FSp_fopen( spec, "rb" ); if ( !file ) return FT_Err_Cannot_Open_Resource; fseek( file, 0, SEEK_END ); stream->size = ftell( file ); fseek( file, 0, SEEK_SET ); stream->descriptor.pointer = file; stream->pathname.pointer = NULL; stream->pos = 0; stream->read = ft_FSp_stream_io; stream->close = ft_FSp_stream_close; args.flags = FT_OPEN_STREAM; args.stream = stream; error = FT_Open_Face( library, &args, face_index, aface ); if ( error == FT_Err_Ok ) (*aface)->face_flags &= ~FT_FACE_FLAG_EXTERNAL_STREAM;#else /* !(__MWERKS__ && !TARGET_RT_MAC_MACHO) */ { FSRef ref; UInt8 path[256]; OSErr err; err = FSpMakeFSRef(spec, &ref); if ( !err ) { err = FSRefMakePath( &ref, path, sizeof ( path ) ); if ( !err ) error = FT_New_Face( library, (const char*)path, face_index, aface ); } if ( err ) error = FT_Err_Cannot_Open_Resource; }#endif /* !(__MWERKS__ && !TARGET_RT_MAC_MACHO) */ return error; }/* END */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -