1 /****************************************************************************
   2  *
   3  * ftdrv.h
   4  *
   5  *   FreeType internal font driver interface (specification).
   6  *
   7  * Copyright (C) 1996-2019 by
   8  * David Turner, Robert Wilhelm, and Werner Lemberg.
   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 #ifndef FTDRV_H_
  20 #define FTDRV_H_
  21 
  22 
  23 #include <ft2build.h>
  24 #include FT_MODULE_H
  25 
  26 
  27 FT_BEGIN_HEADER
  28 
  29 
  30   typedef FT_Error
  31   (*FT_Face_InitFunc)( FT_Stream      stream,
  32                        FT_Face        face,
  33                        FT_Int         typeface_index,
  34                        FT_Int         num_params,
  35                        FT_Parameter*  parameters );
  36 
  37   typedef void
  38   (*FT_Face_DoneFunc)( FT_Face  face );
  39 
  40 
  41   typedef FT_Error
  42   (*FT_Size_InitFunc)( FT_Size  size );
  43 
  44   typedef void
  45   (*FT_Size_DoneFunc)( FT_Size  size );
  46 
  47 
  48   typedef FT_Error
  49   (*FT_Slot_InitFunc)( FT_GlyphSlot  slot );
  50 
  51   typedef void
  52   (*FT_Slot_DoneFunc)( FT_GlyphSlot  slot );
  53 
  54 
  55   typedef FT_Error
  56   (*FT_Size_RequestFunc)( FT_Size          size,
  57                           FT_Size_Request  req );
  58 
  59   typedef FT_Error
  60   (*FT_Size_SelectFunc)( FT_Size   size,
  61                          FT_ULong  size_index );
  62 
  63   typedef FT_Error
  64   (*FT_Slot_LoadFunc)( FT_GlyphSlot  slot,
  65                        FT_Size       size,
  66                        FT_UInt       glyph_index,
  67                        FT_Int32      load_flags );
  68 
  69 
  70   typedef FT_Error
  71   (*FT_Face_GetKerningFunc)( FT_Face     face,
  72                              FT_UInt     left_glyph,
  73                              FT_UInt     right_glyph,
  74                              FT_Vector*  kerning );
  75 
  76 
  77   typedef FT_Error
  78   (*FT_Face_AttachFunc)( FT_Face    face,
  79                          FT_Stream  stream );
  80 
  81 
  82   typedef FT_Error
  83   (*FT_Face_GetAdvancesFunc)( FT_Face    face,
  84                               FT_UInt    first,
  85                               FT_UInt    count,
  86                               FT_Int32   flags,
  87                               FT_Fixed*  advances );
  88 
  89 
  90   /**************************************************************************
  91    *
  92    * @struct:
  93    *   FT_Driver_ClassRec
  94    *
  95    * @description:
  96    *   The font driver class.  This structure mostly contains pointers to
  97    *   driver methods.
  98    *
  99    * @fields:
 100    *   root ::
 101    *     The parent module.
 102    *
 103    *   face_object_size ::
 104    *     The size of a face object in bytes.
 105    *
 106    *   size_object_size ::
 107    *     The size of a size object in bytes.
 108    *
 109    *   slot_object_size ::
 110    *     The size of a glyph object in bytes.
 111    *
 112    *   init_face ::
 113    *     The format-specific face constructor.
 114    *
 115    *   done_face ::
 116    *     The format-specific face destructor.
 117    *
 118    *   init_size ::
 119    *     The format-specific size constructor.
 120    *
 121    *   done_size ::
 122    *     The format-specific size destructor.
 123    *
 124    *   init_slot ::
 125    *     The format-specific slot constructor.
 126    *
 127    *   done_slot ::
 128    *     The format-specific slot destructor.
 129    *
 130    *
 131    *   load_glyph ::
 132    *     A function handle to load a glyph to a slot.  This field is
 133    *     mandatory!
 134    *
 135    *   get_kerning ::
 136    *     A function handle to return the unscaled kerning for a given pair of
 137    *     glyphs.  Can be set to 0 if the format doesn't support kerning.
 138    *
 139    *   attach_file ::
 140    *     This function handle is used to read additional data for a face from
 141    *     another file/stream.  For example, this can be used to add data from
 142    *     AFM or PFM files on a Type 1 face, or a CIDMap on a CID-keyed face.
 143    *
 144    *   get_advances ::
 145    *     A function handle used to return advance widths of 'count' glyphs
 146    *     (in font units), starting at 'first'.  The 'vertical' flag must be
 147    *     set to get vertical advance heights.  The 'advances' buffer is
 148    *     caller-allocated.  The idea of this function is to be able to
 149    *     perform device-independent text layout without loading a single
 150    *     glyph image.
 151    *
 152    *   request_size ::
 153    *     A handle to a function used to request the new character size.  Can
 154    *     be set to 0 if the scaling done in the base layer suffices.
 155    *
 156    *   select_size ::
 157    *     A handle to a function used to select a new fixed size.  It is used
 158    *     only if @FT_FACE_FLAG_FIXED_SIZES is set.  Can be set to 0 if the
 159    *     scaling done in the base layer suffices.
 160    * @note:
 161    *   Most function pointers, with the exception of `load_glyph`, can be set
 162    *   to 0 to indicate a default behaviour.
 163    */
 164   typedef struct  FT_Driver_ClassRec_
 165   {
 166     FT_Module_Class          root;
 167 
 168     FT_Long                  face_object_size;
 169     FT_Long                  size_object_size;
 170     FT_Long                  slot_object_size;
 171 
 172     FT_Face_InitFunc         init_face;
 173     FT_Face_DoneFunc         done_face;
 174 
 175     FT_Size_InitFunc         init_size;
 176     FT_Size_DoneFunc         done_size;
 177 
 178     FT_Slot_InitFunc         init_slot;
 179     FT_Slot_DoneFunc         done_slot;
 180 
 181     FT_Slot_LoadFunc         load_glyph;
 182 
 183     FT_Face_GetKerningFunc   get_kerning;
 184     FT_Face_AttachFunc       attach_file;
 185     FT_Face_GetAdvancesFunc  get_advances;
 186 
 187     /* since version 2.2 */
 188     FT_Size_RequestFunc      request_size;
 189     FT_Size_SelectFunc       select_size;
 190 
 191   } FT_Driver_ClassRec, *FT_Driver_Class;
 192 
 193 
 194   /**************************************************************************
 195    *
 196    * @macro:
 197    *   FT_DECLARE_DRIVER
 198    *
 199    * @description:
 200    *   Used to create a forward declaration of an FT_Driver_ClassRec struct
 201    *   instance.
 202    *
 203    * @macro:
 204    *   FT_DEFINE_DRIVER
 205    *
 206    * @description:
 207    *   Used to initialize an instance of FT_Driver_ClassRec struct.
 208    *
 209    *   `ftinit.c` (ft_create_default_module_classes) already contains a
 210    *   mechanism to call these functions for the default modules described in
 211    *   `ftmodule.h`.
 212    *
 213    *   The struct will be allocated in the global scope (or the scope where
 214    *   the macro is used).
 215    */
 216 #define FT_DECLARE_DRIVER( class_ )  \
 217   FT_CALLBACK_TABLE                  \
 218   const FT_Driver_ClassRec  class_;
 219 
 220 #define FT_DEFINE_DRIVER(                    \
 221           class_,                            \
 222           flags_,                            \
 223           size_,                             \
 224           name_,                             \
 225           version_,                          \
 226           requires_,                         \
 227           interface_,                        \
 228           init_,                             \
 229           done_,                             \
 230           get_interface_,                    \
 231           face_object_size_,                 \
 232           size_object_size_,                 \
 233           slot_object_size_,                 \
 234           init_face_,                        \
 235           done_face_,                        \
 236           init_size_,                        \
 237           done_size_,                        \
 238           init_slot_,                        \
 239           done_slot_,                        \
 240           load_glyph_,                       \
 241           get_kerning_,                      \
 242           attach_file_,                      \
 243           get_advances_,                     \
 244           request_size_,                     \
 245           select_size_ )                     \
 246   FT_CALLBACK_TABLE_DEF                      \
 247   const FT_Driver_ClassRec  class_ =         \
 248   {                                          \
 249     FT_DEFINE_ROOT_MODULE( flags_,           \
 250                            size_,            \
 251                            name_,            \
 252                            version_,         \
 253                            requires_,        \
 254                            interface_,       \
 255                            init_,            \
 256                            done_,            \
 257                            get_interface_ )  \
 258                                              \
 259     face_object_size_,                       \
 260     size_object_size_,                       \
 261     slot_object_size_,                       \
 262                                              \
 263     init_face_,                              \
 264     done_face_,                              \
 265                                              \
 266     init_size_,                              \
 267     done_size_,                              \
 268                                              \
 269     init_slot_,                              \
 270     done_slot_,                              \
 271                                              \
 272     load_glyph_,                             \
 273                                              \
 274     get_kerning_,                            \
 275     attach_file_,                            \
 276     get_advances_,                           \
 277                                              \
 278     request_size_,                           \
 279     select_size_                             \
 280   };
 281 
 282 
 283 FT_END_HEADER
 284 
 285 #endif /* FTDRV_H_ */
 286 
 287 
 288 /* END */