static short count_faces( Handle fond, const UInt8* pathname ) { ResID sfnt_id; short have_sfnt, have_lwfn; Str255 lwfn_file_name; UInt8 buff[PATH_MAX]; FT_Error err; short num_faces; have_sfnt = have_lwfn = 0; parse_fond( *fond, &have_sfnt, &sfnt_id, lwfn_file_name, 0 ); if ( lwfn_file_name[0] ) { err = lookup_lwfn_by_fond( pathname, lwfn_file_name, buff, sizeof ( buff ) ); if ( FT_Err_Ok == err ) have_lwfn = 1; } if ( have_lwfn && ( !have_sfnt || PREFER_LWFN ) ) num_faces = 1; else num_faces = count_faces_scalable( *fond ); return num_faces; }
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; }
int gp_enumerate_fonts_next(void *enum_state, char **fontname, char **path) { fontenum_t *state = (fontenum_t *)enum_state; FMFontIterator *Iterator = &state->Iterator; FMFont Font; FourCharCode Format; FMFontFamily FontFamily; FMFontStyle Style; FSSpec FontContainer; char type[5]; char fontpath[256]; char *psname; fond_table *table = NULL; OSStatus result; result = FMGetNextFont(Iterator, &Font); if (result != noErr) return 0; /* no more fonts */ result = FMGetFontFormat(Font, &Format); type[0] = ((char*)&Format)[0]; type[1] = ((char*)&Format)[1]; type[2] = ((char*)&Format)[2]; type[3] = ((char*)&Format)[3]; type[4] = '\0'; FMGetFontFamilyInstanceFromFont(Font, &FontFamily, &Style); if (state->name) free (state->name); psname = makePSFontName(FontFamily, Style); if (psname == NULL) { state->name = strdup("GSPlaceHolder"); } else { state->name = psname; } result = FMGetFontContainer(Font, &FontContainer); if (!memcmp(&FontContainer, &state->last_container, sizeof(FSSpec))) { /* we have cached data on this file */ strncpy(fontpath, state->last_container_path, 256); table = state->last_table; } else { convertSpecToPath(&FontContainer, fontpath, 256); if (!is_ttf_file(fontpath) && !is_otf_file(fontpath)) table = parse_fond(&FontContainer); /* cache data on the new font file */ memcpy(&state->last_container, &FontContainer, sizeof(FSSpec)); if (state->last_container_path) free (state->last_container_path); state->last_container_path = strdup(fontpath); if (state->last_table) fond_table_free(state->last_table); state->last_table = table; } if (state->path) { free(state->path); state->path = NULL; } if (table != NULL) { int i; for (i = 0; i < table->entries; i++) { if (table->refs[i].size == 0) { /* ignore non-scalable fonts */ if (table->refs[i].style == Style) { int len = strlen(fontpath) + strlen("%macresource%#sfnt+") + 6; state->path = malloc(len); snprintf(state->path, len, "%%macresource%%%s#sfnt+%d", fontpath, table->refs[i].id); break; } } } } else { /* regular font file */ state->path = strdup(fontpath); } if (state->path == NULL) { /* no matching font was found in the FOND resource table. this usually */ /* means an LWFN file, which we don't handle yet. */ /* we still specify these with a %macresource% path, but no res id */ /* TODO: check file type */ int len = strlen(fontpath) + strlen("%macresource%#POST") + 1; state->path = malloc(len); snprintf(state->path, len, "%%macresource%%%s#POST", fontpath); } #ifdef DEBUG dlprintf2("fontenum: returning '%s' in '%s'\n", state->name, state->path); #endif *fontname = state->name; *path = state->path; state->count += 1; return 1; }