# FreeType-2.1.4 API Reference

# Cache Sub-System

## Synopsys

| FTC_Manager |  | FTC_CMapType |  | FTC_ManagerRec
| FTC_FaceID |  | FTC_CMapIdRec |  | FTC_Manager_Compress
| FTC_Face_Requester |  | FTC_CMapDescRec |  | FTC_Node_Unref
| FTC_FontRec |  | FTC_CMapCache_New |  | FTC_SBit
| FTC_Font |  | FTC_CMapCache_Lookup |  | FTC_SBitRec
| FTC_Node |  | FTC_ImageTypeRec |  | FTC_SBitCache
| FTC_Manager_New |  | FTC_ImageCache |  | FTC_SBit_Cache
| FTC_Manager_Reset |  | FTC_ImageCache_New |  | FTC_SBitCache_New
| FTC_Manager_Done |  | FTC_ImageCache_Lookup |  | FTC_SBitCache_Lookup
| FTC_Manager_Lookup_Face |  | FTC_Image_Desc |  | FTC_SBit_Cache_New
| FTC_Manager_Lookup_Size |  | FTC_Image_Cache |  | FTC_SBit_Cache_Lookup
| FTC_CmapCache |  | FTC_Image_Cache_New |  |
| FTC_CMapDesc |  | FTC_Image_Cache_Lookup |  |

This section describes the FreeType 2 cache sub-system which is stile in beta.

#### FTC_Manager
      typedef struct FTC_ManagerRec_*  FTC_Manager;
This object is used to cache one or more FT_Face objects, along with corresponding FT_Size objects.

#### FTC_FaceID
      typedef FT_Pointer  FTC_FaceID;
A generic pointer type that is used to identity face objects. The contents of such objects is application-dependent.

#### FTC_Face_Requester
      typedef FT_Error
      (*FTC_Face_Requester)( FTC_FaceID  face_id,
                             FT_Library  library,
                             FT_Pointer  request_data,
                             FT_Face*    aface );
A callback function provided by client applications. It is used to translate a given FTC_FaceID into a new valid FT_Face object.
input
face_id | The face ID to resolve.
library | A handle to a FreeType library object.
data | Application-provided request data.
output
aface | A new FT_Face handle.
return
FreeType error code. 0 means success.
note
The face requester should not perform funny things on the returned face object, like creating a new FT_Size for it, or setting a transformation through FT_Set_Transform

#### FTC_FontRec
      typedef struct  FTC_FontRec_
      {
        FTC_FaceID  face_id;
        FT_UShort   pix_width;
        FT_UShort   pix_height;

      } FTC_FontRec;
A simple structure used to describe a given `font' to the cache manager. Note that a `font' is the combination of a given face with a given character size.
fields
face_id | The ID of the face to use.
pix_width | The character width in integer pixels.
pix_height | The character height in integer pixels.

#### FTC_Font
      typedef FTC_FontRec*  FTC_Font;
A simple handle to an FTC_FontRec structure.

#### FTC_Node
      typedef struct FTC_NodeRec_*  FTC_Node;
