Commit 145f94cb261afc5bdbd924b130cd5d856c42e4b9

David Turner 2001-12-07T14:43:45

added new charmap cache. see include/freetype/cache/ftccmap.h

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
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
diff --git a/ChangeLog b/ChangeLog
index a6259d5..2f6763a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2001-12-07  David Turner  <david@freetype.org>
+
+    * include/freetype/cache/ftccmap.h, src/cache/ftccmap.c: added new
+    charmap cache
+
+
 2001-12-06  Leonard Rosenthol  <leonardr@lazerware.com>
 
 	* src/base/ftmac.c: Added support for reading .dfont files on 
@@ -7,22 +13,36 @@
 	
 	* include/freetype/ftmac.h: Exported FT_GetFile_From_Mac_Name()
 
+
 2001-12-06  Werner Lemberg  <wl@gnu.org>
 
 	* INSTALL: Small update.
 
+
 2001-12-05  David Turner  <david@freetype.org>
 
-	* src/base/ftglyph.c (FT_Glyph_To_Bitmap): Re-ordered code for
-	debugging purposes.
+    * src/base/ftglyph.c (FT_Glyph_To_Bitmap): re-ordered code for debugging
+    purposes..
+
+    * src/smooth/ftsmooth.c (ft_smooth_render): fixed a nasty hidden bug where
+    outline shifting wasn't correctly undone after bitmap rasterization. this
+    created problems with certain glyphs (like '"' of certain fonts..) and
+    the cache system..
 
-	* src/smooth/ftsmooth.c (ft_smooth_render): Fixed a nasty hidden bug
-	where outline shifting wasn't correctly undone after bitmap
-	rasterization.  This created problems with certain glyphs (like '"'
-	of certain fonts) and the cache system.
 
 2001-12-05  David Turner  <david@freetype.org>
 
