michael@0: /***************************************************************************/ michael@0: /* */ michael@0: /* ftcache.h */ michael@0: /* */ michael@0: /* FreeType Cache subsystem (specification). */ michael@0: /* */ michael@0: /* Copyright 1996-2008, 2010, 2013 by */ michael@0: /* David Turner, Robert Wilhelm, and Werner Lemberg. */ michael@0: /* */ michael@0: /* This file is part of the FreeType project, and may only be used, */ michael@0: /* modified, and distributed under the terms of the FreeType project */ michael@0: /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ michael@0: /* this file you indicate that you have read the license and */ michael@0: /* understand and accept it fully. */ michael@0: /* */ michael@0: /***************************************************************************/ michael@0: michael@0: michael@0: #ifndef __FTCACHE_H__ michael@0: #define __FTCACHE_H__ michael@0: michael@0: michael@0: #include michael@0: #include FT_GLYPH_H michael@0: michael@0: michael@0: FT_BEGIN_HEADER michael@0: michael@0: michael@0: /************************************************************************* michael@0: * michael@0: *
michael@0: * cache_subsystem michael@0: * michael@0: * michael@0: * Cache Sub-System michael@0: * michael@0: * <Abstract> michael@0: * How to cache face, size, and glyph data with FreeType~2. michael@0: * michael@0: * <Description> michael@0: * This section describes the FreeType~2 cache sub-system, which is used michael@0: * to limit the number of concurrently opened @FT_Face and @FT_Size michael@0: * objects, as well as caching information like character maps and glyph michael@0: * images while limiting their maximum memory usage. michael@0: * michael@0: * Note that all types and functions begin with the `FTC_' prefix. michael@0: * michael@0: * The cache is highly portable and thus doesn't know anything about the michael@0: * fonts installed on your system, or how to access them. This implies michael@0: * the following scheme: michael@0: * michael@0: * First, available or installed font faces are uniquely identified by michael@0: * @FTC_FaceID values, provided to the cache by the client. Note that michael@0: * the cache only stores and compares these values, and doesn't try to michael@0: * interpret them in any way. michael@0: * michael@0: * Second, the cache calls, only when needed, a client-provided function michael@0: * to convert an @FTC_FaceID into a new @FT_Face object. The latter is michael@0: * then completely managed by the cache, including its termination michael@0: * through @FT_Done_Face. To monitor termination of face objects, the michael@0: * finalizer callback in the `generic' field of the @FT_Face object can michael@0: * be used, which might also be used to store the @FTC_FaceID of the michael@0: * face. michael@0: * michael@0: * Clients are free to map face IDs to anything else. The most simple michael@0: * usage is to associate them to a (pathname,face_index) pair that is michael@0: * used to call @FT_New_Face. However, more complex schemes are also michael@0: * possible. michael@0: * michael@0: * Note that for the cache to work correctly, the face ID values must be michael@0: * *persistent*, which means that the contents they point to should not michael@0: * change at runtime, or that their value should not become invalid. michael@0: * michael@0: * If this is unavoidable (e.g., when a font is uninstalled at runtime), michael@0: * you should call @FTC_Manager_RemoveFaceID as soon as possible, to let michael@0: * the cache get rid of any references to the old @FTC_FaceID it may michael@0: * keep internally. Failure to do so will lead to incorrect behaviour michael@0: * or even crashes. michael@0: * michael@0: * To use the cache, start with calling @FTC_Manager_New to create a new michael@0: * @FTC_Manager object, which models a single cache instance. You can michael@0: * then look up @FT_Face and @FT_Size objects with michael@0: * @FTC_Manager_LookupFace and @FTC_Manager_LookupSize, respectively. michael@0: * michael@0: * If you want to use the charmap caching, call @FTC_CMapCache_New, then michael@0: * later use @FTC_CMapCache_Lookup to perform the equivalent of michael@0: * @FT_Get_Char_Index, only much faster. michael@0: * michael@0: * If you want to use the @FT_Glyph caching, call @FTC_ImageCache, then michael@0: * later use @FTC_ImageCache_Lookup to retrieve the corresponding michael@0: * @FT_Glyph objects from the cache. michael@0: * michael@0: * If you need lots of small bitmaps, it is much more memory efficient michael@0: * to call @FTC_SBitCache_New followed by @FTC_SBitCache_Lookup. This michael@0: * returns @FTC_SBitRec structures, which are used to store small michael@0: * bitmaps directly. (A small bitmap is one whose metrics and michael@0: * dimensions all fit into 8-bit integers). michael@0: * michael@0: * We hope to also provide a kerning cache in the near future. michael@0: * michael@0: * michael@0: * <Order> michael@0: * FTC_Manager michael@0: * FTC_FaceID michael@0: * FTC_Face_Requester michael@0: * michael@0: * FTC_Manager_New michael@0: * FTC_Manager_Reset michael@0: * FTC_Manager_Done michael@0: * FTC_Manager_LookupFace michael@0: * FTC_Manager_LookupSize michael@0: * FTC_Manager_RemoveFaceID michael@0: * michael@0: * FTC_Node michael@0: * FTC_Node_Unref michael@0: * michael@0: * FTC_ImageCache michael@0: * FTC_ImageCache_New michael@0: * FTC_ImageCache_Lookup michael@0: * michael@0: * FTC_SBit michael@0: * FTC_SBitCache michael@0: * FTC_SBitCache_New michael@0: * FTC_SBitCache_Lookup michael@0: * michael@0: * FTC_CMapCache michael@0: * FTC_CMapCache_New michael@0: * FTC_CMapCache_Lookup michael@0: * michael@0: *************************************************************************/ michael@0: michael@0: michael@0: /*************************************************************************/ michael@0: /*************************************************************************/ michael@0: /*************************************************************************/ michael@0: /***** *****/ michael@0: /***** BASIC TYPE DEFINITIONS *****/ michael@0: /***** *****/ michael@0: /*************************************************************************/ michael@0: /*************************************************************************/ michael@0: /*************************************************************************/ michael@0: michael@0: michael@0: /************************************************************************* michael@0: * michael@0: * @type: FTC_FaceID michael@0: * michael@0: * @description: michael@0: * An opaque pointer type that is used to identity face objects. The michael@0: * contents of such objects is application-dependent. michael@0: * michael@0: * These pointers are typically used to point to a user-defined michael@0: * structure containing a font file path, and face index. michael@0: * michael@0: * @note: michael@0: * Never use NULL as a valid @FTC_FaceID. michael@0: * michael@0: * Face IDs are passed by the client to the cache manager that calls, michael@0: * when needed, the @FTC_Face_Requester to translate them into new michael@0: * @FT_Face objects. michael@0: * michael@0: * If the content of a given face ID changes at runtime, or if the value michael@0: * becomes invalid (e.g., when uninstalling a font), you should michael@0: * immediately call @FTC_Manager_RemoveFaceID before any other cache michael@0: * function. michael@0: * michael@0: * Failure to do so will result in incorrect behaviour or even michael@0: * memory leaks and crashes. michael@0: */ michael@0: typedef FT_Pointer FTC_FaceID; michael@0: michael@0: michael@0: /************************************************************************ michael@0: * michael@0: * @functype: michael@0: * FTC_Face_Requester michael@0: * michael@0: * @description: michael@0: * A callback function provided by client applications. It is used by michael@0: * the cache manager to translate a given @FTC_FaceID into a new valid michael@0: * @FT_Face object, on demand. michael@0: * michael@0: * <Input> michael@0: * face_id :: michael@0: * The face ID to resolve. michael@0: * michael@0: * library :: michael@0: * A handle to a FreeType library object. michael@0: * michael@0: * req_data :: michael@0: * Application-provided request data (see note below). michael@0: * michael@0: * <Output> michael@0: * aface :: michael@0: * A new @FT_Face handle. michael@0: * michael@0: * <Return> michael@0: * FreeType error code. 0~means success. michael@0: * michael@0: * <Note> michael@0: * The third parameter `req_data' is the same as the one passed by the michael@0: * client when @FTC_Manager_New is called. michael@0: * michael@0: * The face requester should not perform funny things on the returned michael@0: * face object, like creating a new @FT_Size for it, or setting a michael@0: * transformation through @FT_Set_Transform! michael@0: */ michael@0: typedef FT_Error michael@0: (*FTC_Face_Requester)( FTC_FaceID face_id, michael@0: FT_Library library, michael@0: FT_Pointer request_data, michael@0: FT_Face* aface ); michael@0: michael@0: /* */ michael@0: michael@0: michael@0: /*************************************************************************/ michael@0: /*************************************************************************/ michael@0: /*************************************************************************/ michael@0: /***** *****/ michael@0: /***** CACHE MANAGER OBJECT *****/ michael@0: /***** *****/ michael@0: /*************************************************************************/ michael@0: /*************************************************************************/ michael@0: /*************************************************************************/ michael@0: michael@0: michael@0: /*************************************************************************/ michael@0: /* */ michael@0: /* <Type> */ michael@0: /* FTC_Manager */ michael@0: /* */ michael@0: /* <Description> */ michael@0: /* This object corresponds to one instance of the cache-subsystem. */ michael@0: /* It is used to cache one or more @FT_Face objects, along with */ michael@0: /* corresponding @FT_Size objects. */ michael@0: /* */ michael@0: /* The manager intentionally limits the total number of opened */ michael@0: /* @FT_Face and @FT_Size objects to control memory usage. See the */ michael@0: /* `max_faces' and `max_sizes' parameters of @FTC_Manager_New. */ michael@0: /* */ michael@0: /* The manager is also used to cache `nodes' of various types while */ michael@0: /* limiting their total memory usage. */ michael@0: /* */ michael@0: /* All limitations are enforced by keeping lists of managed objects */ michael@0: /* in most-recently-used order, and flushing old nodes to make room */ michael@0: /* for new ones. */ michael@0: /* */ michael@0: typedef struct FTC_ManagerRec_* FTC_Manager; michael@0: michael@0: michael@0: /*************************************************************************/ michael@0: /* */ michael@0: /* <Type> */ michael@0: /* FTC_Node */ michael@0: /* */ michael@0: /* <Description> */ michael@0: /* An opaque handle to a cache node object. Each cache node is */ michael@0: /* reference-counted. A node with a count of~0 might be flushed */ michael@0: /* out of a full cache whenever a lookup request is performed. */ michael@0: /* */ michael@0: /* If you look up nodes, you have the ability to `acquire' them, */ michael@0: /* i.e., to increment their reference count. This will prevent the */ michael@0: /* node from being flushed out of the cache until you explicitly */ michael@0: /* `release' it (see @FTC_Node_Unref). */ michael@0: /* */ michael@0: /* See also @FTC_SBitCache_Lookup and @FTC_ImageCache_Lookup. */ michael@0: /* */ michael@0: typedef struct FTC_NodeRec_* FTC_Node; michael@0: michael@0: michael@0: /*************************************************************************/ michael@0: /* */ michael@0: /* <Function> */ michael@0: /* FTC_Manager_New */ michael@0: /* */ michael@0: /* <Description> */ michael@0: /* Create a new cache manager. */ michael@0: /* */ michael@0: /* <Input> */ michael@0: /* library :: The parent FreeType library handle to use. */ michael@0: /* */ michael@0: /* max_faces :: Maximum number of opened @FT_Face objects managed by */ michael@0: /* this cache instance. Use~0 for defaults. */ michael@0: /* */ michael@0: /* max_sizes :: Maximum number of opened @FT_Size objects managed by */ michael@0: /* this cache instance. Use~0 for defaults. */ michael@0: /* */ michael@0: /* max_bytes :: Maximum number of bytes to use for cached data nodes. */ michael@0: /* Use~0 for defaults. Note that this value does not */ michael@0: /* account for managed @FT_Face and @FT_Size objects. */ michael@0: /* */ michael@0: /* requester :: An application-provided callback used to translate */ michael@0: /* face IDs into real @FT_Face objects. */ michael@0: /* */ michael@0: /* req_data :: A generic pointer that is passed to the requester */ michael@0: /* each time it is called (see @FTC_Face_Requester). */ michael@0: /* */ michael@0: /* <Output> */ michael@0: /* amanager :: A handle to a new manager object. 0~in case of */ michael@0: /* failure. */ michael@0: /* */ michael@0: /* <Return> */ michael@0: /* FreeType error code. 0~means success. */ michael@0: /* */ michael@0: FT_EXPORT( FT_Error ) michael@0: FTC_Manager_New( FT_Library library, michael@0: FT_UInt max_faces, michael@0: FT_UInt max_sizes, michael@0: FT_ULong max_bytes, michael@0: FTC_Face_Requester requester, michael@0: FT_Pointer req_data, michael@0: FTC_Manager *amanager ); michael@0: michael@0: michael@0: /*************************************************************************/ michael@0: /* */ michael@0: /* <Function> */ michael@0: /* FTC_Manager_Reset */ michael@0: /* */ michael@0: /* <Description> */ michael@0: /* Empty a given cache manager. This simply gets rid of all the */ michael@0: /* currently cached @FT_Face and @FT_Size objects within the manager. */ michael@0: /* */ michael@0: /* <InOut> */ michael@0: /* manager :: A handle to the manager. */ michael@0: /* */ michael@0: FT_EXPORT( void ) michael@0: FTC_Manager_Reset( FTC_Manager manager ); michael@0: michael@0: michael@0: /*************************************************************************/ michael@0: /* */ michael@0: /* <Function> */ michael@0: /* FTC_Manager_Done */ michael@0: /* */ michael@0: /* <Description> */ michael@0: /* Destroy a given manager after emptying it. */ michael@0: /* */ michael@0: /* <Input> */ michael@0: /* manager :: A handle to the target cache manager object. */ michael@0: /* */ michael@0: FT_EXPORT( void ) michael@0: FTC_Manager_Done( FTC_Manager manager ); michael@0: michael@0: michael@0: /*************************************************************************/ michael@0: /* */ michael@0: /* <Function> */ michael@0: /* FTC_Manager_LookupFace */ michael@0: /* */ michael@0: /* <Description> */ michael@0: /* Retrieve the @FT_Face object that corresponds to a given face ID */ michael@0: /* through a cache manager. */ michael@0: /* */ michael@0: /* <Input> */ michael@0: /* manager :: A handle to the cache manager. */ michael@0: /* */ michael@0: /* face_id :: The ID of the face object. */ michael@0: /* */ michael@0: /* <Output> */ michael@0: /* aface :: A handle to the face object. */ michael@0: /* */ michael@0: /* <Return> */ michael@0: /* FreeType error code. 0~means success. */ michael@0: /* */ michael@0: /* <Note> */ michael@0: /* The returned @FT_Face object is always owned by the manager. You */ michael@0: /* should never try to discard it yourself. */ michael@0: /* */ michael@0: /* The @FT_Face object doesn't necessarily have a current size object */ michael@0: /* (i.e., face->size can be~0). If you need a specific `font size', */ michael@0: /* use @FTC_Manager_LookupSize instead. */ michael@0: /* */ michael@0: /* Never change the face's transformation matrix (i.e., never call */ michael@0: /* the @FT_Set_Transform function) on a returned face! If you need */ michael@0: /* to transform glyphs, do it yourself after glyph loading. */ michael@0: /* */ michael@0: /* When you perform a lookup, out-of-memory errors are detected */ michael@0: /* _within_ the lookup and force incremental flushes of the cache */ michael@0: /* until enough memory is released for the lookup to succeed. */ michael@0: /* */ michael@0: /* If a lookup fails with `FT_Err_Out_Of_Memory' the cache has */ michael@0: /* already been completely flushed, and still no memory was available */ michael@0: /* for the operation. */ michael@0: /* */ michael@0: FT_EXPORT( FT_Error ) michael@0: FTC_Manager_LookupFace( FTC_Manager manager, michael@0: FTC_FaceID face_id, michael@0: FT_Face *aface ); michael@0: michael@0: michael@0: /*************************************************************************/ michael@0: /* */ michael@0: /* <Struct> */ michael@0: /* FTC_ScalerRec */ michael@0: /* */ michael@0: /* <Description> */ michael@0: /* A structure used to describe a given character size in either */ michael@0: /* pixels or points to the cache manager. See */ michael@0: /* @FTC_Manager_LookupSize. */ michael@0: /* */ michael@0: /* <Fields> */ michael@0: /* face_id :: The source face ID. */ michael@0: /* */ michael@0: /* width :: The character width. */ michael@0: /* */ michael@0: /* height :: The character height. */ michael@0: /* */ michael@0: /* pixel :: A Boolean. If 1, the `width' and `height' fields are */ michael@0: /* interpreted as integer pixel character sizes. */ michael@0: /* Otherwise, they are expressed as 1/64th of points. */ michael@0: /* */ michael@0: /* x_res :: Only used when `pixel' is value~0 to indicate the */ michael@0: /* horizontal resolution in dpi. */ michael@0: /* */ michael@0: /* y_res :: Only used when `pixel' is value~0 to indicate the */ michael@0: /* vertical resolution in dpi. */ michael@0: /* */ michael@0: /* <Note> */ michael@0: /* This type is mainly used to retrieve @FT_Size objects through the */ michael@0: /* cache manager. */ michael@0: /* */ michael@0: typedef struct FTC_ScalerRec_ michael@0: { michael@0: FTC_FaceID face_id; michael@0: FT_UInt width; michael@0: FT_UInt height; michael@0: FT_Int pixel; michael@0: FT_UInt x_res; michael@0: FT_UInt y_res; michael@0: michael@0: } FTC_ScalerRec; michael@0: michael@0: michael@0: /*************************************************************************/ michael@0: /* */ michael@0: /* <Struct> */ michael@0: /* FTC_Scaler */ michael@0: /* */ michael@0: /* <Description> */ michael@0: /* A handle to an @FTC_ScalerRec structure. */ michael@0: /* */ michael@0: typedef struct FTC_ScalerRec_* FTC_Scaler; michael@0: michael@0: michael@0: /*************************************************************************/ michael@0: /* */ michael@0: /* <Function> */ michael@0: /* FTC_Manager_LookupSize */ michael@0: /* */ michael@0: /* <Description> */ michael@0: /* Retrieve the @FT_Size object that corresponds to a given */ michael@0: /* @FTC_ScalerRec pointer through a cache manager. */ michael@0: /* */ michael@0: /* <Input> */ michael@0: /* manager :: A handle to the cache manager. */ michael@0: /* */ michael@0: /* scaler :: A scaler handle. */ michael@0: /* */ michael@0: /* <Output> */ michael@0: /* asize :: A handle to the size object. */ michael@0: /* */ michael@0: /* <Return> */ michael@0: /* FreeType error code. 0~means success. */ michael@0: /* */ michael@0: /* <Note> */ michael@0: /* The returned @FT_Size object is always owned by the manager. You */ michael@0: /* should never try to discard it by yourself. */ michael@0: /* */ michael@0: /* You can access the parent @FT_Face object simply as `size->face' */ michael@0: /* if you need it. Note that this object is also owned by the */ michael@0: /* manager. */ michael@0: /* */ michael@0: /* <Note> */ michael@0: /* When you perform a lookup, out-of-memory errors are detected */ michael@0: /* _within_ the lookup and force incremental flushes of the cache */ michael@0: /* until enough memory is released for the lookup to succeed. */ michael@0: /* */ michael@0: /* If a lookup fails with `FT_Err_Out_Of_Memory' the cache has */ michael@0: /* already been completely flushed, and still no memory is available */ michael@0: /* for the operation. */ michael@0: /* */ michael@0: FT_EXPORT( FT_Error ) michael@0: FTC_Manager_LookupSize( FTC_Manager manager, michael@0: FTC_Scaler scaler, michael@0: FT_Size *asize ); michael@0: michael@0: michael@0: /*************************************************************************/ michael@0: /* */ michael@0: /* <Function> */ michael@0: /* FTC_Node_Unref */ michael@0: /* */ michael@0: /* <Description> */ michael@0: /* Decrement a cache node's internal reference count. When the count */ michael@0: /* reaches 0, it is not destroyed but becomes eligible for subsequent */ michael@0: /* cache flushes. */ michael@0: /* */ michael@0: /* <Input> */ michael@0: /* node :: The cache node handle. */ michael@0: /* */ michael@0: /* manager :: The cache manager handle. */ michael@0: /* */ michael@0: FT_EXPORT( void ) michael@0: FTC_Node_Unref( FTC_Node node, michael@0: FTC_Manager manager ); michael@0: michael@0: michael@0: /************************************************************************* michael@0: * michael@0: * @function: michael@0: * FTC_Manager_RemoveFaceID michael@0: * michael@0: * @description: michael@0: * A special function used to indicate to the cache manager that michael@0: * a given @FTC_FaceID is no longer valid, either because its michael@0: * content changed, or because it was deallocated or uninstalled. michael@0: * michael@0: * @input: michael@0: * manager :: michael@0: * The cache manager handle. michael@0: * michael@0: * face_id :: michael@0: * The @FTC_FaceID to be removed. michael@0: * michael@0: * @note: michael@0: * This function flushes all nodes from the cache corresponding to this michael@0: * `face_id', with the exception of nodes with a non-null reference michael@0: * count. michael@0: * michael@0: * Such nodes are however modified internally so as to never appear michael@0: * in later lookups with the same `face_id' value, and to be immediately michael@0: * destroyed when released by all their users. michael@0: * michael@0: */ michael@0: FT_EXPORT( void ) michael@0: FTC_Manager_RemoveFaceID( FTC_Manager manager, michael@0: FTC_FaceID face_id ); michael@0: michael@0: michael@0: /*************************************************************************/ michael@0: /* */ michael@0: /* <Section> */ michael@0: /* cache_subsystem */ michael@0: /* */ michael@0: /*************************************************************************/ michael@0: michael@0: /************************************************************************* michael@0: * michael@0: * @type: michael@0: * FTC_CMapCache michael@0: * michael@0: * @description: michael@0: * An opaque handle used to model a charmap cache. This cache is to michael@0: * hold character codes -> glyph indices mappings. michael@0: * michael@0: */ michael@0: typedef struct FTC_CMapCacheRec_* FTC_CMapCache; michael@0: michael@0: michael@0: /************************************************************************* michael@0: * michael@0: * @function: michael@0: * FTC_CMapCache_New michael@0: * michael@0: * @description: michael@0: * Create a new charmap cache. michael@0: * michael@0: * @input: michael@0: * manager :: michael@0: * A handle to the cache manager. michael@0: * michael@0: * @output: michael@0: * acache :: michael@0: * A new cache handle. NULL in case of error. michael@0: * michael@0: * @return: michael@0: * FreeType error code. 0~means success. michael@0: * michael@0: * @note: michael@0: * Like all other caches, this one will be destroyed with the cache michael@0: * manager. michael@0: * michael@0: */ michael@0: FT_EXPORT( FT_Error ) michael@0: FTC_CMapCache_New( FTC_Manager manager, michael@0: FTC_CMapCache *acache ); michael@0: michael@0: michael@0: /************************************************************************ michael@0: * michael@0: * @function: michael@0: * FTC_CMapCache_Lookup michael@0: * michael@0: * @description: michael@0: * Translate a character code into a glyph index, using the charmap michael@0: * cache. michael@0: * michael@0: * @input: michael@0: * cache :: michael@0: * A charmap cache handle. michael@0: * michael@0: * face_id :: michael@0: * The source face ID. michael@0: * michael@0: * cmap_index :: michael@0: * The index of the charmap in the source face. Any negative value michael@0: * means to use the cache @FT_Face's default charmap. michael@0: * michael@0: * char_code :: michael@0: * The character code (in the corresponding charmap). michael@0: * michael@0: * @return: michael@0: * Glyph index. 0~means `no glyph'. michael@0: * michael@0: */ michael@0: FT_EXPORT( FT_UInt ) michael@0: FTC_CMapCache_Lookup( FTC_CMapCache cache, michael@0: FTC_FaceID face_id, michael@0: FT_Int cmap_index, michael@0: FT_UInt32 char_code ); michael@0: michael@0: michael@0: /*************************************************************************/ michael@0: /* */ michael@0: /* <Section> */ michael@0: /* cache_subsystem */ michael@0: /* */ michael@0: /*************************************************************************/ michael@0: michael@0: michael@0: /*************************************************************************/ michael@0: /*************************************************************************/ michael@0: /*************************************************************************/ michael@0: /***** *****/ michael@0: /***** IMAGE CACHE OBJECT *****/ michael@0: /***** *****/ michael@0: /*************************************************************************/ michael@0: /*************************************************************************/ michael@0: /*************************************************************************/ michael@0: michael@0: michael@0: /************************************************************************* michael@0: * michael@0: * @struct: michael@0: * FTC_ImageTypeRec michael@0: * michael@0: * @description: michael@0: * A structure used to model the type of images in a glyph cache. michael@0: * michael@0: * @fields: michael@0: * face_id :: michael@0: * The face ID. michael@0: * michael@0: * width :: michael@0: * The width in pixels. michael@0: * michael@0: * height :: michael@0: * The height in pixels. michael@0: * michael@0: * flags :: michael@0: * The load flags, as in @FT_Load_Glyph. michael@0: * michael@0: */ michael@0: typedef struct FTC_ImageTypeRec_ michael@0: { michael@0: FTC_FaceID face_id; michael@0: FT_Int width; michael@0: FT_Int height; michael@0: FT_Int32 flags; michael@0: michael@0: } FTC_ImageTypeRec; michael@0: michael@0: michael@0: /************************************************************************* michael@0: * michael@0: * @type: michael@0: * FTC_ImageType michael@0: * michael@0: * @description: michael@0: * A handle to an @FTC_ImageTypeRec structure. michael@0: * michael@0: */ michael@0: typedef struct FTC_ImageTypeRec_* FTC_ImageType; michael@0: michael@0: michael@0: /* */ michael@0: michael@0: michael@0: #define FTC_IMAGE_TYPE_COMPARE( d1, d2 ) \ michael@0: ( (d1)->face_id == (d2)->face_id && \ michael@0: (d1)->width == (d2)->width && \ michael@0: (d1)->flags == (d2)->flags ) michael@0: michael@0: michael@0: /*************************************************************************/ michael@0: /* */ michael@0: /* <Type> */ michael@0: /* FTC_ImageCache */ michael@0: /* */ michael@0: /* <Description> */ michael@0: /* A handle to a glyph image cache object. They are designed to */ michael@0: /* hold many distinct glyph images while not exceeding a certain */ michael@0: /* memory threshold. */ michael@0: /* */ michael@0: typedef struct FTC_ImageCacheRec_* FTC_ImageCache; michael@0: michael@0: michael@0: /*************************************************************************/ michael@0: /* */ michael@0: /* <Function> */ michael@0: /* FTC_ImageCache_New */ michael@0: /* */ michael@0: /* <Description> */ michael@0: /* Create a new glyph image cache. */ michael@0: /* */ michael@0: /* <Input> */ michael@0: /* manager :: The parent manager for the image cache. */ michael@0: /* */ michael@0: /* <Output> */ michael@0: /* acache :: A handle to the new glyph image cache object. */ michael@0: /* */ michael@0: /* <Return> */ michael@0: /* FreeType error code. 0~means success. */ michael@0: /* */ michael@0: FT_EXPORT( FT_Error ) michael@0: FTC_ImageCache_New( FTC_Manager manager, michael@0: FTC_ImageCache *acache ); michael@0: michael@0: michael@0: /*************************************************************************/ michael@0: /* */ michael@0: /* <Function> */ michael@0: /* FTC_ImageCache_Lookup */ michael@0: /* */ michael@0: /* <Description> */ michael@0: /* Retrieve a given glyph image from a glyph image cache. */ michael@0: /* */ michael@0: /* <Input> */ michael@0: /* cache :: A handle to the source glyph image cache. */ michael@0: /* */ michael@0: /* type :: A pointer to a glyph image type descriptor. */ michael@0: /* */ michael@0: /* gindex :: The glyph index to retrieve. */ michael@0: /* */ michael@0: /* <Output> */ michael@0: /* aglyph :: The corresponding @FT_Glyph object. 0~in case of */ michael@0: /* failure. */ michael@0: /* */ michael@0: /* anode :: Used to return the address of of the corresponding cache */ michael@0: /* node after incrementing its reference count (see note */ michael@0: /* below). */ michael@0: /* */ michael@0: /* <Return> */ michael@0: /* FreeType error code. 0~means success. */ michael@0: /* */ michael@0: /* <Note> */ michael@0: /* The returned glyph is owned and managed by the glyph image cache. */ michael@0: /* Never try to transform or discard it manually! You can however */ michael@0: /* create a copy with @FT_Glyph_Copy and modify the new one. */ michael@0: /* */ michael@0: /* If `anode' is _not_ NULL, it receives the address of the cache */ michael@0: /* node containing the glyph image, after increasing its reference */ michael@0: /* count. This ensures that the node (as well as the @FT_Glyph) will */ michael@0: /* always be kept in the cache until you call @FTC_Node_Unref to */ michael@0: /* `release' it. */ michael@0: /* */ michael@0: /* If `anode' is NULL, the cache node is left unchanged, which means */ michael@0: /* that the @FT_Glyph could be flushed out of the cache on the next */ michael@0: /* call to one of the caching sub-system APIs. Don't assume that it */ michael@0: /* is persistent! */ michael@0: /* */ michael@0: FT_EXPORT( FT_Error ) michael@0: FTC_ImageCache_Lookup( FTC_ImageCache cache, michael@0: FTC_ImageType type, michael@0: FT_UInt gindex, michael@0: FT_Glyph *aglyph, michael@0: FTC_Node *anode ); michael@0: michael@0: michael@0: /*************************************************************************/ michael@0: /* */ michael@0: /* <Function> */ michael@0: /* FTC_ImageCache_LookupScaler */ michael@0: /* */ michael@0: /* <Description> */ michael@0: /* A variant of @FTC_ImageCache_Lookup that uses an @FTC_ScalerRec */ michael@0: /* to specify the face ID and its size. */ michael@0: /* */ michael@0: /* <Input> */ michael@0: /* cache :: A handle to the source glyph image cache. */ michael@0: /* */ michael@0: /* scaler :: A pointer to a scaler descriptor. */ michael@0: /* */ michael@0: /* load_flags :: The corresponding load flags. */ michael@0: /* */ michael@0: /* gindex :: The glyph index to retrieve. */ michael@0: /* */ michael@0: /* <Output> */ michael@0: /* aglyph :: The corresponding @FT_Glyph object. 0~in case of */ michael@0: /* failure. */ michael@0: /* */ michael@0: /* anode :: Used to return the address of of the corresponding */ michael@0: /* cache node after incrementing its reference count */ michael@0: /* (see note below). */ michael@0: /* */ michael@0: /* <Return> */ michael@0: /* FreeType error code. 0~means success. */ michael@0: /* */ michael@0: /* <Note> */ michael@0: /* The returned glyph is owned and managed by the glyph image cache. */ michael@0: /* Never try to transform or discard it manually! You can however */ michael@0: /* create a copy with @FT_Glyph_Copy and modify the new one. */ michael@0: /* */ michael@0: /* If `anode' is _not_ NULL, it receives the address of the cache */ michael@0: /* node containing the glyph image, after increasing its reference */ michael@0: /* count. This ensures that the node (as well as the @FT_Glyph) will */ michael@0: /* always be kept in the cache until you call @FTC_Node_Unref to */ michael@0: /* `release' it. */ michael@0: /* */ michael@0: /* If `anode' is NULL, the cache node is left unchanged, which means */ michael@0: /* that the @FT_Glyph could be flushed out of the cache on the next */ michael@0: /* call to one of the caching sub-system APIs. Don't assume that it */ michael@0: /* is persistent! */ michael@0: /* */ michael@0: /* Calls to @FT_Set_Char_Size and friends have no effect on cached */ michael@0: /* glyphs; you should always use the FreeType cache API instead. */ michael@0: /* */ michael@0: FT_EXPORT( FT_Error ) michael@0: FTC_ImageCache_LookupScaler( FTC_ImageCache cache, michael@0: FTC_Scaler scaler, michael@0: FT_ULong load_flags, michael@0: FT_UInt gindex, michael@0: FT_Glyph *aglyph, michael@0: FTC_Node *anode ); michael@0: michael@0: michael@0: /*************************************************************************/ michael@0: /* */ michael@0: /* <Type> */ michael@0: /* FTC_SBit */ michael@0: /* */ michael@0: /* <Description> */ michael@0: /* A handle to a small bitmap descriptor. See the @FTC_SBitRec */ michael@0: /* structure for details. */ michael@0: /* */ michael@0: typedef struct FTC_SBitRec_* FTC_SBit; michael@0: michael@0: michael@0: /*************************************************************************/ michael@0: /* */ michael@0: /* <Struct> */ michael@0: /* FTC_SBitRec */ michael@0: /* */ michael@0: /* <Description> */ michael@0: /* A very compact structure used to describe a small glyph bitmap. */ michael@0: /* */ michael@0: /* <Fields> */ michael@0: /* width :: The bitmap width in pixels. */ michael@0: /* */ michael@0: /* height :: The bitmap height in pixels. */ michael@0: /* */ michael@0: /* left :: The horizontal distance from the pen position to the */ michael@0: /* left bitmap border (a.k.a. `left side bearing', or */ michael@0: /* `lsb'). */ michael@0: /* */ michael@0: /* top :: The vertical distance from the pen position (on the */ michael@0: /* baseline) to the upper bitmap border (a.k.a. `top */ michael@0: /* side bearing'). The distance is positive for upwards */ michael@0: /* y~coordinates. */ michael@0: /* */ michael@0: /* format :: The format of the glyph bitmap (monochrome or gray). */ michael@0: /* */ michael@0: /* max_grays :: Maximum gray level value (in the range 1 to~255). */ michael@0: /* */ michael@0: /* pitch :: The number of bytes per bitmap line. May be positive */ michael@0: /* or negative. */ michael@0: /* */ michael@0: /* xadvance :: The horizontal advance width in pixels. */ michael@0: /* */ michael@0: /* yadvance :: The vertical advance height in pixels. */ michael@0: /* */ michael@0: /* buffer :: A pointer to the bitmap pixels. */ michael@0: /* */ michael@0: typedef struct FTC_SBitRec_ michael@0: { michael@0: FT_Byte width; michael@0: FT_Byte height; michael@0: FT_Char left; michael@0: FT_Char top; michael@0: michael@0: FT_Byte format; michael@0: FT_Byte max_grays; michael@0: FT_Short pitch; michael@0: FT_Char xadvance; michael@0: FT_Char yadvance; michael@0: michael@0: FT_Byte* buffer; michael@0: michael@0: } FTC_SBitRec; michael@0: michael@0: michael@0: /*************************************************************************/ michael@0: /* */ michael@0: /* <Type> */ michael@0: /* FTC_SBitCache */ michael@0: /* */ michael@0: /* <Description> */ michael@0: /* A handle to a small bitmap cache. These are special cache objects */ michael@0: /* used to store small glyph bitmaps (and anti-aliased pixmaps) in a */ michael@0: /* much more efficient way than the traditional glyph image cache */ michael@0: /* implemented by @FTC_ImageCache. */ michael@0: /* */ michael@0: typedef struct FTC_SBitCacheRec_* FTC_SBitCache; michael@0: michael@0: michael@0: /*************************************************************************/ michael@0: /* */ michael@0: /* <Function> */ michael@0: /* FTC_SBitCache_New */ michael@0: /* */ michael@0: /* <Description> */ michael@0: /* Create a new cache to store small glyph bitmaps. */ michael@0: /* */ michael@0: /* <Input> */ michael@0: /* manager :: A handle to the source cache manager. */ michael@0: /* */ michael@0: /* <Output> */ michael@0: /* acache :: A handle to the new sbit cache. NULL in case of error. */ michael@0: /* */ michael@0: /* <Return> */ michael@0: /* FreeType error code. 0~means success. */ michael@0: /* */ michael@0: FT_EXPORT( FT_Error ) michael@0: FTC_SBitCache_New( FTC_Manager manager, michael@0: FTC_SBitCache *acache ); michael@0: michael@0: michael@0: /*************************************************************************/ michael@0: /* */ michael@0: /* <Function> */ michael@0: /* FTC_SBitCache_Lookup */ michael@0: /* */ michael@0: /* <Description> */ michael@0: /* Look up a given small glyph bitmap in a given sbit cache and */ michael@0: /* `lock' it to prevent its flushing from the cache until needed. */ michael@0: /* */ michael@0: /* <Input> */ michael@0: /* cache :: A handle to the source sbit cache. */ michael@0: /* */ michael@0: /* type :: A pointer to the glyph image type descriptor. */ michael@0: /* */ michael@0: /* gindex :: The glyph index. */ michael@0: /* */ michael@0: /* <Output> */ michael@0: /* sbit :: A handle to a small bitmap descriptor. */ michael@0: /* */ michael@0: /* anode :: Used to return the address of of the corresponding cache */ michael@0: /* node after incrementing its reference count (see note */ michael@0: /* below). */ michael@0: /* */ michael@0: /* <Return> */ michael@0: /* FreeType error code. 0~means success. */ michael@0: /* */ michael@0: /* <Note> */ michael@0: /* The small bitmap descriptor and its bit buffer are owned by the */ michael@0: /* cache and should never be freed by the application. They might */ michael@0: /* as well disappear from memory on the next cache lookup, so don't */ michael@0: /* treat them as persistent data. */ michael@0: /* */ michael@0: /* The descriptor's `buffer' field is set to~0 to indicate a missing */ michael@0: /* glyph bitmap. */ michael@0: /* */ michael@0: /* If `anode' is _not_ NULL, it receives the address of the cache */ michael@0: /* node containing the bitmap, after increasing its reference count. */ michael@0: /* This ensures that the node (as well as the image) will always be */ michael@0: /* kept in the cache until you call @FTC_Node_Unref to `release' it. */ michael@0: /* */ michael@0: /* If `anode' is NULL, the cache node is left unchanged, which means */ michael@0: /* that the bitmap could be flushed out of the cache on the next */ michael@0: /* call to one of the caching sub-system APIs. Don't assume that it */ michael@0: /* is persistent! */ michael@0: /* */ michael@0: FT_EXPORT( FT_Error ) michael@0: FTC_SBitCache_Lookup( FTC_SBitCache cache, michael@0: FTC_ImageType type, michael@0: FT_UInt gindex, michael@0: FTC_SBit *sbit, michael@0: FTC_Node *anode ); michael@0: michael@0: michael@0: /*************************************************************************/ michael@0: /* */ michael@0: /* <Function> */ michael@0: /* FTC_SBitCache_LookupScaler */ michael@0: /* */ michael@0: /* <Description> */ michael@0: /* A variant of @FTC_SBitCache_Lookup that uses an @FTC_ScalerRec */ michael@0: /* to specify the face ID and its size. */ michael@0: /* */ michael@0: /* <Input> */ michael@0: /* cache :: A handle to the source sbit cache. */ michael@0: /* */ michael@0: /* scaler :: A pointer to the scaler descriptor. */ michael@0: /* */ michael@0: /* load_flags :: The corresponding load flags. */ michael@0: /* */ michael@0: /* gindex :: The glyph index. */ michael@0: /* */ michael@0: /* <Output> */ michael@0: /* sbit :: A handle to a small bitmap descriptor. */ michael@0: /* */ michael@0: /* anode :: Used to return the address of of the corresponding */ michael@0: /* cache node after incrementing its reference count */ michael@0: /* (see note below). */ michael@0: /* */ michael@0: /* <Return> */ michael@0: /* FreeType error code. 0~means success. */ michael@0: /* */ michael@0: /* <Note> */ michael@0: /* The small bitmap descriptor and its bit buffer are owned by the */ michael@0: /* cache and should never be freed by the application. They might */ michael@0: /* as well disappear from memory on the next cache lookup, so don't */ michael@0: /* treat them as persistent data. */ michael@0: /* */ michael@0: /* The descriptor's `buffer' field is set to~0 to indicate a missing */ michael@0: /* glyph bitmap. */ michael@0: /* */ michael@0: /* If `anode' is _not_ NULL, it receives the address of the cache */ michael@0: /* node containing the bitmap, after increasing its reference count. */ michael@0: /* This ensures that the node (as well as the image) will always be */ michael@0: /* kept in the cache until you call @FTC_Node_Unref to `release' it. */ michael@0: /* */ michael@0: /* If `anode' is NULL, the cache node is left unchanged, which means */ michael@0: /* that the bitmap could be flushed out of the cache on the next */ michael@0: /* call to one of the caching sub-system APIs. Don't assume that it */ michael@0: /* is persistent! */ michael@0: /* */ michael@0: FT_EXPORT( FT_Error ) michael@0: FTC_SBitCache_LookupScaler( FTC_SBitCache cache, michael@0: FTC_Scaler scaler, michael@0: FT_ULong load_flags, michael@0: FT_UInt gindex, michael@0: FTC_SBit *sbit, michael@0: FTC_Node *anode ); michael@0: michael@0: michael@0: /* */ michael@0: michael@0: FT_END_HEADER michael@0: michael@0: #endif /* __FTCACHE_H__ */ michael@0: michael@0: michael@0: /* END */