ftcglyph.h 8.48 KB
Newer Older
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
/***************************************************************************/
/*                                                                         */
/*  ftcglyph.h                                                             */
/*                                                                         */
/*    FreeType glyph image (FT_Glyph) cache..                              */
/*                                                                         */
/*  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.                                        */
/*                                                                         */
/*                                                                         */
/*  Important: the functions defined in this file are only used            */
/*             to implement an abstract glyph cache class. You             */
/*             need to provide additional logic to implement               */
/*             a complete cache. For example, see "ftcimage.h"             */
/*             and "ftcimage.c" which implement a FT_Glyph cache           */
/*             based on this code..                                        */
/*                                                                         */
/***************************************************************************/

 /**************************************************************************/
 /**************************************************************************/
 /**************************************************************************/
 /**************************************************************************/
 /**************************************************************************/
 /*********                                                       **********/
 /*********                                                       **********/
 /*********        WARNING, THIS IS ALPHA CODE, THIS API          **********/
 /*********    IS DUE TO CHANGE UNTIL STRICTLY NOTIFIED BY THE    **********/
 /*********            FREETYPE DEVELOPMENT TEAM                  **********/
 /*********                                                       **********/
 /**************************************************************************/
 /**************************************************************************/
 /**************************************************************************/
 /**************************************************************************/
 /**************************************************************************/


#ifndef FTCGLYPH_H
#define FTCGLYPH_H

#include <freetype/cache/ftcmanag.h>
#include <freetype/ftglyph.h>
#include <stddef.h>

