ftcache.h
上传用户:yisoukefu
上传日期:2020-08-09
资源大小:39506k
文件大小:58k
源码类别:

其他游戏

开发平台:

Visual C++

  1. /***************************************************************************/
  2. /*                                                                         */
  3. /*  ftcache.h                                                              */
  4. /*                                                                         */
  5. /*    FreeType Cache subsystem (specification).                            */
  6. /*                                                                         */
  7. /*  Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007 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. #ifndef __FTCACHE_H__
  18. #define __FTCACHE_H__
  19. #include <ft2build.h>
  20. #include FT_GLYPH_H
  21. FT_BEGIN_HEADER
  22.   /*************************************************************************
  23.    *
  24.    * <Section>
  25.    *    cache_subsystem
  26.    *
  27.    * <Title>
  28.    *    Cache Sub-System
  29.    *
  30.    * <Abstract>
  31.    *    How to cache face, size, and glyph data with FreeType 2.
  32.    *
  33.    * <Description>
  34.    *   This section describes the FreeType 2 cache sub-system, which is used
  35.    *   to limit the number of concurrently opened @FT_Face and @FT_Size
  36.    *   objects, as well as caching information like character maps and glyph
  37.    *   images while limiting their maximum memory usage.
  38.    *
  39.    *   Note that all types and functions begin with the `FTC_' prefix.
  40.    *
  41.    *   The cache is highly portable and thus doesn't know anything about the
  42.    *   fonts installed on your system, or how to access them.  This implies
  43.    *   the following scheme:
  44.    *
  45.    *   First, available or installed font faces are uniquely identified by
  46.    *   @FTC_FaceID values, provided to the cache by the client.  Note that
  47.    *   the cache only stores and compares these values, and doesn't try to
  48.    *   interpret them in any way.
  49.    *
  50.    *   Second, the cache calls, only when needed, a client-provided function
  51.    *   to convert a @FTC_FaceID into a new @FT_Face object.  The latter is
  52.    *   then completely managed by the cache, including its termination
  53.    *   through @FT_Done_Face.
  54.    *
  55.    *   Clients are free to map face IDs to anything else.  The most simple
  56.    *   usage is to associate them to a (pathname,face_index) pair that is
  57.    *   used to call @FT_New_Face.  However, more complex schemes are also
  58.    *   possible.
  59.    *
  60.    *   Note that for the cache to work correctly, the face ID values must be
  61.    *   *persistent*, which means that the contents they point to should not
  62.    *   change at runtime, or that their value should not become invalid.
  63.    *
  64.    *   If this is unavoidable (e.g., when a font is uninstalled at runtime),
  65.    *   you should call @FTC_Manager_RemoveFaceID as soon as possible, to let
  66.    *   the cache get rid of any references to the old @FTC_FaceID it may
  67.    *   keep internally.  Failure to do so will lead to incorrect behaviour
  68.    *   or even crashes.
  69.    *
  70.    *   To use the cache, start with calling @FTC_Manager_New to create a new
  71.    *   @FTC_Manager object, which models a single cache instance.  You can
  72.    *   then look up @FT_Face and @FT_Size objects with
  73.    *   @FTC_Manager_LookupFace and @FTC_Manager_LookupSize, respectively.
  74.    *
  75.    *   If you want to use the charmap caching, call @FTC_CMapCache_New, then
  76.    *   later use @FTC_CMapCache_Lookup to perform the equivalent of
  77.    *   @FT_Get_Char_Index, only much faster.
  78.    *
  79.    *   If you want to use the @FT_Glyph caching, call @FTC_ImageCache, then
  80.    *   later use @FTC_ImageCache_Lookup to retrieve the corresponding
  81.    *   @FT_Glyph objects from the cache.
  82.    *
  83.    *   If you need lots of small bitmaps, it is much more memory efficient
  84.    *   to call @FTC_SBitCache_New followed by @FTC_SBitCache_Lookup.  This
  85.    *   returns @FTC_SBitRec structures, which are used to store small
  86.    *   bitmaps directly.  (A small bitmap is one whose metrics and
  87.    *   dimensions all fit into 8-bit integers).
  88.    *
  89.    *   We hope to also provide a kerning cache in the near future.
  90.    *
  91.    *
  92.    * <Order>
  93.    *   FTC_Manager
  94.    *   FTC_FaceID
  95.    *   FTC_Face_Requester
  96.    *
  97.    *   FTC_Manager_New
  98.    *   FTC_Manager_Reset
  99.    *   FTC_Manager_Done
  100.    *   FTC_Manager_LookupFace
  101.    *   FTC_Manager_LookupSize
  102.    *   FTC_Manager_RemoveFaceID
  103.    *
  104.    *   FTC_Node
  105.    *   FTC_Node_Unref
  106.    *
  107.    *   FTC_ImageCache
  108.    *   FTC_ImageCache_New
  109.    *   FTC_ImageCache_Lookup
  110.    *
  111.    *   FTC_SBit
  112.    *   FTC_SBitCache
  113.    *   FTC_SBitCache_New
  114.    *   FTC_SBitCache_Lookup
  115.    *
  116.    *   FTC_CMapCache
  117.    *   FTC_CMapCache_New
  118.    *   FTC_CMapCache_Lookup
  119.    *
  120.    *************************************************************************/
  121.   /*************************************************************************/
  122.   /*************************************************************************/
  123.   /*************************************************************************/
  124.   /*****                                                               *****/
  125.   /*****                    BASIC TYPE DEFINITIONS                     *****/
  126.   /*****                                                               *****/
  127.   /*************************************************************************/
  128.   /*************************************************************************/
  129.   /*************************************************************************/
  130.   /*************************************************************************
  131.    *
  132.    * @type: FTC_FaceID
  133.    *
  134.    * @description:
  135.    *   An opaque pointer type that is used to identity face objects.  The
  136.    *   contents of such objects is application-dependent.
  137.    *
  138.    *   These pointers are typically used to point to a user-defined
  139.    *   structure containing a font file path, and face index.
  140.    *
  141.    * @note:
  142.    *   Never use NULL as a valid @FTC_FaceID.
  143.    *
  144.    *   Face IDs are passed by the client to the cache manager, which calls,
  145.    *   when needed, the @FTC_Face_Requester to translate them into new
  146.    *   @FT_Face objects.
  147.    *
  148.    *   If the content of a given face ID changes at runtime, or if the value
  149.    *   becomes invalid (e.g., when uninstalling a font), you should
  150.    *   immediately call @FTC_Manager_RemoveFaceID before any other cache
  151.    *   function.
  152.    *
  153.    *   Failure to do so will result in incorrect behaviour or even
  154.    *   memory leaks and crashes.
  155.    */
  156.   typedef struct FTC_FaceIDRec_*  FTC_FaceID;
  157.   /************************************************************************
  158.    *
  159.    * @functype:
  160.    *   FTC_Face_Requester
  161.    *
  162.    * @description:
  163.    *   A callback function provided by client applications.  It is used by
  164.    *   the cache manager to translate a given @FTC_FaceID into a new valid
  165.    *   @FT_Face object, on demand.
  166.    *
  167.    * <Input>
  168.    *   face_id ::
  169.    *     The face ID to resolve.
  170.    *
  171.    *   library ::
  172.    *     A handle to a FreeType library object.
  173.    *
  174.    *   req_data ::
  175.    *     Application-provided request data (see note below).
  176.    *
  177.    * <Output>
  178.    *   aface ::
  179.    *     A new @FT_Face handle.
  180.    *
  181.    * <Return>
  182.    *   FreeType error code.  0 means success.
  183.    *
  184.    * <Note>
  185.    *   The third parameter `req_data' is the same as the one passed by the
  186.    *   client when @FTC_Manager_New is called.
  187.    *
  188.    *   The face requester should not perform funny things on the returned
  189.    *   face object, like creating a new @FT_Size for it, or setting a
  190.    *   transformation through @FT_Set_Transform!
  191.    */
  192.   typedef FT_Error
  193.   (*FTC_Face_Requester)( FTC_FaceID  face_id,
  194.                          FT_Library  library,
  195.                          FT_Pointer  request_data,
  196.                          FT_Face*    aface );
  197.  /* */
  198. #define FT_POINTER_TO_ULONG( p )  ( (FT_ULong)(FT_Pointer)(p) )
  199. #define FTC_FACE_ID_HASH( i )                                
  200.           ((FT_UInt32)(( FT_POINTER_TO_ULONG( i ) >> 3 ) ^   
  201.                        ( FT_POINTER_TO_ULONG( i ) << 7 ) ) )
  202.   /*************************************************************************/
  203.   /*************************************************************************/
  204.   /*************************************************************************/
  205.   /*****                                                               *****/
  206.   /*****                      CACHE MANAGER OBJECT                     *****/
  207.   /*****                                                               *****/
  208.   /*************************************************************************/
  209.   /*************************************************************************/
  210.   /*************************************************************************/
  211.   /*************************************************************************/
  212.   /*                                                                       */
  213.   /* <Type>                                                                */
  214.   /*    FTC_Manager                                                        */
  215.   /*                                                                       */
  216.   /* <Description>                                                         */
  217.   /*    This object corresponds to one instance of the cache-subsystem.    */
  218.   /*    It is used to cache one or more @FT_Face objects, along with       */
  219.   /*    corresponding @FT_Size objects.                                    */
  220.   /*                                                                       */
  221.   /*    The manager intentionally limits the total number of opened        */
  222.   /*    @FT_Face and @FT_Size objects to control memory usage.  See the    */
  223.   /*    `max_faces' and `max_sizes' parameters of @FTC_Manager_New.        */
  224.   /*                                                                       */
  225.   /*    The manager is also used to cache `nodes' of various types while   */
  226.   /*    limiting their total memory usage.                                 */
  227.   /*                                                                       */
  228.   /*    All limitations are enforced by keeping lists of managed objects   */
  229.   /*    in most-recently-used order, and flushing old nodes to make room   */
  230.   /*    for new ones.                                                      */
  231.   /*                                                                       */
  232.   typedef struct FTC_ManagerRec_*  FTC_Manager;
  233.   /*************************************************************************/
  234.   /*                                                                       */
  235.   /* <Type>                                                                */
  236.   /*    FTC_Node                                                           */
  237.   /*                                                                       */
  238.   /* <Description>                                                         */
  239.   /*    An opaque handle to a cache node object.  Each cache node is       */
  240.   /*    reference-counted.  A node with a count of 0 might be flushed      */
  241.   /*    out of a full cache whenever a lookup request is performed.        */
  242.   /*                                                                       */
  243.   /*    If you lookup nodes, you have the ability to `acquire' them, i.e., */
  244.   /*    to increment their reference count.  This will prevent the node    */
  245.   /*    from being flushed out of the cache until you explicitly `release' */
  246.   /*    it (see @FTC_Node_Unref).                                          */
  247.   /*                                                                       */
  248.   /*    See also @FTC_SBitCache_Lookup and @FTC_ImageCache_Lookup.         */
  249.   /*                                                                       */
  250.   typedef struct FTC_NodeRec_*  FTC_Node;
  251.   /*************************************************************************/
  252.   /*                                                                       */
  253.   /* <Function>                                                            */
  254.   /*    FTC_Manager_New                                                    */
  255.   /*                                                                       */
  256.   /* <Description>                                                         */
  257.   /*    Creates a new cache manager.                                       */
  258.   /*                                                                       */
  259.   /* <Input>                                                               */
  260.   /*    library   :: The parent FreeType library handle to use.            */
  261.   /*                                                                       */
  262.   /*    max_faces :: Maximum number of opened @FT_Face objects managed by  */
  263.   /*                 this cache instance.  Use 0 for defaults.             */
  264.   /*                                                                       */
  265.   /*    max_sizes :: Maximum number of opened @FT_Size objects managed by  */
  266.   /*                 this cache instance.  Use 0 for defaults.             */
  267.   /*                                                                       */
  268.   /*    max_bytes :: Maximum number of bytes to use for cached data nodes. */
  269.   /*                 Use 0 for defaults.  Note that this value does not    */
  270.   /*                 account for managed @FT_Face and @FT_Size objects.    */
  271.   /*                                                                       */
  272.   /*    requester :: An application-provided callback used to translate    */
  273.   /*                 face IDs into real @FT_Face objects.                  */
  274.   /*                                                                       */
  275.   /*    req_data  :: A generic pointer that is passed to the requester     */
  276.   /*                 each time it is called (see @FTC_Face_Requester).     */
  277.   /*                                                                       */
  278.   /* <Output>                                                              */
  279.   /*    amanager  :: A handle to a new manager object.  0 in case of       */
  280.   /*                 failure.                                              */
  281.   /*                                                                       */
  282.   /* <Return>                                                              */
  283.   /*    FreeType error code.  0 means success.                             */
  284.   /*                                                                       */
  285.   FT_EXPORT( FT_Error )
  286.   FTC_Manager_New( FT_Library          library,
  287.                    FT_UInt             max_faces,
  288.                    FT_UInt             max_sizes,
  289.                    FT_ULong            max_bytes,
  290.                    FTC_Face_Requester  requester,
  291.                    FT_Pointer          req_data,
  292.                    FTC_Manager        *amanager );
  293.   /*************************************************************************/
  294.   /*                                                                       */
  295.   /* <Function>                                                            */
  296.   /*    FTC_Manager_Reset                                                  */
  297.   /*                                                                       */
  298.   /* <Description>                                                         */
  299.   /*    Empties a given cache manager.  This simply gets rid of all the    */
  300.   /*    currently cached @FT_Face and @FT_Size objects within the manager. */
  301.   /*                                                                       */
  302.   /* <InOut>                                                               */
  303.   /*    manager :: A handle to the manager.                                */
  304.   /*                                                                       */
  305.   FT_EXPORT( void )
  306.   FTC_Manager_Reset( FTC_Manager  manager );
  307.   /*************************************************************************/
  308.   /*                                                                       */
  309.   /* <Function>                                                            */
  310.   /*    FTC_Manager_Done                                                   */
  311.   /*                                                                       */
  312.   /* <Description>                                                         */
  313.   /*    Destroys a given manager after emptying it.                        */
  314.   /*                                                                       */
  315.   /* <Input>                                                               */
  316.   /*    manager :: A handle to the target cache manager object.            */
  317.   /*                                                                       */
  318.   FT_EXPORT( void )
  319.   FTC_Manager_Done( FTC_Manager  manager );
  320.   /*************************************************************************/
  321.   /*                                                                       */
  322.   /* <Function>                                                            */
  323.   /*    FTC_Manager_LookupFace                                             */
  324.   /*                                                                       */
  325.   /* <Description>                                                         */
  326.   /*    Retrieves the @FT_Face object that corresponds to a given face ID  */
  327.   /*    through a cache manager.                                           */
  328.   /*                                                                       */
  329.   /* <Input>                                                               */
  330.   /*    manager :: A handle to the cache manager.                          */
  331.   /*                                                                       */
  332.   /*    face_id :: The ID of the face object.                              */
  333.   /*                                                                       */
  334.   /* <Output>                                                              */
  335.   /*    aface   :: A handle to the face object.                            */
  336.   /*                                                                       */
  337.   /* <Return>                                                              */
  338.   /*    FreeType error code.  0 means success.                             */
  339.   /*                                                                       */
  340.   /* <Note>                                                                */
  341.   /*    The returned @FT_Face object is always owned by the manager.  You  */
  342.   /*    should never try to discard it yourself.                           */
  343.   /*                                                                       */
  344.   /*    The @FT_Face object doesn't necessarily have a current size object */
  345.   /*    (i.e., face->size can be 0).  If you need a specific `font size',  */
  346.   /*    use @FTC_Manager_LookupSize instead.                               */
  347.   /*                                                                       */
  348.   /*    Never change the face's transformation matrix (i.e., never call    */
  349.   /*    the @FT_Set_Transform function) on a returned face!  If you need   */
  350.   /*    to transform glyphs, do it yourself after glyph loading.           */
  351.   /*                                                                       */
  352.   /*    When you perform a lookup, out-of-memory errors are detected       */
  353.   /*    _within_ the lookup and force incremental flushes of the cache     */
  354.   /*    until enough memory is released for the lookup to succeed.         */
  355.   /*                                                                       */
  356.   /*    If a lookup fails with `FT_Err_Out_Of_Memory' the cache has        */
  357.   /*    already been completely flushed, and still no memory was available */
  358.   /*    for the operation.                                                 */
  359.   /*                                                                       */
  360.   FT_EXPORT( FT_Error )
  361.   FTC_Manager_LookupFace( FTC_Manager  manager,
  362.                           FTC_FaceID   face_id,
  363.                           FT_Face     *aface );
  364.   /*************************************************************************/
  365.   /*                                                                       */
  366.   /* <Struct>                                                              */
  367.   /*    FTC_ScalerRec                                                      */
  368.   /*                                                                       */
  369.   /* <Description>                                                         */
  370.   /*    A structure used to describe a given character size in either      */
  371.   /*    pixels or points to the cache manager.  See                        */
  372.   /*    @FTC_Manager_LookupSize.                                           */
  373.   /*                                                                       */
  374.   /* <Fields>                                                              */
  375.   /*    face_id :: The source face ID.                                     */
  376.   /*                                                                       */
  377.   /*    width   :: The character width.                                    */
  378.   /*                                                                       */
  379.   /*    height  :: The character height.                                   */
  380.   /*                                                                       */
  381.   /*    pixel   :: A Boolean.  If 1, the `width' and `height' fields are   */
  382.   /*               interpreted as integer pixel character sizes.           */
  383.   /*               Otherwise, they are expressed as 1/64th of points.      */
  384.   /*                                                                       */
  385.   /*    x_res   :: Only used when `pixel' is value 0 to indicate the       */
  386.   /*               horizontal resolution in dpi.                           */
  387.   /*                                                                       */
  388.   /*    y_res   :: Only used when `pixel' is value 0 to indicate the       */
  389.   /*               vertical resolution in dpi.                             */
  390.   /*                                                                       */
  391.   /* <Note>                                                                */
  392.   /*    This type is mainly used to retrieve @FT_Size objects through the  */
  393.   /*    cache manager.                                                     */
  394.   /*                                                                       */
  395.   typedef struct  FTC_ScalerRec_
  396.   {
  397.     FTC_FaceID  face_id;
  398.     FT_UInt     width;
  399.     FT_UInt     height;
  400.     FT_Int      pixel;
  401.     FT_UInt     x_res;
  402.     FT_UInt     y_res;
  403.   } FTC_ScalerRec, *FTC_Scaler;
  404.   /*************************************************************************/
  405.   /*                                                                       */
  406.   /* <Function>                                                            */
  407.   /*    FTC_Manager_LookupSize                                             */
  408.   /*                                                                       */
  409.   /* <Description>                                                         */
  410.   /*    Retrieve the @FT_Size object that corresponds to a given           */
  411.   /*    @FTC_ScalerRec pointer through a cache manager.                    */
  412.   /*                                                                       */
  413.   /* <Input>                                                               */
  414.   /*    manager :: A handle to the cache manager.                          */
  415.   /*                                                                       */
  416.   /*    scaler  :: A scaler handle.                                        */
  417.   /*                                                                       */
  418.   /* <Output>                                                              */
  419.   /*    asize   :: A handle to the size object.                            */
  420.   /*                                                                       */
  421.   /* <Return>                                                              */
  422.   /*    FreeType error code.  0 means success.                             */
  423.   /*                                                                       */
  424.   /* <Note>                                                                */
  425.   /*    The returned @FT_Size object is always owned by the manager.  You  */
  426.   /*    should never try to discard it by yourself.                        */
  427.   /*                                                                       */
  428.   /*    You can access the parent @FT_Face object simply as `size->face'   */
  429.   /*    if you need it.  Note that this object is also owned by the        */
  430.   /*    manager.                                                           */
  431.   /*                                                                       */
  432.   /* <Note>                                                                */
  433.   /*    When you perform a lookup, out-of-memory errors are detected       */
  434.   /*    _within_ the lookup and force incremental flushes of the cache     */
  435.   /*    until enough memory is released for the lookup to succeed.         */
  436.   /*                                                                       */
  437.   /*    If a lookup fails with `FT_Err_Out_Of_Memory' the cache has        */
  438.   /*    already been completely flushed, and still no memory is available  */
  439.   /*    for the operation.                                                 */
  440.   /*                                                                       */
  441.   FT_EXPORT( FT_Error )
  442.   FTC_Manager_LookupSize( FTC_Manager  manager,
  443.                           FTC_Scaler   scaler,
  444.                           FT_Size     *asize );
  445.   /*************************************************************************/
  446.   /*                                                                       */
  447.   /* <Function>                                                            */
  448.   /*    FTC_Node_Unref                                                     */
  449.   /*                                                                       */
  450.   /* <Description>                                                         */
  451.   /*    Decrement a cache node's internal reference count.  When the count */
  452.   /*    reaches 0, it is not destroyed but becomes eligible for subsequent */
  453.   /*    cache flushes.                                                     */
  454.   /*                                                                       */
  455.   /* <Input>                                                               */
  456.   /*    node    :: The cache node handle.                                  */
  457.   /*                                                                       */
  458.   /*    manager :: The cache manager handle.                               */
  459.   /*                                                                       */
  460.   FT_EXPORT( void )
  461.   FTC_Node_Unref( FTC_Node     node,
  462.                   FTC_Manager  manager );
  463.   /*************************************************************************
  464.    *
  465.    * @function:
  466.    *   FTC_Manager_RemoveFaceID
  467.    *
  468.    * @description:
  469.    *   A special function used to indicate to the cache manager that
  470.    *   a given @FTC_FaceID is no longer valid, either because its
  471.    *   content changed, or because it was deallocated or uninstalled.
  472.    *
  473.    * @input:
  474.    *   manager ::
  475.    *     The cache manager handle.
  476.    *
  477.    *   face_id ::
  478.    *     The @FTC_FaceID to be removed.
  479.    *
  480.    * @note:
  481.    *   This function flushes all nodes from the cache corresponding to this
  482.    *   `face_id', with the exception of nodes with a non-null reference
  483.    *   count.
  484.    *
  485.    *   Such nodes are however modified internally so as to never appear
  486.    *   in later lookups with the same `face_id' value, and to be immediately
  487.    *   destroyed when released by all their users.
  488.    *
  489.    */
  490.   FT_EXPORT( void )
  491.   FTC_Manager_RemoveFaceID( FTC_Manager  manager,
  492.                             FTC_FaceID   face_id );
  493.   /*************************************************************************/
  494.   /*                                                                       */
  495.   /* <Section>                                                             */
  496.   /*    cache_subsystem                                                    */
  497.   /*                                                                       */
  498.   /*************************************************************************/
  499.   /*************************************************************************
  500.    *
  501.    * @type:
  502.    *   FTC_CMapCache
  503.    *
  504.    * @description:
  505.    *   An opaque handle used to model a charmap cache.  This cache is to
  506.    *   hold character codes -> glyph indices mappings.
  507.    *
  508.    */
  509.   typedef struct FTC_CMapCacheRec_*  FTC_CMapCache;
  510.   /*************************************************************************
  511.    *
  512.    * @function:
  513.    *   FTC_CMapCache_New
  514.    *
  515.    * @description:
  516.    *   Create a new charmap cache.
  517.    *
  518.    * @input:
  519.    *   manager ::
  520.    *     A handle to the cache manager.
  521.    *
  522.    * @output:
  523.    *   acache ::
  524.    *     A new cache handle.  NULL in case of error.
  525.    *
  526.    * @return:
  527.    *   FreeType error code.  0 means success.
  528.    *
  529.    * @note:
  530.    *   Like all other caches, this one will be destroyed with the cache
  531.    *   manager.
  532.    *
  533.    */
  534.   FT_EXPORT( FT_Error )
  535.   FTC_CMapCache_New( FTC_Manager     manager,
  536.                      FTC_CMapCache  *acache );
  537.   /************************************************************************
  538.    *
  539.    * @function:
  540.    *   FTC_CMapCache_Lookup
  541.    *
  542.    * @description:
  543.    *   Translate a character code into a glyph index, using the charmap
  544.    *   cache.
  545.    *
  546.    * @input:
  547.    *   cache ::
  548.    *     A charmap cache handle.
  549.    *
  550.    *   face_id ::
  551.    *     The source face ID.
  552.    *
  553.    *   cmap_index ::
  554.    *     The index of the charmap in the source face.
  555.    *
  556.    *   char_code ::
  557.    *     The character code (in the corresponding charmap).
  558.    *
  559.    * @return:
  560.    *    Glyph index.  0 means `no glyph'.
  561.    *
  562.    */
  563.   FT_EXPORT( FT_UInt )
  564.   FTC_CMapCache_Lookup( FTC_CMapCache  cache,
  565.                         FTC_FaceID     face_id,
  566.                         FT_Int         cmap_index,
  567.                         FT_UInt32      char_code );
  568.   /*************************************************************************/
  569.   /*                                                                       */
  570.   /* <Section>                                                             */
  571.   /*    cache_subsystem                                                    */
  572.   /*                                                                       */
  573.   /*************************************************************************/
  574.   /*************************************************************************/
  575.   /*************************************************************************/
  576.   /*************************************************************************/
  577.   /*****                                                               *****/
  578.   /*****                       IMAGE CACHE OBJECT                      *****/
  579.   /*****                                                               *****/
  580.   /*************************************************************************/
  581.   /*************************************************************************/
  582.   /*************************************************************************/
  583.   /*************************************************************************
  584.    *
  585.    * @struct:
  586.    *   FTC_ImageTypeRec
  587.    *
  588.    * @description:
  589.    *   A structure used to model the type of images in a glyph cache.
  590.    *
  591.    * @fields:
  592.    *   face_id ::
  593.    *     The face ID.
  594.    *
  595.    *   width ::
  596.    *     The width in pixels.
  597.    *
  598.    *   height ::
  599.    *     The height in pixels.
  600.    *
  601.    *   flags ::
  602.    *     The load flags, as in @FT_Load_Glyph.
  603.    *
  604.    */
  605.   typedef struct  FTC_ImageTypeRec_
  606.   {
  607.     FTC_FaceID  face_id;
  608.     FT_Int      width;
  609.     FT_Int      height;
  610.     FT_Int32    flags;
  611.   } FTC_ImageTypeRec;
  612.   /*************************************************************************
  613.    *
  614.    * @type:
  615.    *   FTC_ImageType
  616.    *
  617.    * @description:
  618.    *   A handle to an @FTC_ImageTypeRec structure.
  619.    *
  620.    */
  621.   typedef struct FTC_ImageTypeRec_*  FTC_ImageType;
  622.   /* */
  623. #define FTC_IMAGE_TYPE_COMPARE( d1, d2 )      
  624.           ( (d1)->face_id == (d2)->face_id && 
  625.             (d1)->width   == (d2)->width   && 
  626.             (d1)->flags   == (d2)->flags   )
  627. #define FTC_IMAGE_TYPE_HASH( d )                          
  628.           (FT_UFast)( FTC_FACE_ID_HASH( (d)->face_id )  ^ 
  629.                       ( (d)->width << 8 ) ^ (d)->height ^ 
  630.                       ( (d)->flags << 4 )               )
  631.   /*************************************************************************/
  632.   /*                                                                       */
  633.   /* <Type>                                                                */
  634.   /*    FTC_ImageCache                                                     */
  635.   /*                                                                       */
  636.   /* <Description>                                                         */
  637.   /*    A handle to an glyph image cache object.  They are designed to     */
  638.   /*    hold many distinct glyph images while not exceeding a certain      */
  639.   /*    memory threshold.                                                  */
  640.   /*                                                                       */
  641.   typedef struct FTC_ImageCacheRec_*  FTC_ImageCache;
  642.   /*************************************************************************/
  643.   /*                                                                       */
  644.   /* <Function>                                                            */
  645.   /*    FTC_ImageCache_New                                                 */
  646.   /*                                                                       */
  647.   /* <Description>                                                         */
  648.   /*    Creates a new glyph image cache.                                   */
  649.   /*                                                                       */
  650.   /* <Input>                                                               */
  651.   /*    manager :: The parent manager for the image cache.                 */
  652.   /*                                                                       */
  653.   /* <Output>                                                              */
  654.   /*    acache  :: A handle to the new glyph image cache object.           */
  655.   /*                                                                       */
  656.   /* <Return>                                                              */
  657.   /*    FreeType error code.  0 means success.                             */
  658.   /*                                                                       */
  659.   FT_EXPORT( FT_Error )
  660.   FTC_ImageCache_New( FTC_Manager      manager,
  661.                       FTC_ImageCache  *acache );
  662.   /*************************************************************************/
  663.   /*                                                                       */
  664.   /* <Function>                                                            */
  665.   /*    FTC_ImageCache_Lookup                                              */
  666.   /*                                                                       */
  667.   /* <Description>                                                         */
  668.   /*    Retrieves a given glyph image from a glyph image cache.            */
  669.   /*                                                                       */
  670.   /* <Input>                                                               */
  671.   /*    cache  :: A handle to the source glyph image cache.                */
  672.   /*                                                                       */
  673.   /*    type   :: A pointer to a glyph image type descriptor.              */
  674.   /*                                                                       */
  675.   /*    gindex :: The glyph index to retrieve.                             */
  676.   /*                                                                       */
  677.   /* <Output>                                                              */
  678.   /*    aglyph :: The corresponding @FT_Glyph object.  0 in case of        */
  679.   /*              failure.                                                 */
  680.   /*                                                                       */
  681.   /*    anode  :: Used to return the address of of the corresponding cache */
  682.   /*              node after incrementing its reference count (see note    */
  683.   /*              below).                                                  */
  684.   /*                                                                       */
  685.   /* <Return>                                                              */
  686.   /*    FreeType error code.  0 means success.                             */
  687.   /*                                                                       */
  688.   /* <Note>                                                                */
  689.   /*    The returned glyph is owned and managed by the glyph image cache.  */
  690.   /*    Never try to transform or discard it manually!  You can however    */
  691.   /*    create a copy with @FT_Glyph_Copy and modify the new one.          */
  692.   /*                                                                       */
  693.   /*    If `anode' is _not_ NULL, it receives the address of the cache     */
  694.   /*    node containing the glyph image, after increasing its reference    */
  695.   /*    count.  This ensures that the node (as well as the @FT_Glyph) will */
  696.   /*    always be kept in the cache until you call @FTC_Node_Unref to      */
  697.   /*    `release' it.                                                      */
  698.   /*                                                                       */
  699.   /*    If `anode' is NULL, the cache node is left unchanged, which means  */
  700.   /*    that the @FT_Glyph could be flushed out of the cache on the next   */
  701.   /*    call to one of the caching sub-system APIs.  Don't assume that it  */
  702.   /*    is persistent!                                                     */
  703.   /*                                                                       */
  704.   FT_EXPORT( FT_Error )
  705.   FTC_ImageCache_Lookup( FTC_ImageCache  cache,
  706.                          FTC_ImageType   type,
  707.                          FT_UInt         gindex,
  708.                          FT_Glyph       *aglyph,
  709.                          FTC_Node       *anode );
  710.   /*************************************************************************/
  711.   /*                                                                       */
  712.   /* <Function>                                                            */
  713.   /*    FTC_ImageCache_LookupScaler                                        */
  714.   /*                                                                       */
  715.   /* <Description>                                                         */
  716.   /*    A variant of @FTC_ImageCache_Lookup that uses an @FTC_ScalerRec    */
  717.   /*    to specify the face ID and its size.                               */
  718.   /*                                                                       */
  719.   /* <Input>                                                               */
  720.   /*    cache      :: A handle to the source glyph image cache.            */
  721.   /*                                                                       */
  722.   /*    scaler     :: A pointer to a scaler descriptor.                    */
  723.   /*                                                                       */
  724.   /*    load_flags :: The corresponding load flags.                        */
  725.   /*                                                                       */
  726.   /*    gindex     :: The glyph index to retrieve.                         */
  727.   /*                                                                       */
  728.   /* <Output>                                                              */
  729.   /*    aglyph     :: The corresponding @FT_Glyph object.  0 in case of    */
  730.   /*                  failure.                                             */
  731.   /*                                                                       */
  732.   /*    anode      :: Used to return the address of of the corresponding   */
  733.   /*                  cache node after incrementing its reference count    */
  734.   /*                  (see note below).                                    */
  735.   /*                                                                       */
  736.   /* <Return>                                                              */
  737.   /*    FreeType error code.  0 means success.                             */
  738.   /*                                                                       */
  739.   /* <Note>                                                                */
  740.   /*    The returned glyph is owned and managed by the glyph image cache.  */
  741.   /*    Never try to transform or discard it manually!  You can however    */
  742.   /*    create a copy with @FT_Glyph_Copy and modify the new one.          */
  743.   /*                                                                       */
  744.   /*    If `anode' is _not_ NULL, it receives the address of the cache     */
  745.   /*    node containing the glyph image, after increasing its reference    */
  746.   /*    count.  This ensures that the node (as well as the @FT_Glyph) will */
  747.   /*    always be kept in the cache until you call @FTC_Node_Unref to      */
  748.   /*    `release' it.                                                      */
  749.   /*                                                                       */
  750.   /*    If `anode' is NULL, the cache node is left unchanged, which means  */
  751.   /*    that the @FT_Glyph could be flushed out of the cache on the next   */
  752.   /*    call to one of the caching sub-system APIs.  Don't assume that it  */
  753.   /*    is persistent!                                                     */
  754.   /*                                                                       */
  755.   FT_EXPORT( FT_Error )
  756.   FTC_ImageCache_LookupScaler( FTC_ImageCache  cache,
  757.                                FTC_Scaler      scaler,
  758.                                FT_ULong        load_flags,
  759.                                FT_UInt         gindex,
  760.                                FT_Glyph       *aglyph,
  761.                                FTC_Node       *anode );
  762.   /*************************************************************************/
  763.   /*                                                                       */
  764.   /* <Type>                                                                */
  765.   /*    FTC_SBit                                                           */
  766.   /*                                                                       */
  767.   /* <Description>                                                         */
  768.   /*    A handle to a small bitmap descriptor.  See the @FTC_SBitRec       */
  769.   /*    structure for details.                                             */
  770.   /*                                                                       */
  771.   typedef struct FTC_SBitRec_*  FTC_SBit;
  772.   /*************************************************************************/
  773.   /*                                                                       */
  774.   /* <Struct>                                                              */
  775.   /*    FTC_SBitRec                                                        */
  776.   /*                                                                       */
  777.   /* <Description>                                                         */
  778.   /*    A very compact structure used to describe a small glyph bitmap.    */
  779.   /*                                                                       */
  780.   /* <Fields>                                                              */
  781.   /*    width     :: The bitmap width in pixels.                           */
  782.   /*                                                                       */
  783.   /*    height    :: The bitmap height in pixels.                          */
  784.   /*                                                                       */
  785.   /*    left      :: The horizontal distance from the pen position to the  */
  786.   /*                 left bitmap border (a.k.a. `left side bearing', or    */
  787.   /*                 `lsb').                                               */
  788.   /*                                                                       */
  789.   /*    top       :: The vertical distance from the pen position (on the   */
  790.   /*                 baseline) to the upper bitmap border (a.k.a. `top     */
  791.   /*                 side bearing').  The distance is positive for upwards */
  792.   /*                 Y coordinates.                                        */
  793.   /*                                                                       */
  794.   /*    format    :: The format of the glyph bitmap (monochrome or gray).  */
  795.   /*                                                                       */
  796.   /*    max_grays :: Maximum gray level value (in the range 1 to 255).     */
  797.   /*                                                                       */
  798.   /*    pitch     :: The number of bytes per bitmap line.  May be positive */
  799.   /*                 or negative.                                          */
  800.   /*                                                                       */
  801.   /*    xadvance  :: The horizontal advance width in pixels.               */
  802.   /*                                                                       */
  803.   /*    yadvance  :: The vertical advance height in pixels.                */
  804.   /*                                                                       */
  805.   /*    buffer    :: A pointer to the bitmap pixels.                       */
  806.   /*                                                                       */
  807.   typedef struct  FTC_SBitRec_
  808.   {
  809.     FT_Byte   width;
  810.     FT_Byte   height;
  811.     FT_Char   left;
  812.     FT_Char   top;
  813.     FT_Byte   format;
  814.     FT_Byte   max_grays;
  815.     FT_Short  pitch;
  816.     FT_Char   xadvance;
  817.     FT_Char   yadvance;
  818.     FT_Byte*  buffer;
  819.   } FTC_SBitRec;
  820.   /*************************************************************************/
  821.   /*                                                                       */
  822.   /* <Type>                                                                */
  823.   /*    FTC_SBitCache                                                      */
  824.   /*                                                                       */
  825.   /* <Description>                                                         */
  826.   /*    A handle to a small bitmap cache.  These are special cache objects */
  827.   /*    used to store small glyph bitmaps (and anti-aliased pixmaps) in a  */
  828.   /*    much more efficient way than the traditional glyph image cache     */
  829.   /*    implemented by @FTC_ImageCache.                                    */
  830.   /*                                                                       */
  831.   typedef struct FTC_SBitCacheRec_*  FTC_SBitCache;
  832.   /*************************************************************************/
  833.   /*                                                                       */
  834.   /* <Function>                                                            */
  835.   /*    FTC_SBitCache_New                                                  */
  836.   /*                                                                       */
  837.   /* <Description>                                                         */
  838.   /*    Creates a new cache to store small glyph bitmaps.                  */
  839.   /*                                                                       */
  840.   /* <Input>                                                               */
  841.   /*    manager :: A handle to the source cache manager.                   */
  842.   /*                                                                       */
  843.   /* <Output>                                                              */
  844.   /*    acache  :: A handle to the new sbit cache.  NULL in case of error. */
  845.   /*                                                                       */
  846.   /* <Return>                                                              */
  847.   /*    FreeType error code.  0 means success.                             */
  848.   /*                                                                       */
  849.   FT_EXPORT( FT_Error )
  850.   FTC_SBitCache_New( FTC_Manager     manager,
  851.                      FTC_SBitCache  *acache );
  852.   /*************************************************************************/
  853.   /*                                                                       */
  854.   /* <Function>                                                            */
  855.   /*    FTC_SBitCache_Lookup                                               */
  856.   /*                                                                       */
  857.   /* <Description>                                                         */
  858.   /*    Looks up a given small glyph bitmap in a given sbit cache and      */
  859.   /*    `lock' it to prevent its flushing from the cache until needed.     */
  860.   /*                                                                       */
  861.   /* <Input>                                                               */
  862.   /*    cache  :: A handle to the source sbit cache.                       */
  863.   /*                                                                       */
  864.   /*    type   :: A pointer to the glyph image type descriptor.            */
  865.   /*                                                                       */
  866.   /*    gindex :: The glyph index.                                         */
  867.   /*                                                                       */
  868.   /* <Output>                                                              */
  869.   /*    sbit   :: A handle to a small bitmap descriptor.                   */
  870.   /*                                                                       */
  871.   /*    anode  :: Used to return the address of of the corresponding cache */
  872.   /*              node after incrementing its reference count (see note    */
  873.   /*              below).                                                  */
  874.   /*                                                                       */
  875.   /* <Return>                                                              */
  876.   /*    FreeType error code.  0 means success.                             */
  877.   /*                                                                       */
  878.   /* <Note>                                                                */
  879.   /*    The small bitmap descriptor and its bit buffer are owned by the    */
  880.   /*    cache and should never be freed by the application.  They might    */
  881.   /*    as well disappear from memory on the next cache lookup, so don't   */
  882.   /*    treat them as persistent data.                                     */
  883.   /*                                                                       */
  884.   /*    The descriptor's `buffer' field is set to 0 to indicate a missing  */
  885.   /*    glyph bitmap.                                                      */
  886.   /*                                                                       */
  887.   /*    If `anode' is _not_ NULL, it receives the address of the cache     */
  888.   /*    node containing the bitmap, after increasing its reference count.  */
  889.   /*    This ensures that the node (as well as the image) will always be   */
  890.   /*    kept in the cache until you call @FTC_Node_Unref to `release' it.  */
  891.   /*                                                                       */
  892.   /*    If `anode' is NULL, the cache node is left unchanged, which means  */
  893.   /*    that the bitmap could be flushed out of the cache on the next      */
  894.   /*    call to one of the caching sub-system APIs.  Don't assume that it  */
  895.   /*    is persistent!                                                     */
  896.   /*                                                                       */
  897.   FT_EXPORT( FT_Error )
  898.   FTC_SBitCache_Lookup( FTC_SBitCache    cache,
  899.                         FTC_ImageType    type,
  900.                         FT_UInt          gindex,
  901.                         FTC_SBit        *sbit,
  902.                         FTC_Node        *anode );
  903.   /*************************************************************************/
  904.   /*                                                                       */
  905.   /* <Function>                                                            */
  906.   /*    FTC_SBitCache_LookupScaler                                         */
  907.   /*                                                                       */
  908.   /* <Description>                                                         */
  909.   /*    A variant of @FTC_SBitCache_Lookup that uses an @FTC_ScalerRec     */
  910.   /*    to specify the face ID and its size.                               */
  911.   /*                                                                       */
  912.   /* <Input>                                                               */
  913.   /*    cache      :: A handle to the source sbit cache.                   */
  914.   /*                                                                       */
  915.   /*    scaler     :: A pointer to the scaler descriptor.                  */
  916.   /*                                                                       */
  917.   /*    load_flags :: The corresponding load flags.                        */
  918.   /*                                                                       */
  919.   /*    gindex     :: The glyph index.                                     */
  920.   /*                                                                       */
  921.   /* <Output>                                                              */
  922.   /*    sbit       :: A handle to a small bitmap descriptor.               */
  923.   /*                                                                       */
  924.   /*    anode      :: Used to return the address of of the corresponding   */
  925.   /*                  cache node after incrementing its reference count    */
  926.   /*                  (see note below).                                    */
  927.   /*                                                                       */
  928.   /* <Return>                                                              */
  929.   /*    FreeType error code.  0 means success.                             */
  930.   /*                                                                       */
  931.   /* <Note>                                                                */
  932.   /*    The small bitmap descriptor and its bit buffer are owned by the    */
  933.   /*    cache and should never be freed by the application.  They might    */
  934.   /*    as well disappear from memory on the next cache lookup, so don't   */
  935.   /*    treat them as persistent data.                                     */
  936.   /*                                                                       */
  937.   /*    The descriptor's `buffer' field is set to 0 to indicate a missing  */
  938.   /*    glyph bitmap.                                                      */
  939.   /*                                                                       */
  940.   /*    If `anode' is _not_ NULL, it receives the address of the cache     */
  941.   /*    node containing the bitmap, after increasing its reference count.  */
  942.   /*    This ensures that the node (as well as the image) will always be   */
  943.   /*    kept in the cache until you call @FTC_Node_Unref to `release' it.  */
  944.   /*                                                                       */
  945.   /*    If `anode' is NULL, the cache node is left unchanged, which means  */
  946.   /*    that the bitmap could be flushed out of the cache on the next      */
  947.   /*    call to one of the caching sub-system APIs.  Don't assume that it  */
  948.   /*    is persistent!                                                     */
  949.   /*                                                                       */
  950.   FT_EXPORT( FT_Error )
  951.   FTC_SBitCache_LookupScaler( FTC_SBitCache  cache,
  952.                               FTC_Scaler     scaler,
  953.                               FT_ULong       load_flags,
  954.                               FT_UInt        gindex,
  955.                               FTC_SBit      *sbit,
  956.                               FTC_Node      *anode );
  957.  /* */
  958. #ifdef FT_CONFIG_OPTION_OLD_INTERNALS
  959.   /*@***********************************************************************/
  960.   /*                                                                       */
  961.   /* <Struct>                                                              */
  962.   /*    FTC_FontRec                                                        */
  963.   /*                                                                       */
  964.   /* <Description>                                                         */
  965.   /*    A simple structure used to describe a given `font' to the cache    */
  966.   /*    manager.  Note that a `font' is the combination of a given face    */
  967.   /*    with a given character size.                                       */
  968.   /*                                                                       */
  969.   /* <Fields>                                                              */
  970.   /*    face_id    :: The ID of the face to use.                           */
  971.   /*                                                                       */
  972.   /*    pix_width  :: The character width in integer pixels.               */
  973.   /*                                                                       */
  974.   /*    pix_height :: The character height in integer pixels.              */
  975.   /*                                                                       */
  976.   typedef struct  FTC_FontRec_
  977.   {
  978.     FTC_FaceID  face_id;
  979.     FT_UShort   pix_width;
  980.     FT_UShort   pix_height;
  981.   } FTC_FontRec;
  982.   /* */
  983. #define FTC_FONT_COMPARE( f1, f2 )                  
  984.           ( (f1)->face_id    == (f2)->face_id    && 
  985.             (f1)->pix_width  == (f2)->pix_width  && 
  986.             (f1)->pix_height == (f2)->pix_height )
  987. #define FTC_FONT_HASH( f )                              
  988.           (FT_UInt32)( FTC_FACE_ID_HASH((f)->face_id) ^ 
  989.                        ((f)->pix_width << 8)          ^ 
  990.                        ((f)->pix_height)              )
  991.   typedef FTC_FontRec*  FTC_Font;
  992.   FT_EXPORT( FT_Error )
  993.   FTC_Manager_Lookup_Face( FTC_Manager  manager,
  994.                            FTC_FaceID   face_id,
  995.                            FT_Face     *aface );
  996.   FT_EXPORT( FT_Error )
  997.   FTC_Manager_Lookup_Size( FTC_Manager  manager,
  998.                            FTC_Font     font,
  999.                            FT_Face     *aface,
  1000.                            FT_Size     *asize );
  1001. #endif /* FT_CONFIG_OPTION_OLD_INTERNALS */
  1002.  /* */
  1003. FT_END_HEADER
  1004. #endif /* __FTCACHE_H__ */
  1005. /* END */