Commit 9b11b9e3e42c68070aba0f02a50da0d12aca4038

David Turner 2000-09-15T22:50:59

adding updated cache 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
diff --git a/include/freetype/cache/ftcglyph.h b/include/freetype/cache/ftcglyph.h
new file mode 100644
index 0000000..621ee93
--- /dev/null
+++ b/include/freetype/cache/ftcglyph.h
@@ -0,0 +1,211 @@
+/***************************************************************************/
+/*                                                                         */
+/*  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;
+  typedef struct FTC_Glyph_CacheRec_*    FTC_Glyph_Cache;  
+
+  typedef struct  FTC_GlyphNodeRec_
+  {
+    FTC_CacheNodeRec  root;
+
+    /* link.data contains a handle to a FT_Glyph object */
+    FT_ListNodeRec    link;
+    
+    FT_UShort         glyph_index;
+    FT_UShort         queue_index;
+ 
+  } 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 );
+                                                
+  typedef void      (*FTC_Glyph_Queue_DoneFunc)   ( FTC_Glyph_Queue  queue );
+  
+  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 );
+                
+
+  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;
+    
+    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;
+  
+  } 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;
+    
+  } 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     */
+  /* pars of the cache sub-system internals..                    */
+  /*                                                             */
+
+  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++
+             
+#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 );
+
+  FT_EXPORT_DEF(FT_Error)   FTC_Glyph_Queue_New( 
+                                 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 */
diff --git a/include/freetype/config/ftoption.h b/include/freetype/config/ftoption.h
index 11553a3..7474a55 100644
--- a/include/freetype/config/ftoption.h
+++ b/include/freetype/config/ftoption.h
@@ -220,7 +220,7 @@
   /*                                                                       */
   /* This must be greater than 4kByte.                                     */
   /*                                                                       */
-#define FT_RENDER_POOL_SIZE  16384
+#define FT_RENDER_POOL_SIZE  32768
 
 
   /*************************************************************************/
@@ -310,7 +310,7 @@
   /* By undefining this, you will only compile the code necessary to load  */
   /* TrueType glyphs without hinting.                                      */
   /*                                                                       */
-#undef  TT_CONFIG_OPTION_BYTECODE_INTERPRETER
+#define  TT_CONFIG_OPTION_BYTECODE_INTERPRETER
 
 
   /*************************************************************************/
diff --git a/include/freetype/ftcache.h b/include/freetype/ftcache.h
index ae1dc19..4baa058 100644
--- a/include/freetype/ftcache.h
+++ b/include/freetype/ftcache.h
@@ -98,11 +98,12 @@
   /*************************************************************************/
   /*                                                                       */
   /* <Struct>                                                              */
-  /*    FTC_SizeRec                                                        */
+  /*    FTC_FontRec                                                        */
   /*                                                                       */
   /* <Description>                                                         */
-  /*    A simple structure used to describe a given `font size' to the     */
-  /*    cache manager.                                                     */
+  /*    A simple structure used to describe a given `font' to the cache    */
+  /*    manager. Note that a "font" is the combination of a given face     */
+  /*    with a given character size..                                      */
   /*                                                                       */
   /* <Fields>                                                              */
   /*    face_id    :: The ID of the face to use.                           */
@@ -111,24 +112,24 @@
   /*                                                                       */
   /*    pix_height :: The character height in integer pixels.              */
   /*                                                                       */
-  typedef struct  FTC_SizeRec_
+  typedef struct  FTC_FontRec_
   {
     FTC_FaceID  face_id;
     FT_UShort   pix_width;
     FT_UShort   pix_height;
     
-  } FTC_SizeRec;
+  } FTC_FontRec;
 
 
   /*************************************************************************/
   /*                                                                       */
   /* <Type>                                                                */
-  /*    FTC_SizeID                                                         */
+  /*    FTC_Font                                                           */
   /*                                                                       */
   /* <Description>                                                         */
-  /*    A simple handle to a FTC_SizeRec structure.                        */
+  /*    A simple handle to a FTC_FontRec structure.                        */
   /*                                                                       */
-  typedef FTC_SizeRec*  FTC_SizeID;
+  typedef FTC_FontRec*  FTC_Font;
  
 
   /*************************************************************************/
@@ -171,6 +172,9 @@
   /*    max_sizes :: Maximum number of sizes to keep alive in manager.     */
   /*                 Use 0 for defaults.                                   */
   /*                                                                       */
+  /*    max_bytes :: Maximum number of bytes to use for cached data.       */
+  /*                 Use 0 for defaults.                                   */
+  /*                                                                       */
   /*    requester :: An application-provided callback used to translate    */
   /*                 face IDs into real FT_Face objects.                   */
   /*                                                                       */
@@ -187,6 +191,7 @@
   FT_EXPORT_DEF( FT_Error )  FTC_Manager_New( FT_Library          library,
                                               FT_UInt             max_faces,
                                               FT_UInt             max_sizes,
+                                              FT_ULong            max_bytes,
                                               FTC_Face_Requester  requester,
                                               FT_Pointer          req_data,
                                               FTC_Manager*        amanager );