#ifdef __cplusplus
  extern "C" {
#endif

/* maximum number of queues per image cache, must be < 256 */
#define FTC_MAX_GLYPH_QUEUES  16

#define FTC_QUEUE_HASH_SIZE_DEFAULT  64

  typedef struct FTC_Glyph_QueueRec_*    FTC_Glyph_Queue;
  typedef struct FTC_GlyphNodeRec_*      FTC_GlyphNode;
David Turner's avatar
David Turner committed
62
  typedef struct FTC_Glyph_CacheRec_*    FTC_Glyph_Cache;
63
64
65
66
67
68
69

  typedef struct  FTC_GlyphNodeRec_
  {
    FTC_CacheNodeRec  root;

    /* link.data contains a handle to a FT_Glyph object */
    FT_ListNodeRec    link;
David Turner's avatar
David Turner committed
70

71
72
    FT_UShort         glyph_index;
    FT_UShort         queue_index;
David Turner's avatar
David Turner committed
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
  } FTC_GlyphNodeRec;


#define FTC_GLYPHNODE_GET_GLYPH(n)    ((FT_Glyph)((n)->link.data))
#define FTC_GLYPHNODE_SET_GLYPH(n,g)  do { (n)->link.data = (g); } while (0)

  /* this macro is used to extract a handle to the bucket's lru list */
  /* corresponding to a given image node                             */
#define FTC_GLYPHNODE_TO_LISTNODE( n ) \
          ( (FT_ListNode)&(n)->link )

  /* 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_GLYPHNODE( p )                              \
          ( (FTC_GlyphNode)( (char*)(p) -                           \
                             offsetof( FTC_GlyphNodeRec,link ) ) )

#define FTC_GLYPHNODE_TO_LRUNODE(n)  ((FT_ListNode)(n))
#define FTC_LRUNODE_TO_GLYPHNODE(n)  ((FTC_GlyphNode)(n))


 /* glyph queue methods *****************************************************/

  typedef FT_Error  (*FTC_Glyph_Queue_InitFunc)   ( FTC_Glyph_Queue  queue,
                                                    FT_Pointer       type );
David Turner's avatar
David Turner committed
99

100
  typedef void      (*FTC_Glyph_Queue_DoneFunc)   ( FTC_Glyph_Queue  queue );
David Turner's avatar
David Turner committed
101

102
103
104
105
106
107
108
109
110
  typedef FT_Bool   (*FTC_Glyph_Queue_CompareFunc)( FTC_Glyph_Queue  queue,
                                                    FT_Pointer       type );

  typedef FT_Error  (*FTC_Glyph_Queue_NewNodeFunc)( FTC_Glyph_Queue  queue,
                                                    FT_UInt          gindex,
                                                    FTC_GlyphNode   *anode );

  typedef void  (*FTC_Glyph_Queue_DestroyNodeFunc)( FTC_GlyphNode    node,
                                                    FTC_Glyph_Queue  queue );
David Turner's avatar
David Turner committed
111

112
113
114
115
116
117
118

  typedef FT_ULong (*FTC_Glyph_Queue_SizeNodeFunc)( FTC_GlyphNode    node,
                                                    FTC_Glyph_Queue  queue );

  typedef struct FTC_Glyph_Queue_Class_
  {
    FT_UInt                          queue_byte_size;
David Turner's avatar
David Turner committed
119

120
121
122
123
124
125
126
    FTC_Glyph_Queue_InitFunc         init;
    FTC_Glyph_Queue_DoneFunc         done;
    FTC_Glyph_Queue_CompareFunc      compare;

    FTC_Glyph_Queue_NewNodeFunc      new_node;
    FTC_Glyph_Queue_SizeNodeFunc     size_node;
    FTC_Glyph_Queue_DestroyNodeFunc  destroy_node;
David Turner's avatar
David Turner committed
127

128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
  } FTC_Glyph_Queue_Class;


  typedef struct  FTC_Glyph_QueueRec_
  {
    FTC_Glyph_Cache         cache;
    FTC_Manager             manager;
    FT_Memory               memory;
    FTC_Glyph_Queue_Class*  clazz;
    FTC_Image_Desc          descriptor;
    FT_UInt                 hash_size;
    FT_List                 buckets;
    FT_UInt                 queue_index;  /* index in parent cache    */

  } FTC_Glyph_QueueRec;


 /* the abstract glyph cache class */
  typedef  struct FTC_Glyph_Cache_Class_
  {
    FTC_Cache_Class         root;
    FTC_Glyph_Queue_Class*  queue_class;
David Turner's avatar
David Turner committed
150

151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
  } FTC_Glyph_Cache_Class;


 /* the abstract glyph cache object */
  typedef struct  FTC_Glyph_CacheRec_
  {
    FTC_CacheRec          root;
    FT_Lru                queues_lru;  /* static queues lru list */
    FTC_Glyph_Queue       last_queue;  /* small cache            */

  } FTC_Glyph_CacheRec;


  /* these function are exported so that they can be called from */
  /* user-provided cache classes.. otherwise, they're really     */
David Turner's avatar
David Turner committed
166
  /* part of the cache sub-system internals..                    */
167
168
169
170
171
172
173
174
  /*                                                             */

  FT_EXPORT_FUNC(void)   FTC_GlyphNode_Init( FTC_GlyphNode    node,
                                             FTC_Glyph_Queue  queue,
                                             FT_UInt          gindex );

#define  FTC_GlyphNode_Ref(n)  \
             FTC_CACHENODE_TO_DATA_P(&(n)->root)->ref_count++
David Turner's avatar
David Turner committed
175

176
177
178
179
180
181
182
183
184
185
186
187
#define  FTC_GlyphNode_Unref(n)  \
             FTC_CACHENODE_TO_DATA_P(&(n)->root)->ref_count--


  FT_EXPORT_DEF(void)       FTC_Destroy_Glyph_Node( FTC_GlyphNode    node,
                                                    FTC_Glyph_Cache  cache );


  FT_EXPORT_DEF(FT_Error)   FTC_Glyph_Cache_Init( FTC_Glyph_Cache cache );

  FT_EXPORT_DEF(void)       FTC_Glyph_Cache_Done( FTC_Glyph_Cache  cache );

David Turner's avatar
David Turner committed
188
  FT_EXPORT_DEF(FT_Error)   FTC_Glyph_Queue_New(
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
                                 FTC_Glyph_Cache         cache,
                                 FT_Pointer              type,
                                 FTC_Glyph_Queue        *aqueue );

  FT_EXPORT_DEF(FT_Error)   FTC_Glyph_Queue_Lookup_Node(
                                         FTC_Glyph_Queue  queue,
                                         FT_UInt          glyph_index,
                                         FTC_GlyphNode*   anode );


  FT_EXPORT_DEF(FT_Error)   FTC_Glyph_Cache_Init( FTC_Glyph_Cache cache );

  FT_EXPORT_DEF(void)       FTC_Glyph_Cache_Done( FTC_Glyph_Cache  cache );

#ifdef __cplusplus
  }
#endif


#endif /* FTCIMAGE_H */

/* END */