+    First of all, a big thanks to Werner and Antoine for their latest work !!
+    
+    * src/pshinter/pshalgo2.c (psh2_hint_table_init),
+      src/pshinter/pshalgo1.c (psh1_hint_table_init): removed compiler
+      warnings
+
+    * include/freetype/cache/*, src/cache/*: yet another massive rewrite of
+    the caching sub-system, in order to both increase performance and allow
+    simpler cache sub-classing. As an example, the code for the image and
+    sbit caches is now much simpler
+
 	* src/pshinter/pshalgo2.c (psh2_hint_table_init),
 	src/pshinter/pshalgo1.c (psh1_hint_table_init): Removed compiler
 	warnings
diff --git a/include/freetype/cache/ftccmap.h b/include/freetype/cache/ftccmap.h
new file mode 100644
index 0000000..3966016
--- /dev/null
+++ b/include/freetype/cache/ftccmap.h
@@ -0,0 +1,195 @@
+/***************************************************************************/
+/*                                                                         */
+/*  ftccmap.h                                                              */
+/*                                                                         */
+/*    FreeType charmap cache                                               */
+/*                                                                         */
+/*  Copyright 2000-2001 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 __FT_CACHE_CHARMAP_H__
+#define __FT_CACHE_CHARMAP_H__
+
+#include <ft2build.h>
+#include FT_CACHE_H
+
+FT_BEGIN_HEADER
+
+ /************************************************************************
+  *
+  * @type: FTC_CmapCache
+  *
+  * @description:
+  *   opaque handle used to manager a charmap cache. This cache is used
+  *   to hold character codes -> glyph indices mappings
+  */
+  typedef struct FTC_CMapCacheRec_*    FTC_CMapCache;
+
+
+ /************************************************************************
+  *
+  * @type: FTC_CMapDesc
+  *
+  * @description:
+  *   handle to a @FTC_CMapDescRec structure used to describe a given charmap
+  *   in a charmap cache.
+  *
+  *   each @FTC_CMapDesc describes which charmap, of which @FTC_Face we
+  *   want to use in @FTC_CMapCache_Lookup
+  */
+  typedef struct FTC_CMapDescRec_*         FTC_CMapDesc;
+
+
+ /************************************************************************
+  *
+  * @enum: FTC_CMapType
+  *
+  * @description:
+  *   the list of valid @FTC_CMap types, they indicate how we want to
+  *   address a charmap within a @FTC_FaceID
+  *
+  * @values:
+  *   FTC_CMAP_BY_INDEX ::
+  *     used to indicate that we want to address a charmap by its index in
+  *     the corresponding @FT_Face
+  *
+  *   FTC_CMAP_BY_ENCODING ::
+  *     used to indicate that we want to use a @FT_Face charmap that
+  *     corresponds to a given encoding
+  *
+  *   FTC_CMAP_BY_ID ::
+  *     used to indicate that we want to use a @FT_Face charmap that
+  *     corresponds to a given (platform,encoding) id. see @FTC_CMapIdRec
+  */
+  typedef enum
+  {
+    FTC_CMAP_BY_INDEX    = 0,
+    FTC_CMAP_BY_ENCODING = 1,
+    FTC_CMAP_BY_ID       = 2
+  
+  } FTC_CMapType;
+
+
+ /************************************************************************
+  *
+  * @struct: FTC_CMapIdRec
+  *
+  * @description:
+  *   a short structure used to identify a charmap by a (platform,encoding)
+  *   pair of values
+  *
+  * @fields:
+  *   platform :: platform ID
+  *   encoding :: encoding ID
+  */
+  typedef struct FTC_CMapIdRec_
+  {
+    FT_UInt  platform;
+    FT_UInt  encoding;
+  
+  } FTC_CMapIdRec;
+
+
+ /************************************************************************
+  *
+  * @struct: FTC_CMapDescRec
+  *
+  * @description:
+  *   a structure used to describe a given charmap to the @FTC_CMapCache
+  *
+  * @fields:
+  *   face_id :: @FTC_FaceID of the face this charmap belongs to
+  *   type    :: type of charmap, see @FTC_CMapType
+  *
+  *   u.index    :: for @FTC_CMAP_BY_INDEX types, this is the charmap index
+  *                 (within a @FT_Face) we want to use.
+  *
+  *   u.encoding :: for @FTC_CMAP_BY_ENCODING types, this is the charmap
+  *                 encoding we want to use. see @FT_Encoding
+  *
+  *   u.id       :: for @FTC_CMAP_BY_ID types, this is the (platform,encoding)
+  *                 pair we want to use. see @FTC_CMapIdRec and
+  *                 @FT_CharMapRec
+  */
+  typedef struct FTC_CMapDescRec_
+  {
+    FTC_FaceID    face_id;
+    FTC_CMapType  type;
+
+    union
+    {
+      FT_UInt        index;
+      FT_Encoding    encoding;
+      FTC_CMapIdRec  id;
+      
+    } u;
+     
+  } FTC_CMapDescRec;
+
+
+
+ /************************************************************************
+  *
+  * @function: FTC_CMapCache_New
+  *
+  * @description:
+  *   create a new charmap cache
+  *
+  * @input:
+  *   manager :: handle to cache manager
+  *
+  * @output:
+  *   acache  :: new cache handle. NULL in case of error
+  *
+  * @return:
+  *   FreeType error code. 0 means success
+  *
+  * @note:
+  *   like all other caches, this one will be destroyed with the
+  *   cache manager
+  */
+  FT_EXPORT( FT_Error )
+  FTC_CMapCache_New( FTC_Manager     manager,
+                     FTC_CMapCache  *acache );
+
+
+
+ /************************************************************************
+  *
+  * @function: FTC_CMapCache_Lookup
+  *
+  * @description:
+  *   translate a character code into a glyph index, using the charmap
+  *   cache.
+  *
+  * @input:
+  *   cache     :: charmap cache handle
+  *   cmap_desc :: charmap descriptor handle
+  *   char_code :: character code (in the corresponding charmap)
+  *
+  * @return:
+  *   glyph index. 0 means "no glyph" !!
+  *
+  * @note:
+  *   this function doesn't return @FTC_Node handles, since there is
+  *   no real use for them with typical uses of charmaps
+  */
+  FT_EXPORT( FT_UInt )
+  FTC_CMapCache_Lookup( FTC_CMapCache  cache,
+                        FTC_CMapDesc   cmap_desc,
+                        FT_UInt32      char_code );
+
+
+ /* */
+
+FT_END_HEADER
+
+#endif /* __FT_CACHE_CHARMAP_H__ */
diff --git a/include/freetype/config/ftheader.h b/include/freetype/config/ftheader.h
index bd64ce4..b216d86 100644
--- a/include/freetype/config/ftheader.h
+++ b/include/freetype/config/ftheader.h
@@ -420,6 +420,18 @@
   /*************************************************************************/
   /*                                                                       */
   /* @macro:                                                               */