@@ -298,10 +303,23 @@
   /*    that you can call FT_Load_Glyph() with the face if you need to.    */
   /*                                                                       */
   FT_EXPORT_DEF( FT_Error )  FTC_Manager_Lookup_Size( FTC_Manager  manager,
-                                                      FTC_SizeID   size_id,
+                                                      FTC_Font     font,
                                                       FT_Face*     aface,
                                                       FT_Size*     asize );
 
+
+  /* a cache class is used to describe a unique cache type to the */
+  /* manager..                                                    */
+  typedef struct FTC_Cache_Class_  FTC_Cache_Class;
+  typedef struct FTC_CacheRec_*    FTC_Cache;
+
+
+  /* this must be used internally for the moment */
+  FT_EXPORT_DEF( FT_Error )  FTC_Manager_Register_Cache(
+                                   FTC_Manager       manager,
+                                   FTC_Cache_Class*  clazz,
+                                   FTC_Cache        *acache );
+
   
   /*************************************************************************/
   /*************************************************************************/
@@ -349,12 +367,12 @@
     ftc_image_flag_unscaled   = 128,
     ftc_image_flag_no_sbits   = 256,
     
-    ftc_image_mono             = ftc_image_format_bitmap |
-                                 ftc_image_flag_monochrome, /* monochrome bitmap   */
+    ftc_image_mono            = ftc_image_format_bitmap |
+                                ftc_image_flag_monochrome, /* monochrome bitmap   */
                                 
-    ftc_image_grays            = ftc_image_format_bitmap,   /* anti-aliased bitmap */
+    ftc_image_grays           = ftc_image_format_bitmap,   /* anti-aliased bitmap */
                                 
-    ftc_image_outline          = ftc_image_format_outline   /* scaled outline */
+    ftc_image_outline         = ftc_image_format_outline   /* scaled outline */
   
   } FTC_Image_Type;
 
@@ -375,7 +393,7 @@
   /*                                                                       */
   typedef struct  FTC_Image_Desc_
   {
-    FTC_SizeRec  size;
+    FTC_FontRec  font;
     FT_UInt      image_type;
   
   } FTC_Image_Desc;
@@ -405,9 +423,6 @@
   /* <Input>                                                               */
   /*    manager   :: The parent manager for the image cache.               */
   /*                                                                       */
-  /*    max_bytes :: The maximum amount of memory that will be used to     */
-  /*                 store glyph images.                                   */
-  /*                                                                       */
   /* <Output>                                                              */
   /*    acache    :: A handle to the new glyph image cache object.         */
   /*                                                                       */
@@ -415,27 +430,12 @@
   /*    FreeType error code.  0 means success.                             */
   /*                                                                       */
   FT_EXPORT_DEF( FT_Error )  FTC_Image_Cache_New( FTC_Manager       manager,
-                                                  FT_ULong          max_bytes,
                                                   FTC_Image_Cache*  acache );
                                                 
 
   /*************************************************************************/
   /*                                                                       */
   /* <Function>                                                            */
-  /*    FTC_Image_Cache_Done                                               */
-  /*                                                                       */
-  /* <Description>                                                         */
-  /*    Destroys a given glyph image cache (and all glyphs within it).     */
-  /*                                                                       */
-  /* <Input>                                                               */
-  /*    manager :: The parent manager for the image cache.                 */
-  /*                                                                       */
-  FT_EXPORT_DEF( void )  FTC_Image_Cache_Done( FTC_Image_Cache  cache );
-
-
-  /*************************************************************************/
-  /*                                                                       */
-  /* <Function>                                                            */
   /*    FTC_Image_Cache_Lookup                                             */
   /*                                                                       */
   /* <Description>                                                         */
diff --git a/include/freetype/fterrors.h b/include/freetype/fterrors.h
index 4dda516..94d3e97 100644
--- a/include/freetype/fterrors.h
+++ b/include/freetype/fterrors.h
@@ -163,6 +163,11 @@
   FT_ERRORDEF( FT_Err_Raster_Negative_Height,       0x0063, \
                "negative height while rastering" )
 
+  /* cache errors */
+  
+  FT_ERRORDEF( FT_Err_Too_Many_Caches,              0x0070, \
+               "too many registered caches" )
+
   /* range 0x400 - 0x4FF is reserved for TrueType specific stuff */
 
   /* range 0x500 - 0x5FF is reserved for CFF specific stuff */
diff --git a/include/freetype/internal/ftdebug.h b/include/freetype/internal/ftdebug.h
index c70b7e8..c364892 100644
--- a/include/freetype/internal/ftdebug.h
+++ b/include/freetype/internal/ftdebug.h
@@ -63,6 +63,9 @@
     trace_raster,    /* rasterizer              (ftraster.c) */
     trace_stream,    /* stream manager          (ftstream.c) */
 
+    /* Cache sub-system */
+    trace_cache,
+
     /* SFNT driver components */
     trace_sfobjs,    /* SFNT object handler     (sfobjs.c)   */
     trace_ttcmap,    /* charmap handler         (ttcmap.c)   */