Home | History | Annotate | Download | only in internal
      1 /****************************************************************************
      2  *
      3  * ftrfork.h
      4  *
      5  *   Embedded resource forks accessor (specification).
      6  *
      7  * Copyright 2004-2018 by
      8  * Masatake YAMATO and Redhat K.K.
      9  *
     10  * This file is part of the FreeType project, and may only be used,
     11  * modified, and distributed under the terms of the FreeType project
     12  * license, LICENSE.TXT.  By continuing to use, modify, or distribute
     13  * this file you indicate that you have read the license and
     14  * understand and accept it fully.
     15  *
     16  */
     17 
     18 /****************************************************************************
     19  * Development of the code in this file is support of
     20  * Information-technology Promotion Agency, Japan.
     21  */
     22 
     23 
     24 #ifndef FTRFORK_H_
     25 #define FTRFORK_H_
     26 
     27 
     28 #include <ft2build.h>
     29 #include FT_INTERNAL_OBJECTS_H
     30 
     31 
     32 FT_BEGIN_HEADER
     33 
     34 
     35   /* Number of guessing rules supported in `FT_Raccess_Guess'.            */
     36   /* Don't forget to increment the number if you add a new guessing rule. */
     37 #define FT_RACCESS_N_RULES  9
     38 
     39 
     40   /* A structure to describe a reference in a resource by its resource ID */
     41   /* and internal offset.  The `POST' resource expects to be concatenated */
     42   /* by the order of resource IDs instead of its appearance in the file.  */
     43 
     44   typedef struct  FT_RFork_Ref_
     45   {
     46     FT_Short  res_id;
     47     FT_Long   offset;
     48 
     49   } FT_RFork_Ref;
     50 
     51 
     52 #ifdef FT_CONFIG_OPTION_GUESSING_EMBEDDED_RFORK
     53   typedef FT_Error
     54   (*ft_raccess_guess_func)( FT_Library  library,
     55                             FT_Stream   stream,
     56                             char       *base_file_name,
     57                             char      **result_file_name,
     58                             FT_Long    *result_offset );
     59 
     60   typedef enum  FT_RFork_Rule_ {
     61     FT_RFork_Rule_invalid = -2,
     62     FT_RFork_Rule_uknown, /* -1 */
     63     FT_RFork_Rule_apple_double,
     64     FT_RFork_Rule_apple_single,
     65     FT_RFork_Rule_darwin_ufs_export,
     66     FT_RFork_Rule_darwin_newvfs,
     67     FT_RFork_Rule_darwin_hfsplus,
     68     FT_RFork_Rule_vfat,
     69     FT_RFork_Rule_linux_cap,
     70     FT_RFork_Rule_linux_double,
     71     FT_RFork_Rule_linux_netatalk
     72   } FT_RFork_Rule;
     73 
     74   /* For fast translation between rule index and rule type,
     75    * the macros FT_RFORK_xxx should be kept consistent with
     76    * the raccess_guess_funcs table
     77    */
     78   typedef struct ft_raccess_guess_rec_ {
     79     ft_raccess_guess_func  func;
     80     FT_RFork_Rule          type;
     81   } ft_raccess_guess_rec;
     82 
     83 
     84 #define CONST_FT_RFORK_RULE_ARRAY_BEGIN( name, type )  \
     85           static const type name[] = {
     86 #define CONST_FT_RFORK_RULE_ARRAY_ENTRY( func_suffix, type_suffix )  \
     87           { raccess_guess_ ## func_suffix,                           \
     88             FT_RFork_Rule_ ## type_suffix },
     89   /* this array is a storage, thus a final `;' is needed */
     90 #define CONST_FT_RFORK_RULE_ARRAY_END  };
     91 
     92 #endif /* FT_CONFIG_OPTION_GUESSING_EMBEDDED_RFORK */
     93 
     94 
     95   /**************************************************************************
     96    *
     97    * @function:
     98    *   FT_Raccess_Guess
     99    *
    100    * @description:
    101    *   Guess a file name and offset where the actual resource fork is
    102    *   stored.  The macro FT_RACCESS_N_RULES holds the number of
    103    *   guessing rules;  the guessed result for the Nth rule is
    104    *   represented as a triplet: a new file name (new_names[N]), a file
    105    *   offset (offsets[N]), and an error code (errors[N]).
    106    *
    107    * @input:
    108    *   library ::
    109    *     A FreeType library instance.
    110    *
    111    *   stream ::
    112    *     A file stream containing the resource fork.
    113    *
    114    *   base_name ::
    115    *     The (base) file name of the resource fork used for some
    116    *     guessing rules.
    117    *
    118    * @output:
    119    *   new_names ::
    120    *     An array of guessed file names in which the resource forks may
    121    *     exist.  If `new_names[N]' is NULL, the guessed file name is
    122    *     equal to `base_name'.
    123    *
    124    *   offsets ::
    125    *     An array of guessed file offsets.  `offsets[N]' holds the file
    126    *     offset of the possible start of the resource fork in file
    127    *     `new_names[N]'.
    128    *
    129    *   errors ::
    130    *     An array of FreeType error codes.  `errors[N]' is the error
    131    *     code of Nth guessing rule function.  If `errors[N]' is not
    132    *     FT_Err_Ok, `new_names[N]' and `offsets[N]' are meaningless.
    133    */
    134   FT_BASE( void )
    135   FT_Raccess_Guess( FT_Library  library,
    136                     FT_Stream   stream,
    137                     char*       base_name,
    138                     char**      new_names,
    139                     FT_Long*    offsets,
    140                     FT_Error*   errors );
    141 
    142 
    143   /**************************************************************************
    144    *
    145    * @function:
    146    *   FT_Raccess_Get_HeaderInfo
    147    *
    148    * @description:
    149    *   Get the information from the header of resource fork.  The
    150    *   information includes the file offset where the resource map
    151    *   starts, and the file offset where the resource data starts.
    152    *   `FT_Raccess_Get_DataOffsets' requires these two data.
    153    *
    154    * @input:
    155    *   library ::
    156    *     A FreeType library instance.
    157    *
    158    *   stream ::
    159    *     A file stream containing the resource fork.
    160    *
    161    *   rfork_offset ::
    162    *     The file offset where the resource fork starts.
    163    *
    164    * @output:
    165    *   map_offset ::
    166    *     The file offset where the resource map starts.
    167    *
    168    *   rdata_pos ::
    169    *     The file offset where the resource data starts.
    170    *
    171    * @return:
    172    *   FreeType error code.  FT_Err_Ok means success.
    173    */
    174   FT_BASE( FT_Error )
    175   FT_Raccess_Get_HeaderInfo( FT_Library  library,
    176                              FT_Stream   stream,
    177                              FT_Long     rfork_offset,
    178                              FT_Long    *map_offset,
    179                              FT_Long    *rdata_pos );
    180 
    181 
    182   /**************************************************************************
    183    *
    184    * @function:
    185    *   FT_Raccess_Get_DataOffsets
    186    *
    187    * @description:
    188    *   Get the data offsets for a tag in a resource fork.  Offsets are
    189    *   stored in an array because, in some cases, resources in a resource
    190    *   fork have the same tag.
    191    *
    192    * @input:
    193    *   library ::
    194    *     A FreeType library instance.
    195    *
    196    *   stream ::
    197    *     A file stream containing the resource fork.
    198    *
    199    *   map_offset ::
    200    *     The file offset where the resource map starts.
    201    *
    202    *   rdata_pos ::
    203    *     The file offset where the resource data starts.
    204    *
    205    *   tag ::
    206    *     The resource tag.
    207    *
    208    *   sort_by_res_id ::
    209    *     A Boolean to sort the fragmented resource by their ids.
    210    *     The fragmented resources for `POST' resource should be sorted
    211    *     to restore Type1 font properly.  For `sfnt' resources, sorting
    212    *     may induce a different order of the faces in comparison to that
    213    *     by QuickDraw API.
    214    *
    215    * @output:
    216    *   offsets ::
    217    *     The stream offsets for the resource data specified by `tag'.
    218    *     This array is allocated by the function, so you have to call
    219    *     @ft_mem_free after use.
    220    *
    221    *   count ::
    222    *     The length of offsets array.
    223    *
    224    * @return:
    225    *   FreeType error code.  FT_Err_Ok means success.
    226    *
    227    * @note:
    228    *   Normally you should use `FT_Raccess_Get_HeaderInfo' to get the
    229    *   value for `map_offset' and `rdata_pos'.
    230    */
    231   FT_BASE( FT_Error )
    232   FT_Raccess_Get_DataOffsets( FT_Library  library,
    233                               FT_Stream   stream,
    234                               FT_Long     map_offset,
    235                               FT_Long     rdata_pos,
    236                               FT_Long     tag,
    237                               FT_Bool     sort_by_res_id,
    238                               FT_Long   **offsets,
    239                               FT_Long    *count );
    240 
    241 
    242 FT_END_HEADER
    243 
    244 #endif /* FTRFORK_H_ */
    245 
    246 
    247 /* END */
    248