freetype-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Devel] extensible resource forks accessor


From: Masatake YAMATO
Subject: [Devel] extensible resource forks accessor
Date: Tue, 17 Feb 2004 22:16:23 +0900 (JST)

Hi, here is a rather big patch.

I've reorganized codes related to resource forks.
The aims of reorganization are:

1. support and make it possible to support more ways to access
   resource forks; and
2. support more datum in the resource fork like FOND even on the OS
   other than MacOS

I'll try to explain each of them detail.

1. support and make it possible to support more ways to access 
   resource forks

There are several ways to access the resource fork from a given file
name. In some case the resource fork is not started from the head of
file; it has some offset. As you know some of them are already
supported in FT2.  E.g. On Mac OSX, to access the the resource fork of
"foo", you have to use "foo/rsrc". I am afraid that Apple or other OS
add another way to access the resource fork from a given file
name. FT2 code to access resource forks are not extensible enough to
add a new way.

I've defined `FT_Raccess_Guess' as the unified front end to access
resource folks. You can add a new way to the layer behind `FT_Raccess_Guess'.
To show the usefulness of the layer, I've added the some ways to the layer 
including

- Apple Double
- Apple Single
- darwin ufs export(foo => ._foo)
- darwin hfsplus(foo => foo/rsrc, based on FT2 code)
- vfat (foo => resource.frk/foo, based on FT2 code)
- linux cap(foo => .resource/foo)
- linux double(foo => %foo)
- linux netatalk(foo => ./AppleDouble/foo)

You can turn `FT_Raccess_Guess' off at the build-time with 
FT_CONFIG_OPTION_GUESSING_EMBEDDED_RFORK.

2. support more datum in the resource fork like FOND even on the OS
   other than MacOS

In FT2, only sfnt and POST resource forks are used on the OS other than MacOS
now. It may be interesting to support FOND or something MacOS own font format
in FT2. FT2 code is not flexible enough to enable such challenges; FT2
assume accessing only sfnt and POST.

I've defined two new functions based on FT2 code to make it more flexible
to access specified datum in the resource forks.

- FT_Raccess_Get_HeaderInfo
- FT_Raccess_Get_DataOffsets

Some lines common in Mac_Read_POST_Resource and Mac_Read_sfnt_Resource
are unified into FT_Raccess_Get_HeaderInfo and FT_Raccess_Get_DataOffsets.

2004-02-17  Masatake YAMATO  <address@hidden>

        * src/base/ftraccess.c: New file.

        * include/freetype/internal/ftraccess.h: New file.
        
        * src/base/rules.mk (BASE_SRC): Added ftraccess.c.

        * src/base/ftobjs.c: Include FT_INTERNAL_RACCESS_H.
        (Mac_Read_POST_Resource): remove arguments `resource_listoffset' 
        and `resource_data'. These value are calculated outside of
        the functions. Added new argument `offsets'.
        (IsMacResource): Use `FT_Raccess_Get_HeaderInfo' and 
        `FT_Raccess_Get_DataOffsets'.
        (load_face_in_embedded_rfork): New function.
        (load_mac_face): Use load_face_in_embedded_rfork.

        (Mac_Read_sfnt_Resource): Ditto.

        * src/base/ftbase.c: Added ftraccess.c.

        * src/base/Jamfile: Added ftraccess.

        * include/freetype/internal/internal.h (FT_INTERNAL_RACCESS_H): Added 
ftraccess.h.

        * include/freetype/internal/fttrace.h: Added `raccess' as new a trace 
def.

        * include/freetype/config/ftoption.h 
(FT_CONFIG_OPTION_GUESSING_EMBEDDED_RFORK): 
        New option.

        * devel/ftoption.h (FT_CONFIG_OPTION_GUESSING_EMBEDDED_RFORK): New 
option.

diff -c -r --exclude='*.o' --exclude=config.log --exclude=TAGS 
--exclude=cscope.files --exclude=cscope.out --exclude=CVS --exclude=.cvsignore 
--exclude=stamp-vti --exclude=version.texi --exclude='.#*' --exclude='*~' 
--exclude='*.orig' --exclude='automake.info*' --exclude=aclocal 
--exclude=autom4te.cache --exclude=automake --exclude=config.status 
--exclude=Makefile --exclude=samples --exclude=amversion.m4 
--exclude=automake-1.5e --new-file freetype2/devel/ftoption.h 
freetype2.new/devel/ftoption.h
*** freetype2/devel/ftoption.h  2003-12-20 16:43:45.000000000 +0900
--- freetype2.new/devel/ftoption.h      2004-02-17 18:31:47.000000000 +0900
***************
*** 229,234 ****
--- 229,253 ----
    /*                                                                       */
  #define FT_CONFIG_OPTION_MAC_FONTS
  
+   /*************************************************************************/
+   /*                                                                       */
+   /* Guessing methods to access embedded resource forks                    */
+   /*                                                                       */
+   /*   Enable extra Mac fonts support on non-Mac platforms(e.g. GNU/Linux).*/
+   /*   Resource fork which includes fonts data is stored to somewhere      */
+   /*   different place where users/developers are expected.                */
+   /*   In some case, resource fork starts with some offsets from the head  */
+   /*   of file. In another case, actual resource fork are stored to        */
+   /*   different file than the user specifies. If this option, turns on    */
+   /*   FreeType guesses such offset and new file name.                     */
+   /*                                                                       */
+   /*   Note that normal(direct) resource fork accessing is supported in    */
+   /*   FT_CONFIG_OPTION_MAC_FONTS option.                                  */
+   /*                                                                       */
+ #ifdef FT_CONFIG_OPTION_MAC_FONTS
+ #define FT_CONFIG_OPTION_GUESSING_EMBEDDED_RFORK
+ #endif
+ 
  
    /*************************************************************************/
    /*                                                                       */
diff -c -r --exclude='*.o' --exclude=config.log --exclude=TAGS 
--exclude=cscope.files --exclude=cscope.out --exclude=CVS --exclude=.cvsignore 
--exclude=stamp-vti --exclude=version.texi --exclude='.#*' --exclude='*~' 
--exclude='*.orig' --exclude='automake.info*' --exclude=aclocal 
--exclude=autom4te.cache --exclude=automake --exclude=config.status 
--exclude=Makefile --exclude=samples --exclude=amversion.m4 
--exclude=automake-1.5e --new-file freetype2/include/freetype/config/ftoption.h 
freetype2.new/include/freetype/config/ftoption.h
*** freetype2/include/freetype/config/ftoption.h        2003-12-20 
16:43:45.000000000 +0900
--- freetype2.new/include/freetype/config/ftoption.h    2004-02-17 
18:43:16.000000000 +0900
***************
*** 229,234 ****
--- 229,253 ----
    /*                                                                       */
  #define FT_CONFIG_OPTION_MAC_FONTS
  
+   /*************************************************************************/
+   /*                                                                       */
+   /* Guessing methods to access embedded resource forks                    */
+   /*                                                                       */
+   /*   Enable extra Mac fonts support on non-Mac platforms(e.g. GNU/Linux).*/
+   /*   Resource fork which includes fonts data is stored to somewhere      */
+   /*   different place where users/developers are expected.                */
+   /*   In some case, resource fork starts with some offsets from the head  */
+   /*   of file. In another case, actual resource fork are stored to        */
+   /*   different file than the user specifies. If this option turns on,    */
+   /*   FreeType guesses such offset and new file name.                     */
+   /*                                                                       */
+   /*   Note that normal(direct) resource fork accessing is supported in    */
+   /*   FT_CONFIG_OPTION_MAC_FONTS option.                                  */
+   /*                                                                       */
+ #ifdef FT_CONFIG_OPTION_MAC_FONTS
+ #define FT_CONFIG_OPTION_GUESSING_EMBEDDED_RFORK
+ #endif
+ 
  
    /*************************************************************************/
    /*                                                                       */