+  /*    FT_CACHE_CHARMAP_H                                                 */
+  /*                                                                       */
+  /* @description:                                                         */
+  /*    A macro used in #include statements to name the file containing    */
+  /*    the `charmap'API of the FreeType 2 cache sub-system.               */
+  /*                                                                       */
+#define FT_CACHE_CHARMAP_H        <freetype/cache/ftccmap.h>
+
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* @macro:                                                               */
   /*    FT_MAC_H                                                           */
   /*                                                                       */
   /* @description:                                                         */
diff --git a/src/cache/Jamfile b/src/cache/Jamfile
index a4905b1..3148f55 100644
--- a/src/cache/Jamfile
+++ b/src/cache/Jamfile
@@ -16,7 +16,7 @@ HDRMACRO  [ FT2_SubDir  include ftcache.h ] ;
 
   if $(FT2_MULTI)
   {
-    _sources = ftlru ftcmanag ftccache ftcglyph ftcsbits ftcimage ;
+    _sources = ftlru ftcmanag ftccache ftcglyph ftcsbits ftcimage ftccmap ;
   }
   else
   {
diff --git a/src/cache/ftccache.c b/src/cache/ftccache.c
index 582d679..147a624 100644
--- a/src/cache/ftccache.c
+++ b/src/cache/ftccache.c
@@ -559,8 +559,8 @@
         if ( ALLOC( node, clazz->node_size ) )
           goto Exit;
 
-        /* node initializer must set 'hash' field */
         node->fam_index = (FT_UShort) family->fam_index;
+        node->hash      = query->hash;
         node->ref_count = 0;
 
         error = clazz->node_init( node, query, cache );
diff --git a/src/cache/ftccmap.c b/src/cache/ftccmap.c
new file mode 100644
index 0000000..fa72a38
--- /dev/null
+++ b/src/cache/ftccmap.c
@@ -0,0 +1,391 @@
+/***************************************************************************/
+/*                                                                         */
+/*  ftccmap.c                                                              */
+/*                                                                         */
+/*    FreeType CharMap cache                                               */
+/*                                                                         */
+/*  Copyright 2000-2001 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.                                        */
+/*                                                                         */
+/***************************************************************************/
+
+
+#include <ft2build.h>
+#include FT_FREETYPE_H
+#include FT_CACHE_H
+#include FT_CACHE_CHARMAP_H
+#include FT_CACHE_MANAGER_H
+#include FT_INTERNAL_MEMORY_H
+#include FT_INTERNAL_DEBUG_H
+
+#include "ftcerror.h"
+
+
+
+ /* each FTC_CMapNode contains a simple array used to map a  */
+ /* range of character codes to equivalent glyph indices     */
+ /*                                                          */
+ /* for now, the implementation is very basic: each node     */
+ /* maps a range of 128 consecutive character codes to their */
+ /* correspondingglyph indices..                             */
+ /*                                                          */
+ /* we could do more complex things, but I don't think it's  */
+ /* really very useful..                                     */
+ /*                                                          */
+
+ /* number of glyph indices / character code per node */
+#define  FTC_CMAP_INDICES_MAX  128
+
+
+  typedef struct FTC_CMapNodeRec_
+  {
+    FTC_NodeRec  node;
+    FT_UInt32    first;         /* first character in node      */
+    FT_UInt16    indices[ FTC_CMAP_INDICES_MAX ];  /* array of glyph indices */
+
+  } FTC_CMapNodeRec, *FTC_CMapNode;
+
+#define  FTC_CMAP_NODE( x )       ((FTC_CMapNode)( x ))
+
+ /* compute node hash value from cmap family and "requested" glyph index */
+#define  FTC_CMAP_HASH(cfam,cquery)   \
+              ((cfam)->hash + ((cquery)->char_code/FTC_CMAP_INDICES_MAX))
+
+
+ /* if (indices[n] == FTC_CMAP_UNKNOWN), we assume that the corresponding */
+ /* glyph indices hasn't been queried through @FT_Get_Glyph_Index yet..   */
+ /*                                                                       */
+#define  FTC_CMAP_UNKNOWN  ((FT_UInt16)-1)
+
+
+  /* the charmap query */
+  typedef struct FTC_CMapQueryRec_
+  {
+    FTC_QueryRec  query;
+    FTC_CMapDesc  desc;
+    FT_UInt32     char_code;
+
+  } FTC_CMapQueryRec, *FTC_CMapQuery;
+
+#define  FTC_CMAP_QUERY( x )  ((FTC_CMapQuery)( x ))
+
+
+  /* the charmap family */
+  typedef struct FTC_CMapFamilyRec_
+  {
+    FTC_FamilyRec    family;
+    FT_UInt32        hash;
+    FTC_CMapDescRec  desc;
+    FT_UInt          index;
+
+  } FTC_CMapFamilyRec, *FTC_CMapFamily;
+
+#define  FTC_CMAP_FAMILY( x )           ((FTC_CMapFamily)( x ))
+#define  FTC_CMAP_FAMILY_MEMORY( x )     FTC_FAMILY(x)->memory
+
+
+  /*************************************************************************/
+  /*************************************************************************/
+  /*****                                                               *****/
+  /*****                        CHARMAP NODES                          *****/
+  /*****                                                               *****/
+  /*************************************************************************/
+  /*************************************************************************/
+
+
+  /* no need for specific finalizer, we'll use "ftc_node_done" directly */
+
+  /* initialize a new cmap node */
+  FT_CALLBACK_DEF( FT_Error )
+  ftc_cmap_node_init( FTC_CMapNode   cnode,
+                      FTC_CMapQuery  cquery,
+                      FTC_Cache      cache )
+  {
+    FTC_CMapFamily  cfam = FTC_CMAP_FAMILY( FTC_QUERY(cquery)->family );
+    FT_UInt32       first;
+    FT_UInt         n;
+
+
+    first = (cquery->char_code / FTC_CMAP_INDICES_MAX) * FTC_CMAP_INDICES_MAX;
+
+    cnode->first = first;
+    for ( n = 0; n < FTC_CMAP_INDICES_MAX; n++ )
+      cnode->indices[n] = FTC_CMAP_UNKNOWN;
+
+    return 0;
+  }
+
+
+ /* compute the weight of a given cmap node */
+  FT_CALLBACK_DEF( FT_ULong )
+  ftc_cmap_node_weight( FTC_CMapNode  cnode )
+  {
+    return sizeof(*cnode);
+  }
+
+
+ /* compare a cmap node to a given query */
+  FT_CALLBACK_DEF( FT_Bool )
+  ftc_cmap_node_compare( FTC_CMapNode   cnode,
+                         FTC_CMapQuery  cquery )
+  {
+    FT_UInt32  offset = (FT_UInt32)( cquery->char_code - cnode->first );
+
+
+    return ( offset < FTC_CMAP_INDICES_MAX );
+  }
+
+
+  /*************************************************************************/
+  /*************************************************************************/
+  /*****                                                               *****/
+  /*****                    CHARMAP FAMILY                             *****/
+  /*****                                                               *****/
+  /*************************************************************************/
+  /*************************************************************************/
+
+
+  FT_CALLBACK_DEF( FT_Error )
+  ftc_cmap_family_init( FTC_CMapFamily  cfam,
+                        FTC_CMapQuery   cquery,
+                        FTC_Cache       cache )
+  {
+    FTC_Manager   manager = cache->manager;
+    FTC_CMapDesc  desc = cquery->desc;
+    FT_UInt32     hash;
+    FT_Error      error;
+    FT_Face       face;
+
+
+    /* setup charmap descriptor */
+    cfam->desc = *desc;
+
+    /* let's see if the rest is correct too */
+    error = FTC_Manager_Lookup_Face( manager, desc->face_id, &face );
+    if ( !error )
+    {
+      FT_UInt      count = face->num_charmaps;
+      FT_UInt      index = count;
+      FT_CharMap*  cur   = face->charmaps;
+      
+      switch ( desc->type )
+      {
+        case FTC_CMAP_BY_INDEX:
+          {
+            index = desc->u.index;
+            hash  = index*33;
+            break;
+          }
+
+
+        case FTC_CMAP_BY_ENCODING:
+          {
+            for ( index = 0; index < count; index++, cur++ )
+              if ( cur[0]->encoding == desc->u.encoding )
+                break;
+            
+            hash = index*67;
+            break;
+          }
+
+
+        case FTC_CMAP_BY_ID:
+          {
+            for ( index = 0; index < count; index++, cur++ )
+            {
+              if ( (FT_UInt) cur[0]->platform_id == desc->u.id.platform &&
+                   (FT_UInt) cur[0]->encoding_id == desc->u.id.encoding )
+              {
+                hash = ((desc->u.id.platform << 8) | desc->u.id.encoding)*7;
+                break;
+              }
+            }
+            break;
+          }
+
+        default:
+          ;
+      }
+
+      if ( index >= count )
+        goto Bad_Descriptor;
+
+      /* compute hash value, both in family and query */
+      cfam->index             = index;
+      cfam->hash              = hash ^ FTC_FACE_ID_HASH(desc->face_id);
+      FTC_QUERY(cquery)->hash = FTC_CMAP_HASH(cfam,cquery);
+
+      error = ftc_family_init( FTC_FAMILY(cfam), FTC_QUERY(cquery), cache );
+    }
+    
+    return error;
+
+
+  Bad_Descriptor:
+    FT_ERROR(( "FreeType.cache.cmap.lookup: invalid charmap descriptor\n" ));
+    return FT_Err_Invalid_Argument;
+  }
+
+
+
+  FT_CALLBACK_DEF( FT_Bool )
+  ftc_cmap_family_compare( FTC_CMapFamily  cfam,
+                           FTC_CMapQuery   cquery )
+  {
+    FT_Int  result = 0;
+
+
+    /* first, compare face id and type */
+    if ( cfam->desc.face_id != cquery->desc->face_id ||
+         cfam->desc.type    != cquery->desc->type    )
+      goto Exit;
+
+    switch ( cfam->desc.type )
+    {
+      case FTC_CMAP_BY_INDEX:
+        result = ( cfam->desc.u.index == cquery->desc->u.index );
+        break;
+
+      case FTC_CMAP_BY_ENCODING:
+        result = ( cfam->desc.u.encoding == cquery->desc->u.encoding );
+        break;
+
+      case FTC_CMAP_BY_ID:
+        result = ( cfam->desc.u.id.platform == cquery->desc->u.id.platform &&
+                   cfam->desc.u.id.encoding == cquery->desc->u.id.encoding );
+        break;
+
+      default:
+        ;
+    }
+
+    if (result)
+    {
+      /* when found, update the 'family' and 'hash' field of the query */
+      FTC_QUERY(cquery)->family = FTC_FAMILY(cfam);
+      FTC_QUERY(cquery)->hash   = FTC_CMAP_HASH(cfam,cquery);
+    }
+
+  Exit:
+    return FT_BOOL(result);
+  }
+
+
+  /*************************************************************************/
+  /*************************************************************************/
+  /*****                                                               *****/
+  /*****                    GLYPH IMAGE CACHE                          *****/
+  /*****                                                               *****/
+  /*************************************************************************/
+  /*************************************************************************/
+
+
+
+  FT_CALLBACK_TABLE_DEF
+  const FTC_Cache_ClassRec  ftc_cmap_cache_class =
+  {
+    sizeof( FTC_CacheRec ),
+    (FTC_Cache_InitFunc)       ftc_cache_init,
+    (FTC_Cache_ClearFunc)      ftc_cache_clear,
+    (FTC_Cache_DoneFunc)       ftc_cache_done,
+
+    sizeof( FTC_CMapFamilyRec ),
+    (FTC_Family_InitFunc)      ftc_cmap_family_init,
+    (FTC_Family_CompareFunc)   ftc_cmap_family_compare,
+    (FTC_Family_DoneFunc)      ftc_family_done,
+
+    sizeof( FTC_CMapNodeRec ),
+    (FTC_Node_InitFunc)        ftc_cmap_node_init,
+    (FTC_Node_WeightFunc)      ftc_cmap_node_weight,
+    (FTC_Node_CompareFunc)     ftc_cmap_node_compare,
+    (FTC_Node_DoneFunc)        ftc_node_done
+  };
+
+
+  /* documentation is in ftccmap.h */
+
+  FT_EXPORT_DEF( FT_Error )
+  FTC_CMapCache_New( FTC_Manager     manager,
+                     FTC_CMapCache  *acache )
+  {
+    return FTC_Manager_Register_Cache(
+             manager,
+             (FTC_Cache_Class)&ftc_cmap_cache_class,
+             FTC_CACHE_P( acache ) );
+  }
+
+
+  /* documentation is in ftccmap.h */
+
+  FT_EXPORT_DEF( FT_UInt )
+  FTC_CMapCache_Lookup( FTC_CMapCache  cache,
+                        FTC_CMapDesc   desc,
+                        FT_UInt32      char_code )
+  {
+    FTC_CMapQueryRec  cquery;
+    FTC_CMapNode      node;
+    FT_Error          error;
+    FT_UInt           gindex;
+
+    if ( !cache || !desc )
+    {
+      FT_ERROR(( "FTC_CMapCache_Lookup: bad arguments, returning 0 !!\n" ));
+      return 0;
+    }
+
+    cquery.desc      = desc;
+    cquery.char_code = char_code;
+
+    error = ftc_cache_lookup( FTC_CACHE(cache),
+                              FTC_QUERY(&cquery),
+                              (FTC_Node*) &node );
+    if ( !error )
+    {
+      FT_UInt  offset = (FT_UInt)( char_code - node->first );
+
+      gindex = node->indices[offset];
+      if ( gindex == FTC_CMAP_UNKNOWN )
+      {
+        FT_Face     face;
+        FT_CharMap  old, cmap, limit;
+
+        /* we need to use @FT_Get_Char_Index */
+        gindex = 0;
+
+        error = FTC_Manager_Lookup_Face( FTC_CACHE(cache)->manager,
+                                         desc->face_id,
+                                         &face );
+        if (!error)
+        {
+          FT_CharMap   old, cmap  = NULL;
+          FT_UInt      cmap_index;
+
+          /* save old charmap, select new one */
+          old        = face->charmap;
+          cmap_index = FTC_CMAP_FAMILY( FTC_QUERY(&cquery)->family )->index;
+          cmap       = face->charmaps[cmap_index];
+
+          FT_Set_Charmap( face, cmap );
+
+          /* perform lookup */
+          gindex                = FT_Get_Char_Index( face, char_code );
+          node->indices[offset] = gindex;
+
+          /* restore old charmap */
+          FT_Set_Charmap( face, old );
+        }
+      }
+    }
+
+    return gindex;
+  }
+
+
+
+/* END */
diff --git a/src/cache/ftcglyph.c b/src/cache/ftcglyph.c
index 8be466f..d1b5d49 100644
--- a/src/cache/ftcglyph.c
+++ b/src/cache/ftcglyph.c
@@ -39,9 +39,7 @@
     FT_UInt    start = FTC_GLYPH_FAMILY_START(gfam,gindex);
 
 
-    gnode->node.fam_index = (FT_UShort) gfam->family.fam_index;
-    gnode->node.hash      = FTC_GLYPH_FAMILY_HASH(gfam,gindex);
-    gnode->item_start     = (FT_UShort) start;
+    gnode->item_start = (FT_UShort) start;
 
     len = gfam->item_total - start;
     if ( len > gfam->item_count )
@@ -68,12 +66,10 @@
   ftc_glyph_node_compare( FTC_GlyphNode    gnode,
                           FTC_GlyphQuery   gquery )
   {
-    FT_UInt  fam_index = (FT_UInt) FTC_NODE(gnode)->fam_index;
     FT_UInt  start     = (FT_UInt) gnode->item_start;
     FT_UInt  count     = (FT_UInt) gnode->item_count;
 
-    return FT_BOOL( (FT_UInt)(gquery->gindex - start) < count &&
-                     gquery->query.family->fam_index == fam_index );
+    return FT_BOOL( (FT_UInt)(gquery->gindex - start) < count );
   }
 
 
@@ -103,7 +99,7 @@
       gfam->hash       = hash;
       gfam->item_total = item_total;
       gfam->item_count = item_count;
-
+      
       FTC_GLYPH_FAMILY_FOUND(gfam,gquery);
     }
 