An opaque handle to a cache node object. Each cache node is reference-counted. A node with a count of 0 might be flushed out of a full cache whenever a lookup request is performed. If you lookup nodes, you have the ability to "acquire" them, i.e., to increment their reference count. This will prevent the node from being flushed out of the cache until you explicitly "release" it (see ?FTC_Node_Release? See also ?FTC_BitsetCache_Lookup? and FTC_ImageCache_Lookup

#### FTC_Manager_New
      FT_EXPORT( FT_Error )
      FTC_Manager_New( FT_Library          library,
                       FT_UInt             max_faces,
                       FT_UInt             max_sizes,
                       FT_ULong            max_bytes,
                       FTC_Face_Requester  requester,
                       FT_Pointer          req_data,
                       FTC_Manager        *amanager );
Creates a new cache manager.
input
library | The parent FreeType library handle to use.
max_faces | Maximum number of faces to keep alive in manager. Use 0 for defaults.
max_sizes | Maximum number of sizes to keep alive in manager. Use 0 for defaults.
max_bytes | Maximum number of bytes to use for cached data. Use 0 for defaults.
requester | An application-provided callback used to translate face IDs into real FT_Face objects.
req_data | A generic pointer that is passed to the requester each time it is called (see FTC_Face_Requester
output
amanager | A handle to a new manager object. 0 in case of failure.
return
FreeType error code. 0 means success.

#### FTC_Manager_Reset
      FT_EXPORT( void )
      FTC_Manager_Reset( FTC_Manager  manager );
Empties a given cache manager. This simply gets rid of all the currently cached FT_Face and FT_Size objects within the manager.
inout
manager | A handle to the manager.

#### FTC_Manager_Done
      FT_EXPORT( void )
      FTC_Manager_Done( FTC_Manager  manager );
Destroys a given manager after emptying it.
input
manager | A handle to the target cache manager object.

#### FTC_Manager_Lookup_Face
      FT_EXPORT( FT_Error )
      FTC_Manager_Lookup_Face( FTC_Manager  manager,
                               FTC_FaceID   face_id,
                               FT_Face     *aface );
Retrieves the FT_Face object that corresponds to a given face ID through a cache manager.
input
manager | A handle to the cache manager.
face_id | The ID of the face object.
output
aface | A handle to the face object.
return
FreeType error code. 0 means success.
note
The returned FT_Face object is always owned by the manager. You should never try to discard it yourself. The FT_Face object doesn't necessarily have a current size object (i.e., face->size can be 0). If you need a specific `font size', use FTC_Manager_Lookup_Size instead. Never change the face's transformation matrix (i.e., never call the FT_Set_Transform function) on a returned face! If you need to transform glyphs, do it yourself after glyph loading.

#### FTC_Manager_Lookup_Size
      FT_EXPORT( FT_Error )
      FTC_Manager_Lookup_Size( FTC_Manager  manager,
                               FTC_Font     font,
                               FT_Face     *aface,
                               FT_Size     *asize );

    FT_END_HEADER

    #endif /* __FTCACHE_H__ */

    /* END */
Retrieves the FT_Face and FT_Size objects that correspond to a given ?FTC_SizeID?
input
manager | A handle to the cache manager.
size_id | The ID of the `font size' to use.
output
aface | A pointer to the handle of the face object. Set it to zero if you don't need it.
asize | A pointer to the handle of the size object. Set it to zero if you don't need it.
return
FreeType error code. 0 means success.
note
The returned FT_Face object is always owned by the manager. You should never try to discard it yourself. Never change the face's transformation matrix (i.e., never call the FT_Set_Transform function) on a returned face! If you need to transform glyphs, do it yourself after glyph loading. Similarly, the returned FT_Size object is always owned by the manager. You should never try to discard it, and never change its settings with FT_Set_Pixel_Sizes or FT_Set_Char_Size The returned size object is the face's current size, which means that you can call FT_Load_Glyph with the face if you need to.

#### FTC_CmapCache
      typedef struct FTC_CMapCacheRec_*  FTC_CMapCache;
An opaque handle used to manager a charmap cache. This cache is to hold character codes -> glyph indices mappings.

#### FTC_CMapDesc
      typedef struct FTC_CMapDescRec_*  FTC_CMapDesc;
A handle to an FTC_CMapDescRec structure used to describe a given charmap in a charmap cache. Each FTC_CMapDesc describes which charmap (of which ?FTC_Face? we want to use in FTC_CMapCache_Lookup

#### FTC_CMapType
      typedef enum  FTC_CMapType_
      {
        FTC_CMAP_BY_INDEX    = 0,
        FTC_CMAP_BY_ENCODING = 1,
        FTC_CMAP_BY_ID       = 2

      } FTC_CMapType;
The list of valid ?FTC_CMap? types. They indicate how we want to address a charmap within an FTC_FaceID
values
FTC_CMAP_BY_INDEX | Address a charmap by its index in the corresponding FT_Face
FTC_CMAP_BY_ENCODING | Use a FT_Face charmap that corresponds to a given encoding.
FTC_CMAP_BY_ID | Use an FT_Face charmap that corresponds to a given (platform,encoding) ID. See FTC_CMapIdRec

#### FTC_CMapIdRec
      typedef struct  FTC_CMapIdRec_
      {
        FT_UInt  platform;
        FT_UInt  encoding;

      } FTC_CMapIdRec;
A short structure to identify a charmap by a (platform,encoding) pair of values.
fields
platform | The platform ID.
encoding | The encoding ID.

#### FTC_CMapDescRec
      typedef struct  FTC_CMapDescRec_
      {
        FTC_FaceID    face_id;
        FTC_CMapType  type;

        union
        {
          FT_UInt        index;
          FT_Encoding    encoding;
          FTC_CMapIdRec  id;

        } u;

      } FTC_CMapDescRec;
A structure to describe a given charmap to ?FTC_CMapCache?
fields
face_id | FTC_FaceID of the face this charmap belongs to.
type | The type of charmap, see FTC_CMapType u.index :: For FTC_CMAP_BY_INDEX types, this is the charmap index (within a FT_Face we want to use. u.encoding :: For FTC_CMAP_BY_ENCODING types, this is the charmap encoding we want to use. see FT_Encoding u.id :: For FTC_CMAP_BY_ID types, this is the (platform,encoding) pair we want to use. see FTC_CMapIdRec and FT_CharMapRec

#### FTC_CMapCache_New
      FT_EXPORT( FT_Error )
      FTC_CMapCache_New( FTC_Manager     manager,
                         FTC_CMapCache  *acache );
Creates a new charmap cache.
input
manager | A handle to the cache manager.
output
acache | A new cache handle. NULL in case of error.
return
FreeType error code. 0 means success.
note
Like all other caches, this one will be destroyed with the cache manager.

#### FTC_CMapCache_Lookup
      FT_EXPORT( FT_UInt )
      FTC_CMapCache_Lookup( FTC_CMapCache  cache,
                            FTC_CMapDesc   cmap_desc,
                            FT_UInt32      char_code );
Translates a character code into a glyph index, using the charmap cache.
input
cache | A charmap cache handle.
cmap_desc | A charmap descriptor handle.
char_code | The character code (in the corresponding charmap).
return
Glyph index. 0 means "no glyph".
note
This function doesn't return FTC_Node handles, since there is no real use for them with typical uses of charmaps.

#### FTC_ImageTypeRec
      typedef struct  FTC_ImageTypeRec_
      {
        FTC_FontRec  font;
        FT_Int32     flags;

      } FTC_ImageTypeRec;

      typedef struct FTC_ImageTypeRec_*   FTC_ImageType;
A simple structure used to describe the type of glyph image to be loaded into the cache.
fields
font | An FTC_FontRec used to describe the glyph's face and size.
flags | The load flags to be applied when loading the glyph; see the FT_LOAD_XXX constants for details.
note
This type completely replaces the FTC_Image_Desc structure which is now obsolete.

#### FTC_ImageCache
      typedef struct FTC_ImageCacheRec_*  FTC_ImageCache;
A handle to an glyph image cache object. They are designed to hold many distinct glyph images while not exceeding a certain memory threshold.

#### FTC_ImageCache_New
      FT_EXPORT( FT_Error )
      FTC_ImageCache_New( FTC_Manager      manager,
                          FTC_ImageCache  *acache );
Creates a new glyph image cache.
input
manager | The parent manager for the image cache.
output
acache | A handle to the new glyph image cache object.
return
FreeType error code. 0 means success.

#### FTC_ImageCache_Lookup
      FT_EXPORT( FT_Error )
      FTC_ImageCache_Lookup( FTC_ImageCache  cache,
                             FTC_ImageType   type,
                             FT_UInt         gindex,
                             FT_Glyph       *aglyph,
                             FTC_Node       *anode );
Retrieves a given glyph image from a glyph image cache.
input
cache | A handle to the source glyph image cache.
type | A pointer to a glyph image type descriptor.
gindex | The glyph index to retrieve.
output
aglyph | The corresponding FT_Glyph object. 0 in case of failure.
anode | Used to return the address of of the corresponding cache node after incrementing its reference count (see note below).
return
FreeType error code. 0 means success.
note
The returned glyph is owned and managed by the glyph image cache. Never try to transform or discard it manually! You can however create a copy with FT_Glyph_Copy and modify the new one. If "anode" is not NULL, it receives the address of the cache node containing the glyph image, after increasing its reference count. This ensures that the node (as well as the FT_Glyph) will always be kept in the cache until you call FTC_Node_Unref to "release" it. If "anode" is NULL, the cache node is left unchanged, which means that the FT_Glyph could be flushed out of the cache on the next call to one of the caching sub-system APIs. Don't assume that it is persistent!

#### FTC_Image_Desc
      typedef struct  FTC_Image_Desc_
      {
        FTC_FontRec  font;
        FT_UInt      image_type;

      } FTC_Image_Desc;
THIS TYPE IS DEPRECATED. Use ?FTC_ImageDesc? instead. A simple structure used to describe a given glyph image category.
fields
size | An ?FTC_SizeRec? used to describe the glyph's face and size.
image_type | The glyph image's type.

#### FTC_Image_Cache
      typedef FTC_ImageCache  FTC_Image_Cache;
THIS TYPE IS DEPRECATED. Use FTC_ImageCache instead.

#### FTC_Image_Cache_New
      FT_EXPORT( FT_Error )
      FTC_Image_Cache_New( FTC_Manager       manager,
                           FTC_Image_Cache  *acache );
THIS FUNCTION IS DEPRECATED. Use FTC_ImageCache_New instead. Creates a new glyph image cache.
input
manager | The parent manager for the image cache.
output
acache | A handle to the new glyph image cache object.
return
FreeType error code. 0 means success.

#### FTC_Image_Cache_Lookup
      FT_EXPORT( FT_Error )
      FTC_Image_Cache_Lookup( FTC_Image_Cache  cache,
                              FTC_Image_Desc*  desc,
                              FT_UInt          gindex,
                              FT_Glyph        *aglyph );
THIS FUNCTION IS DEPRECATED. Use FTC_ImageCache_Lookup instead.
input
cache | A handle to the source glyph image cache.
desc | A pointer to a glyph image descriptor.
gindex | The glyph index to retrieve.
output
aglyph | The corresponding FT_Glyph object. 0 in case of failure.
return
FreeType error code. 0 means success.
note
The returned glyph is owned and managed by the glyph image cache. Never try to transform or discard it manually! You can however create a copy with FT_Glyph_Copy and modify the new one. Because the glyph image cache limits the total amount of memory taken by the glyphs it holds, the returned glyph might disappear on a later invocation of this function! It is a cache after all... Use this function to "lock" the glyph as long as it is needed.

#### FTC_ManagerRec
      typedef struct  FTC_ManagerRec_
      {
        FT_Library          library;
        FT_LruList          faces_list;
        FT_LruList          sizes_list;

        FT_ULong            max_weight;
        FT_ULong            cur_weight;

        FT_UInt             num_nodes;
        FTC_Node            nodes_list;

        FTC_Cache           caches[FTC_MAX_CACHES];

        FT_Pointer          request_data;
        FTC_Face_Requester  request_face;

        FTC_FamilyTableRec  families;

      } FTC_ManagerRec;
The cache manager structure.
fields
library | A handle to a FreeType library instance.
faces_list | The lru list of FT_Face objects in the cache.
sizes_list | The lru list of FT_Size objects in the cache.
max_weight | The maximum cache pool weight.
cur_weight | The current cache pool weight.
num_nodes | The current number of nodes in the manager.
nodes_list | The global lru list of all cache nodes.
caches | A table of installed/registered cache objects.
request_data | User-provided data passed to the requester.
request_face | User-provided function used to implement a mapping between abstract FTC_FaceID values and real FT_Face objects.
families | Global table of families.

#### FTC_Manager_Compress
      FT_EXPORT( void )
      FTC_Manager_Compress( FTC_Manager  manager );

      /* this must be used internally for the moment */
      FT_EXPORT( FT_Error )
      FTC_Manager_Register_Cache( FTC_Manager      manager,
                                  FTC_Cache_Class  clazz,
                                  FTC_Cache       *acache );

      /* can be called to increment a node's reference count */
      FT_EXPORT( void )
      FTC_Node_Ref( FTC_Node     node,
                    FTC_Manager  manager );
This function is used to check the state of the cache manager if its `num_bytes' field is greater than its `max_bytes' field. It will flush as many old cache nodes as possible (ignoring cache nodes with a non-zero reference count).
inout
manager | A handle to the cache manager.
note
Client applications should not call this function directly. It is normally invoked by specific cache implementations. The reason this function is exported is to allow client-specific cache classes.

#### FTC_Node_Unref
      FT_EXPORT( void )
      FTC_Node_Unref( FTC_Node     node,
                      FTC_Manager  manager );
Decrement a cache node's internal reference count. When the count reaches 0, it is not destroyed but becomes eligible for subsequent cache flushes.
input
node | The cache node handle.
manager | The cache manager handle.

#### FTC_SBit
      typedef struct FTC_SBitRec_*  FTC_SBit;
A handle to a small bitmap descriptor. See the FTC_SBitRec structure for details.

#### FTC_SBitRec
      typedef struct  FTC_SBitRec_
      {
        FT_Byte   width;
        FT_Byte   height;
        FT_Char   left;
        FT_Char   top;

        FT_Byte   format;
        FT_Byte   max_grays;
        FT_Short  pitch;
        FT_Char   xadvance;
        FT_Char   yadvance;

        FT_Byte*  buffer;

      } FTC_SBitRec;
A very compact structure used to describe a small glyph bitmap.
fields
width | The bitmap width in pixels.
height | The bitmap height in pixels.
left | The horizontal distance from the pen position to the left bitmap border (a.k.a. `left side bearing', or `lsb').
top | The vertical distance from the pen position (on the baseline) to the upper bitmap border (a.k.a. `top side bearing'). The distance is positive for upwards Y coordinates.
format | The format of the glyph bitmap (monochrome or gray).
max_grays | Maximum gray level value (in the range 1 to 255).
pitch | The number of bytes per bitmap line. May be positive or negative.
xadvance | The horizontal advance width in pixels.
yadvance | The vertical advance height in pixels.
buffer | A pointer to the bitmap pixels.

#### FTC_SBitCache
      typedef struct FTC_SBitCacheRec_*  FTC_SBitCache;
A handle to a small bitmap cache. These are special cache objects used to store small glyph bitmaps (and anti-aliased pixmaps) in a much more efficient way than the traditional glyph image cache implemented by FTC_ImageCache

#### FTC_SBit_Cache
      typedef FTC_SBitCache  FTC_SBit_Cache;
DEPRECATED. Use FTC_SBitCache instead.

#### FTC_SBitCache_New
      FT_EXPORT( FT_Error )
      FTC_SBitCache_New( FTC_Manager     manager,
                         FTC_SBitCache  *acache );
Creates a new cache to store small glyph bitmaps.
input
manager | A handle to the source cache manager.
output
acache | A handle to the new sbit cache. NULL in case of error.
return
FreeType error code. 0 means success.

#### FTC_SBitCache_Lookup
      FT_EXPORT( FT_Error )
      FTC_SBitCache_Lookup( FTC_SBitCache    cache,
                            FTC_ImageType    type,
                            FT_UInt          gindex,
                            FTC_SBit        *sbit,
                            FTC_Node        *anode );
Looks up a given small glyph bitmap in a given sbit cache and "lock" it to prevent its flushing from the cache until needed
input
cache | A handle to the source sbit cache.
type | A pointer to the glyph image type descriptor.
gindex | The glyph index.
output
sbit | A handle to a small bitmap descriptor.
anode | Used to return the address of of the corresponding cache node after incrementing its reference count (see note below).
return
FreeType error code. 0 means success.
note
The small bitmap descriptor and its bit buffer are owned by the cache and should never be freed by the application. They might as well disappear from memory on the next cache lookup, so don't treat them as persistent data. The descriptor's `buffer' field is set to 0 to indicate a missing glyph bitmap. If "anode" is not NULL, it receives the address of the cache node containing the bitmap, after increasing its reference count. This ensures that the node (as well as the image) will always be kept in the cache until you call FTC_Node_Unref to "release" it. If "anode" is NULL, the cache node is left unchanged, which means that the bitmap could be flushed out of the cache on the next call to one of the caching sub-system APIs. Don't assume that it is persistent!

#### FTC_SBit_Cache_New
      FT_EXPORT( FT_Error )
      FTC_SBit_Cache_New( FTC_Manager      manager,
                          FTC_SBit_Cache  *acache );
DEPRECATED. Use FTC_SBitCache_New instead. Creates a new cache to store small glyph bitmaps.
input
manager | A handle to the source cache manager.
output
acache | A handle to the new sbit cache. NULL in case of error.
return
FreeType error code. 0 means success.

#### FTC_SBit_Cache_Lookup
      FT_EXPORT( FT_Error )
      FTC_SBit_Cache_Lookup( FTC_SBit_Cache   cache,
                             FTC_Image_Desc*  desc,
                             FT_UInt          gindex,
                             FTC_SBit        *sbit );

    FT_END_HEADER

    #endif /* __FTCSBITS_H__ */

    /* END */
DEPRECATED. Use FTC_SBitCache_Lookup instead. Looks up a given small glyph bitmap in a given sbit cache.
input
cache | A handle to the source sbit cache.
desc | A pointer to the glyph image descriptor.
gindex | The glyph index.
output
sbit | A handle to a small bitmap descriptor.
return
FreeType error code. 0 means success.
note
The small bitmap descriptor and its bit buffer are owned by the cache and should never be freed by the application. They might as well disappear from memory on the next cache lookup, so don't treat them as persistent data. The descriptor's `buffer' field is set to 0 to indicate a missing glyph bitmap.