diff -c -r --exclude='*.o' --exclude=config.log --exclude=TAGS 
--exclude=cscope.files --exclude=cscope.out --exclude=CVS --exclude=.cvsignore 
--exclude=stamp-vti --exclude=version.texi --exclude='.#*' --exclude='*~' 
--exclude='*.orig' --exclude='automake.info*' --exclude=aclocal 
--exclude=autom4te.cache --exclude=automake --exclude=config.status 
--exclude=Makefile --exclude=samples --exclude=amversion.m4 
--exclude=automake-1.5e --new-file freetype2/include/freetype/config/ftstdlib.h 
freetype2.new/include/freetype/config/ftstdlib.h
*** freetype2/include/freetype/config/ftstdlib.h        2004-01-24 
04:52:39.000000000 +0900
--- freetype2.new/include/freetype/config/ftstdlib.h    2004-02-17 
18:43:44.000000000 +0900
***************
*** 93,98 ****
--- 93,100 ----
  #define ft_memmove  memmove
  #define ft_memcmp   memcmp
  
+ #define ft_strrchr  strrchr
+ 
  #include <stdio.h>
  
  #define ft_sprintf  sprintf
diff -c -r --exclude='*.o' --exclude=config.log --exclude=TAGS 
--exclude=cscope.files --exclude=cscope.out --exclude=CVS --exclude=.cvsignore 
--exclude=stamp-vti --exclude=version.texi --exclude='.#*' --exclude='*~' 
--exclude='*.orig' --exclude='automake.info*' --exclude=aclocal 
--exclude=autom4te.cache --exclude=automake --exclude=config.status 
--exclude=Makefile --exclude=samples --exclude=amversion.m4 
--exclude=automake-1.5e --new-file 
freetype2/include/freetype/internal/ftraccess.h 
freetype2.new/include/freetype/internal/ftraccess.h
*** freetype2/include/freetype/internal/ftraccess.h     1970-01-01 
09:00:00.000000000 +0900
--- freetype2.new/include/freetype/internal/ftraccess.h 2004-02-17 
18:31:43.000000000 +0900
***************
*** 0 ****
--- 1,147 ----
+ /***************************************************************************/
+ /*                                                                         */
+ /*  ftraccess.h                                                            */
+ /*                                                                         */
+ /*    Embedded resource forks accessor (specification).                    */
+ /*                                                                         */
+ /*  Copyright 2003 by                                                      */
+ /*  Masatake YAMATO and Redhat K.K.                                        */
+ /*                                                                         */
+ /*  This file may only be used,                                            */
+ /*  modified, and distributed under the terms of the FreeType project      */
+ /*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
+ /*  this file you indicate that you have read the license and              */
+ /*  understand and accept it fully.                                        */
+ /*                                                                         */
+ /***************************************************************************/
+ 
+ /***************************************************************************/
+ /* Development of the code in this file is support of                      */
+ /* Information-technology Promotion Agency, Japan.                         */
+ /***************************************************************************/
+ 
+ #ifndef __FTRACCESS_H_
+ #define __FTRACCESS_H_ 
+ 
+ #include <ft2build.h>
+ #include FT_INTERNAL_OBJECTS_H
+ 
+ FT_BEGIN_HEADER
+ 
+ /* Number of guessing rules supported in `FT_Raccess_Guess'.            */
+ /* Don't forget to increment the number if you add a new guessing rule. */
+ #define FT_RACCESS_N_RUULES 8
+ 
+   /*************************************************************************/
+   /*                                                                       */
+   /* <Function>                                                            */
+   /*    FT_Raccess_Guess                                                   */
+   /*                                                                       */
+   /* <Description>                                                         */
+   /*    Guess a file name and offset where the actual resource fork is     */
+   /*    stored. The plural number(FT_RACCESS_N_RUULES) of guessing rules   */
+   /*    are existed. The guessed result for Nth rule is represented in 3   */
+   /*    values; new file name(new_names[N]), file offset(offsets[N]) and   */
+   /*    error code(errors[N]) guessing rule.                               */
+   /*                                                                       */
+   /* <Input>                                                               */
+   /*    library :: FreeType library instance                               */
+   /*    stream ::  File stream including the resource fork                 */
+   /*    base_name :: Base file name                                        */
+   /*                                                                       */
+   /* <Output>                                                              */
+   /*  new_names :: Array of guessed file name in which the resoruce for    */
+   /*               may exist                                               */
+   /*               If new_names[N] is NULL, the guessed file name is       */
+   /*             equals to the base_name.                                */
+   /*  offsets :: Array of guessed file offset                              */
+   /*             offsets[N] is file offsets where the resource fork may    */
+   /*             start in the file, new_names[N].                          */
+   /*  errors ::  Array of FreeType error code                              */
+   /*             errors[N] is error code of Nth guessing rule function.    */
+   /*             If errors[N] is other than FT_Err_Ok, new_names[N] and    */
+   /*             offsets[N] are meaningless.                               */
+   /*                                                                       */ 
 
+   FT_BASE( void )
+   FT_Raccess_Guess ( FT_Library           library,
+                    FT_Stream            stream,
+                    char*                base_name,
+                    char*                new_names[FT_RACCESS_N_RUULES],
+                    FT_Long              offsets[FT_RACCESS_N_RUULES],
+                    FT_Error             errors[FT_RACCESS_N_RUULES] );
+ 
+   /*************************************************************************/
+   /*                                                                       */
+   /* <Function>                                                            */
+   /*    FT_Raccess_Get_HeaderInfo                                          */
+   /*                                                                       */
+   /* <Description>                                                         */
+   /*    Get the information from the header of resource fork.              */
+   /*    The information includes the file offset where the resource map    */
+   /*    starts and the file offset where the resource data starts.         */
+   /*    `FT_Raccess_Get_DataOffsets' requires these two data.              */
+   /*                                                                       */
+   /* <Input>                                                               */
+   /*    library :: FreeType library instance                               */
+   /*    stream ::  File stream including the resource fork                 */
+   /*    rfork_offset :: The file offset where the resource fork starts     */
+   /*                                                                       */
+   /* <Output>                                                              */
+   /*  map_offset :: The file offset where the resource map starts          */
+   /*  rdata_pos :: The file offset where the resource data starts          */
+   /*                                                                       */
+   /* <Return>                                                              */
+   /*    FreeType error code.  FT_Err_Ok means success.                     */
+   /*                                                                       */ 
 
+   FT_BASE( FT_Error )
+   FT_Raccess_Get_HeaderInfo ( FT_Library           library,
+                             FT_Stream            stream,
+                             FT_Long              rfork_offset,
+                             FT_Long             *map_offset,
+                             FT_Long             *rdata_pos );
+ 
+   /*************************************************************************/
+   /*                                                                       */
+   /* <Function>                                                            */
+   /*    FT_Raccess_Get_DataOffsets                                         */
+   /*                                                                       */
+   /* <Description>                                                         */
+   /*    Get the data offsets for a tag in a resource fork.                 */
+   /*    Offsets are stored in a array because                              */
+   /*    in some case, resources in a resource fork have the same tag.      */
+   /*                                                                       */
+   /* <Input>                                                               */
+   /*    library :: FreeType library instance                               */
+   /*    stream ::  File stream including the resource fork                 */
+   /*    map_offset :: The file offset where the resource map starts        */
+   /*    rdata_pos :: The file offset where the resource data starts        */
+   /*    tag :: The resource tag you are seeking                            */
+   /*                                                                       */
+   /*    Normally you should use `FT_Raccess_Get_HeaderInfo' to get the     */
+   /*    value for map_offset and rdata_pos.                                */
+   /*                                                                       */
+   /* <Output>                                                              */
+   /*  offsets :: The stream offsets for the resource data specified by tag */
+   /*             An array is allocated in the function. So you have to     */
+   /*             call FT_Free after using.                                 */
+   /*  count ::   The length of offsets array.                              */
+   /*                                                                       */
+   /* <Return>                                                              */
+   /*    FreeType error code.  FT_Err_Ok means success.                     */
+   /*                                                                       */ 
 