diff --git a/src/cache/ftcimage.c b/src/cache/ftcimage.c
index 2d5cfcc..291b1cc 100644
--- a/src/cache/ftcimage.c
+++ b/src/cache/ftcimage.c
@@ -261,7 +261,6 @@
     FT_Bool  result;
 
 
-    /* we must set iquery.glyph.gfam for faster glyph node comparisons */
     result = FT_BOOL( FTC_IMAGE_DESC_COMPARE( &ifam->desc, &iquery->desc ) );
     if ( result )
       FTC_GLYPH_FAMILY_FOUND(ifam,iquery);
diff --git a/src/cache/ftcsbits.c b/src/cache/ftcsbits.c
index e917e2d..7386ad7 100644
--- a/src/cache/ftcsbits.c
+++ b/src/cache/ftcsbits.c
@@ -120,19 +120,19 @@
 
 
   static FT_Error
-  ftc_sbit_node_load( FTC_SBitNode  snode,
-                      FTC_Manager   manager,
-                      FT_UInt       gindex,
-                      FT_ULong     *asize )
+  ftc_sbit_node_load( FTC_SBitNode   snode,
+                      FTC_Manager    manager,
+                      FTC_SBitFamily sfam,
+                      FT_UInt        gindex,
+                      FT_ULong      *asize )
   {
-    FT_Error       error;
-    FTC_GlyphNode  gnode = FTC_GLYPH_NODE(snode);
-    FTC_GlyphFamily   gfam;
-    FTC_SBitFamily    sfam;
-    FT_Memory      memory;
-    FT_Face        face;
-    FT_Size        size;
-    FTC_SBit       sbit;
+    FT_Error          error;
+    FTC_GlyphNode     gnode = FTC_GLYPH_NODE(snode);
+    FTC_GlyphFamily   gfam  = FTC_GLYPH_FAMILY(sfam);
+    FT_Memory         memory;
+    FT_Face           face;
+    FT_Size           size;
+    FTC_SBit          sbit;
 
     if ( gindex <  (FT_UInt)gnode->item_start                     ||
          gindex >= (FT_UInt)gnode->item_start + gnode->item_count )
@@ -141,8 +141,6 @@
       return FTC_Err_Invalid_Argument;
     }
 
