FreeType-2.1.10 API Reference

Cache Sub-System

Synopsis

FTC_ManagerFTC_Manager_LookupSizeFTC_SBitCache_New
FTC_FaceIDFTC_Node_UnrefFTC_SBitCache_Lookup
FTC_Face_RequesterFTC_CMapCacheFTC_CMapCache
FTC_FontRecFTC_CMapCache_NewFTC_CMapDesc
FTC_FontFTC_CMapCache_LookupFTC_CMapType
FTC_NodeFTC_ImageCacheFTC_CMapIdRec
FTC_Manager_NewFTC_ImageCache_NewFTC_CMapDescRec
FTC_Manager_ResetFTC_ImageCache_LookupFTC_CMapCache_New
FTC_Manager_DoneFTC_SBitFTC_CMapCache_Lookup
FTC_Manager_LookupFaceFTC_SBitRecFTC_Manager_Compress
FTC_ScalerRecFTC_SBitCache


This section describes the FreeType 2 cache sub-system which is still 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 struct FTC_FaceIDRec_*  FTC_FaceID;


An opaque 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_Unref).

See also FTC_SBitCache_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_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_LookupFace


  FT_EXPORT( FT_Error )
  FTC_Manager_LookupFace( 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_LookupSize 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_ScalerRec


  typedef struct  FTC_ScalerRec_
  {
    FTC_FaceID  face_id;
    FT_UInt     width;
    FT_UInt     height;
    FT_Int      pixel;
    FT_UInt     x_res;
    FT_UInt     y_res;

  } FTC_ScalerRec, *FTC_Scaler;


A structure used to describe a given character size in either pixels or points to the cache manager. See FTC_Manager_LookupSize.


fields
face_id

The source face ID.

width

The character width.

height

The character height.

pixel

A Boolean. If TRUE, the `width' and `height' fields are interpreted as integer pixel character sizes. Otherwise, they are expressed as 1/64th of points.

x_res

Only used when `pixel' is FALSE to indicate the horizontal resolution in dpi.

y_res

Only used when `pixel' is FALSE to indicate the vertical resolution in dpi.

note

This type is mainly used to retrieve FT_Size objects through the cache manager.


FTC_Manager_LookupSize


  FT_EXPORT( FT_Error )
  FTC_Manager_LookupSize( FTC_Manager  manager,
                          FTC_Scaler   scaler,
                          FT_Size     *asize );


Retrieve the FT_Size object that corresponds to a given ?FTC_Scaler? through a cache manager.


input
manager

A handle to the cache manager.

scaler

A scaler handle.

output
asize

A handle to the size object.

return

FreeType error code. 0 means success.

note

The returned FT_Size object is always owned by the manager. You should never try to discard it by yourself.

You can access the parent FT_Face object simply as `size->face' if you need it. Note that this object is also owned by the manager.


FTC_Node_Unref


  FT_EXPORT( void )
  FTC_Node_Unref( FTC_Node     node,
                  FTC_Manager  manager );


  /* remove all nodes belonging to a given face_id */
  FT_EXPORT( void )
  FTC_Manager_RemoveFaceID( FTC_Manager  manager,
                            FTC_FaceID   face_id );


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_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_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_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_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_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_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_FaceID) 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_CMapDesc 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_Manager_Compress


  FT_EXPORT( void )
  FTC_Manager_Compress( FTC_Manager  manager );


  /* try to flush `count' old nodes from the cache; return the number
   * of really flushed nodes
   */
  FT_EXPORT( FT_UInt )
  FTC_Manager_FlushN( FTC_Manager  manager,
                      FT_UInt      count );


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


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.