+   FT_BASE( FT_Error ) 
+   FT_Raccess_Get_DataOffsets  ( FT_Library           library,
+                               FT_Stream            stream,
+                               FT_Long              map_offset,
+                               FT_Long              rdata_pos,
+                               FT_Long              tag,
+                               FT_Long            **offsets,
+                               FT_Long             *count );
+ 
+ 
+ FT_END_HEADER
+ 
+ #endif /* __FTRACCESS_H_ */
+ 
+ /* END */
+ 
diff -c -r --exclude='*.o' --exclude=config.log --exclude=TAGS 
--exclude=cscope.files --exclude=cscope.out --exclude=CVS --exclude=.cvsignore 
--exclude=stamp-vti --exclude=version.texi --exclude='.#*' --exclude='*~' 
--exclude='*.orig' --exclude='automake.info*' --exclude=aclocal 
--exclude=autom4te.cache --exclude=automake --exclude=config.status 
--exclude=Makefile --exclude=samples --exclude=amversion.m4 
--exclude=automake-1.5e --new-file 
freetype2/include/freetype/internal/fttrace.h 
freetype2.new/include/freetype/internal/fttrace.h
*** freetype2/include/freetype/internal/fttrace.h       2002-05-21 
23:13:00.000000000 +0900
--- freetype2.new/include/freetype/internal/fttrace.h   2004-02-17 
18:44:27.000000000 +0900
***************
*** 35,40 ****
--- 35,41 ----
  FT_TRACE_DEF( raster )    /* monochrome rasterizer   (ftraster.c) */
  FT_TRACE_DEF( smooth )    /* anti-aliasing raster    (ftgrays.c)  */
  FT_TRACE_DEF( mm )        /* MM interface            (ftmm.c)     */
+ FT_TRACE_DEF( raccess )   /* resource fork accessor  (ftraccess.c) */
  
  /* Cache sub-system */
  FT_TRACE_DEF( cache )     /* cache sub-system        (ftcache.c, etc..) */
diff -c -r --exclude='*.o' --exclude=config.log --exclude=TAGS 
--exclude=cscope.files --exclude=cscope.out --exclude=CVS --exclude=.cvsignore 
--exclude=stamp-vti --exclude=version.texi --exclude='.#*' --exclude='*~' 
--exclude='*.orig' --exclude='automake.info*' --exclude=aclocal 
--exclude=autom4te.cache --exclude=automake --exclude=config.status 
--exclude=Makefile --exclude=samples --exclude=amversion.m4 
--exclude=automake-1.5e --new-file 
freetype2/include/freetype/internal/internal.h 
freetype2.new/include/freetype/internal/internal.h
*** freetype2/include/freetype/internal/internal.h      2003-10-30 
06:43:51.000000000 +0900
--- freetype2.new/include/freetype/internal/internal.h  2004-02-17 
18:45:03.000000000 +0900
***************
*** 34,39 ****
--- 34,40 ----
  #define FT_INTERNAL_GLYPH_LOADER_H        <freetype/internal/ftgloadr.h>
  #define FT_INTERNAL_SFNT_H                <freetype/internal/sfnt.h>
  #define FT_INTERNAL_SERVICE_H             <freetype/internal/ftserv.h>
+ #define FT_INTERNAL_RACCESS_H             <freetype/internal/ftraccess.h>
  
  #define FT_INTERNAL_TRUETYPE_TYPES_H      <freetype/internal/tttypes.h>
  #define FT_INTERNAL_TYPE1_TYPES_H         <freetype/internal/t1types.h>
