sdk-world v2026.11.05
PS2 SDK - world tier (copyleft-allowed, non-essential packages)
Loading...
Searching...
No Matches
ftcache.h
Go to the documentation of this file.
1/****************************************************************************
2 *
3 * ftcache.h
4 *
5 * FreeType Cache subsystem (specification).
6 *
7 * Copyright (C) 1996-2025 by
8 * David Turner, Robert Wilhelm, and Werner Lemberg.
9 *
10 * This file is part of the FreeType project, and may only be used,
11 * modified, and distributed under the terms of the FreeType project
12 * license, LICENSE.TXT. By continuing to use, modify, or distribute
13 * this file you indicate that you have read the license and
14 * understand and accept it fully.
15 *
16 */
17
18
23#ifndef FTCACHE_H_
24#define FTCACHE_H_
25
26
27#include <freetype/ftglyph.h>
28
29
30FT_BEGIN_HEADER
31
32
33 /**************************************************************************
34 *
35 * @section:
36 * cache_subsystem
37 *
38 * @title:
39 * Cache Sub-System
40 *
41 * @abstract:
42 * How to cache face, size, and glyph data with FreeType~2.
43 *
44 * @description:
45 * This section describes the FreeType~2 cache sub-system, which is used
46 * to limit the number of concurrently opened @FT_Face and @FT_Size
47 * objects, as well as caching information like character maps and glyph
48 * images while limiting their maximum memory usage.
49 *
50 * Note that all types and functions begin with the `FTC_` prefix rather
51 * than the usual `FT_` prefix in the rest of FreeType.
52 *
53 * The cache is highly portable and, thus, doesn't know anything about
54 * the fonts installed on your system, or how to access them. Therefore,
55 * it requires the following.
56 *
57 * * @FTC_FaceID, an arbitrary non-zero value that uniquely identifies
58 * available or installed font faces, has to be provided to the
59 * cache by the client. Note that the cache only stores and compares
60 * these values and doesn't try to interpret them in any way, but they
61 * have to be persistent on the client side.
62 *
63 * * @FTC_Face_Requester, a method to convert an @FTC_FaceID into a new
64 * @FT_Face object when necessary, has to be provided to the cache by
65 * the client. The @FT_Face object is completely managed by the cache,
66 * including its termination through @FT_Done_Face. To monitor
67 * termination of face objects, the finalizer callback in the `generic`
68 * field of the @FT_Face object can be used, which might also be used
69 * to store the @FTC_FaceID of the face.
70 *
71 * Clients are free to map face IDs to anything useful. The most simple
72 * usage is, for example, to associate them to a `{pathname,face_index}`
73 * pair that is then used by @FTC_Face_Requester to call @FT_New_Face.
74 * However, more complex schemes are also possible.
75 *
76 * Note that for the cache to work correctly, the face ID values must be
77 * **persistent**, which means that the contents they point to should not
78 * change at runtime, or that their value should not become invalid.
79 * If this is unavoidable (e.g., when a font is uninstalled at runtime),
80 * you should call @FTC_Manager_RemoveFaceID as soon as possible to let
81 * the cache get rid of any references to the old @FTC_FaceID it may keep
82 * internally. Failure to do so will lead to incorrect behaviour or even
83 * crashes in @FTC_Face_Requester.
84 *
85 * To use the cache, start with calling @FTC_Manager_New to create a new
86 * @FTC_Manager object, which models a single cache instance. You can
87 * then look up @FT_Face and @FT_Size objects with
88 * @FTC_Manager_LookupFace and @FTC_Manager_LookupSize, respectively, and
89 * use them in any FreeType work stream. You can also cache other
90 * FreeType objects as follows.
91 *
92 * * If you want to use the charmap caching, call @FTC_CMapCache_New,
93 * then later use @FTC_CMapCache_Lookup to perform the equivalent of
94 * @FT_Get_Char_Index, only much faster.
95 *
96 * * If you want to use the @FT_Glyph caching, call @FTC_ImageCache_New,
97 * then later use @FTC_ImageCache_Lookup to retrieve the corresponding
98 * @FT_Glyph objects from the cache.
99 *
100 * * If you need lots of small bitmaps, it is much more memory-efficient
101 * to call @FTC_SBitCache_New followed by @FTC_SBitCache_Lookup. This
102 * returns @FTC_SBitRec structures, which are used to store small
103 * bitmaps directly. (A small bitmap is one whose metrics and
104 * dimensions all fit into 8-bit integers).
105 *
106 * @order:
107 * FTC_Manager
108 * FTC_FaceID
109 * FTC_Face_Requester
110 *
111 * FTC_Manager_New
112 * FTC_Manager_Reset
113 * FTC_Manager_Done
114 * FTC_Manager_LookupFace
115 * FTC_Manager_LookupSize
116 * FTC_Manager_RemoveFaceID
117 *
118 * FTC_Node
119 * FTC_Node_Unref
120 *
121 * FTC_ImageCache
122 * FTC_ImageCache_New
123 * FTC_ImageCache_Lookup
124 *
125 * FTC_SBit
126 * FTC_SBitCache
127 * FTC_SBitCache_New
128 * FTC_SBitCache_Lookup
129 *
130 * FTC_CMapCache
131 * FTC_CMapCache_New
132 * FTC_CMapCache_Lookup
133 *
134 *************************************************************************/
135
136
137 /*************************************************************************/
138 /*************************************************************************/
139 /*************************************************************************/
140 /***** *****/
141 /***** BASIC TYPE DEFINITIONS *****/
142 /***** *****/
143 /*************************************************************************/
144 /*************************************************************************/
145 /*************************************************************************/
146
147
148 /**************************************************************************
149 *
150 * @type:
151 * FTC_FaceID
152 *
153 * @description:
154 * An opaque pointer type that is used to identity face objects. The
155 * contents of such objects is application-dependent.
156 *
157 * These pointers are typically used to point to a user-defined structure
158 * containing a font file path, and face index.
159 *
160 * @note:
161 * Never use `NULL` as a valid @FTC_FaceID.
162 *
163 * Face IDs are passed by the client to the cache manager that calls,
164 * when needed, the @FTC_Face_Requester to translate them into new
165 * @FT_Face objects.
166 *
167 * If the content of a given face ID changes at runtime, or if the value
168 * becomes invalid (e.g., when uninstalling a font), you should
169 * immediately call @FTC_Manager_RemoveFaceID before any other cache
170 * function.
171 *
172 * Failure to do so will result in incorrect behaviour or even memory
173 * leaks and crashes.
174 */
175 typedef FT_Pointer FTC_FaceID;
176
177
178 /**************************************************************************
179 *
180 * @functype:
181 * FTC_Face_Requester
182 *
183 * @description:
184 * A callback function provided by client applications. It is used by
185 * the cache manager to translate a given @FTC_FaceID into a new valid
186 * @FT_Face object, on demand.
187 *
188 * @input:
189 * face_id ::
190 * The face ID to resolve.
191 *
192 * library ::
193 * A handle to a FreeType library object.
194 *
195 * req_data ::
196 * Application-provided request data (see note below).
197 *
198 * @output:
199 * aface ::
200 * A new @FT_Face handle.
201 *
202 * @return:
203 * FreeType error code. 0~means success.
204 *
205 * @note:
206 * The third parameter `req_data` is the same as the one passed by the
207 * client when @FTC_Manager_New is called.
208 *
209 * The face requester should not perform funny things on the returned
210 * face object, like creating a new @FT_Size for it, or setting a
211 * transformation through @FT_Set_Transform!
212 */
213 typedef FT_Error
214 (*FTC_Face_Requester)( FTC_FaceID face_id,
215 FT_Library library,
216 FT_Pointer req_data,
217 FT_Face* aface );
218
219 /* */
220
221
222 /*************************************************************************/
223 /*************************************************************************/
224 /*************************************************************************/
225 /***** *****/
226 /***** CACHE MANAGER OBJECT *****/
227 /***** *****/
228 /*************************************************************************/
229 /*************************************************************************/
230 /*************************************************************************/
231
232
233 /**************************************************************************
234 *
235 * @type:
236 * FTC_Manager
237 *
238 * @description:
239 * This object corresponds to one instance of the cache-subsystem. It is
240 * used to cache one or more @FT_Face objects, along with corresponding
241 * @FT_Size objects.
242 *
243 * The manager intentionally limits the total number of opened @FT_Face
244 * and @FT_Size objects to control memory usage. See the `max_faces` and
245 * `max_sizes` parameters of @FTC_Manager_New.
246 *
247 * The manager is also used to cache 'nodes' of various types while
248 * limiting their total memory usage.
249 *
250 * All limitations are enforced by keeping lists of managed objects in
251 * most-recently-used order, and flushing old nodes to make room for new
252 * ones.
253 */
254 typedef struct FTC_ManagerRec_* FTC_Manager;
255
256
257 /**************************************************************************
258 *
259 * @type:
260 * FTC_Node
261 *
262 * @description:
263 * An opaque handle to a cache node object. Each cache node is
264 * reference-counted. A node with a count of~0 might be flushed out of a
265 * full cache whenever a lookup request is performed.
266 *
267 * If you look up nodes, you have the ability to 'acquire' them, i.e., to
268 * increment their reference count. This will prevent the node from
269 * being flushed out of the cache until you explicitly 'release' it (see
270 * @FTC_Node_Unref).
271 *
272 * See also @FTC_SBitCache_Lookup and @FTC_ImageCache_Lookup.
273 */
274 typedef struct FTC_NodeRec_* FTC_Node;
275
276
277 /**************************************************************************
278 *
279 * @function:
280 * FTC_Manager_New
281 *
282 * @description:
283 * Create a new cache manager.
284 *
285 * @input:
286 * library ::
287 * The parent FreeType library handle to use.
288 *
289 * max_faces ::
290 * Maximum number of opened @FT_Face objects managed by this cache
291 * instance. Use~0 for defaults.
292 *
293 * max_sizes ::
294 * Maximum number of opened @FT_Size objects managed by this cache
295 * instance. Use~0 for defaults.
296 *
297 * max_bytes ::
298 * Maximum number of bytes to use for cached data nodes. Use~0 for
299 * defaults. Note that this value does not account for managed
300 * @FT_Face and @FT_Size objects.
301 *
302 * requester ::
303 * An application-provided callback used to translate face IDs into
304 * real @FT_Face objects.
305 *
306 * req_data ::
307 * A generic pointer that is passed to the requester each time it is
308 * called (see @FTC_Face_Requester).
309 *
310 * @output:
311 * amanager ::
312 * A handle to a new manager object. 0~in case of failure.
313 *
314 * @return:
315 * FreeType error code. 0~means success.
316 */
317 FT_EXPORT( FT_Error )
318 FTC_Manager_New( FT_Library library,
319 FT_UInt max_faces,
320 FT_UInt max_sizes,
321 FT_ULong max_bytes,
322 FTC_Face_Requester requester,
323 FT_Pointer req_data,
324 FTC_Manager *amanager );
325
326
327 /**************************************************************************
328 *
329 * @function:
330 * FTC_Manager_Reset
331 *
332 * @description:
333 * Empty a given cache manager. This simply gets rid of all the
334 * currently cached @FT_Face and @FT_Size objects within the manager.
335 *
336 * @inout:
337 * manager ::
338 * A handle to the manager.
339 */
340 FT_EXPORT( void )
341 FTC_Manager_Reset( FTC_Manager manager );
342
343
344 /**************************************************************************
345 *
346 * @function:
347 * FTC_Manager_Done
348 *
349 * @description:
350 * Destroy a given manager after emptying it.
351 *
352 * @input:
353 * manager ::
354 * A handle to the target cache manager object.
355 */
356 FT_EXPORT( void )
357 FTC_Manager_Done( FTC_Manager manager );
358
359
360 /**************************************************************************
361 *
362 * @function:
363 * FTC_Manager_LookupFace
364 *
365 * @description:
366 * Retrieve the @FT_Face object that corresponds to a given face ID
367 * through a cache manager.
368 *
369 * @input:
370 * manager ::
371 * A handle to the cache manager.
372 *
373 * face_id ::
374 * The ID of the face object.
375 *
376 * @output:
377 * aface ::
378 * A handle to the face object.
379 *
380 * @return:
381 * FreeType error code. 0~means success.
382 *
383 * @note:
384 * The returned @FT_Face object is always owned by the manager. You
385 * should never try to discard it yourself.
386 *
387 * The @FT_Face object doesn't necessarily have a current size object
388 * (i.e., face->size can be~0). If you need a specific 'font size', use
389 * @FTC_Manager_LookupSize instead.
390 *
391 * Never change the face's transformation matrix (i.e., never call the
392 * @FT_Set_Transform function) on a returned face! If you need to
393 * transform glyphs, do it yourself after glyph loading.
394 *
395 * When you perform a lookup, out-of-memory errors are detected _within_
396 * the lookup and force incremental flushes of the cache until enough
397 * memory is released for the lookup to succeed.
398 *
399 * If a lookup fails with `FT_Err_Out_Of_Memory` the cache has already
400 * been completely flushed, and still no memory was available for the
401 * operation.
402 */
403 FT_EXPORT( FT_Error )
404 FTC_Manager_LookupFace( FTC_Manager manager,
405 FTC_FaceID face_id,
406 FT_Face *aface );
407
408
409 /**************************************************************************
410 *
411 * @struct:
412 * FTC_ScalerRec
413 *
414 * @description:
415 * A structure used to describe a given character size in either pixels
416 * or points to the cache manager. See @FTC_Manager_LookupSize.
417 *
418 * @fields:
419 * face_id ::
420 * The source face ID.
421 *
422 * width ::
423 * The character width.
424 *
425 * height ::
426 * The character height.
427 *
428 * pixel ::
429 * A Boolean. If 1, the `width` and `height` fields are interpreted as
430 * integer pixel character sizes. Otherwise, they are expressed as
431 * 1/64 of points.
432 *
433 * x_res ::
434 * Only used when `pixel` is value~0 to indicate the horizontal
435 * resolution in dpi.
436 *
437 * y_res ::
438 * Only used when `pixel` is value~0 to indicate the vertical
439 * resolution in dpi.
440 *
441 * @note:
442 * This type is mainly used to retrieve @FT_Size objects through the
443 * cache manager.
444 */
445 typedef struct FTC_ScalerRec_
446 {
447 FTC_FaceID face_id;
448 FT_UInt width;
449 FT_UInt height;
450 FT_Int pixel;
451 FT_UInt x_res;
452 FT_UInt y_res;
453
454 } FTC_ScalerRec;
455
456
457 /**************************************************************************
458 *
459 * @struct:
460 * FTC_Scaler
461 *
462 * @description:
463 * A handle to an @FTC_ScalerRec structure.
464 */
465 typedef struct FTC_ScalerRec_* FTC_Scaler;
466
467
468 /**************************************************************************
469 *
470 * @function:
471 * FTC_Manager_LookupSize
472 *
473 * @description:
474 * Retrieve the @FT_Size object that corresponds to a given
475 * @FTC_ScalerRec pointer through a cache manager.
476 *
477 * @input:
478 * manager ::
479 * A handle to the cache manager.
480 *
481 * scaler ::
482 * A scaler handle.
483 *
484 * @output:
485 * asize ::
486 * A handle to the size object.
487 *
488 * @return:
489 * FreeType error code. 0~means success.
490 *
491 * @note:
492 * The returned @FT_Size object is always owned by the manager. You
493 * should never try to discard it by yourself.
494 *
495 * You can access the parent @FT_Face object simply as `size->face` if
496 * you need it. Note that this object is also owned by the manager.
497 *
498 * @note:
499 * When you perform a lookup, out-of-memory errors are detected _within_
500 * the lookup and force incremental flushes of the cache until enough
501 * memory is released for the lookup to succeed.
502 *
503 * If a lookup fails with `FT_Err_Out_Of_Memory` the cache has already
504 * been completely flushed, and still no memory is available for the
505 * operation.
506 */
507 FT_EXPORT( FT_Error )
508 FTC_Manager_LookupSize( FTC_Manager manager,
509 FTC_Scaler scaler,
510 FT_Size *asize );
511
512
513 /**************************************************************************
514 *
515 * @function:
516 * FTC_Node_Unref
517 *
518 * @description:
519 * Decrement a cache node's internal reference count. When the count
520 * reaches 0, it is not destroyed but becomes eligible for subsequent
521 * cache flushes.
522 *
523 * @input:
524 * node ::
525 * The cache node handle.
526 *
527 * manager ::
528 * The cache manager handle.
529 */
530 FT_EXPORT( void )
531 FTC_Node_Unref( FTC_Node node,
532 FTC_Manager manager );
533
534
535 /**************************************************************************
536 *
537 * @function:
538 * FTC_Manager_RemoveFaceID
539 *
540 * @description:
541 * A special function used to indicate to the cache manager that a given
542 * @FTC_FaceID is no longer valid, either because its content changed, or
543 * because it was deallocated or uninstalled.
544 *
545 * @input:
546 * manager ::
547 * The cache manager handle.
548 *
549 * face_id ::
550 * The @FTC_FaceID to be removed.
551 *
552 * @note:
553 * This function flushes all nodes from the cache corresponding to this
554 * `face_id`, with the exception of nodes with a non-null reference
555 * count.
556 *
557 * Such nodes are however modified internally so as to never appear in
558 * later lookups with the same `face_id` value, and to be immediately
559 * destroyed when released by all their users.
560 *
561 */
562 FT_EXPORT( void )
563 FTC_Manager_RemoveFaceID( FTC_Manager manager,
564 FTC_FaceID face_id );
565
566
567 /**************************************************************************
568 *
569 * @type:
570 * FTC_CMapCache
571 *
572 * @description:
573 * An opaque handle used to model a charmap cache. This cache is to hold
574 * character codes -> glyph indices mappings.
575 *
576 */
577 typedef struct FTC_CMapCacheRec_* FTC_CMapCache;
578
579
580 /**************************************************************************
581 *
582 * @function:
583 * FTC_CMapCache_New
584 *
585 * @description:
586 * Create a new charmap cache.
587 *
588 * @input:
589 * manager ::
590 * A handle to the cache manager.
591 *
592 * @output:
593 * acache ::
594 * A new cache handle. `NULL` in case of error.
595 *
596 * @return:
597 * FreeType error code. 0~means success.
598 *
599 * @note:
600 * Like all other caches, this one will be destroyed with the cache
601 * manager.
602 *
603 */
604 FT_EXPORT( FT_Error )
605 FTC_CMapCache_New( FTC_Manager manager,
606 FTC_CMapCache *acache );
607
608
609 /**************************************************************************
610 *
611 * @function:
612 * FTC_CMapCache_Lookup
613 *
614 * @description:
615 * Translate a character code into a glyph index, using the charmap
616 * cache.
617 *
618 * @input:
619 * cache ::
620 * A charmap cache handle.
621 *
622 * face_id ::
623 * The source face ID.
624 *
625 * cmap_index ::
626 * The index of the charmap in the source face. Any negative value
627 * means to use the cache @FT_Face's default charmap.
628 *
629 * char_code ::
630 * The character code (in the corresponding charmap).
631 *
632 * @return:
633 * Glyph index. 0~means 'no glyph'.
634 *
635 */
636 FT_EXPORT( FT_UInt )
637 FTC_CMapCache_Lookup( FTC_CMapCache cache,
638 FTC_FaceID face_id,
639 FT_Int cmap_index,
640 FT_UInt32 char_code );
641
642
643 /*************************************************************************/
644 /*************************************************************************/
645 /*************************************************************************/
646 /***** *****/
647 /***** IMAGE CACHE OBJECT *****/
648 /***** *****/
649 /*************************************************************************/
650 /*************************************************************************/
651 /*************************************************************************/
652
653
654 /**************************************************************************
655 *
656 * @struct:
657 * FTC_ImageTypeRec
658 *
659 * @description:
660 * A structure used to model the type of images in a glyph cache.
661 *
662 * @fields:
663 * face_id ::
664 * The face ID.
665 *
666 * width ::
667 * The width in pixels.
668 *
669 * height ::
670 * The height in pixels.
671 *
672 * flags ::
673 * The load flags, as in @FT_Load_Glyph.
674 *
675 */
676 typedef struct FTC_ImageTypeRec_
677 {
678 FTC_FaceID face_id;
679 FT_UInt width;
680 FT_UInt height;
681 FT_Int32 flags;
682
683 } FTC_ImageTypeRec;
684
685
686 /**************************************************************************
687 *
688 * @type:
689 * FTC_ImageType
690 *
691 * @description:
692 * A handle to an @FTC_ImageTypeRec structure.
693 *
694 */
695 typedef struct FTC_ImageTypeRec_* FTC_ImageType;
696
697
698 /* */
699
700
701#define FTC_IMAGE_TYPE_COMPARE( d1, d2 ) \
702 ( (d1)->face_id == (d2)->face_id && \
703 (d1)->width == (d2)->width && \
704 (d1)->flags == (d2)->flags )
705
706
707 /**************************************************************************
708 *
709 * @type:
710 * FTC_ImageCache
711 *
712 * @description:
713 * A handle to a glyph image cache object. They are designed to hold
714 * many distinct glyph images while not exceeding a certain memory
715 * threshold.
716 */
717 typedef struct FTC_ImageCacheRec_* FTC_ImageCache;
718
719
720 /**************************************************************************
721 *
722 * @function:
723 * FTC_ImageCache_New
724 *
725 * @description:
726 * Create a new glyph image cache.
727 *
728 * @input:
729 * manager ::
730 * The parent manager for the image cache.
731 *
732 * @output:
733 * acache ::
734 * A handle to the new glyph image cache object.
735 *
736 * @return:
737 * FreeType error code. 0~means success.
738 */
739 FT_EXPORT( FT_Error )
740 FTC_ImageCache_New( FTC_Manager manager,
741 FTC_ImageCache *acache );
742
743
744 /**************************************************************************
745 *
746 * @function:
747 * FTC_ImageCache_Lookup
748 *
749 * @description:
750 * Retrieve a given glyph image from a glyph image cache.
751 *
752 * @input:
753 * cache ::
754 * A handle to the source glyph image cache.
755 *
756 * type ::
757 * A pointer to a glyph image type descriptor.
758 *
759 * gindex ::
760 * The glyph index to retrieve.
761 *
762 * @output:
763 * aglyph ::
764 * The corresponding @FT_Glyph object. 0~in case of failure.
765 *
766 * anode ::
767 * Used to return the address of the corresponding cache node after
768 * incrementing its reference count (see note below).
769 *
770 * @return:
771 * FreeType error code. 0~means success.
772 *
773 * @note:
774 * The returned glyph is owned and managed by the glyph image cache.
775 * Never try to transform or discard it manually! You can however create
776 * a copy with @FT_Glyph_Copy and modify the new one.
777 *
778 * If `anode` is _not_ `NULL`, it receives the address of the cache node
779 * containing the glyph image, after increasing its reference count.
780 * This ensures that the node (as well as the @FT_Glyph) will always be
781 * kept in the cache until you call @FTC_Node_Unref to 'release' it.
782 *
783 * If `anode` is `NULL`, the cache node is left unchanged, which means
784 * that the @FT_Glyph could be flushed out of the cache on the next call
785 * to one of the caching sub-system APIs. Don't assume that it is
786 * persistent!
787 */
788 FT_EXPORT( FT_Error )
789 FTC_ImageCache_Lookup( FTC_ImageCache cache,
790 FTC_ImageType type,
791 FT_UInt gindex,
792 FT_Glyph *aglyph,
793 FTC_Node *anode );
794
795
796 /**************************************************************************
797 *
798 * @function:
799 * FTC_ImageCache_LookupScaler
800 *
801 * @description:
802 * A variant of @FTC_ImageCache_Lookup that uses an @FTC_ScalerRec to
803 * specify the face ID and its size.
804 *
805 * @input:
806 * cache ::
807 * A handle to the source glyph image cache.
808 *
809 * scaler ::
810 * A pointer to a scaler descriptor.
811 *
812 * load_flags ::
813 * The corresponding load flags.
814 *
815 * gindex ::
816 * The glyph index to retrieve.
817 *
818 * @output:
819 * aglyph ::
820 * The corresponding @FT_Glyph object. 0~in case of failure.
821 *
822 * anode ::
823 * Used to return the address of the corresponding cache node after
824 * incrementing its reference count (see note below).
825 *
826 * @return:
827 * FreeType error code. 0~means success.
828 *
829 * @note:
830 * The returned glyph is owned and managed by the glyph image cache.
831 * Never try to transform or discard it manually! You can however create
832 * a copy with @FT_Glyph_Copy and modify the new one.
833 *
834 * If `anode` is _not_ `NULL`, it receives the address of the cache node
835 * containing the glyph image, after increasing its reference count.
836 * This ensures that the node (as well as the @FT_Glyph) will always be
837 * kept in the cache until you call @FTC_Node_Unref to 'release' it.
838 *
839 * If `anode` is `NULL`, the cache node is left unchanged, which means
840 * that the @FT_Glyph could be flushed out of the cache on the next call
841 * to one of the caching sub-system APIs. Don't assume that it is
842 * persistent!
843 *
844 * Calls to @FT_Set_Char_Size and friends have no effect on cached
845 * glyphs; you should always use the FreeType cache API instead.
846 */
847 FT_EXPORT( FT_Error )
848 FTC_ImageCache_LookupScaler( FTC_ImageCache cache,
849 FTC_Scaler scaler,
850 FT_ULong load_flags,
851 FT_UInt gindex,
852 FT_Glyph *aglyph,
853 FTC_Node *anode );
854
855
856 /**************************************************************************
857 *
858 * @type:
859 * FTC_SBit
860 *
861 * @description:
862 * A handle to a small bitmap descriptor. See the @FTC_SBitRec structure
863 * for details.
864 */
865 typedef struct FTC_SBitRec_* FTC_SBit;
866
867
868 /**************************************************************************
869 *
870 * @struct:
871 * FTC_SBitRec
872 *
873 * @description:
874 * A very compact structure used to describe a small glyph bitmap.
875 *
876 * @fields:
877 * width ::
878 * The bitmap width in pixels.
879 *
880 * height ::
881 * The bitmap height in pixels.
882 *
883 * left ::
884 * The horizontal distance from the pen position to the left bitmap
885 * border (a.k.a. 'left side bearing', or 'lsb').
886 *
887 * top ::
888 * The vertical distance from the pen position (on the baseline) to the
889 * upper bitmap border (a.k.a. 'top side bearing'). The distance is
890 * positive for upwards y~coordinates.
891 *
892 * format ::
893 * The format of the glyph bitmap (monochrome or gray).
894 *
895 * max_grays ::
896 * Maximum gray level value (in the range 1 to~255).
897 *
898 * pitch ::
899 * The number of bytes per bitmap line. May be positive or negative.
900 *
901 * xadvance ::
902 * The horizontal advance width in pixels.
903 *
904 * yadvance ::
905 * The vertical advance height in pixels.
906 *
907 * buffer ::
908 * A pointer to the bitmap pixels.
909 */
910 typedef struct FTC_SBitRec_
911 {
912 FT_Byte width;
913 FT_Byte height;
914 FT_Char left;
915 FT_Char top;
916
917 FT_Byte format;
918 FT_Byte max_grays;
919 FT_Short pitch;
920 FT_Char xadvance;
921 FT_Char yadvance;
922
923 FT_Byte* buffer;
924
925 } FTC_SBitRec;
926
927
928 /**************************************************************************
929 *
930 * @type:
931 * FTC_SBitCache
932 *
933 * @description:
934 * A handle to a small bitmap cache. These are special cache objects
935 * used to store small glyph bitmaps (and anti-aliased pixmaps) in a much
936 * more efficient way than the traditional glyph image cache implemented
937 * by @FTC_ImageCache.
938 */
939 typedef struct FTC_SBitCacheRec_* FTC_SBitCache;
940
941
942 /**************************************************************************
943 *
944 * @function:
945 * FTC_SBitCache_New
946 *
947 * @description:
948 * Create a new cache to store small glyph bitmaps.
949 *
950 * @input:
951 * manager ::
952 * A handle to the source cache manager.
953 *
954 * @output:
955 * acache ::
956 * A handle to the new sbit cache. `NULL` in case of error.
957 *
958 * @return:
959 * FreeType error code. 0~means success.
960 */
961 FT_EXPORT( FT_Error )
962 FTC_SBitCache_New( FTC_Manager manager,
963 FTC_SBitCache *acache );
964
965
966 /**************************************************************************
967 *
968 * @function:
969 * FTC_SBitCache_Lookup
970 *
971 * @description:
972 * Look up a given small glyph bitmap in a given sbit cache and 'lock' it
973 * to prevent its flushing from the cache until needed.
974 *
975 * @input:
976 * cache ::
977 * A handle to the source sbit cache.
978 *
979 * type ::
980 * A pointer to the glyph image type descriptor.
981 *
982 * gindex ::
983 * The glyph index.
984 *
985 * @output:
986 * sbit ::
987 * A handle to a small bitmap descriptor.
988 *
989 * anode ::
990 * Used to return the address of the corresponding cache node after
991 * incrementing its reference count (see note below).
992 *
993 * @return:
994 * FreeType error code. 0~means success.
995 *
996 * @note:
997 * The small bitmap descriptor and its bit buffer are owned by the cache
998 * and should never be freed by the application. They might as well
999 * disappear from memory on the next cache lookup, so don't treat them as
1000 * persistent data.
1001 *
1002 * The descriptor's `buffer` field is set to~0 to indicate a missing
1003 * glyph bitmap.
1004 *
1005 * If `anode` is _not_ `NULL`, it receives the address of the cache node
1006 * containing the bitmap, after increasing its reference count. This
1007 * ensures that the node (as well as the image) will always be kept in
1008 * the cache until you call @FTC_Node_Unref to 'release' it.
1009 *
1010 * If `anode` is `NULL`, the cache node is left unchanged, which means
1011 * that the bitmap could be flushed out of the cache on the next call to
1012 * one of the caching sub-system APIs. Don't assume that it is
1013 * persistent!
1014 */
1015 FT_EXPORT( FT_Error )
1016 FTC_SBitCache_Lookup( FTC_SBitCache cache,
1017 FTC_ImageType type,
1018 FT_UInt gindex,
1019 FTC_SBit *sbit,
1020 FTC_Node *anode );
1021
1022
1023 /**************************************************************************
1024 *
1025 * @function:
1026 * FTC_SBitCache_LookupScaler
1027 *
1028 * @description:
1029 * A variant of @FTC_SBitCache_Lookup that uses an @FTC_ScalerRec to
1030 * specify the face ID and its size.
1031 *
1032 * @input:
1033 * cache ::
1034 * A handle to the source sbit cache.
1035 *
1036 * scaler ::
1037 * A pointer to the scaler descriptor.
1038 *
1039 * load_flags ::
1040 * The corresponding load flags.
1041 *
1042 * gindex ::
1043 * The glyph index.
1044 *
1045 * @output:
1046 * sbit ::
1047 * A handle to a small bitmap descriptor.
1048 *
1049 * anode ::
1050 * Used to return the address of the corresponding cache node after
1051 * incrementing its reference count (see note below).
1052 *
1053 * @return:
1054 * FreeType error code. 0~means success.
1055 *
1056 * @note:
1057 * The small bitmap descriptor and its bit buffer are owned by the cache
1058 * and should never be freed by the application. They might as well
1059 * disappear from memory on the next cache lookup, so don't treat them as
1060 * persistent data.
1061 *
1062 * The descriptor's `buffer` field is set to~0 to indicate a missing
1063 * glyph bitmap.
1064 *
1065 * If `anode` is _not_ `NULL`, it receives the address of the cache node
1066 * containing the bitmap, after increasing its reference count. This
1067 * ensures that the node (as well as the image) will always be kept in
1068 * the cache until you call @FTC_Node_Unref to 'release' it.
1069 *
1070 * If `anode` is `NULL`, the cache node is left unchanged, which means
1071 * that the bitmap could be flushed out of the cache on the next call to
1072 * one of the caching sub-system APIs. Don't assume that it is
1073 * persistent!
1074 */
1075 FT_EXPORT( FT_Error )
1076 FTC_SBitCache_LookupScaler( FTC_SBitCache cache,
1077 FTC_Scaler scaler,
1078 FT_ULong load_flags,
1079 FT_UInt gindex,
1080 FTC_SBit *sbit,
1081 FTC_Node *anode );
1082
1083 /* */
1084
1085
1086FT_END_HEADER
1087
1088#endif /* FTCACHE_H_ */
1089
1090
1091/* END */