1 /***************************************************************************/
5 /* Mac FOND support. Written by just@letterror.com. */
6 /* Heavily modified by mpsuzuki, George Williams, and Sean McBride. */
8 /* This file is for Mac OS X only; see builds/mac/ftoldmac.c for */
9 /* classic platforms built by MPW. */
11 /* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007 by */
12 /* Just van Rossum, David Turner, Robert Wilhelm, and Werner Lemberg. */
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. */
20 /***************************************************************************/
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.
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.
36 The Mac FOND support works roughly like this:
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,
41 which isn't usable for us, since the FOND resources live in the
42 resource fork. So we just grab the stream->pathname field.
44 - Read the FOND resource into memory, then check whether there is a
45 TrueType font and/or(!) a Type 1 font available.
47 - If there is a Type 1 font available (as a separate `LWFN' file), read
48 its data into memory, massage it slightly so it becomes PFB data, wrap
49 it into a memory stream, load the Type 1 driver and delegate the rest
50 of the work to it by calling FT_Open_Face(). (XXX TODO: after this
51 has been done, the kerning data from the FOND resource should be
52 appended to the face: On the Mac there are usually no AFM files
53 available. However, this is tricky since we need to map Mac char
54 codes to ps glyph names to glyph ID's...)
56 - If there is a TrueType font (an `sfnt' resource), read it into memory,
57 wrap it into a memory stream, load the TrueType driver and delegate
58 the rest of the work to it, by calling FT_Open_Face().
60 - Some suitcase fonts (notably Onyx) might point the `LWFN' file to
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
63 ignore errors from the `LWFN' and fallback to the `sfnt' if both are
69 #include FT_FREETYPE_H
70 #include FT_INTERNAL_STREAM_H
72 /* This is for Mac OS X. Without redefinition, OS_INLINE */
73 /* expands to `static inline' which doesn't survive the */
74 /* -ansi compilation flag of GCC. */
75 #if !HAVE_ANSI_OS_INLINE
77 #define OS_INLINE static __inline__
79 #include <Carbon/Carbon.h>
81 #ifndef HFS_MAXPATHLEN
82 #define HFS_MAXPATHLEN 1024
85 #define FT_DEPRECATED_ATTRIBUTE
89 /* undefine blocking-macros in ftmac.h */
90 #undef FT_GetFile_From_Mac_Name( a, b, c )
91 #undef FT_GetFile_From_Mac_ATS_Name( a, b, c )
92 #undef FT_New_Face_From_FSSpec( a, b, c, d )
95 /* Set PREFER_LWFN to 1 if LWFN (Type 1) is preferred over
96 TrueType in case *both* are available (this is not common,
97 but it *is* possible). */
103 FT_EXPORT_DEF( FT_Error
)
104 FT_GetFile_From_Mac_Name( const char* fontName
,
106 FT_Long
* face_index
)
108 FT_UNUSED( fontName
);
109 FT_UNUSED( pathSpec
);
110 FT_UNUSED( face_index
);
112 return FT_Err_Unimplemented_Feature
;
116 /* Private function. */
117 /* The FSSpec type has been discouraged for a long time, */
118 /* but for some reason, there is no FSRef version of */
119 /* ATSFontGetFileSpecification(), so we made our own. */
120 /* Apple will provide one eventually. */
122 FT_ATSFontGetFileReference( ATSFontRef ats_font_id
,
123 FSRef
* ats_font_ref
)
126 FT_UNUSED( ats_font_id
);
127 FT_UNUSED( ats_font_ref
);
135 err
= ATSFontGetFileSpecification( ats_font_id
, &spec
);
137 err
= FSpMakeFSRef( &spec
, ats_font_ref
);
145 FT_GetFileRef_From_Mac_ATS_Name( const char* fontName
,
147 FT_Long
* face_index
)
149 CFStringRef cf_fontName
;
150 ATSFontRef ats_font_id
;
155 cf_fontName
= CFStringCreateWithCString( NULL
, fontName
,
156 kCFStringEncodingMacRoman
);
157 ats_font_id
= ATSFontFindFromName( cf_fontName
,
158 kATSOptionFlagsUnRestrictedScope
);
159 CFRelease( cf_fontName
);
161 if ( ats_font_id
== 0 || ats_font_id
== 0xFFFFFFFFUL
)
162 return FT_Err_Unknown_File_Format
;
164 if ( noErr
!= FT_ATSFontGetFileReference( ats_font_id
, ats_font_ref
) )
165 return FT_Err_Unknown_File_Format
;
167 /* face_index calculation by searching preceding fontIDs */
168 /* with same FSRef */
170 ATSFontRef id2
= ats_font_id
- 1;
176 if ( noErr
!= FT_ATSFontGetFileReference( id2
, &ref2
) )
178 if ( noErr
!= FSCompareFSRefs( ats_font_ref
, &ref2
) )
183 *face_index
= ats_font_id
- ( id2
+ 1 );
190 FT_EXPORT_DEF( FT_Error
)
191 FT_GetFilePath_From_Mac_ATS_Name( const char* fontName
,
194 FT_Long
* face_index
)
200 err
= FT_GetFileRef_From_Mac_ATS_Name( fontName
, &ref
, face_index
);
201 if ( FT_Err_Ok
!= err
)
204 if ( noErr
!= FSRefMakePath( &ref
, path
, maxPathSize
) )
205 return FT_Err_Unknown_File_Format
;
211 /* This function is deprecated because FSSpec is deprecated in Mac OS X */
212 FT_EXPORT_DEF( FT_Error
)
213 FT_GetFile_From_Mac_ATS_Name( const char* fontName
,
215 FT_Long
* face_index
)
218 FT_UNUSED( fontName
);
219 FT_UNUSED( pathSpec
);
220 FT_UNUSED( face_index
);
222 return FT_Err_Unimplemented_Feature
;
228 err
= FT_GetFileRef_From_Mac_ATS_Name( fontName
, &ref
, face_index
);
229 if ( FT_Err_Ok
!= err
)
232 if ( noErr
!= FSGetCatalogInfo( &ref
, kFSCatInfoNone
, NULL
, NULL
,
234 return FT_Err_Unknown_File_Format
;
242 FT_FSPathMakeRes( const UInt8
* pathname
,
249 if ( noErr
!= FSPathMakeRef( pathname
, &ref
, FALSE
) )
250 return FT_Err_Cannot_Open_Resource
;
252 /* at present, no support for dfont format */
253 err
= FSOpenResourceFile( &ref
, 0, NULL
, fsRdPerm
, res
);
257 /* fallback to original resource-fork font */
258 *res
= FSOpenResFile( &ref
, fsRdPerm
);
265 /* Return the file type for given pathname */
267 get_file_type_from_path( const UInt8
* pathname
)
273 if ( noErr
!= FSPathMakeRef( pathname
, &ref
, FALSE
) )
276 if ( noErr
!= FSGetCatalogInfo( &ref
, kFSCatInfoFinderInfo
, &info
,
280 return ((FInfo
*)(info
.finderInfo
))->fdType
;
284 /* Given a PostScript font name, create the Macintosh LWFN file name. */
286 create_lwfn_name( char* ps_name
,
287 Str255 lwfn_file_name
)
289 int max
= 5, count
= 0;
290 FT_Byte
* p
= lwfn_file_name
;
291 FT_Byte
* q
= (FT_Byte
*)ps_name
;
294 lwfn_file_name
[0] = 0;
298 if ( ft_isupper( *q
) )
304 if ( count
< max
&& ( ft_isalnum( *q
) || *q
== '_' ) )
316 count_faces_sfnt( char* fond_data
)
318 /* The count is 1 greater than the value in the FOND. */
319 /* Isn't that cute? :-) */
321 return EndianS16_BtoN( *( (short*)( fond_data
+
322 sizeof ( FamRec
) ) ) ) + 1;
327 count_faces_scalable( char* fond_data
)
331 short i
, face
, face_all
;
334 fond
= (FamRec
*)fond_data
;
335 face_all
= EndianS16_BtoN( *( (short *)( fond_data
+
336 sizeof ( FamRec
) ) ) ) + 1;
337 assoc
= (AsscEntry
*)( fond_data
+ sizeof ( FamRec
) + 2 );
340 for ( i
= 0; i
< face_all
; i
++ )
342 if ( 0 == EndianS16_BtoN( assoc
[i
].fontSize
) )
349 /* Look inside the FOND data, answer whether there should be an SFNT
350 resource, and answer the name of a possible LWFN Type 1 file.
352 Thanks to Paul Miller (paulm@profoundeffects.com) for the fix
353 to load a face OTHER than the first one in the FOND!
358 parse_fond( char* fond_data
,
361 Str255 lwfn_file_name
,
365 AsscEntry
* base_assoc
;
371 lwfn_file_name
[0] = 0;
373 fond
= (FamRec
*)fond_data
;
374 assoc
= (AsscEntry
*)( fond_data
+ sizeof ( FamRec
) + 2 );
377 /* Let's do a little range checking before we get too excited here */
378 if ( face_index
< count_faces_sfnt( fond_data
) )
380 assoc
+= face_index
; /* add on the face_index! */
382 /* if the face at this index is not scalable,
383 fall back to the first one (old behavior) */
384 if ( EndianS16_BtoN( assoc
->fontSize
) == 0 )
387 *sfnt_id
= EndianS16_BtoN( assoc
->fontID
);
389 else if ( base_assoc
->fontSize
== 0 )
392 *sfnt_id
= EndianS16_BtoN( base_assoc
->fontID
);
396 if ( EndianS32_BtoN( fond
->ffStylOff
) )
398 unsigned char* p
= (unsigned char*)fond_data
;
400 unsigned short string_count
;
402 unsigned char* names
[64];
406 p
+= EndianS32_BtoN( fond
->ffStylOff
);
407 style
= (StyleTable
*)p
;
408 p
+= sizeof ( StyleTable
);
409 string_count
= EndianS16_BtoN( *(short*)(p
) );
410 p
+= sizeof ( short );
412 for ( i
= 0; i
< string_count
&& i
< 64; i
++ )
420 size_t ps_name_len
= (size_t)names
[0][0];
423 if ( ps_name_len
!= 0 )
425 ft_memcpy(ps_name
, names
[0] + 1, ps_name_len
);
426 ps_name
[ps_name_len
] = 0;
428 if ( style
->indexes
[0] > 1 )
430 unsigned char* suffixes
= names
[style
->indexes
[0] - 1];
433 for ( i
= 1; i
<= suffixes
[0]; i
++ )
436 size_t j
= suffixes
[i
] - 1;
439 if ( j
< string_count
&& ( s
= names
[j
] ) != NULL
)
441 size_t s_len
= (size_t)s
[0];
444 if ( s_len
!= 0 && ps_name_len
+ s_len
< sizeof ( ps_name
) )
446 ft_memcpy( ps_name
+ ps_name_len
, s
+ 1, s_len
);
447 ps_name_len
+= s_len
;
448 ps_name
[ps_name_len
] = 0;
455 create_lwfn_name( ps_name
, lwfn_file_name
);
461 lookup_lwfn_by_fond( const UInt8
* path_fond
,
462 ConstStr255Param base_lwfn
,
470 /* Pathname for FSRef can be in various formats: HFS, HFS+, and POSIX. */
471 /* We should not extract parent directory by string manipulation. */
473 if ( noErr
!= FSPathMakeRef( path_fond
, &ref
, FALSE
) )
474 return FT_Err_Invalid_Argument
;
476 if ( noErr
!= FSGetCatalogInfo( &ref
, kFSCatInfoNone
,
477 NULL
, NULL
, NULL
, &par_ref
) )
478 return FT_Err_Invalid_Argument
;
480 if ( noErr
!= FSRefMakePath( &par_ref
, path_lwfn
, path_size
) )
481 return FT_Err_Invalid_Argument
;
483 if ( ft_strlen( (char *)path_lwfn
) + 1 + base_lwfn
[0] > path_size
)
484 return FT_Err_Invalid_Argument
;
486 /* now we have absolute dirname in path_lwfn */
487 ft_strcat( (char *)path_lwfn
, "/" );
488 dirname_len
= ft_strlen( (char *)path_lwfn
);
489 ft_strcat( (char *)path_lwfn
, (char *)base_lwfn
+ 1 );
490 path_lwfn
[dirname_len
+ base_lwfn
[0]] = '\0';
492 if ( noErr
!= FSPathMakeRef( path_lwfn
, &ref
, FALSE
) )
493 return FT_Err_Cannot_Open_Resource
;
495 if ( noErr
!= FSGetCatalogInfo( &ref
, kFSCatInfoNone
,
496 NULL
, NULL
, NULL
, NULL
) )
497 return FT_Err_Cannot_Open_Resource
;
504 count_faces( Handle fond
,
505 const UInt8
* pathname
)
508 short have_sfnt
, have_lwfn
;
509 Str255 lwfn_file_name
;
510 UInt8 buff
[HFS_MAXPATHLEN
];
515 have_sfnt
= have_lwfn
= 0;
517 parse_fond( *fond
, &have_sfnt
, &sfnt_id
, lwfn_file_name
, 0 );
519 if ( lwfn_file_name
[0] )
521 err
= lookup_lwfn_by_fond( pathname
, lwfn_file_name
,
522 buff
, sizeof ( buff
) );
523 if ( FT_Err_Ok
== err
)
527 if ( have_lwfn
&& ( !have_sfnt
|| PREFER_LWFN
) )
530 num_faces
= count_faces_scalable( *fond
);
536 /* Read Type 1 data from the POST resources inside the LWFN file,
537 return a PFB buffer. This is somewhat convoluted because the FT2
538 PFB parser wants the ASCII header as one chunk, and the LWFN
539 chunks are often not organized that way, so we glue chunks
540 of the same type together. */
542 read_lwfn( FT_Memory memory
,
547 FT_Error error
= FT_Err_Ok
;
549 unsigned char *buffer
, *p
, *size_p
= NULL
;
550 FT_ULong total_size
= 0;
551 FT_ULong old_total_size
= 0;
552 FT_ULong post_size
, pfb_chunk_size
;
554 char code
, last_code
;
559 /* First pass: load all POST resources, and determine the size of */
560 /* the output buffer. */
566 post_data
= Get1Resource( 'POST', res_id
++ );
567 if ( post_data
== NULL
)
568 break; /* we are done */
570 code
= (*post_data
)[0];
572 if ( code
!= last_code
)
575 total_size
+= 2; /* just the end code */
577 total_size
+= 6; /* code + 4 bytes chunk length */
580 total_size
+= GetHandleSize( post_data
) - 2;
583 /* detect integer overflows */
584 if ( total_size
< old_total_size
)
586 error
= FT_Err_Array_Too_Large
;
590 old_total_size
= total_size
;
593 if ( FT_ALLOC( buffer
, (FT_Long
)total_size
) )
596 /* Second pass: append all POST data to the buffer, add PFB fields. */
597 /* Glue all consecutive chunks of the same type together. */
605 post_data
= Get1Resource( 'POST', res_id
++ );
606 if ( post_data
== NULL
)
607 break; /* we are done */
609 post_size
= (FT_ULong
)GetHandleSize( post_data
) - 2;
610 code
= (*post_data
)[0];
612 if ( code
!= last_code
)
614 if ( last_code
!= -1 )
616 /* we are done adding a chunk, fill in the size field */
617 if ( size_p
!= NULL
)
619 *size_p
++ = (FT_Byte
)( pfb_chunk_size
& 0xFF );
620 *size_p
++ = (FT_Byte
)( ( pfb_chunk_size
>> 8 ) & 0xFF );
621 *size_p
++ = (FT_Byte
)( ( pfb_chunk_size
>> 16 ) & 0xFF );
622 *size_p
++ = (FT_Byte
)( ( pfb_chunk_size
>> 24 ) & 0xFF );
629 *p
++ = 0x03; /* the end */
630 else if ( code
== 2 )
631 *p
++ = 0x02; /* binary segment */
633 *p
++ = 0x01; /* ASCII segment */
637 size_p
= p
; /* save for later */
638 p
+= 4; /* make space for size field */
642 ft_memcpy( p
, *post_data
+ 2, post_size
);
643 pfb_chunk_size
+= post_size
;
657 /* Finalizer for a memory stream; gets called by FT_Done_Face().
658 It frees the memory it uses. */
660 memory_stream_close( FT_Stream stream
)
662 FT_Memory memory
= stream
->memory
;
665 FT_FREE( stream
->base
);
673 /* Create a new memory stream from a buffer and a size. */
675 new_memory_stream( FT_Library library
,
678 FT_Stream_CloseFunc close
,
687 return FT_Err_Invalid_Library_Handle
;
690 return FT_Err_Invalid_Argument
;
693 memory
= library
->memory
;
694 if ( FT_NEW( stream
) )
697 FT_Stream_OpenMemory( stream
, base
, size
);
699 stream
->close
= close
;
708 /* Create a new FT_Face given a buffer and a driver name. */
710 open_face_from_buffer( FT_Library library
,
720 FT_Memory memory
= library
->memory
;
723 error
= new_memory_stream( library
,
734 args
.flags
= FT_OPEN_STREAM
;
735 args
.stream
= stream
;
738 args
.flags
= args
.flags
| FT_OPEN_DRIVER
;
739 args
.driver
= FT_Get_Module( library
, driver_name
);
742 /* At this point, face_index has served its purpose; */
743 /* whoever calls this function has already used it to */
744 /* locate the correct font data. We should not propagate */
745 /* this index to FT_Open_Face() (unless it is negative). */
747 if ( face_index
> 0 )
750 error
= FT_Open_Face( library
, &args
, face_index
, aface
);
751 if ( error
== FT_Err_Ok
)
752 (*aface
)->face_flags
&= ~FT_FACE_FLAG_EXTERNAL_STREAM
;
754 FT_Stream_Free( stream
, 0 );
760 /* Create a new FT_Face from a file spec to an LWFN file. */
762 FT_New_Face_From_LWFN( FT_Library library
,
763 const UInt8
* pathname
,
773 if ( noErr
!= FT_FSPathMakeRes( pathname
, &res
) )
774 return FT_Err_Cannot_Open_Resource
;
778 error
= read_lwfn( library
->memory
, res
, &pfb_data
, &pfb_size
);
779 CloseResFile( res
); /* PFB is already loaded, useless anymore */
783 return open_face_from_buffer( library
,
792 /* Create a new FT_Face from an SFNT resource, specified by res ID. */
794 FT_New_Face_From_SFNT( FT_Library library
,
802 FT_Error error
= FT_Err_Ok
;
803 FT_Memory memory
= library
->memory
;
807 sfnt
= GetResource( 'sfnt', sfnt_id
);
809 return FT_Err_Invalid_Handle
;
811 sfnt_size
= (FT_ULong
)GetHandleSize( sfnt
);
812 if ( FT_ALLOC( sfnt_data
, (FT_Long
)sfnt_size
) )
814 ReleaseResource( sfnt
);
818 ft_memcpy( sfnt_data
, *sfnt
, sfnt_size
);
819 ReleaseResource( sfnt
);
821 is_cff
= sfnt_size
> 4 && sfnt_data
[0] == 'O' &&
822 sfnt_data
[1] == 'T' &&
823 sfnt_data
[2] == 'T' &&
826 return open_face_from_buffer( library
,
830 is_cff
? "cff" : "truetype",
835 /* Create a new FT_Face from a file spec to a suitcase file. */
837 FT_New_Face_From_Suitcase( FT_Library library
,
838 const UInt8
* pathname
,
842 FT_Error error
= FT_Err_Cannot_Open_Resource
;
843 short res_ref
, res_index
;
845 short num_faces_in_res
, num_faces_in_fond
;
848 if ( noErr
!= FT_FSPathMakeRes( pathname
, &res_ref
) )
849 return FT_Err_Cannot_Open_Resource
;
851 UseResFile( res_ref
);
853 return FT_Err_Cannot_Open_Resource
;
855 num_faces_in_res
= 0;
856 for ( res_index
= 1; ; ++res_index
)
858 fond
= Get1IndResource( 'FOND', res_index
);
862 num_faces_in_fond
= count_faces( fond
, pathname
);
863 num_faces_in_res
+= num_faces_in_fond
;
865 if ( 0 <= face_index
&& face_index
< num_faces_in_fond
&& error
)
866 error
= FT_New_Face_From_FOND( library
, fond
, face_index
, aface
);
868 face_index
-= num_faces_in_fond
;
871 CloseResFile( res_ref
);
872 if ( FT_Err_Ok
== error
&& NULL
!= aface
)
873 (*aface
)->num_faces
= num_faces_in_res
;
878 /* documentation is in ftmac.h */
880 FT_EXPORT_DEF( FT_Error
)
881 FT_New_Face_From_FOND( FT_Library library
,
886 short sfnt_id
, have_sfnt
, have_lwfn
= 0;
890 Str255 lwfn_file_name
;
891 UInt8 path_lwfn
[HFS_MAXPATHLEN
];
893 FT_Error error
= FT_Err_Ok
;
896 GetResInfo( fond
, &fond_id
, &fond_type
, fond_name
);
897 if ( ResError() != noErr
|| fond_type
!= 'FOND' )
898 return FT_Err_Invalid_File_Format
;
900 parse_fond( *fond
, &have_sfnt
, &sfnt_id
, lwfn_file_name
, face_index
);
902 if ( lwfn_file_name
[0] )
907 res
= HomeResFile( fond
);
908 if ( noErr
!= ResError() )
909 goto found_no_lwfn_file
;
912 UInt8 path_fond
[HFS_MAXPATHLEN
];
916 err
= FSGetForkCBInfo( res
, kFSInvalidVolumeRefNum
,
917 NULL
, NULL
, NULL
, &ref
, NULL
);
919 goto found_no_lwfn_file
;
921 err
= FSRefMakePath( &ref
, path_fond
, sizeof ( path_fond
) );
923 goto found_no_lwfn_file
;
925 error
= lookup_lwfn_by_fond( path_fond
, lwfn_file_name
,
926 path_lwfn
, sizeof ( path_lwfn
) );
927 if ( FT_Err_Ok
== error
)
932 if ( have_lwfn
&& ( !have_sfnt
|| PREFER_LWFN
) )
933 error
= FT_New_Face_From_LWFN( library
,
938 error
= FT_Err_Unknown_File_Format
;
941 if ( have_sfnt
&& FT_Err_Ok
!= error
)
942 error
= FT_New_Face_From_SFNT( library
,
951 /* Common function to load a new FT_Face from a resource file. */
953 FT_New_Face_From_Resource( FT_Library library
,
954 const UInt8
* pathname
,
962 /* LWFN is a (very) specific file format, check for it explicitly */
963 file_type
= get_file_type_from_path( pathname
);
964 if ( file_type
== 'LWFN' )
965 return FT_New_Face_From_LWFN( library
, pathname
, face_index
, aface
);
967 /* Otherwise the file type doesn't matter (there are more than */
968 /* `FFIL' and `tfil'). Just try opening it as a font suitcase; */
969 /* if it works, fine. */
971 error
= FT_New_Face_From_Suitcase( library
, pathname
, face_index
, aface
);
975 /* let it fall through to normal loader (.ttf, .otf, etc.); */
976 /* we signal this by returning no error and no FT_Face */
982 /*************************************************************************/
988 /* This is the Mac-specific implementation of FT_New_Face. In */
989 /* addition to the standard FT_New_Face() functionality, it also */
990 /* accepts pathnames to Mac suitcase files. For further */
991 /* documentation see the original FT_New_Face() in freetype.h. */
993 FT_EXPORT_DEF( FT_Error
)
994 FT_New_Face( FT_Library library
,
995 const char* pathname
,
1003 /* test for valid `library' and `aface' delayed to FT_Open_Face() */
1005 return FT_Err_Invalid_Argument
;
1010 /* try resourcefork based font: LWFN, FFIL */
1011 error
= FT_New_Face_From_Resource( library
, (UInt8
*)pathname
,
1012 face_index
, aface
);
1013 if ( error
!= 0 || *aface
!= NULL
)
1016 /* let it fall through to normal loader (.ttf, .otf, etc.) */
1017 args
.flags
= FT_OPEN_PATHNAME
;
1018 args
.pathname
= (char*)pathname
;
1019 return FT_Open_Face( library
, &args
, face_index
, aface
);
1023 /*************************************************************************/
1026 /* FT_New_Face_From_FSRef */
1029 /* FT_New_Face_From_FSRef is identical to FT_New_Face except it */
1030 /* accepts an FSRef instead of a path. */
1032 FT_EXPORT_DEF( FT_Error
)
1033 FT_New_Face_From_FSRef( FT_Library library
,
1041 UInt8 pathname
[HFS_MAXPATHLEN
];
1045 return FT_Err_Invalid_Argument
;
1047 err
= FSRefMakePath( ref
, pathname
, sizeof ( pathname
) );
1049 error
= FT_Err_Cannot_Open_Resource
;
1051 error
= FT_New_Face_From_Resource( library
, pathname
, face_index
, aface
);
1052 if ( error
!= 0 || *aface
!= NULL
)
1055 /* fallback to datafork font */
1056 args
.flags
= FT_OPEN_PATHNAME
;
1057 args
.pathname
= (char*)pathname
;
1058 return FT_Open_Face( library
, &args
, face_index
, aface
);
1062 /*************************************************************************/
1065 /* FT_New_Face_From_FSSpec */
1068 /* FT_New_Face_From_FSSpec is identical to FT_New_Face except it */
1069 /* accepts an FSSpec instead of a path. */
1071 FT_EXPORT_DEF( FT_Error
)
1072 FT_New_Face_From_FSSpec( FT_Library library
,
1078 FT_UNUSED( library
);
1080 FT_UNUSED( face_index
);
1083 return FT_Err_Unimplemented_Feature
;
1088 if ( !spec
|| FSpMakeFSRef( spec
, &ref
) != noErr
)
1089 return FT_Err_Invalid_Argument
;
1091 return FT_New_Face_From_FSRef( library
, &ref
, face_index
, aface
);