diff -c -r --exclude='*.o' --exclude=config.log --exclude=TAGS 
--exclude=cscope.files --exclude=cscope.out --exclude=CVS --exclude=.cvsignore 
--exclude=stamp-vti --exclude=version.texi --exclude='.#*' --exclude='*~' 
--exclude='*.orig' --exclude='automake.info*' --exclude=aclocal 
--exclude=autom4te.cache --exclude=automake --exclude=config.status 
--exclude=Makefile --exclude=samples --exclude=amversion.m4 
--exclude=automake-1.5e --new-file freetype2/src/base/Jamfile 
freetype2.new/src/base/Jamfile
*** freetype2/src/base/Jamfile  2003-06-07 13:02:21.000000000 +0900
--- freetype2.new/src/base/Jamfile      2004-02-17 18:45:47.000000000 +0900
***************
*** 10,16 ****
    if $(FT2_MULTI)
    {
      _sources = ftutil ftdbgmem ftstream ftcalc fttrigon ftgloadr ftoutln
!                ftobjs ftnames ;
    }
    else
    {
--- 10,16 ----
    if $(FT2_MULTI)
    {
      _sources = ftutil ftdbgmem ftstream ftcalc fttrigon ftgloadr ftoutln
!                ftobjs ftnames ftraccess;
    }
    else
    {
diff -c -r --exclude='*.o' --exclude=config.log --exclude=TAGS 
--exclude=cscope.files --exclude=cscope.out --exclude=CVS --exclude=.cvsignore 
--exclude=stamp-vti --exclude=version.texi --exclude='.#*' --exclude='*~' 
--exclude='*.orig' --exclude='automake.info*' --exclude=aclocal 
--exclude=autom4te.cache --exclude=automake --exclude=config.status 
--exclude=Makefile --exclude=samples --exclude=amversion.m4 
--exclude=automake-1.5e --new-file freetype2/src/base/ftbase.c 
freetype2.new/src/base/ftbase.c
*** freetype2/src/base/ftbase.c 2003-05-11 16:12:26.000000000 +0900
--- freetype2.new/src/base/ftbase.c     2004-02-17 18:31:44.000000000 +0900
***************
*** 29,34 ****
--- 29,35 ----
  #include "ftgloadr.c"
  #include "ftobjs.c"
  #include "ftnames.c"
+ #include "ftraccess.c"
  
  #if defined( __APPLE__ ) && !defined ( DARWIN_NO_CARBON )
  #include "ftmac.c"
diff -c -r --exclude='*.o' --exclude=config.log --exclude=TAGS 
--exclude=cscope.files --exclude=cscope.out --exclude=CVS --exclude=.cvsignore 
--exclude=stamp-vti --exclude=version.texi --exclude='.#*' --exclude='*~' 
--exclude='*.orig' --exclude='automake.info*' --exclude=aclocal 
--exclude=autom4te.cache --exclude=automake --exclude=config.status 
--exclude=Makefile --exclude=samples --exclude=amversion.m4 
--exclude=automake-1.5e --new-file freetype2/src/base/ftobjs.c 
freetype2.new/src/base/ftobjs.c
*** freetype2/src/base/ftobjs.c 2004-02-16 21:53:59.000000000 +0900
--- freetype2.new/src/base/ftobjs.c     2004-02-17 19:09:14.000000000 +0900
***************
*** 21,26 ****
--- 21,27 ----
  #include FT_OUTLINE_H
  #include FT_INTERNAL_OBJECTS_H
  #include FT_INTERNAL_DEBUG_H
+ #include FT_INTERNAL_RACCESS_H
  #include FT_INTERNAL_STREAM_H
  #include FT_INTERNAL_SFNT_H    /* for SFNT_Load_Table_Func */
  #include FT_TRUETYPE_TABLES_H
***************
*** 1133,1141 ****
    static FT_Error
    Mac_Read_POST_Resource( FT_Library  library,
                            FT_Stream   stream,
!                           FT_Long     resource_listoffset,
                            FT_Long     resource_cnt,
-                           FT_Long     resource_data,
                            FT_Long     face_index,
                            FT_Face    *aface )
    {
--- 1134,1141 ----
    static FT_Error
    Mac_Read_POST_Resource( FT_Library  library,
                            FT_Stream   stream,
!                           FT_Long    *offsets,
                            FT_Long     resource_cnt,
                            FT_Long     face_index,
                            FT_Face    *aface )
    {
***************
*** 1146,1152 ****
      FT_Long    len;
      FT_Long    pfb_len, pfb_pos, pfb_lenpos;
      FT_Long    rlen, temp;
-     FT_Long   *offsets;
  
  
      if ( face_index == -1 )
--- 1146,1151 ----
***************
*** 1154,1176 ****
      if ( face_index != 0 )
        return error;
  
-     if ( FT_ALLOC( offsets, (FT_Long)resource_cnt * sizeof ( FT_Long ) ) )
-       return error;
- 
-     error = FT_Stream_Seek( stream, resource_listoffset );
-     if ( error )
-       goto Exit;
- 
-     /* Find all the POST resource offsets */
-     for ( i = 0; i < resource_cnt; ++i )
-     {
-       (void)FT_STREAM_SKIP( 4 );    /* resource id and resource name */
-       if ( FT_READ_LONG( temp ) )
-         goto Exit;
-       offsets[i] = resource_data + ( temp & 0xFFFFFFL );
-       (void)FT_STREAM_SKIP( 4 );    /* mbz */
-     }
- 
      /* Find the length of all the POST resources, concatenated.  Assume */
      /* worst case (each resource in its own section).                   */
      pfb_len = 0;
--- 1153,1158 ----
***************
*** 1256,1262 ****
      FT_FREE( pfb_data );
  
    Exit:
-     FT_FREE( offsets );
      return error;
    }
  
--- 1238,1243 ----
***************
*** 1269,1285 ****
    static FT_Error
    Mac_Read_sfnt_Resource( FT_Library  library,
                            FT_Stream   stream,
!                           FT_Long     resource_listoffset,
                            FT_Long     resource_cnt,
-                           FT_Long     resource_data,
                            FT_Long     face_index,
                            FT_Face    *aface )
    {
      FT_Memory  memory = library->memory;
      FT_Byte*   sfnt_data;
      FT_Error   error;
!     int        i;
!     FT_Long    flag_offset= 0xFFFFFFL;
      FT_Long    rlen;
      int        is_cff;
  
--- 1250,1264 ----
    static FT_Error
    Mac_Read_sfnt_Resource( FT_Library  library,
                            FT_Stream   stream,
!                           FT_Long    *offsets,
                            FT_Long     resource_cnt,
                            FT_Long     face_index,
                            FT_Face    *aface )
    {
      FT_Memory  memory = library->memory;
      FT_Byte*   sfnt_data;
      FT_Error   error;
!     FT_Long    flag_offset;
      FT_Long    rlen;
      int        is_cff;
  
***************
*** 1289,1311 ****
      if ( face_index >= resource_cnt )
        return FT_Err_Cannot_Open_Resource;
  
!     error = FT_Stream_Seek( stream, resource_listoffset );
!     if ( error )
!       goto Exit;
! 
!     for ( i = 0; i <= face_index; ++i )
!     {
!       (void)FT_STREAM_SKIP( 4 );    /* resource id and resource name */
!       if ( FT_READ_LONG( flag_offset ) )
!         goto Exit;
!       flag_offset &= 0xFFFFFFL;
!       (void)FT_STREAM_SKIP( 4 );    /* mbz */
!     }
! 
!     if ( flag_offset == 0xFFFFFFL )
!       return FT_Err_Cannot_Open_Resource;
! 
!     error = FT_Stream_Seek( stream, flag_offset + resource_data );
      if ( error )
        goto Exit;
      if ( FT_READ_LONG( rlen ) )
--- 1268,1275 ----
      if ( face_index >= resource_cnt )
        return FT_Err_Cannot_Open_Resource;
  
!     flag_offset = offsets[face_index];
!     error = FT_Stream_Seek( stream, flag_offset );
      if ( error )
        goto Exit;
      if ( FT_READ_LONG( rlen ) )
***************
*** 1348,1457 ****
                   FT_Long     face_index,
                   FT_Face    *aface )
    {
      FT_Error       error;
!     unsigned char  head[16], head2[16];
!     FT_Long        rdata_pos, map_pos, rdata_len;
!     int            allzeros, allmatch, i, cnt, subcnt;
!     FT_Long        type_list, rpos;
!     FT_ULong       tag;
! 
! 
!     error = FT_Stream_Seek( stream, resource_offset );
!     if ( error )
!       goto Exit;
!     error = FT_Stream_Read( stream, (FT_Byte *)head, 16 );
!     if ( error )
!       goto Exit;
! 
!     rdata_pos = resource_offset + ( ( head[0] << 24 ) |
!                                     ( head[1] << 16 ) |
!                                     ( head[2] <<  8 ) |
!                                       head[3]         );
!     map_pos   = resource_offset + ( ( head[4] << 24 ) |
!                                     ( head[5] << 16 ) |
!                                     ( head[6] <<  8 ) |
!                                       head[7]         );
!     rdata_len = ( head[ 8] << 24 ) |
!                 ( head[ 9] << 16 ) |
!                 ( head[10] <<  8 ) |
!                   head[11];
!     /* map_len = head[12] .. head[15] */
! 
!     if ( rdata_pos + rdata_len != map_pos || map_pos == resource_offset )
!       return FT_Err_Unknown_File_Format;
! 
!     error = FT_Stream_Seek( stream, map_pos );
!     if ( error )
!       goto Exit;
! 
!     head2[15] = (FT_Byte)( head[15] + 1 );     /* make it be different */
! 
!     error = FT_Stream_Read( stream, (FT_Byte*)head2, 16 );
!     if ( error )
!       goto Exit;
! 
!     allzeros = 1;
!     allmatch = 1;
!     for ( i = 0; i < 16; ++i )
!     {
!       if ( head2[i] != 0 )
!         allzeros = 0;
!       if ( head2[i] != head[i] )
!         allmatch = 0;
!     }
!     if ( !allzeros && !allmatch )
!       return FT_Err_Unknown_File_Format;
! 
!     /* If we've gotten this far then it's probably a mac resource file. */
!     /* Now, does it contain any interesting resources?                  */
! 
!     /* Skip handle to next resource map, the file resource number, and  */
!     /* attributes.                                                      */
!     (void)FT_STREAM_SKIP( 4 + 2 + 2 );
! 
!     if ( FT_READ_USHORT( type_list ) )
!       goto Exit;
!     if ( type_list == -1 )
!       return FT_Err_Unknown_File_Format;
! 
!     error = FT_Stream_Seek( stream, map_pos + type_list );
      if ( error )
!       goto Exit;
! 
!     if ( FT_READ_USHORT( cnt ) )
!       goto Exit;
! 
!     ++cnt;
!     for ( i = 0; i < cnt; ++i )
!     {
!       if ( FT_READ_LONG( tag )      ||
!            FT_READ_USHORT( subcnt ) ||
!            FT_READ_USHORT( rpos )   )
!         goto Exit;
  
!       ++subcnt;
!       rpos += map_pos + type_list;
!       if ( tag == FT_MAKE_TAG( 'P', 'O', 'S', 'T' ) )
!         return Mac_Read_POST_Resource( library,
!                                        stream,
!                                        rpos,
!                                        subcnt,
!                                        rdata_pos,
!                                        face_index,
!                                        aface );
!       else if ( tag == FT_MAKE_TAG( 's', 'f', 'n', 't' ) )
!         return Mac_Read_sfnt_Resource( library,
!                                        stream,
!                                        rpos,
!                                        subcnt,
!                                        rdata_pos,
!                                        face_index,
!                                        aface );
!     }
  
!     error = FT_Err_Cannot_Open_Resource; /* this file contains no
!                                             interesting resources */
!   Exit:
      return error;
    }
  
--- 1312,1350 ----
                   FT_Long     face_index,
                   FT_Face    *aface )
    {
+     FT_Memory      memory = library->memory;
      FT_Error       error;
!     FT_Long        map_offset, rdara_pos;
!     FT_Long        *data_offsets;
!     FT_Long        count;
!     error = FT_Raccess_Get_HeaderInfo (library, stream, resource_offset, 
!                                      &map_offset, &rdara_pos);
      if ( error )
!       return error;
  
!     error = FT_Raccess_Get_DataOffsets (library, stream, map_offset, 
rdara_pos,
!                                       FT_MAKE_TAG( 'P', 'O', 'S', 'T' ),
!                                       &data_offsets,
!                                       &count);    
!     if ( !error )
!       {
!       error = Mac_Read_POST_Resource (library, stream, data_offsets, count,
!                                       face_index, aface);
!       FT_FREE(data_offsets);
!       return error;
!       }
  
!     error = FT_Raccess_Get_DataOffsets (library, stream, map_offset, 
rdara_pos,
!                                       FT_MAKE_TAG( 's', 'f', 'n', 't' ),
!                                       &data_offsets,
!                                       &count);    
!     if ( !error )
!       {
!       error = Mac_Read_sfnt_Resource (library, stream, data_offsets, count,
!                                       face_index, aface);
!       FT_FREE(data_offsets);
!       return error;
!       }
      return error;
    }
  
***************
*** 1506,1516 ****
    }
  
  
    /* Check for some macintosh formats                              */
    /* Is this a macbinary file?  If so look at the resource fork.   */
    /* Is this a mac dfont file?                                     */
    /* Is this an old style resource fork? (in data)                 */
!   /* Else if we're on Mac OS/X, open the resource fork explicitly. */
    /*                                                               */
    static FT_Error
    load_mac_face( FT_Library           library,
--- 1399,1469 ----
    }
  
  
+   static FT_Error
+   load_face_in_embedded_rfork( FT_Library           library,
+                              FT_Stream            stream,
+                              FT_Long              face_index,
+                              FT_Face             *aface,
+                              const FT_Open_Args  *args )
+   {
+ #undef  FT_COMPONENT
+ #define FT_COMPONENT  trace_raccess       
+     FT_Memory     memory = library->memory;
+     FT_Error      error  = FT_Err_Unknown_File_Format;
+     int i;
+     char *  file_names[FT_RACCESS_N_RUULES];  
+     FT_Long offsets[FT_RACCESS_N_RUULES];
+     FT_Error errors[FT_RACCESS_N_RUULES];
+   
+     FT_Open_Args  args2;
+     FT_Stream stream2;
+   
+     FT_Raccess_Guess(library, stream, args->pathname, file_names, offsets, 
errors);
+     for (i = 0; i < FT_RACCESS_N_RUULES; i++)
+       {
+       if ( errors[i] )
+         {
+           FT_TRACE3(( "Error[%d] is occured in rule %d\n", errors[i], i));
+           continue;
+         }
+       args2.flags = FT_OPEN_PATHNAME;
+       args2.pathname = file_names[i]? file_names[i]: args->pathname;
+       
+       FT_TRACE3(( "Try rule %d: %s(offset=%d)...", i, args2.pathname, 
offsets[i]));
+       error = ft_input_stream_new( library, &args2, &stream2 );      
+       
+       if ( error )
+         {
+           FT_TRACE3(( "failed\n" ));
+           continue;
+         }
+        
+       error = IsMacResource ( library, stream2, offsets[i], face_index, aface 
);
+       FT_Stream_Close( stream2 );
+       FT_TRACE3(( "%s\n", error? "failed": "successful" ));
+       if (!error )
+         break;
+       }
+     for (i = 0; i < FT_RACCESS_N_RUULES; i++)
+       {
+       if ( file_names[i] )
+         FT_FREE(file_names[i]);
+       }
+ 
+     /* Invoker (load_mac_face requires FT_Err_Unknown_File_Format. */
+     if ( error )
+       error = FT_Err_Unknown_File_Format;
+     return error;
+ #undef  FT_COMPONENT
+ #define FT_COMPONENT trace_objs           
+   }
+ 
    /* Check for some macintosh formats                              */
    /* Is this a macbinary file?  If so look at the resource fork.   */
    /* Is this a mac dfont file?                                     */
    /* Is this an old style resource fork? (in data)                 */
!   /* Else call load_face_in_embedded_rfork to try extra rules      */
!   /* defined ftraccess.c.                                          */
    /*                                                               */
    static FT_Error
    load_mac_face( FT_Library           library,
***************
*** 1522,1565 ****
      FT_Error error;
      FT_UNUSED( args );
  
- 
      error = IsMacBinary( library, stream, face_index, aface );
      if ( FT_ERROR_BASE( error ) == FT_Err_Unknown_File_Format )
-       error = IsMacResource( library, stream, 0, face_index, aface );
- 
-     /* Only meaningful on sytems with hfs+ drivers (or Macs) */
- 
-     if ( ( FT_ERROR_BASE( error ) == FT_Err_Unknown_File_Format      ||
-            FT_ERROR_BASE( error ) == FT_Err_Invalid_Stream_Operation )  &&
-            ( args->flags & FT_OPEN_PATHNAME )                           )
-     {
-       FT_Open_Args  args2;
-       char*         newpath;
-       FT_Memory     memory;
-       FT_Stream     stream2;
- 
- 
-       memory = library->memory;
- 
-       if ( FT_ALLOC( newpath,
-                      ft_strlen( args->pathname ) + ft_strlen( "/rsrc" ) + 1 ) 
)
-         goto Fail;
- 
-       ft_strcpy( newpath, args->pathname );
-       ft_strcat( newpath, "/rsrc" );
- 
-       args2.flags    = FT_OPEN_PATHNAME;
-       args2.pathname = (char*)newpath;
-       error = ft_input_stream_new( library, &args2, &stream2 );
-       if ( !error )
        {
!         error = IsMacResource( library, stream2, 0, face_index, aface );
!         FT_Stream_Close( stream2 );
        }
!       FT_FREE( newpath );
!     }
! 
!   Fail:
      return error;
    }
  
--- 1475,1495 ----
      FT_Error error;
      FT_UNUSED( args );
  
      error = IsMacBinary( library, stream, face_index, aface );
      if ( FT_ERROR_BASE( error ) == FT_Err_Unknown_File_Format )
        {
! #undef  FT_COMPONENT
! #define FT_COMPONENT  trace_raccess   
!       FT_TRACE3(( "Try as dfont: %s...", args->pathname));
!       error = IsMacResource( library, stream, 0, face_index, aface );
!       FT_TRACE3(( "%s\n", error? "failed": "successful" ));
! #undef  FT_COMPONENT
! #define FT_COMPONENT trace_objs
        }
!     if ( (FT_ERROR_BASE( error ) == FT_Err_Unknown_File_Format      ||
!         FT_ERROR_BASE( error ) == FT_Err_Invalid_Stream_Operation )  &&
!          ( args->flags & FT_OPEN_PATHNAME ))
!       error = load_face_in_embedded_rfork(library, stream, face_index, aface, 
args);
      return error;
    }
  
diff -c -r --exclude='*.o' --exclude=config.log --exclude=TAGS 
--exclude=cscope.files --exclude=cscope.out --exclude=CVS --exclude=.cvsignore 
--exclude=stamp-vti --exclude=version.texi --exclude='.#*' --exclude='*~' 
--exclude='*.orig' --exclude='automake.info*' --exclude=aclocal 
--exclude=autom4te.cache --exclude=automake --exclude=config.status 
--exclude=Makefile --exclude=samples --exclude=amversion.m4 
--exclude=automake-1.5e --new-file freetype2/src/base/ftraccess.c 
freetype2.new/src/base/ftraccess.c
*** freetype2/src/base/ftraccess.c      1970-01-01 09:00:00.000000000 +0900
--- freetype2.new/src/base/ftraccess.c  2004-02-17 18:31:44.000000000 +0900
***************
*** 0 ****
--- 1,606 ----
+ /***************************************************************************/
+ /*                                                                         */
+ /*  ftraccess.c                                                            */
+ /*                                                                         */
+ /*    Embedded resource forks accessor (body).                             */
+ /*                                                                         */
+ /*  Copyright 2003 by                                                      */
+ /*  Masatake YAMATO and Redhat K.K.                                        */
+ /*                                                                         */
+ /*  FT_Raccess_Get_HeaderInfo () and raccess_guess_darwin_hfsplus () are   */
+ /*  drived from ftobjs.c.                                                  */
+ /*  About ftobjs.c:                                                        */
+ /*  Copyright 1996-2001, 2002, 2003 by                                     */
+ /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
+ /*                                                                         */
+ /*  This file may only be used,                                            */
+ /*  modified, and distributed under the terms of the FreeType project      */
+ /*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
+ /*  this file you indicate that you have read the license and              */
+ /*  understand and accept it fully.                                        */
+ /*                                                                         */
+ /***************************************************************************/
+ 
+ /***************************************************************************/
+ /* Development of the code in this file is support of                      */
+ /* Information-technology Promotion Agency, Japan.                         */
+ /***************************************************************************/
+ 
+ #include <ft2build.h>
+ #include FT_INTERNAL_DEBUG_H
+ #include FT_INTERNAL_RACCESS_H
+ 
+ 
+ #undef  FT_COMPONENT
+ #define FT_COMPONENT  trace_raccess
+ 
+ 
+   /*************************************************************************/
+   /*************************************************************************/
+   /*************************************************************************/
+   /****                                                                 ****/
+   /****                                                                 ****/
+   /****               Resource fork directory access                    ****/
+   /****                                                                 ****/
+   /****                                                                 ****/
+   /*************************************************************************/
+   /*************************************************************************/
+   /*************************************************************************/
+ 
+   FT_BASE_DEF( FT_Error )
+   FT_Raccess_Get_HeaderInfo ( FT_Library           library,
+                             FT_Stream            stream,
+                             FT_Long              rfork_offset,
+                             FT_Long             *map_offset,
+                             FT_Long             *rdata_pos )
+   {
+     FT_Error       error;
+     unsigned char  head[16], head2[16];
+     FT_Long        map_pos, rdata_len;
+     int            allzeros, allmatch, i;
+     FT_Long        type_list;
+ 
+     error = FT_Stream_Seek( stream, rfork_offset );
+     if ( error )
+       return error;
+     error = FT_Stream_Read( stream, (FT_Byte *)head, 16 );
+     if ( error )
+       return error;
+   
+     *rdata_pos = rfork_offset + ( ( head[0] << 24 ) |
+                                 ( head[1] << 16 ) |
+                                 ( head[2] <<  8 ) |
+                                 head[3]         );
+     map_pos   = rfork_offset + ( ( head[4] << 24 ) |
+                                ( head[5] << 16 ) |
+                                ( head[6] <<  8 ) |
+                                  head[7]         );
+     rdata_len = ( head[ 8] << 24 ) |
+       ( head[ 9] << 16 ) |
+       ( head[10] <<  8 ) |
+       head[11];
+ 
+     /* map_len = head[12] .. head[15] */    
+     
+     if ( *rdata_pos + rdata_len != map_pos || map_pos == rfork_offset )
+       return FT_Err_Unknown_File_Format;
+   
+     error = FT_Stream_Seek( stream, map_pos );
+     if ( error )
+       return error;
+     
+     head2[15] = (FT_Byte)( head[15] + 1 );       /* make it be different */
+ 
+     error = FT_Stream_Read( stream, (FT_Byte*)head2, 16 );
+     if ( error )
+       return error;
+   
+     allzeros = 1;
+     allmatch = 1;
+     for ( i = 0; i < 16; ++i )
+       {
+       if ( head2[i] != 0 )
+         allzeros = 0;
+       if ( head2[i] != head[i] )
+         allmatch = 0;
+       }
+     if ( !allzeros && !allmatch )
+       return FT_Err_Unknown_File_Format;
+ 
+     /* If we've gotten this far then it's probably a mac resource file. */
+     /* Now, does it contain any interesting resources?                  */
+     /* Skip handle to next resource map, the file resource number, and  */
+     /* attributes.                                                      */
+     (void)FT_STREAM_SKIP( 
+                        4      /* skip handle to next resource map */
+                        + 2    /* skip file resource number */
+                        + 2    /* skip attributes */
+                        );
+ 
+     if ( FT_READ_USHORT( type_list ) )
+       return error;
+     if ( type_list == -1 )
+       return FT_Err_Unknown_File_Format;
+     error = FT_Stream_Seek( stream, map_pos + type_list );
+     if ( error )
+       return error;
+     *map_offset = map_pos + type_list;
+     return FT_Err_Ok;
+   } 
+   
+   FT_BASE_DEF( FT_Error ) 
+   FT_Raccess_Get_DataOffsets  ( FT_Library           library,
+                               FT_Stream            stream,
+                               FT_Long              map_offset,
+                               FT_Long              rdata_pos,
+                               FT_Long              tag,
+                               FT_Long            **offsets,
+                               FT_Long             *count )
+   {
+     FT_Error       error;
+     int            i, j, cnt, subcnt;
+     FT_Long        tag_internal, rpos;
+     FT_Memory      memory = library->memory;
+     FT_Long        temp;
+     FT_Long        *offsets_internal;
+   
+     error = FT_Stream_Seek( stream, map_offset );
+     if ( error )
+       return error;
+   
+     if ( FT_READ_USHORT( cnt ) )
+       return error;
+     cnt++;
+ 
+     for ( i = 0; i < cnt; ++i )
+       {
+       if ( FT_READ_LONG( tag_internal ) ||
+            FT_READ_USHORT( subcnt )     ||
+            FT_READ_USHORT( rpos )   )
+         return error;
+ 
+       FT_TRACE2(( "Resource tags: %c%c%c%c\n", 
+                   (char)(0xff & (tag_internal >> 24)),
+                   (char)(0xff & (tag_internal >> 16)),
+                   (char)(0xff & (tag_internal >> 8)),
+                   (char)(0xff & (tag_internal >> 0)) ));
+       
+       if ( tag_internal == tag )
+         {
+           *count = subcnt + 1;
+           rpos  += map_offset;
+           error = FT_Stream_Seek( stream, rpos );
+           if ( error )
+             return error;
+         
+           if ( FT_ALLOC( offsets_internal, *count * sizeof( FT_Long ) ) )
+             return error;
+           for ( j = 0; j < *count; ++j )
+             {
+               (void)FT_STREAM_SKIP( 2 ); /* resource id */ 
+               (void)FT_STREAM_SKIP( 2 ); /* rsource name */
+               if ( FT_READ_LONG( temp ) )
+                 {
+                   FT_FREE( offsets_internal );
+                   return error;
+                 }
+               offsets_internal[j] = rdata_pos + ( temp & 0xFFFFFFL );
+               (void)FT_STREAM_SKIP( 4 ); /* mbz */ 
+             }
+           *offsets = offsets_internal;
+           return FT_Err_Ok;;
+         }
+       }
+     return FT_Err_Cannot_Open_Resource;
+   }
+ 
+ 
+ #ifdef FT_CONFIG_OPTION_GUESSING_EMBEDDED_RFORK
+ 
+   /*************************************************************************/
+   /*************************************************************************/
+   /*************************************************************************/
+   /****                                                                 ****/
+   /****                                                                 ****/
+   /****                     Guessing functions                          ****/
+   /****                                                                 ****/
+   /****            When you add a new guessing function,                ****/
+   /****           update FT_RACCESS_N_RUULES in ftraccess.h.            ****/
+   /****                                                                 ****/
+   /*************************************************************************/
+   /*************************************************************************/
+   /*************************************************************************/
+ 
+   typedef FT_Error (* raccess_guess_func)( FT_Library           library,
+                                          FT_Stream            stream,
+                                          char * base_file_name,
+                                          char ** result_file_name,
+                                          FT_Long *result_offset);
+ 
+   static FT_Error raccess_guess_apple_double( FT_Library           library,
+                                             FT_Stream            stream,
+                                             char  * base_file_name,
+                                             char ** result_file_name,
+                                             FT_Long *result_offset);
+   static FT_Error raccess_guess_apple_single( FT_Library           library,
+                                             FT_Stream            stream,
+                                             char  * base_file_name,
+                                             char ** result_file_name,
+                                             FT_Long *result_offset);
+   static FT_Error raccess_guess_darwin_ufs_export ( FT_Library           
library,
+                                                   FT_Stream            stream,
+                                                   char  * base_file_name,
+                                                   char ** result_file_name,
+                                                   FT_Long *result_offset);
+   static FT_Error raccess_guess_darwin_hfsplus ( FT_Library           library,
+                                                FT_Stream            stream,
+                                                char  * base_file_name,
+                                                char ** result_file_name,
+                                                FT_Long *result_offset);
+ 
+   static FT_Error raccess_guess_vfat ( FT_Library           library,
+                                      FT_Stream            stream,
+                                      char  * base_file_name,
+                                      char ** result_file_name,
+                                      FT_Long *result_offset);
+   static FT_Error raccess_guess_linux_cap ( FT_Library           library,
+                                           FT_Stream            stream,
+                                           char  * base_file_name,
+                                           char ** result_file_name,
+                                           FT_Long *result_offset);
+   static FT_Error raccess_guess_linux_double ( FT_Library           library,
+                                              FT_Stream            stream,
+                                              char  * base_file_name,
+                                              char ** result_file_name,
+                                              FT_Long *result_offset);
+   static FT_Error raccess_guess_linux_netatalk ( FT_Library           library,
+                                                FT_Stream            stream,
+                                                char  * base_file_name,
+                                                char ** result_file_name,
+                                                FT_Long *result_offset);
+ 
+   /*************************************************************************/
+   /****                                                                 ****/
+   /****                       Helper functions                          ****/
+   /****                                                                 ****/
+   /*************************************************************************/
+ 
+   static FT_Error raccess_guess_apple_generic( FT_Library           library,
+                                              FT_Stream            stream,
+                                              char  * base_file_name,
+                                              FT_Int32             magic,
+                                              FT_Long *result_offset);
+   static FT_Error raccess_guess_linux_double_from_file_name ( FT_Library 
library,
+                                                             char * file_name,
+                                                             FT_Long 
*result_offset );
+ 
+   static char* raccess_make_file_name( FT_Memory         memory,
+                                      const char        *original_name,
+                                      const char        *insertion);
+ 
+   FT_BASE_DEF( void )
+   FT_Raccess_Guess ( FT_Library           library,
+                    FT_Stream            stream,
+                    char*                base_name,
+                    char*                new_names[FT_RACCESS_N_RUULES],
+                    FT_Long              offsets[FT_RACCESS_N_RUULES],
+                    FT_Error             errors[FT_RACCESS_N_RUULES] )
+   {
+     FT_Long    i;
+     raccess_guess_func funcs[FT_RACCESS_N_RUULES] = 
+       { 
+       raccess_guess_apple_double,
+       raccess_guess_apple_single,
+       raccess_guess_darwin_ufs_export,
+       raccess_guess_darwin_hfsplus,
+       raccess_guess_vfat,
+       raccess_guess_linux_cap,
+       raccess_guess_linux_double,
+       raccess_guess_linux_netatalk,
+       };
+ 
+     for ( i = 0; i < FT_RACCESS_N_RUULES; i++ )
+       {
+       new_names[i] = NULL;
+       errors[i] = FT_Stream_Seek( stream, 0 );
+       if ( errors[i] )
+         continue ;
+       errors[i] = (funcs[i])(library, stream, base_name, &(new_names[i]), 
&(offsets[i]));
+       }
+     return;
+   }
+ 
+   static FT_Error
+   raccess_guess_apple_double( FT_Library           library,
+                             FT_Stream            stream,
+                             char  * base_file_name,
+                             char ** result_file_name,
+                             FT_Long *result_offset )
+   {
+     FT_Int32 magic = ((0x00 << 24 | 0x05 << 16 | 0x16 << 8 | 0x07));
+     *result_file_name = NULL;
+     return raccess_guess_apple_generic (library, stream, base_file_name, 
magic, result_offset);
+   }
+ 
+   static FT_Error
+   raccess_guess_apple_single( FT_Library           library,
+                             FT_Stream            stream,
+                             char  * base_file_name,
+                             char ** result_file_name,
+                             FT_Long *result_offset )
+   {
+     FT_Int32 magic   = ((0x00 << 24 | 0x05 << 16 | 0x16 << 8 | 0x00));
+     *result_file_name = NULL;
+     return raccess_guess_apple_generic (library, stream, base_file_name, 
magic, result_offset);
+   }
+ 
+   static FT_Error
+   raccess_guess_darwin_ufs_export ( FT_Library           library,
+                                   FT_Stream            stream,
+                                   char  * base_file_name,
+                                   char ** result_file_name,
+                                   FT_Long *result_offset)
+   {
+     char * newpath;
+     FT_Error error;
+     FT_Memory memory;
+ 
+     memory = library->memory;
+     newpath = raccess_make_file_name(memory, base_file_name, "._");
+     if ( !newpath )
+       return FT_Err_Out_Of_Memory;
+ 
+     error = raccess_guess_linux_double_from_file_name( library, newpath, 
result_offset);
+     if ( !error )
+       *result_file_name = newpath;
+     else
+       FT_FREE(newpath);
+ 
+     return error;
+   }
+ 
+   static FT_Error
+   raccess_guess_darwin_hfsplus ( FT_Library           library,
+                                FT_Stream            stream,
+                                char  * base_file_name,
+                                char ** result_file_name,
+                                FT_Long *result_offset)
+   {
+     /*
+       Only meaningful on systems with hfs+ drivers (or Macs)
+      */
+     FT_Error error;
+     char * newpath;
+     FT_Memory memory;
+     
+     memory  = library->memory;
+     if ( FT_ALLOC( newpath,
+                  ft_strlen( base_file_name ) + ft_strlen( "/rsrc" ) + 1 ) )
+       return error;
+     ft_strcpy( newpath, base_file_name );
+     ft_strcat( newpath, "/rsrc" );
+     *result_file_name = newpath;
+     *result_offset = 0;
+     return FT_Err_Ok;
+   }
+ 
+   static FT_Error
+   raccess_guess_vfat ( FT_Library           library,
+                      FT_Stream            stream,
+                      char  * base_file_name,
+                      char ** result_file_name,
+                      FT_Long *result_offset )
+   {
+     char * newpath;
+     FT_Memory     memory;
+ 
+     memory = library->memory;
+     newpath = raccess_make_file_name(memory, base_file_name, "resource.frk/");
+     if ( !newpath )
+       return FT_Err_Out_Of_Memory;
+     *result_file_name = newpath;
+     *result_offset = 0;
+     return FT_Err_Ok;
+   }
+ 
+   static FT_Error
+   raccess_guess_linux_cap ( FT_Library           library,
+                           FT_Stream            stream,
+                           char  * base_file_name,
+                           char ** result_file_name,
+                           FT_Long *result_offset )
+   {
+     char * newpath;
+     FT_Memory memory;
+ 
+     memory = library->memory;
+     newpath = raccess_make_file_name(memory, base_file_name, ".resource/");
+     if ( !newpath )
+       return FT_Err_Out_Of_Memory;
+     *result_file_name = newpath;
+     *result_offset = 0;
+     return FT_Err_Ok;
+   }
+ 
+   static FT_Error
+   raccess_guess_linux_double ( FT_Library           library,
+                              FT_Stream            stream,
+                              char  * base_file_name,
+                              char ** result_file_name,
+                              FT_Long *result_offset )
+   {
+     char * newpath;
+     FT_Error error;
+     FT_Memory memory;
+ 
+     memory = library->memory;
+     newpath = raccess_make_file_name(memory, base_file_name, "%");
+     if ( !newpath )
+       return FT_Err_Out_Of_Memory;
+ 
+     error = raccess_guess_linux_double_from_file_name( library, newpath, 
result_offset);
+     if ( !error )
+       *result_file_name = newpath;
+     else
+       FT_FREE(newpath);
+ 
+     return error;
+   }
+ 
+   static FT_Error
+   raccess_guess_linux_netatalk ( FT_Library           library,
+                                FT_Stream            stream,
+                                char  * base_file_name,
+                                char ** result_file_name,
+                                FT_Long *result_offset )
+   {
+     char * newpath;
+     FT_Error   error;
+     FT_Memory  memory;
+ 
+     memory = library->memory;
+     newpath = raccess_make_file_name(memory, base_file_name, ".AppleDouble/");
+     if ( !newpath )
+       return FT_Err_Out_Of_Memory;
+ 
+     error = raccess_guess_linux_double_from_file_name( library, newpath, 
result_offset);
+     if ( !error )
+       *result_file_name = newpath;
+     else
+       FT_FREE(newpath);
+ 
+     return error;
+   }
+ 
+   static FT_Error
+   raccess_guess_apple_generic( FT_Library           library,
+                              FT_Stream            stream,
+                              char  * base_file_name,
+                              FT_Int32             magic,
+                              FT_Long *result_offset)
+   {
+     FT_Int32 magic_from_stream;
+     FT_Error error;
+     FT_Int32 version_number;
+     FT_UShort n_of_entries;
+     int i;
+     FT_UInt32 entry_id, entry_offset, entry_length;
+     const FT_UInt32 resource_fork_entry_id = 0x2;
+ 
+     if ( FT_READ_LONG ( magic_from_stream ) )
+       return error;
+     if ( magic_from_stream != magic )
+       return FT_Err_Unknown_File_Format;
+ 
+     if ( FT_READ_LONG(version_number) )
+       return error;
+ 
+     /* filler */
+     error = FT_Stream_Skip( stream, 16 );
+     if ( error )
+       return error;
+ 
+     if ( FT_READ_USHORT ( n_of_entries ) )
+       return error;
+     if ( n_of_entries == 0 )
+       return FT_Err_Unknown_File_Format;
+ 
+     for ( i = 0; i < n_of_entries; i++ )
+       {
+       if ( FT_READ_LONG(entry_id) )
+         return error;
+       if ( entry_id == resource_fork_entry_id )
+         {
+           if ( FT_READ_LONG (entry_offset) ||
+                FT_READ_LONG (entry_length) )
+             continue;
+           *result_offset = entry_offset;
+           return FT_Err_Ok;
+         }
+       else
+         FT_Stream_Skip( stream, 4 + 4 ); /* offset + length */
+       }
+     return FT_Err_Unknown_File_Format;
+   }
+ 
+   static FT_Error
+   raccess_guess_linux_double_from_file_name ( FT_Library library,
+                                             char * file_name,
+                                             FT_Long *result_offset )
+   {
+     FT_Memory  memory;
+     FT_Open_Args  args2;
+     FT_Stream stream2;
+     char * nouse = NULL;
+     FT_Error error;
+ 
+     memory = library->memory;
+     args2.flags = FT_OPEN_PATHNAME;
+     args2.pathname = file_name;
+     error = ft_input_stream_new( library, &args2, &stream2 );
+     if ( error )
+       return error;
+ 
+     error = raccess_guess_apple_double (library, stream2, file_name,
+                                       &nouse, result_offset);
+ 
+     FT_Stream_Close( stream2 );
+     return error;
+   }
+ 
+ 
+   static char*
+   raccess_make_file_name( FT_Memory         memory,
+                         const char        *original_name,
+                         const char        *insertion )
+   {
+     char * new_name;
+     char * tmp;
+     const char * slash;
+     unsigned new_length;
+     FT_ULong error;
+ 
+     new_length = ft_strlen(original_name) + ft_strlen(insertion);
+     if ( FT_ALLOC(new_name, new_length + 1 ) )
+       return NULL;
+ 
+     tmp = ft_strrchr(original_name, '/');  
+     if (tmp)
+       {
+       ft_strncpy(new_name, original_name, tmp - original_name + 1);
+       new_name[tmp - original_name + 1] = '\0';
+       slash = tmp + 1;
+       }
+     else
+       {
+       slash     = original_name;
+       new_name[0] = '\0';
+       }
+     ft_strcat(new_name, insertion);
+     ft_strcat(new_name, slash);
+     return new_name;
+   }
+ #else 
+ /***************************************************************************/
+ /*                  Dummy function just sets errors                        */
+ /***************************************************************************/
+   FT_BASE_DEF( void )
+   FT_Raccess_Guess ( FT_Library           library,
+                    FT_Stream            stream,
+                    char*                base_name,
+                    char*                new_names[FT_RACCESS_N_RUULES],
+                    FT_Long              offsets[FT_RACCESS_N_RUULES],
+                    FT_Error             errors[FT_RACCESS_N_RUULES] )
+   {
+     int i;
+     for ( i = 0; i < FT_RACCESS_N_RUULES; i++ )
+       {
+       new_names[i] = NULL;
+       offsets[i]   = 0;
+       errors[i]    = FT_Err_Unimplemented_Feature;
+       }
+   }
+ #endif  /* FT_CONFIG_OPTION_GUESSING_EMBEDDED_RFORK */
+ 
+ 
+ /* END */
diff -c -r --exclude='*.o' --exclude=config.log --exclude=TAGS 
--exclude=cscope.files --exclude=cscope.out --exclude=CVS --exclude=.cvsignore 
--exclude=stamp-vti --exclude=version.texi --exclude='.#*' --exclude='*~' 
--exclude='*.orig' --exclude='automake.info*' --exclude=aclocal 
--exclude=autom4te.cache --exclude=automake --exclude=config.status 
--exclude=Makefile --exclude=samples --exclude=amversion.m4 
--exclude=automake-1.5e --new-file freetype2/src/base/rules.mk 
freetype2.new/src/base/rules.mk
*** freetype2/src/base/rules.mk 2003-06-09 13:46:27.000000000 +0900
--- freetype2.new/src/base/rules.mk     2004-02-17 18:47:23.000000000 +0900
***************
*** 41,47 ****
              $(BASE_DIR)/ftobjs.c   \
              $(BASE_DIR)/ftapi.c    \
              $(BASE_DIR)/ftnames.c  \
!             $(BASE_DIR)/ftdbgmem.c
  
  # Base layer `extensions' sources
  #
--- 41,48 ----
              $(BASE_DIR)/ftobjs.c   \
              $(BASE_DIR)/ftapi.c    \
              $(BASE_DIR)/ftnames.c  \
!             $(BASE_DIR)/ftdbgmem.c \
!             $(BASE_DIR)/ftraccess.c
  
  # Base layer `extensions' sources
  #

reply via email to

[Prev in Thread] Current Thread [Next in Thread]