This patch changes src/base/ftmac.c to use FSRef at maximum,
if TARGET_API_MAC_OS9 is not defined.
Originally written by Mr. George Williams.
Modified by suzuki toshiya.

diff -NBurb -x {arch} -x '.*' freetype2--mps-macos--0.1--base-0/src/base/ftmac.c freetype2--mps-macos--0.1--patch-4/src/base/ftmac.c
--- freetype2--mps-macos--0.1--base-0/src/base/ftmac.c	2005-09-16 17:58:24.000000000 +0900
+++ freetype2--mps-macos--0.1--patch-4/src/base/ftmac.c	2005-09-16 17:59:14.000000000 +0900
@@ -128,6 +128,18 @@
 
 
   /* Given a pathname, fill in a file spec. */
+#if !TARGET_API_MAC_OS9
+  static int
+  file_ref_from_path( const char*  pathname,
+                      FSRef*       ref )
+  {
+    OSErr e;
+
+    e = FSPathMakeRef( (UInt8 *)pathname, ref, false /* not a directory */ );
+
+    return ( e == noErr ) ? 0 : (-1);
+  }
+#else	/* TARGET_API_MAC_OS9 */
   static int
   file_spec_from_path( const char*  pathname,
                        FSSpec*      spec )
@@ -167,9 +179,24 @@
 #endif
 
   }
+#endif
 
 
   /* Return the file type of the file specified by spec. */
+#if !TARGET_API_MAC_OS9
+  static OSType
+  get_file_type( const FSRef*  ref )
+  {
+    FSCatalogInfo info;
+    FInfo  finfo;
+
+
+    if ( FSGetCatalogInfo( ref, kFSCatInfoFinderInfo, &info, NULL, NULL, NULL ) != noErr )
+      return 0;  /* file might not exist */
+
+    return ((FInfo *) (info.finderInfo))->fdType;
+  }
+#else	/* TARGET_API_MAC_OS9 */
   static OSType
   get_file_type( const FSSpec*  spec )
   {
@@ -181,6 +208,7 @@
 
     return finfo.fdType;
   }
+#endif	/* TARGET_API_MAC_OS9 */
 
 
   /* Given a PostScript font name, create the Macintosh LWFN file name. */
@@ -213,7 +241,14 @@
     }
   }
 
+#if !TARGET_API_MAC_OS9
+  get_file_location( short           ref_num,
+                     FSRef*          fsref )
+  {
 
+    return( FSGetForkCBInfo( ref_num,kFSInvalidVolumeRefNum,NULL,NULL,NULL,fsref,NULL ));
+  }
+#else
   /* Given a file reference, answer its location as a vRefNum
      and a dirID. */
   static FT_Error
@@ -239,8 +274,30 @@
     }
     return error;
   }
+#endif
 
+#if !TARGET_API_MAC_OS9
+  /* Make a file ref for an LWFN file from a FOND resource and
+     a file name. */
+  static FT_Error
+  make_lwfn_spec( Handle               fond,
+                  FSRef*               ref )
+  {
+    FT_Error  error;
+    short     ref_num, v_ref_num;
+    long      dir_id;
+    Str255    fond_file_name;
+
+
+    ref_num = HomeResFile( fond );
+
+    error = ResError();
+    if ( !error )
+      error = get_file_location( ref_num, ref );
 
+    return error;
+  }
+#else		/* TARGET_API_MAC_OS9 */
   /* Make a file spec for an LWFN file from a FOND resource and
      a file name. */
   static FT_Error
@@ -265,10 +322,11 @@
 
     return error;
   }
+#endif		/* TARGET_API_MAC_OS9 */
 
 
   static short
-  count_faces_sfnt( char *fond_data )
+  count_faces_sfnt( char*  fond_data )
   {
     /* The count is 1 greater than the value in the FOND.  */
     /* Isn't that cute? :-)                                */
@@ -393,7 +451,11 @@
   {
     short   sfnt_id, have_sfnt, have_lwfn = 0;
     Str255  lwfn_file_name;
+#if !TARGET_API_MAC_OS9
+    FSRef   lwfn_ref;
+#else
     FSSpec  lwfn_spec;
+#endif
 
 
     HLock( fond );
@@ -402,7 +464,11 @@
 
     if ( lwfn_file_name[0] )
     {
+#if !TARGET_API_MAC_OS9
+      if ( make_lwfn_ref( fond, &lwfn_ref ) == FT_Err_Ok )
+#else
       if ( make_lwfn_spec( fond, lwfn_file_name, &lwfn_spec ) == FT_Err_Ok )
+#endif
         have_lwfn = 1;  /* yeah, we got one! */
       else
         have_lwfn = 0;  /* no LWFN file found */
@@ -548,7 +614,7 @@
                      FT_Byte*             base,
                      FT_ULong             size,
                      FT_Stream_CloseFunc  close,
-                     FT_Stream           *astream )
+                     FT_Stream*           astream )
   {
     FT_Error   error;
     FT_Memory  memory;
@@ -584,7 +650,7 @@
                          FT_ULong    size,
                          FT_Long     face_index,
                          char*       driver_name,
-                         FT_Face    *aface )
+                         FT_Face*    aface )
   {
     FT_Open_Args  args;
     FT_Error      error;
@@ -627,9 +693,23 @@
   }
 
 
