removed obsolete file (ftcimage.h) updated header files
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531
diff --git a/include/freetype/cache/ftcimage.h b/include/freetype/cache/ftcimage.h
deleted file mode 100644
index b807ce0..0000000
--- a/include/freetype/cache/ftcimage.h
+++ /dev/null
@@ -1,133 +0,0 @@
-/***************************************************************************/
-/* */
-/* ftcimage.h */
-/* */
-/* FreeType Image Cache (specification). */
-/* */
-/* Copyright 2000 by */
-/* David Turner, Robert Wilhelm, and Werner Lemberg. */
-/* */
-/* This file is part of the FreeType project, and may only be used, */
-/* modified, and distributed under the terms of the FreeType project */
-/* license, LICENSE.TXT. By continuing to use, modify, or distribute */
-/* this file you indicate that you have read the license and */
-/* understand and accept it fully. */
-/* */
-/***************************************************************************/
-
-
-#ifndef FTCIMAGE_H
-#define FTCIMAGE_H
-
-#include <freetype/cache/ftcmanag.h>
-#include <freetype/ftglyph.h>
-#include <stddef.h>
-
-#ifdef __cplusplus
- extern "C" {
-#endif
-
-#define FTC_MAX_IMAGE_QUEUES 16
-
- typedef struct FTC_Image_QueueRec_* FTC_Image_Queue;
- typedef struct FTC_ImageNodeRec_* FTC_ImageNode;
-
-
- /* macros used to pack a glyph index and a queue index in a single ptr */
-#define FTC_PTR_TO_GINDEX( p ) ( (FT_UInt)( (FT_ULong)(p) >> 16 ) )
-#define FTC_PTR_TO_QINDEX( p ) ( (FT_UInt)( (FT_ULong)(p) & 0xFFFF ) )
-#define FTC_INDICES_TO_PTR( g, q ) \
- ( (FT_Pointer)( ( (FT_ULong)(g) << 16 ) | \
- ( (FT_ULong)(q) & 0xFFFF) ) )
-
- typedef struct FTC_ImageNodeRec_
- {
- /* root1.data contains an FT_Glyph handle */
- FT_ListNodeRec root1;
-
- /* root2.data contains a glyph index + queue index */
- FT_ListNodeRec root2;
-
- } FTC_ImageNodeRec;
-
-
- /* macros to read/set the glyph & queue index in a FTC_ImageNode */
-#define FTC_IMAGENODE_GET_GINDEX( n ) FTC_PTR_TO_GINDEX( (n)->root2.data )
-#define FTC_IMAGENODE_GET_QINDEX( n ) FTC_PTR_TO_QINDEX( (n)->root2.data )
-#define FTC_IMAGENODE_GET_GLYPH( n ) ( (FT_Glyph)(n)->root1.data )
-#define FTC_IMAGENODE_SET_GLYPH( n, g ) \
- do \
- { \
- (n)->root1.data = g; \
- } while ( 0 )
-
-#define FTC_IMAGENODE_SET_INDICES( n, g, q ) \
- do \
- { \
- (n)->root2.data = FTC_INDICES_TO_PTR( g, q ); \
- } while ( 0 )
-
-
- /* this macro is used to extract a handle to the global LRU list node */
- /* corresponding to a given image node */
-#define FTC_IMAGENODE_TO_LISTNODE( n ) \
- ( (FT_ListNode)&(n)->root2 )
-
- /* this macro is used to extract a handle to a given image node from */
- /* the corresponding LRU glyph list node. That's a bit hackish.. */
-#define FTC_LISTNODE_TO_IMAGENODE( p ) \
- ( (FTC_ImageNode)( (char*)(p) - \
- offsetof( FTC_ImageNodeRec,root2 ) ) )
-
-
- typedef struct FTC_Image_CacheRec_
- {
- FTC_CacheRec root;
-
- FT_Lru queues_lru; /* static queues lru list */
- FT_ListRec glyphs_lru; /* global lru list of glyph images */
-
- FTC_Image_Queue last_queue; /* small cache */
-
- } FTC_Image_CacheRec;
-
-
- /* a table of functions used to generate/manager glyph images */
- typedef struct FTC_Image_Class_
- {
- FT_Error (*init_image)( FTC_Image_Queue queue,
- FTC_ImageNode node );
-
- void (*done_image)( FTC_Image_Queue queue,
- FTC_ImageNode node );
-
- FT_ULong (*size_image)( FTC_Image_Queue queue,
- FTC_ImageNode node );
-
- } FTC_Image_Class;
-
-
- typedef struct FTC_Image_QueueRec_
- {
- FTC_Image_Cache cache;
- FTC_Manager manager;
- FT_Memory memory;
- FTC_Image_Class* clazz;
- FTC_Image_Desc descriptor;
- FT_UInt hash_size;
- FT_List buckets;
- FT_UInt index; /* index in parent cache */
-
- } FTC_Image_QueueRec;
-
-
-
-#ifdef __cplusplus
- }
-#endif
-
-
-#endif /* FTCIMAGE_H */
-
-
-/* END */
diff --git a/include/freetype/cache/ftcmanag.h b/include/freetype/cache/ftcmanag.h
index bdb544f..2992998 100644
--- a/include/freetype/cache/ftcmanag.h
+++ b/include/freetype/cache/ftcmanag.h
@@ -13,8 +13,49 @@
/* this file you indicate that you have read the license and */
/* understand and accept it fully. */
/* */
+/* */
+/* A cache manager is in charge of the following: */
+/* */
+/* - maintain a mapping between generic FTC_FaceIDs and live */
+/* FT_Face objects. The mapping itself is performed through a */
+/* user-provided callback. However, the manager maintains a small */
+/* cache of FT_Face & FT_Size objects in order to speed things */
+/* considerably.. */
+/* */
+/* - manage one or more cache object. Each cache is in charge of */
+/* holding a varying number of "cache nodes". Each cache node */
+/* represents a minimal amount of individually-accessible cached */
+/* data. For example, a cache node can be a FT_Glyph image containing */
+/* a vector outline, or some glyph metrics, or anything else.. */
+/* */
+/* each cache node has a certain size in bytes that is added to the */
+/* total amount of "cache memory" within the manager. */
+/* */
+/* all cache nodes are located in a global LRU list, where the */
+/* oldest node is at the tail of the list */
+/* */
+/* each node belongs to a single cache, and includes a reference */
+/* count to avoid destroying it (due to caching) */
+/* */
/***************************************************************************/
+ /**************************************************************************/
+ /**************************************************************************/
+ /**************************************************************************/
+ /**************************************************************************/
+ /**************************************************************************/
+ /********* **********/
+ /********* **********/
+ /********* WARNING, THIS IS ALPHA CODE, THIS API **********/
+ /********* IS DUE TO CHANGE UNTIL STRICTLY NOTIFIED BY THE **********/
+ /********* FREETYPE DEVELOPMENT TEAM **********/
+ /********* **********/
+ /**************************************************************************/
+ /**************************************************************************/
+ /**************************************************************************/
+ /**************************************************************************/
+ /**************************************************************************/
+
#ifndef FTCMANAG_H
#define FTCMANAG_H
@@ -27,89 +68,132 @@
extern "C" {
#endif
+/* default values */
+#define FTC_MAX_FACES_DEFAULT 4
+#define FTC_MAX_SIZES_DEFAULT 8
+#define FTC_MAX_BYTES_DEFAULT 65536 /* 64 Kb by default */
-#define FTC_MAX_FACES_DEFAULT 4
-#define FTC_MAX_SIZES_DEFAULT 8
-#define FTC_MAX_BYTES_DEFAULT 65536
-
-#define FTC_MAX_CACHES 8
-
- /* opaque pointer to a cache object */
- typedef struct FTC_CacheRec_* FTC_Cache;
-
+/* maximum number of caches registered in a single manager */
+#define FTC_MAX_CACHES 16
- /* a ftc node is used to
- typedef FT_ListNode FTC_Node;
+ typedef struct FTC_ManagerRec_
+ {
+ FT_Library library;
+ FT_Lru faces_lru;
+ FT_Lru sizes_lru;
- /* macros to read/set the glyph & queue index in a FTC_Node */
-#define FTC_IMAGENODE_GET_GINDEX( n ) FTC_PTR_TO_GINDEX( (n)->data )
-#define FTC_IMAGENODE_GET_QINDEX( n ) FTC_PTR_TO_QINDEX( (n)->data )
-
-#define FTC_IMAGENODE_SET_INDICES( n, g, q ) \
- do { \
- (n)->data = FTC_INDICES_TO_PTR( g, q ); \
- } while ( 0 )
+ FT_ULong max_bytes;
+ FT_ULong num_bytes;
+ FT_ListRec global_lru;
+ FTC_Cache caches[ FTC_MAX_CACHES ];
+
+ FT_Pointer request_data;
+ FTC_Face_Requester request_face;
+
+ } FTC_ManagerRec;
+ /*********************************************************************/
+ /*********************************************************************/
+ /***** *****/
+ /***** CACHE NODE DEFINITIONS *****/
+ /***** *****/
+ /*********************************************************************/
+ /*********************************************************************/
+
+
+
+ /* each cache controls one or more cache nodes. Each node */
+ /* is part of the global_lru list of the manager. Its "data" */
+ /* field however is used as a reference count for now.. */
+ /* */
+ /* a node can anything, depending on the type of information */
+ /* held by the cache. It can be an individual glyph image, */
+ /* a set of bitmaps glyphs for a given size, some metrics, */
+ /* etc.. */
+ /* */
+
+ typedef FT_ListNodeRec FTC_CacheNodeRec;
+ typedef FTC_CacheNodeRec* FTC_CacheNode;
- /* a function used to initialize a cache */
- typedef FT_Error (FTC_Cache_Init_Func) ( FTC_Cache cache );
+ /* the fields "cachenode.data" is typecasted to this type */
+ typedef struct FTC_CacheNode_Data_
+ {
+ FT_UShort cache_index;
+ FT_Short ref_count;
- /* a function used to finalize a cache */
- typedef void (FTC_Cache_Done_Func) ( FTC_Cache cache );
+ } FTC_CacheNode_Data;
- /* a function used to return the size in bytes of a given cache node */
- typedef FT_ULong (FTC_Cache_Size_Func) ( FTC_Cache cache,
- FT_Pointer object );
-
- /* a function used to purge a given cache node */
- typedef void (FTC_Cache_Purge_Func)( FTC_Cache cache,
- FT_Pointer object );
-
-
- /* cache class */
- typedef struct FTC_Cache_Class_
+/* returns a pointer to the FTC_CacheNode_Data contained in a */
+/* CacheNode's "data" field.. */
+#define FTC_CACHENODE_TO_DATA_P(n) \
+ ((FTC_CacheNode_Data*)&(n)->data)
+
+#define FTC_LIST_TO_CACHENODE(n) ((FTC_CacheNode)(n))
+
+ /* returns the size in bytes of a given cache node */
+ typedef FT_ULong (*FTC_CacheNode_SizeFunc)( FTC_CacheNode node,
+ FT_Pointer user );
+
+ /* finalise a given cache node */
+ typedef void (*FTC_CacheNode_DestroyFunc)( FTC_CacheNode node,
+ FT_Pointer user );
+
+ /* this structure is used to provide functions to the cache manager */
+ /* It will use them to size and destroy cache nodes.. Note that there */
+ /* is no "init_node" there because cache objects are entirely */
+ /* responsible for the creation of new cache nodes */
+ /* */
+ typedef struct FTC_CacheNode_Class_
{
- FT_UInt cache_size; /* size of cache object in bytes */
- FTC_Cache_Init_Func init;
- FTC_Cache_Done_Func done;
- FTC_Cache_Size_Func size;
- FTC_Cache_Purge_Func purge;
+ FTC_CacheNode_SizeFunc size_node;
+ FTC_CacheNode_DestroyFunc destroy_node;
+
+ } FTC_CacheNode_Class;
+
+
+ /*********************************************************************/
+ /*********************************************************************/
+ /***** *****/
+ /***** CACHE DEFINITIONS *****/
+ /***** *****/
+ /*********************************************************************/
+ /*********************************************************************/
+
+
+ typedef FT_Error (*FTC_Cache_InitFunc)( FTC_Cache cache );
+
+ typedef void (*FTC_Cache_DoneFunc)( FTC_Cache cache );
- } FTC_Cache_Class;
-
- typedef struct FTC_CacheRec_
+ struct FTC_Cache_Class_
{
- FTC_Manager manager; /* cache manager.. */
- FTC_Cache_Class* clazz; /* cache clazz */
- FT_Memory memory; /* memory allocator */
- FT_UInt cache_id;
-
- } FTC_CacheRec;
+ FT_UInt cache_byte_size;
+ FTC_Cache_InitFunc init_cache;
+ FTC_Cache_DoneFunc done_cache;
+ };
- typedef struct FTC_ManagerRec_
+
+ typedef struct FTC_CacheRec_
{
- FT_Library library;
- FT_Lru faces_lru;
- FT_Lru sizes_lru;
-
- FT_Pointer request_data;
- FTC_Face_Requester request_face;
+ FTC_Manager manager;
+ FT_Memory memory;
+ FTC_Cache_Class* clazz;
+ FTC_CacheNode_Class* node_clazz;
- FT_ULong num_bytes; /* current number of bytes in the caches */
- FT_ULong max_bytes; /* maximum number of bytes in the caches */
- FT_ListRec global_lru; /* the global LRU list of nodes */
+ FT_UInt cache_index; /* in manager's table */
+ FT_Pointer cache_user; /* passed to cache node methods*/
- FT_UInt num_caches;
- FT_UInt last_id;
- FTC_Cache caches[ FTC_MAX_CACHES ];
-
- } FTC_ManagerRec;
+ } FTC_CacheRec;
+
+ /* "compress" the manager's data, i.e. get rids of old cache nodes */
+ /* that are not referenced anymore in order to limit the total */
+ /* memory used by the cache.. */
+ FT_EXPORT_DEF(void) FTC_Manager_Compress( FTC_Manager manager );
#ifdef __cplusplus
diff --git a/include/freetype/cache/ftlru.h b/include/freetype/cache/ftlru.h
index 28e6409..8e7df53 100644
--- a/include/freetype/cache/ftlru.h
+++ b/include/freetype/cache/ftlru.h
@@ -13,8 +13,46 @@
/* this file you indicate that you have read the license and */
/* understand and accept it fully. */
/* */
+/* */
+/* A LRU is a list that cannot hold more than a certain number of */
+/* elements ("max_elements"). All elements on the list are sorted */
+/* in lest-recently-used order, i.e. the "oldest" element is at */
+/* the tail of the list */
+/* */
+/* When doing a lookup (either through "Lookup" or "Lookup_Node"), */
+/* the list is searched for an element with the corresponding key */
+/* if it is found, the element is moved to the head of the list */
+/* and is returned.. */
+/* */
+/* If no corresponding element is found, the lookup routine will */
+/* try to obtain a new element with the relevant key. If the list */
+/* is already full, the oldest element from the list is discarded */
+/* and replaced by a new one; a new element is added to the list */
+/* otherwise.. */
+/* */
+/* Note that it is possible to pre-allocate the element list nodes. */
+/* That's handy when "max_elements" is sufficiently small, as it */
+/* saves allocations/releases during the lookup process */
+/* */
/***************************************************************************/
+ /**************************************************************************/
+ /**************************************************************************/
+ /**************************************************************************/
+ /**************************************************************************/
+ /**************************************************************************/
+ /********* **********/
+ /********* **********/
+ /********* WARNING, THIS IS ALPHA CODE, THIS API **********/
+ /********* IS DUE TO CHANGE UNTIL STRICTLY NOTIFIED BY THE **********/
+ /********* FREETYPE DEVELOPMENT TEAM **********/
+ /********* **********/
+ /**************************************************************************/
+ /**************************************************************************/
+ /**************************************************************************/
+ /**************************************************************************/
+ /**************************************************************************/
+
#ifndef FTLRU_H
#define FTLRU_H
@@ -26,10 +64,11 @@
extern "C" {
#endif
-
+ /* generic key type */
typedef FT_Pointer FT_LruKey;
+ /* a lru node - node.root.data points to the element */
typedef struct FT_LruNodeRec_
{
FT_ListNodeRec root;
@@ -37,30 +76,43 @@
} FT_LruNodeRec, *FT_LruNode;
-
+ /* forward declaration */
typedef struct FT_LruRec_* FT_Lru;
+ /* LRU clazz */
typedef struct FT_Lru_Class_
{
FT_UInt lru_size; /* object size in bytes */
+ /* this method is used to initialise a new list element node */
FT_Error (*init_element)( FT_Lru lru,
FT_LruNode node );
-
+
+ /* this method is used to finalise a given list element node */
void (*done_element)( FT_Lru lru,
FT_LruNode node );
+ /* when defined, this method is called when the list if full */
+ /* during the lookup process.. it is used to change the content */
+ /* of a list element node, instead of calling "done_element" */
+ /* then "init_element". Put it to 0 for default behaviour */
FT_Error (*flush_element)( FT_Lru lru,
FT_LruNode node,
FT_LruKey new_key );
-
+
+ /* when defined, this method is used to compare a list element node */
+ /* with a given key during a lookup. When set to 0, the "key" */
+ /* fields will be directly compared instead.. */
FT_Bool (*compare_element)( FT_LruNode node,
FT_LruKey key );
} FT_Lru_Class;
-
+ /* a selector is used to indicate wether a given list element node */
+ /* is part of a selection for FT_Lru_Remove_Selection. The function */
+ /* must returns true (i.e. non 0) to indicate that the node is part */
+ /* of it.. */
typedef FT_Bool (*FT_Lru_Selector)( FT_Lru lru,
FT_LruNode node,
FT_Pointer data );
@@ -89,9 +141,9 @@
FT_Bool pre_alloc,
FT_Lru* alru );
- FT_EXPORT_DEF( void ) FT_Lru_Reset( FT_Lru lru );
+ FT_EXPORT_DEF( void ) FT_Lru_Reset( FT_Lru lru );
- FT_EXPORT_DEF( void ) FT_Lru_Done( FT_Lru lru );
+ FT_EXPORT_DEF( void ) FT_Lru_Done( FT_Lru lru );
FT_EXPORT_DEF( FT_Error ) FT_Lru_Lookup_Node( FT_Lru lru,
FT_LruKey key,
@@ -101,12 +153,12 @@
FT_LruKey key,
FT_Pointer* aobject );
- FT_EXPORT_DEF( void ) FT_Lru_Remove_Node( FT_Lru lru,
- FT_LruNode node );
+ FT_EXPORT_DEF( void ) FT_Lru_Remove_Node( FT_Lru lru,
+ FT_LruNode node );
- FT_EXPORT_DEF( void ) FT_Lru_Remove_Selection( FT_Lru lru,
- FT_Lru_Selector selector,
- FT_Pointer data );
+ FT_EXPORT_DEF( void ) FT_Lru_Remove_Selection( FT_Lru lru,
+ FT_Lru_Selector selector,
+ FT_Pointer data );
#ifdef __cplusplus