-    gfam   = FTC_GLYPH_FAMILY( manager->families.entries[ gnode->node.fam_index ].family );
-    sfam   = FTC_SBIT_FAMILY(gfam);
     memory = manager->library->memory;
 
     sbit = snode->sbits + (gindex - gnode->item_start);
@@ -275,7 +273,11 @@
                          gquery->gindex,
                          FTC_GLYPH_FAMILY(gquery->query.family) );
 
-    error = ftc_sbit_node_load( snode, cache->manager, gquery->gindex, NULL );
+    error = ftc_sbit_node_load( snode,
+                                cache->manager,
+                                FTC_SBIT_FAMILY( FTC_QUERY(gquery)->family ),
+                                gquery->gindex,
+                                NULL );
     if ( error )
       ftc_glyph_node_done( FTC_GLYPH_NODE(snode), cache );
 
@@ -336,7 +338,13 @@
       {
         FT_ULong  size;
 
-        ftc_sbit_node_load( snode, cache->manager, gindex, &size );
+        /* yes, it's safe to ignore errors here */
+        ftc_sbit_node_load( snode,
+                            cache->manager,
+                            FTC_SBIT_FAMILY( FTC_QUERY(squery)->family ),
+                            gindex,
+                            &size );
+
         cache->manager->cur_weight += size;
       }
     }
diff --git a/src/cache/rules.mk b/src/cache/rules.mk
index 0620cdd..fb6a177 100644
--- a/src/cache/rules.mk
+++ b/src/cache/rules.mk
@@ -33,7 +33,8 @@ Cache_DRV_SRC := $(CACHE_DIR_)ftlru.c    \
                  $(CACHE_DIR_)ftccache.c \
                  $(CACHE_DIR_)ftcglyph.c \
                  $(CACHE_DIR_)ftcsbits.c \
-                 $(CACHE_DIR_)ftcimage.c
+                 $(CACHE_DIR_)ftcimage.c \
+                 $(CACHE_DIR_)ftccmap.c
 
 # Cache driver headers
 #