FreeType 2 API Reference

FreeType 2 API Reference

Cache Sub-System

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


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 a FTC_FontRec structure.



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_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 &. 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 );

Retrieves the FT_Face &. 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_Image_Desc


  typedef struct  FTC_Image_Desc_
  {
    FTC_FontRec  font;
    FT_UInt      image_type;

  } FTC_Image_Desc;

A simple structure used to describe a given glyph image category.


fields
size

An FTC_SizeRec used to describe the glyph's face &. size.

image_type

The glyph image's type.


FTC_Image_Cache


  typedef struct FTC_Image_CacheRec_*  FTC_Image_Cache;

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_Image_Cache_New


  FT_EXPORT( FT_Error )  FTC_Image_Cache_New( FTC_Manager       manager,
                                              FTC_Image_Cache  *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_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 );

Retrieves a given glyph image from a glyph image cache.


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's a cache after all...


FTC_ManagerRec


  typedef struct  FTC_ManagerRec_
  {
    FT_Library          library;
    FT_Lru              faces_lru;
    FT_Lru              sizes_lru;

    FT_ULong            max_bytes;
    FT_ULong            num_bytes;
    FT_UInt             num_nodes;
    FT_ListRec          global_lru;
    FTC_Cache           caches[FTC_MAX_CACHES];

    FT_Pointer          request_data;
    FTC_Face_Requester  request_face;

  } FTC_ManagerRec;

The cache manager structure.


fields
library

A handle to a FreeType library instance.

faces_lru

The lru list of FT_Face objects in the cache.

sizes_lru

The lru list of FT_Size objects in the cache.

max_bytes

The maximum number of bytes to be allocated in the cache. This is only related to the byte size of the nodes cached by the manager.

num_bytes

The current number of bytes allocated in the cache. Only related to the byte size of cached nodes.

num_nodes

The current number of nodes in the manager.

global_lru

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_FaceIDs and real FT_Face objects.


FTC_Manager_Compress


  FT_EXPORT( void )  FTC_Manager_Compress( 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_CacheNode_SizeFunc


  typedef FT_ULong  (*FTC_CacheNode_SizeFunc)( FTC_CacheNode  node,
                                               FT_Pointer     cache_data );

A function used to compute the total size in bytes of a given cache node. It is used by the cache manager to compute the number of old nodes to flush when the cache is full.


input
node

A handle to the target cache node.

cache_data

A generic pointer passed to the destructor.

return

The size of a given cache node in bytes.


FTC_CacheNode_DestroyFunc


  typedef void  (*FTC_CacheNode_DestroyFunc)( FTC_CacheNode  node,
                                              FT_Pointer     cache_data );

A function used to destroy a given cache node. It is called by the manager when the cache is full and old nodes need to be flushed out.


input
node

A handle to the target cache node.

cache_data

A generic pointer passed to the destructor.


FTC_CacheNode_Class


  typedef struct  FTC_CacheNode_Class_
  {
    FTC_CacheNode_SizeFunc     size_node;
    FTC_CacheNode_DestroyFunc  destroy_node;

  } FTC_CacheNode_Class;

A very simple structure used to describe a cache node's class to the cache manager.


fields
size_node

A function used to size the node.

destroy_node

A function used to destroy the node.

note

The cache node class doesn't include a `new_node' function because the cache manager never allocates cache node directly; it delegates this task to its cache objects.


FTC_Cache_InitFunc


  typedef FT_Error  (*FTC_Cache_InitFunc)( FTC_Cache  cache );

A function used to initialize a given cache object.


input
cache

A handle to the new cache.


FTC_Cache_DoneFunc


  typedef void  (*FTC_Cache_DoneFunc)( FTC_Cache  cache );

A function to finalize a given cache object.


input
cache

A handle to the target cache.


FTC_Cache_Class


  struct  FTC_Cache_Class_
  {
    FT_UInt             cache_byte_size;
    FTC_Cache_InitFunc  init_cache;
    FTC_Cache_DoneFunc  done_cache;
  };

A structure used to describe a given cache object class to the cache manager.


fields
cache_byte_size

The size of the cache object in bytes.

init_cache

The cache object initializer.

done_cache

The cache object finalizer.


FTC_CacheRec


  typedef struct  FTC_CacheRec_
  {
    FTC_Manager           manager;
    FT_Memory             memory;
    FTC_Cache_Class*      clazz;
    FTC_CacheNode_Class*  node_clazz;

    FT_UInt               cache_index;  /* in manager's table           */
    FT_Pointer            cache_data;   /* passed to cache node methods */

  } FTC_CacheRec;

A structure used to describe an abstract cache object.


fields
manager

A handle to the parent cache manager.

memory

A handle to the memory manager.

clazz

A pointer to the cache class.

node_clazz

A pointer to the cache's node class.

cache_index

An index of the cache in the manager's table.

cache_data

Data passed to the cache node constructor/finalizer.


FTC_SBit


  typedef struct FTC_SBitRec_*  FTC_SBit;

A handle to a small bitmap descriptor. See the FTC_SBitRec structure for details.



FTC_SBit_Cache


  typedef struct FTC_SBit_CacheRec_*  FTC_SBit_Cache;

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_Image_Cache.



FTC_SBitRec


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

    FT_Byte   format;
    FT_Char   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).

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_SBit_Cache_New


  FT_EXPORT( FT_Error )  FTC_SBit_Cache_New( FTC_Manager      manager,
                                             FTC_SBit_Cache  *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_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 );

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.


FT_BEGIN_HEADER


#ifdef __cplusplus
#define FT_BEGIN_HEADER  extern "C" {
#else
#define FT_BEGIN_HEADER  /* nothing */
#endif

This macro is used in association with FT_END_HEADER in header files to ensure that the declarations within are properly encapsulated in an `extern "C" { .. }' block when included from a C++ compiler.



FT_END_HEADER


#ifdef __cplusplus
#define FT_END_HEADER  }
#else
#define FT_END_HEADER  /* nothing */
#endif

This macro is used in association with FT_BEGIN_HEADER in header files to ensure that the declarations within are properly encapsulated in an `extern "C" { .. }' block when included from a C++ compiler.



generated on Tue May 29 14:48:55 2001