+#if !TARGET_API_MAC_OS9
+  static FT_Error
+  OpenFileAsResource( const FSRef*   ref,
+                      short*         p_res_ref )
+  {
+    FT_Error  error;
+
+    error = FSOpenResourceFile( ref, 0, NULL, fsRdPerm, p_res_ref );
+
+    return error ? FT_Err_Cannot_Open_Resource : FT_Err_Ok;
+  }
+
+#else		/* TARGET_API_MAC_OS9 */
+
   static FT_Error
   OpenFileAsResource( const FSSpec*  spec,
-                      short         *p_res_ref )
+                      short*         p_res_ref )
   {
     FT_Error  error;
 
@@ -660,14 +740,31 @@
 
     return error ? FT_Err_Cannot_Open_Resource : FT_Err_Ok;
   }
+#endif  /* !TARGET_API_MAC_OS9 */
+
+
+#if !TARGET_API_MAC_OS9
+  /* Create a new FT_Face from a file spec to an LWFN file. */
+  static FT_Error
+  FT_New_Face_From_LWFN( FT_Library    library,
+                         const FSRef*  lwfn_ref,
+                         FT_Long       face_index,
+                         FT_Face*      aface )
+  {
+    FT_Byte*  pfb_data;
+    FT_ULong  pfb_size;
+    FT_Error  error;
+    short     res_ref;
 
 
+    error = OpenFileAsResource( lwfn_ref, &res_ref );
+#else		/* TARGET_API_MAC_OS9 */
   /* Create a new FT_Face from a file spec to an LWFN file. */
   static FT_Error
   FT_New_Face_From_LWFN( FT_Library     library,
                          const FSSpec*  lwfn_spec,
                          FT_Long        face_index,
-                         FT_Face       *aface )
+                         FT_Face*       aface )
   {
     FT_Byte*  pfb_data;
     FT_ULong  pfb_size;
@@ -676,6 +773,7 @@
 
 
     error = OpenFileAsResource( lwfn_spec, &res_ref );
+#endif /* TARGET_API_MAC_OS9 */
     if ( error )
       return error;
 
@@ -697,7 +795,7 @@
   FT_New_Face_From_SFNT( FT_Library  library,
                          short       sfnt_id,
                          FT_Long     face_index,
-                         FT_Face    *aface )
+                         FT_Face*    aface )
   {
     Handle     sfnt = NULL;
     FT_Byte*   sfnt_data;
@@ -742,7 +840,7 @@
   FT_New_Face_From_Suitcase( FT_Library  library,
                              short       res_ref,
                              FT_Long     face_index,
-                             FT_Face    *aface )
+                             FT_Face*    aface )
   {
     FT_Error  error = FT_Err_Ok;
     short     res_index;
@@ -784,14 +882,18 @@
   FT_New_Face_From_FOND( FT_Library  library,
                          Handle      fond,
                          FT_Long     face_index,
-                         FT_Face    *aface )
+                         FT_Face*    aface )
   {
     short   sfnt_id, have_sfnt, have_lwfn = 0;
-    Str255  lwfn_file_name;
     short   fond_id;
     OSType  fond_type;
     Str255  fond_name;
+    Str255  lwfn_file_name;
+#if !TARGET_API_MAC_OS9
+    FSRef   lwfn_ref;
+#else
     FSSpec  lwfn_spec;
+#endif
 
 
     GetResInfo( fond, &fond_id, &fond_type, fond_name );
@@ -804,7 +906,11 @@
 
     if ( lwfn_file_name[0] )
     {
+#if !TARGET_API_MAC_OS9
+      if ( make_lwfn_ref( fond, &lwfn_ref ) == FT_Err_Ok )
+#else
       if ( make_lwfn_spec( fond, lwfn_file_name, &lwfn_spec ) == FT_Err_Ok )
+#endif
         have_lwfn = 1;  /* yeah, we got one! */
       else
         have_lwfn = 0;  /* no LWFN file found */
@@ -812,7 +918,11 @@
 
     if ( have_lwfn && ( !have_sfnt || PREFER_LWFN ) )
       return FT_New_Face_From_LWFN( library,
+#if !TARGET_API_MAC_OS9
+                                    &lwfn_ref,
+#else
                                     &lwfn_spec,
+#endif
                                     face_index,
                                     aface );
     else if ( have_sfnt )
@@ -912,11 +1022,34 @@
 
   /* Common function to load a new FT_Face from a resource file. */
 
+
+#if !TARGET_API_MAC_OS9
   static FT_Error
   FT_New_Face_From_Resource( FT_Library     library,
-                             const FSSpec  *spec,
+                             const FSRef*  ref,
                              FT_Long        face_index,
-                             FT_Face       *aface )
+                             FT_Face*      aface )
+  {
+    OSType    file_type;
+    short     res_ref;
+    FT_Error  error;
+
+
+    if ( OpenFileAsResource( ref, &res_ref ) == FT_Err_Ok )
+    {
+      /* LWFN is a (very) specific file format, check for it explicitly */
+
+      file_type = get_file_type( ref );
+      if ( file_type == 'LWFN' )
+        return FT_New_Face_From_LWFN( library, ref, face_index, aface );
+
+#else		/* TARGET_API_MAC_OS9 */
+
+  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;
@@ -931,6 +1064,8 @@
       if ( file_type == 'LWFN' )
         return FT_New_Face_From_LWFN( library, spec, face_index, aface );
     
+#endif /* TARGET_API_MAC_OS9 */
+
       /* 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.                                           */
@@ -968,10 +1103,14 @@
   FT_New_Face( FT_Library   library,
                const char*  pathname,
                FT_Long      face_index,
-               FT_Face     *aface )
+               FT_Face*     aface )
   {
     FT_Open_Args  args;
+#if !TARGET_API_MAC_OS9
+    FSRef         ref;
+#else
     FSSpec        spec;
+#endif
     FT_Error      error;
 
 
@@ -979,12 +1118,21 @@
     if ( !pathname )
       return FT_Err_Invalid_Argument;
 
+#if !TARGET_API_MAC_OS9
+    if ( file_ref_from_path( pathname, &ref ) )
+      return FT_Err_Invalid_Argument;
+
+    error = FT_New_Face_From_Resource( library, &ref, face_index, aface );
+    if ( error != 0 || *aface != NULL )
+      return error;
+#else
     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;
+#endif
 
     /* let it fall through to normal loader (.ttf, .otf, etc.) */
     args.flags    = FT_OPEN_PATHNAME;
@@ -1004,10 +1152,13 @@
   /*                                                                       */
   FT_EXPORT_DEF( FT_Error )
   FT_New_Face_From_FSSpec( FT_Library    library,
-                           const FSSpec *spec,
+                           const FSSpec*  spec,
                            FT_Long       face_index,
-                           FT_Face      *aface )
+                           FT_Face*       aface )
   {
+#if !TARGET_API_MAC_OS9
+    FSRef         ref;
+#endif
 #if defined( __MWERKS__ ) && !TARGET_RT_MAC_MACHO
     FT_Open_Args  args;
     FT_Stream     stream;
@@ -1021,7 +1172,14 @@
     if ( !spec )
       return FT_Err_Invalid_Argument;
 
+#if !TARGET_API_MAC_OS9
+    if ( FSpMakeFSRef( spec, &ref )!=noErr )
+      return FT_Err_Invalid_Argument;
+
+    error = FT_New_Face_From_Resource( library, &ref, face_index, aface );
+#else
     error = FT_New_Face_From_Resource( library, spec, face_index, aface );
+#endif
     if ( error != 0 || *aface != NULL )
       return error;
 
@@ -1087,4 +1245,50 @@
   }
 
 
+#if !TARGET_API_MAC_OS9
+  /*************************************************************************/
+  /*                                                                       */
+  /* <Function>                                                            */
+  /*    FT_New_Face_From_FSRef                                             */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    FT_New_Face_From_FSRef is identical to FT_New_Face except it       */
+  /*    accepts an FSRef instead of a path.                                */
+  /*                                                                       */
+  FT_EXPORT_DEF( FT_Error )
+  FT_New_Face_From_FSRef( FT_Library    library,
+                          const FSRef*  ref,
+                          FT_Long       face_index,
+                          FT_Face*      aface )
+  {
+    FT_Error  error;
+
+
+    /* test for valid `library' and `aface' delayed to FT_Open_Face() */
+    if ( !ref )
+      return FT_Err_Invalid_Argument;
+
+    error = FT_New_Face_From_Resource( library, ref, face_index, aface );
+    if ( error != 0 || *aface != NULL )
+      return error;
+
+    /* let it fall through to normal loader (.ttf, .otf, etc.) */
+
+    {
+      UInt8  path[256];
+      OSErr  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;
+    }
+
+    return error;
+  }
+#endif
+
 /* END */
