Home | History | Annotate | Download | only in freetype
      1 /****************************************************************************
      2  *
      3  * ftmodapi.h
      4  *
      5  *   FreeType modules public interface (specification).
      6  *
      7  * Copyright 1996-2018 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 FTMODAPI_H_
     20 #define FTMODAPI_H_
     21 
     22 
     23 #include <ft2build.h>
     24 #include FT_FREETYPE_H
     25 
     26 #ifdef FREETYPE_H
     27 #error "freetype.h of FreeType 1 has been loaded!"
     28 #error "Please fix the directory search order for header files"
     29 #error "so that freetype.h of FreeType 2 is found first."
     30 #endif
     31 
     32 
     33 FT_BEGIN_HEADER
     34 
     35 
     36   /**************************************************************************
     37    *
     38    * @section:
     39    *   module_management
     40    *
     41    * @title:
     42    *   Module Management
     43    *
     44    * @abstract:
     45    *   How to add, upgrade, remove, and control modules from FreeType.
     46    *
     47    * @description:
     48    *   The definitions below are used to manage modules within FreeType.
     49    *   Modules can be added, upgraded, and removed at runtime.
     50    *   Additionally, some module properties can be controlled also.
     51    *
     52    *   Here is a list of possible values of the `module_name' field in
     53    *   the @FT_Module_Class structure.
     54    *
     55    *   {
     56    *     autofitter
     57    *     bdf
     58    *     cff
     59    *     gxvalid
     60    *     otvalid
     61    *     pcf
     62    *     pfr
     63    *     psaux
     64    *     pshinter
     65    *     psnames
     66    *     raster1
     67    *     sfnt
     68    *     smooth, smooth-lcd, smooth-lcdv
     69    *     truetype
     70    *     type1
     71    *     type42
     72    *     t1cid
     73    *     winfonts
     74    *   }
     75    *
     76    *   Note that the FreeType Cache sub-system is not a FreeType module.
     77    *
     78    * @order:
     79    *   FT_Module
     80    *   FT_Module_Constructor
     81    *   FT_Module_Destructor
     82    *   FT_Module_Requester
     83    *   FT_Module_Class
     84    *
     85    *   FT_Add_Module
     86    *   FT_Get_Module
     87    *   FT_Remove_Module
     88    *   FT_Add_Default_Modules
     89    *
     90    *   FT_Property_Set
     91    *   FT_Property_Get
     92    *   FT_Set_Default_Properties
     93    *
     94    *   FT_New_Library
     95    *   FT_Done_Library
     96    *   FT_Reference_Library
     97    *
     98    *   FT_Renderer
     99    *   FT_Renderer_Class
    100    *
    101    *   FT_Get_Renderer
    102    *   FT_Set_Renderer
    103    *
    104    *   FT_Set_Debug_Hook
    105    *
    106    */
    107 
    108 
    109   /* module bit flags */
    110 #define FT_MODULE_FONT_DRIVER         1  /* this module is a font driver  */
    111 #define FT_MODULE_RENDERER            2  /* this module is a renderer     */
    112 #define FT_MODULE_HINTER              4  /* this module is a glyph hinter */
    113 #define FT_MODULE_STYLER              8  /* this module is a styler       */
    114 
    115 #define FT_MODULE_DRIVER_SCALABLE      0x100  /* the driver supports      */
    116                                               /* scalable fonts           */
    117 #define FT_MODULE_DRIVER_NO_OUTLINES   0x200  /* the driver does not      */
    118                                               /* support vector outlines  */
    119 #define FT_MODULE_DRIVER_HAS_HINTER    0x400  /* the driver provides its  */
    120                                               /* own hinter               */
    121 #define FT_MODULE_DRIVER_HINTS_LIGHTLY 0x800  /* the driver's hinter      */
    122                                               /* produces LIGHT hints     */
    123 
    124 
    125   /* deprecated values */
    126 #define ft_module_font_driver         FT_MODULE_FONT_DRIVER
    127 #define ft_module_renderer            FT_MODULE_RENDERER
    128 #define ft_module_hinter              FT_MODULE_HINTER
    129 #define ft_module_styler              FT_MODULE_STYLER
    130 
    131 #define ft_module_driver_scalable       FT_MODULE_DRIVER_SCALABLE
    132 #define ft_module_driver_no_outlines    FT_MODULE_DRIVER_NO_OUTLINES
    133 #define ft_module_driver_has_hinter     FT_MODULE_DRIVER_HAS_HINTER
    134 #define ft_module_driver_hints_lightly  FT_MODULE_DRIVER_HINTS_LIGHTLY
    135 
    136 
    137   typedef FT_Pointer  FT_Module_Interface;
    138 
    139 
    140   /**************************************************************************
    141    *
    142    * @functype:
    143    *   FT_Module_Constructor
    144    *
    145    * @description:
    146    *   A function used to initialize (not create) a new module object.
    147    *
    148    * @input:
    149    *   module ::
    150    *     The module to initialize.
    151    */
    152   typedef FT_Error
    153   (*FT_Module_Constructor)( FT_Module  module );
    154 
    155 
    156   /**************************************************************************
    157    *
    158    * @functype:
    159    *   FT_Module_Destructor
    160    *
    161    * @description:
    162    *   A function used to finalize (not destroy) a given module object.
    163    *
    164    * @input:
    165    *   module ::
    166    *     The module to finalize.
    167    */
    168   typedef void
    169   (*FT_Module_Destructor)( FT_Module  module );
    170 
    171 
    172   /**************************************************************************
    173    *
    174    * @functype:
    175    *   FT_Module_Requester
    176    *
    177    * @description:
    178    *   A function used to query a given module for a specific interface.
    179    *
    180    * @input:
    181    *   module ::
    182    *     The module to be searched.
    183    *
    184    *   name ::
    185    *     The name of the interface in the module.
    186    */
    187   typedef FT_Module_Interface
    188   (*FT_Module_Requester)( FT_Module    module,
    189                           const char*  name );
    190 
    191 
    192   /**************************************************************************
    193    *
    194    * @struct:
    195    *   FT_Module_Class
    196    *
    197    * @description:
    198    *   The module class descriptor.  While being a public structure
    199    *   necessary for FreeType's module bookkeeping, most of the fields are
    200    *   essentially internal, not to be used directly by an application.
    201    *
    202    * @fields:
    203    *   module_flags ::
    204    *     Bit flags describing the module.
    205    *
    206    *   module_size ::
    207    *     The size of one module object/instance in bytes.
    208    *
    209    *   module_name ::
    210    *     The name of the module.
    211    *
    212    *   module_version ::
    213    *     The version, as a 16.16 fixed number (major.minor).
    214    *
    215    *   module_requires ::
    216    *     The version of FreeType this module requires, as a 16.16 fixed
    217    *     number (major.minor).  Starts at version 2.0, i.e., 0x20000.
    218    *
    219    *   module_interface ::
    220    *     A typeless pointer to a structure (which varies between different
    221    *     modules) that holds the module's interface functions.  This is
    222    *     essentially what `get_interface' returns.
    223    *
    224    *   module_init ::
    225    *     The initializing function.
    226    *
    227    *   module_done ::
    228    *     The finalizing function.
    229    *
    230    *   get_interface ::
    231    *     The interface requesting function.
    232    */
    233   typedef struct  FT_Module_Class_
    234   {
    235     FT_ULong               module_flags;
    236     FT_Long                module_size;
    237     const FT_String*       module_name;
    238     FT_Fixed               module_version;
    239     FT_Fixed               module_requires;
    240 
    241     const void*            module_interface;
    242 
    243     FT_Module_Constructor  module_init;
    244     FT_Module_Destructor   module_done;
    245     FT_Module_Requester    get_interface;
    246 
    247   } FT_Module_Class;
    248 
    249 
    250   /**************************************************************************
    251    *
    252    * @function:
    253    *   FT_Add_Module
    254    *
    255    * @description:
    256    *   Add a new module to a given library instance.
    257    *
    258    * @inout:
    259    *   library ::
    260    *     A handle to the library object.
    261    *
    262    * @input:
    263    *   clazz ::
    264    *     A pointer to class descriptor for the module.
    265    *
    266    * @return:
    267    *   FreeType error code.  0~means success.
    268    *
    269    * @note:
    270    *   An error will be returned if a module already exists by that name,
    271    *   or if the module requires a version of FreeType that is too great.
    272    */
    273   FT_EXPORT( FT_Error )
    274   FT_Add_Module( FT_Library              library,
    275                  const FT_Module_Class*  clazz );
    276 
    277 
    278   /**************************************************************************
    279    *
    280    * @function:
    281    *   FT_Get_Module
    282    *
    283    * @description:
    284    *   Find a module by its name.
    285    *
    286    * @input:
    287    *   library ::
    288    *     A handle to the library object.
    289    *
    290    *   module_name ::
    291    *     The module's name (as an ASCII string).
    292    *
    293    * @return:
    294    *   A module handle.  0~if none was found.
    295    *
    296    * @note:
    297    *   FreeType's internal modules aren't documented very well, and you
    298    *   should look up the source code for details.
    299    */
    300   FT_EXPORT( FT_Module )
    301   FT_Get_Module( FT_Library   library,
    302                  const char*  module_name );
    303 
    304 
    305   /**************************************************************************
    306    *
    307    * @function:
    308    *   FT_Remove_Module
    309    *
    310    * @description:
    311    *   Remove a given module from a library instance.
    312    *
    313    * @inout:
    314    *   library ::
    315    *     A handle to a library object.
    316    *
    317    * @input:
    318    *   module ::
    319    *     A handle to a module object.
    320    *
    321    * @return:
    322    *   FreeType error code.  0~means success.
    323    *
    324    * @note:
    325    *   The module object is destroyed by the function in case of success.
    326    */
    327   FT_EXPORT( FT_Error )
    328   FT_Remove_Module( FT_Library  library,
    329                     FT_Module   module );
    330 
    331 
    332   /**********************************************************************
    333    *
    334    * @function:
    335    *    FT_Property_Set
    336    *
    337    * @description:
    338    *    Set a property for a given module.
    339    *
    340    * @input:
    341    *    library ::
    342    *      A handle to the library the module is part of.
    343    *
    344    *    module_name ::
    345    *      The module name.
    346    *
    347    *    property_name ::
    348    *      The property name.  Properties are described in section
    349    *      @properties.
    350    *
    351    *      Note that only a few modules have properties.
    352    *
    353    *    value ::
    354    *      A generic pointer to a variable or structure that gives the new
    355    *      value of the property.  The exact definition of `value' is
    356    *      dependent on the property; see section @properties.
    357    *
    358    * @return:
    359    *   FreeType error code.  0~means success.
    360    *
    361    * @note:
    362    *    If `module_name' isn't a valid module name, or `property_name'
    363    *    doesn't specify a valid property, or if `value' doesn't represent a
    364    *    valid value for the given property, an error is returned.
    365    *
    366    *    The following example sets property `bar' (a simple integer) in
    367    *    module `foo' to value~1.
    368    *
    369    *    {
    370    *      FT_UInt  bar;
    371    *
    372    *
    373    *      bar = 1;
    374    *      FT_Property_Set( library, "foo", "bar", &bar );
    375    *    }
    376    *
    377    *    Note that the FreeType Cache sub-system doesn't recognize module
    378    *    property changes.  To avoid glyph lookup confusion within the cache
    379    *    you should call @FTC_Manager_Reset to completely flush the cache if
    380    *    a module property gets changed after @FTC_Manager_New has been
    381    *    called.
    382    *
    383    *    It is not possible to set properties of the FreeType Cache
    384    *    sub-system itself with FT_Property_Set; use @FTC_Property_Set
    385    *    instead.
    386    *
    387    * @since:
    388    *   2.4.11
    389    *
    390    */
    391   FT_EXPORT( FT_Error )
    392   FT_Property_Set( FT_Library        library,
    393                    const FT_String*  module_name,
    394                    const FT_String*  property_name,
    395                    const void*       value );
    396 
    397 
    398   /**********************************************************************
    399    *
    400    * @function:
    401    *    FT_Property_Get
    402    *
    403    * @description:
    404    *    Get a module's property value.
    405    *
    406    * @input:
    407    *    library ::
    408    *      A handle to the library the module is part of.
    409    *
    410    *    module_name ::
    411    *      The module name.
    412    *
    413    *    property_name ::
    414    *      The property name.  Properties are described in section
    415    *      @properties.
    416    *
    417    * @inout:
    418    *    value ::
    419    *      A generic pointer to a variable or structure that gives the
    420    *      value of the property.  The exact definition of `value' is
    421    *      dependent on the property; see section @properties.
    422    *
    423    * @return:
    424    *   FreeType error code.  0~means success.
    425    *
    426    * @note:
    427    *    If `module_name' isn't a valid module name, or `property_name'
    428    *    doesn't specify a valid property, or if `value' doesn't represent a
    429    *    valid value for the given property, an error is returned.
    430    *
    431    *    The following example gets property `baz' (a range) in module `foo'.
    432    *
    433    *    {
    434    *      typedef  range_
    435    *      {
    436    *        FT_Int32  min;
    437    *        FT_Int32  max;
    438    *
    439    *      } range;
    440    *
    441    *      range  baz;
    442    *
    443    *
    444    *      FT_Property_Get( library, "foo", "baz", &baz );
    445    *    }
    446    *
    447    *    It is not possible to retrieve properties of the FreeType Cache
    448    *    sub-system with FT_Property_Get; use @FTC_Property_Get instead.
    449    *
    450    * @since:
    451    *   2.4.11
    452    *
    453    */
    454   FT_EXPORT( FT_Error )
    455   FT_Property_Get( FT_Library        library,
    456                    const FT_String*  module_name,
    457                    const FT_String*  property_name,
    458                    void*             value );
    459 
    460 
    461   /**************************************************************************
    462    *
    463    * @function:
    464    *   FT_Set_Default_Properties
    465    *
    466    * @description:
    467    *   If compilation option FT_CONFIG_OPTION_ENVIRONMENT_PROPERTIES is
    468    *   set, this function reads the `FREETYPE_PROPERTIES' environment
    469    *   variable to control driver properties.  See section @properties
    470    *   for more.
    471    *
    472    *   If the compilation option is not set, this function does nothing.
    473    *
    474    *   `FREETYPE_PROPERTIES' has the following syntax form (broken here
    475    *   into multiple lines for better readability).
    476    *
    477    *   {
    478    *     <optional whitespace>
    479    *     <module-name1> ':'
    480    *     <property-name1> '=' <property-value1>
    481    *     <whitespace>
    482    *     <module-name2> ':'
    483    *     <property-name2> '=' <property-value2>
    484    *     ...
    485    *   }
    486    *
    487    *   Example:
    488    *
    489    *   {
    490    *     FREETYPE_PROPERTIES=truetype:interpreter-version=35 \
    491    *                         cff:no-stem-darkening=1 \
    492    *                         autofitter:warping=1
    493    *   }
    494    *
    495    * @inout:
    496    *   library ::
    497    *     A handle to a new library object.
    498    *
    499    * @since:
    500    *   2.8
    501    */
    502   FT_EXPORT( void )
    503   FT_Set_Default_Properties( FT_Library  library );
    504 
    505 
    506   /**************************************************************************
    507    *
    508    * @function:
    509    *   FT_Reference_Library
    510    *
    511    * @description:
    512    *   A counter gets initialized to~1 at the time an @FT_Library
    513    *   structure is created.  This function increments the counter.
    514    *   @FT_Done_Library then only destroys a library if the counter is~1,
    515    *   otherwise it simply decrements the counter.
    516    *
    517    *   This function helps in managing life-cycles of structures that
    518    *   reference @FT_Library objects.
    519    *
    520    * @input:
    521    *   library ::
    522    *     A handle to a target library object.
    523    *
    524    * @return:
    525    *   FreeType error code.  0~means success.
    526    *
    527    * @since:
    528    *   2.4.2
    529    */
    530   FT_EXPORT( FT_Error )
    531   FT_Reference_Library( FT_Library  library );
    532 
    533 
    534   /**************************************************************************
    535    *
    536    * @function:
    537    *   FT_New_Library
    538    *
    539    * @description:
    540    *   This function is used to create a new FreeType library instance
    541    *   from a given memory object.  It is thus possible to use libraries
    542    *   with distinct memory allocators within the same program.  Note,
    543    *   however, that the used @FT_Memory structure is expected to remain
    544    *   valid for the life of the @FT_Library object.
    545    *
    546    *   Normally, you would call this function (followed by a call to
    547    *   @FT_Add_Default_Modules or a series of calls to @FT_Add_Module,
    548    *   and a call to @FT_Set_Default_Properties) instead of
    549    *   @FT_Init_FreeType to initialize the FreeType library.
    550    *
    551    *   Don't use @FT_Done_FreeType but @FT_Done_Library to destroy a
    552    *   library instance.
    553    *
    554    * @input:
    555    *   memory ::
    556    *     A handle to the original memory object.
    557    *
    558    * @output:
    559    *   alibrary ::
    560    *     A pointer to handle of a new library object.
    561    *
    562    * @return:
    563    *   FreeType error code.  0~means success.
    564    *
    565    * @note:
    566    *   See the discussion of reference counters in the description of
    567    *   @FT_Reference_Library.
    568    */
    569   FT_EXPORT( FT_Error )
    570   FT_New_Library( FT_Memory    memory,
    571                   FT_Library  *alibrary );
    572 
    573 
    574   /**************************************************************************
    575    *
    576    * @function:
    577    *   FT_Done_Library
    578    *
    579    * @description:
    580    *   Discard a given library object.  This closes all drivers and
    581    *   discards all resource objects.
    582    *
    583    * @input:
    584    *   library ::
    585    *     A handle to the target library.
    586    *
    587    * @return:
    588    *   FreeType error code.  0~means success.
    589    *
    590    * @note:
    591    *   See the discussion of reference counters in the description of
    592    *   @FT_Reference_Library.
    593    */
    594   FT_EXPORT( FT_Error )
    595   FT_Done_Library( FT_Library  library );
    596 
    597   /* */
    598 
    599   typedef void
    600   (*FT_DebugHook_Func)( void*  arg );
    601 
    602 
    603   /**************************************************************************
    604    *
    605    * @function:
    606    *   FT_Set_Debug_Hook
    607    *
    608    * @description:
    609    *   Set a debug hook function for debugging the interpreter of a font
    610    *   format.
    611    *
    612    * @inout:
    613    *   library ::
    614    *     A handle to the library object.
    615    *
    616    * @input:
    617    *   hook_index ::
    618    *     The index of the debug hook.  You should use the
    619    *     values defined in `ftobjs.h', e.g.,
    620    *     `FT_DEBUG_HOOK_TRUETYPE'.
    621    *
    622    *   debug_hook ::
    623    *     The function used to debug the interpreter.
    624    *
    625    * @note:
    626    *   Currently, four debug hook slots are available, but only two (for
    627    *   the TrueType and the Type~1 interpreter) are defined.
    628    *
    629    *   Since the internal headers of FreeType are no longer installed,
    630    *   the symbol `FT_DEBUG_HOOK_TRUETYPE' isn't available publicly.
    631    *   This is a bug and will be fixed in a forthcoming release.
    632    */
    633   FT_EXPORT( void )
    634   FT_Set_Debug_Hook( FT_Library         library,
    635                      FT_UInt            hook_index,
    636                      FT_DebugHook_Func  debug_hook );
    637 
    638 
    639   /**************************************************************************
    640    *
    641    * @function:
    642    *   FT_Add_Default_Modules
    643    *
    644    * @description:
    645    *   Add the set of default drivers to a given library object.
    646    *   This is only useful when you create a library object with
    647    *   @FT_New_Library (usually to plug a custom memory manager).
    648    *
    649    * @inout:
    650    *   library ::
    651    *     A handle to a new library object.
    652    */
    653   FT_EXPORT( void )
    654   FT_Add_Default_Modules( FT_Library  library );
    655 
    656 
    657 
    658   /**************************************************************************
    659    *
    660    * @section:
    661    *   truetype_engine
    662    *
    663    * @title:
    664    *   The TrueType Engine
    665    *
    666    * @abstract:
    667    *   TrueType bytecode support.
    668    *
    669    * @description:
    670    *   This section contains a function used to query the level of TrueType
    671    *   bytecode support compiled in this version of the library.
    672    *
    673    */
    674 
    675 
    676   /**************************************************************************
    677    *
    678    * @enum:
    679    *    FT_TrueTypeEngineType
    680    *
    681    * @description:
    682    *    A list of values describing which kind of TrueType bytecode
    683    *    engine is implemented in a given FT_Library instance.  It is used
    684    *    by the @FT_Get_TrueType_Engine_Type function.
    685    *
    686    * @values:
    687    *    FT_TRUETYPE_ENGINE_TYPE_NONE ::
    688    *      The library doesn't implement any kind of bytecode interpreter.
    689    *
    690    *    FT_TRUETYPE_ENGINE_TYPE_UNPATENTED ::
    691    *      Deprecated and removed.
    692    *
    693    *    FT_TRUETYPE_ENGINE_TYPE_PATENTED ::
    694    *      The library implements a bytecode interpreter that covers
    695    *      the full instruction set of the TrueType virtual machine (this
    696    *      was governed by patents until May 2010, hence the name).
    697    *
    698    * @since:
    699    *    2.2
    700    *
    701    */
    702   typedef enum  FT_TrueTypeEngineType_
    703   {
    704     FT_TRUETYPE_ENGINE_TYPE_NONE = 0,
    705     FT_TRUETYPE_ENGINE_TYPE_UNPATENTED,
    706     FT_TRUETYPE_ENGINE_TYPE_PATENTED
    707 
    708   } FT_TrueTypeEngineType;
    709 
    710 
    711   /**************************************************************************
    712    *
    713    * @function:
    714    *    FT_Get_TrueType_Engine_Type
    715    *
    716    * @description:
    717    *    Return an @FT_TrueTypeEngineType value to indicate which level of
    718    *    the TrueType virtual machine a given library instance supports.
    719    *
    720    * @input:
    721    *    library ::
    722    *      A library instance.
    723    *
    724    * @return:
    725    *    A value indicating which level is supported.
    726    *
    727    * @since:
    728    *    2.2
    729    *
    730    */
    731   FT_EXPORT( FT_TrueTypeEngineType )
    732   FT_Get_TrueType_Engine_Type( FT_Library  library );
    733 
    734   /* */
    735 
    736 
    737 FT_END_HEADER
    738 
    739 #endif /* FTMODAPI_H_ */
    740 
    741 
    742 /* END */
    743