Commit 5dea44438f74324403cb2974a5701cac7ceab32a

Werner Lemberg 2001-08-13T11:44:29

Updating to OpenType 1.3. * include/freetype/internal/tttypes.h (TT_CMap0, TT_CMap2, TT_CMap4, TT_CMap6): Adding field `language'. (TT_CMapTable): Removing field `language'. Type of `length' field changed to FT_ULong. Adding fields for cmaps format 8, 10, and 12. (TT_CMapGroup): New auxiliary structure. (TT_CMap8_12, TT_CMap10): New structures. * include/freetype/tttables.h (TT_HoriHeader, TT_VertHeader): Removed last element of `Reserved' array. * include/freetype/ttnameid.h (TT_PLATFORM_CUSTOM, TT_MS_ID_UCS_4, TT_NAME_ID_CID_FINDFONT_NAME): New macros. * src/sfnt/ttcmap.c (TT_CharMap_Load): Updated loading of `language' field to the new structures. Fixed freeing of arrays in case of unsuccessful loads. Added support for loading format 8, 10, and 12 cmaps. (TT_CharMap_Free): Added support for freeing format 8, 10, and 12 cmaps. (code_to_index4): Small improvement. (code_to_index6): Ditto. (code_to_index8_12, code_to_index10): New functions. * src/sfnt/ttload.c (TT_Load_Metrics_Header): Updated to new structure. (TT_Load_CMap): Ditto. * src/sfnt/sfobjs.c (tt_encodings): Add MS UCS4 table (before MS Unicode). * src/type1/t1driver.c (t1_get_name_index): Fix compiler warning.

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
diff --git a/ChangeLog b/ChangeLog
index 689616c..0b49557 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,39 @@
+2001-08-12  Werner Lemberg  <wl@gnu.org>
+
+	Updating to OpenType 1.3.
+
+	* include/freetype/internal/tttypes.h (TT_CMap0, TT_CMap2, TT_CMap4,
+	TT_CMap6): Adding field `language'.
+	(TT_CMapTable): Removing field `language'.
+	Type of `length' field changed to FT_ULong.
+	Adding fields for cmaps format 8, 10, and 12.
+	(TT_CMapGroup): New auxiliary structure.
+	(TT_CMap8_12, TT_CMap10): New structures.
+	* include/freetype/tttables.h (TT_HoriHeader, TT_VertHeader):
+	Removed last element of `Reserved' array.
+	* include/freetype/ttnameid.h (TT_PLATFORM_CUSTOM, TT_MS_ID_UCS_4,
+	TT_NAME_ID_CID_FINDFONT_NAME): New macros.
+
+	* src/sfnt/ttcmap.c (TT_CharMap_Load): Updated loading of `language'
+	field to the new structures.
+	Fixed freeing of arrays in case of unsuccessful loads.
+	Added support for loading format 8, 10, and 12 cmaps.
+	(TT_CharMap_Free): Added support for freeing format 8, 10, and 12
+	cmaps.
+	(code_to_index4): Small improvement.
+	(code_to_index6): Ditto.
+	(code_to_index8_12, code_to_index10): New functions.
+	* src/sfnt/ttload.c (TT_Load_Metrics_Header): Updated to new
+	structure.
+	(TT_Load_CMap): Ditto.
+
+	* src/sfnt/sfobjs.c (tt_encodings): Add MS UCS4 table (before MS
+	Unicode).
+
+2001-08-11  Werner Lemberg  <wl@gnu.org>
+
+	* src/type1/t1driver.c (t1_get_name_index): Fix compiler warning.
+
 2001-08-09  Tom Kacvinsky  <tjk@ams.org>
 
 	* src/cff/cffdrivr.c (get_cff_glyph_name): Renamed to
diff --git a/include/freetype/freetype.h b/include/freetype/freetype.h
index 3c65a98..eb5a595 100644
--- a/include/freetype/freetype.h
+++ b/include/freetype/freetype.h
@@ -2376,7 +2376,7 @@ FT_BEGIN_HEADER
   /*                                                                       */
   FT_EXPORT( FT_UInt )
   FT_Get_Name_Index( FT_Face     face,
-                     FT_String*  glyph_name);
+                     FT_String*  glyph_name );
 
 
 
diff --git a/include/freetype/internal/tttypes.h b/include/freetype/internal/tttypes.h
index bcaeebf..5014e22 100644
--- a/include/freetype/internal/tttypes.h
+++ b/include/freetype/internal/tttypes.h
@@ -922,6 +922,8 @@ FT_BEGIN_HEADER
 
   typedef struct  TT_CMap0_
   {
+    FT_ULong  language;       /* for Mac fonts (originally ushort) */
+
     FT_Byte*  glyphIdArray;
 
   } TT_CMap0;
@@ -941,6 +943,8 @@ FT_BEGIN_HEADER
 
   typedef struct  TT_CMap2_
   {
+    FT_ULong            language;     /* for Mac fonts (originally ushort) */
+
     FT_UShort*          subHeaderKeys;
     /* high byte mapping table            */
     /* value = subHeader index * 8        */
@@ -966,14 +970,16 @@ FT_BEGIN_HEADER
 
   typedef struct  TT_CMap4_
   {
-    FT_UShort         segCountX2;     /* number of segments * 2       */
-    FT_UShort         searchRange;    /* these parameters can be used */
-    FT_UShort         entrySelector;  /* for a binary search          */
+    FT_ULong          language;       /* for Mac fonts (originally ushort) */
+
+    FT_UShort         segCountX2;     /* number of segments * 2            */
+    FT_UShort         searchRange;    /* these parameters can be used      */
+    FT_UShort         entrySelector;  /* for a binary search               */
     FT_UShort         rangeShift;
 
     TT_CMap4Segment*  segments;
     FT_UShort*        glyphIdArray;
-    FT_UShort         numGlyphId;   /* control value */
+    FT_UShort         numGlyphId;    /* control value */
 
     TT_CMap4Segment*  last_segment;  /* last used segment; this is a small  */
                                      /* cache to potentially increase speed */
@@ -984,6 +990,8 @@ FT_BEGIN_HEADER
 
   typedef struct  TT_CMap6_
   {
+    FT_ULong    language;       /* for Mac fonts (originally ushort)     */
+
     FT_UShort   firstCode;      /* first character code of subrange      */
     FT_UShort   entryCount;     /* number of character codes in subrange */
 
@@ -992,6 +1000,48 @@ FT_BEGIN_HEADER
   } TT_CMap6;
 
 
+  /* auxiliary table for format 8 and 12 */
+
+  typedef struct  TT_CMapGroup_
+  {
+    FT_ULong  startCharCode;
+    FT_ULong  endCharCode;
+    FT_ULong  startGlyphID;
+
+  } TT_CMapGroup;
+
+
+  /* FreeType handles format 8 and 12 identically.  It is not necessary to
+     cover mixed 16bit and 32bit codes since FreeType always uses FT_ULong
+     for input character codes -- converting Unicode surrogates to 32bit
+     character codes must be done by the application.                      */
+
+  typedef struct  TT_CMap8_12_
+  {
+    FT_ULong       language;        /* for Mac fonts */
+
+    FT_ULong       nGroups;
+    TT_CMapGroup*  groups;
+
+    TT_CMapGroup*  last_group;      /* last used group; this is a small    */
+                                    /* cache to potentially increase speed */
+  } TT_CMap8_12;
+
+
+  /* format 10 */
+
+  typedef struct  TT_CMap10_
+  {
+    FT_ULong    language;           /* for Mac fonts */
+
+    FT_ULong    startCharCode;      /* first character covered */
+    FT_ULong    numChars;           /* number of characters covered */
+
+    FT_UShort*  glyphs;
+
+  } TT_CMap10;
+
+
   typedef struct TT_CMapTable_  TT_CMapTable;
 
 
@@ -1006,18 +1056,19 @@ FT_BEGIN_HEADER
     FT_UShort  platformID;
     FT_UShort  platformEncodingID;
     FT_UShort  format;
-    FT_UShort  length;
-    FT_UShort  version;
+    FT_ULong   length;          /* must be ulong for formats 8, 10, and 12 */
 
     FT_Bool    loaded;
     FT_ULong   offset;
 
     union
     {
-      TT_CMap0  cmap0;
-      TT_CMap2  cmap2;
-      TT_CMap4  cmap4;
-      TT_CMap6  cmap6;
+      TT_CMap0     cmap0;
+      TT_CMap2     cmap2;
+      TT_CMap4     cmap4;
+      TT_CMap6     cmap6;
+      TT_CMap8_12  cmap8_12;
+      TT_CMap10    cmap10;
     } c;
 
     TT_CharMap_Func  get_index;
diff --git a/include/freetype/ttnameid.h b/include/freetype/ttnameid.h
index 8646192..10ea50d 100644
--- a/include/freetype/ttnameid.h
+++ b/include/freetype/ttnameid.h
@@ -35,6 +35,7 @@ FT_BEGIN_HEADER
 #define TT_PLATFORM_MACINTOSH      1
 #define TT_PLATFORM_ISO            2 /* deprecated */
 #define TT_PLATFORM_MICROSOFT      3
+#define TT_PLATFORM_CUSTOM         4
 
   /* artificial values defined ad-hoc by FreeType */
 #define TT_PLATFORM_ADOBE          7
@@ -46,7 +47,7 @@ FT_BEGIN_HEADER
   /* the name records of the TTF `name' table if the `platform' identifier */
   /* code is TT_PLATFORM_APPLE_UNICODE.                                    */
   /*                                                                       */
-#define TT_APPLE_ID_DEFAULT      0
+#define TT_APPLE_ID_DEFAULT      0 /* Unicode 1.0 */
 #define TT_APPLE_ID_UNICODE_1_1  1 /* specify Hangul at U+34xx */
 #define TT_APPLE_ID_ISO_10646    2 /* deprecated */
 #define TT_APPLE_ID_UNICODE_2_0  3 /* or later */
@@ -113,13 +114,14 @@ FT_BEGIN_HEADER
   /* the name records of the TTF `name' table if the `platform' identifier */
   /* code is TT_PLATFORM_MICROSOFT.                                        */
   /*                                                                       */
-#define TT_MS_ID_SYMBOL_CS   0
-#define TT_MS_ID_UNICODE_CS  1
-#define TT_MS_ID_SJIS        2
-#define TT_MS_ID_GB2312      3
-#define TT_MS_ID_BIG_5       4
-#define TT_MS_ID_WANSUNG     5
-#define TT_MS_ID_JOHAB       6
+#define TT_MS_ID_SYMBOL_CS    0
+#define TT_MS_ID_UNICODE_CS   1
+#define TT_MS_ID_SJIS         2
+#define TT_MS_ID_GB2312       3
+#define TT_MS_ID_BIG_5        4
+#define TT_MS_ID_WANSUNG      5
+#define TT_MS_ID_JOHAB        6
+#define TT_MS_ID_UCS_4       10
 
 
   /*************************************************************************/
@@ -551,6 +553,9 @@ FT_BEGIN_HEADER
 /* The following code is new as of 2000-01-21 */
 #define TT_NAME_ID_SAMPLE_TEXT          19
 
+/* This is new in OpenType 1.3 */
+#define TT_NAME_ID_CID_FINDFONT_NAME    20
+
 
   /*************************************************************************/
   /*                                                                       */
diff --git a/include/freetype/tttables.h b/include/freetype/tttables.h
index d364256..d638a21 100644
--- a/include/freetype/tttables.h
+++ b/include/freetype/tttables.h
@@ -187,7 +187,7 @@ FT_BEGIN_HEADER
     FT_Short   caret_Slope_Run;
     FT_Short   caret_Offset;
 
-    FT_Short   Reserved[5];
+    FT_Short   Reserved[4];
 
     FT_Short   metric_Data_Format;
     FT_UShort  number_Of_HMetrics;
@@ -271,7 +271,11 @@ FT_BEGIN_HEADER
   /*    caret_Slope_Run         :: The run coefficient of the cursor's     */
   /*                               slope.                                  */
   /*                                                                       */
-  /*    Reserved                :: 10 reserved bytes.                      */
+  /*    caret_Offset            :: The cursor's offset for slanted fonts.  */
+  /*                               This value is `reserved' in vmtx        */
+  /*                               version 1.0.                            */
+  /*                                                                       */
+  /*    Reserved                :: 8 reserved bytes.                       */
   /*                                                                       */
   /*    metric_Data_Format      :: Always 0.                               */
   /*                                                                       */
@@ -309,7 +313,7 @@ FT_BEGIN_HEADER
     FT_Short   caret_Slope_Run;
     FT_Short   caret_Offset;
 
-    FT_Short   Reserved[5];
+    FT_Short   Reserved[4];
 
     FT_Short   metric_Data_Format;
     FT_UShort  number_Of_VMetrics;
diff --git a/src/base/ftobjs.c b/src/base/ftobjs.c
index c7454a5..b41562a 100644
--- a/src/base/ftobjs.c
+++ b/src/base/ftobjs.c
@@ -1847,8 +1847,8 @@
     if ( face && FT_HAS_GLYPH_NAMES( face ) )
     {
       /* now, lookup for glyph name */
-      FT_Driver        driver = face->driver;
-      FT_Module_Class* clazz  = FT_MODULE_CLASS( driver );
+      FT_Driver         driver = face->driver;
+      FT_Module_Class*  clazz  = FT_MODULE_CLASS( driver );
 
 
       if ( clazz->get_interface )
diff --git a/src/cff/cffdrivr.c b/src/cff/cffdrivr.c
index 76f04ab..c8270f8 100644
--- a/src/cff/cffdrivr.c
+++ b/src/cff/cffdrivr.c
@@ -328,6 +328,7 @@
   /*                                                                       */
   /* <Input>                                                               */
   /*    face       :: A handle to the source face object.                  */
+  /*                                                                       */
   /*    glyph_name :: The glyph name.                                      */
   /*                                                                       */
   /* <Return>                                                              */
@@ -337,14 +338,15 @@
   cff_get_name_index( CFF_Face    face,
                       FT_String*  glyph_name )
   {
-    CFF_Font*          cff;
-    CFF_Charset*       charset;
-    PSNames_Interface* psnames;
-    FT_String*         name;
-    FT_UShort          sid;
-    FT_UInt            i;
-
-    cff = face->extra.data;
+    CFF_Font*           cff;
+    CFF_Charset*        charset;
+    PSNames_Interface*  psnames;
+    FT_String*          name;
+    FT_UShort           sid;
+    FT_UInt             i;
+
+
+    cff     = face->extra.data;
     charset = &cff->charset;
 
     psnames = (PSNames_Interface*)FT_Get_Module_Interface(
@@ -354,7 +356,7 @@
     {
       sid = charset->sids[i];
 
-      if (sid > 390)
+      if ( sid > 390 )
         name = CFF_Get_Name( &cff->string_index, sid - 391 );
       else
         name = (FT_String *)psnames->adobe_std_strings( sid );
@@ -366,6 +368,7 @@
     return 0;
   }
 
+
   /*************************************************************************/
   /*************************************************************************/
   /*************************************************************************/
diff --git a/src/sfnt/sfobjs.c b/src/sfnt/sfobjs.c
index 36f1dc4..f4966be 100644
--- a/src/sfnt/sfobjs.c
+++ b/src/sfnt/sfobjs.c
@@ -150,6 +150,7 @@
       { TT_PLATFORM_MACINTOSH,     TT_MAC_ID_ROMAN,     ft_encoding_apple_roman },
 
       { TT_PLATFORM_MICROSOFT,     TT_MS_ID_SYMBOL_CS,  ft_encoding_symbol },
+      { TT_PLATFORM_MICROSOFT,     TT_MS_ID_UCS_4,      ft_encoding_unicode },
       { TT_PLATFORM_MICROSOFT,     TT_MS_ID_UNICODE_CS, ft_encoding_unicode },
       { TT_PLATFORM_MICROSOFT,     TT_MS_ID_SJIS,       ft_encoding_sjis },
       { TT_PLATFORM_MICROSOFT,     TT_MS_ID_GB2312,     ft_encoding_gb2312 },
diff --git a/src/sfnt/ttcmap.c b/src/sfnt/ttcmap.c
index d1f6d92..64dd3bb 100644
--- a/src/sfnt/ttcmap.c
+++ b/src/sfnt/ttcmap.c
@@ -50,6 +50,14 @@
   code_to_index6( TT_CMapTable*  charmap,
                   FT_ULong       char_code );
 
+  FT_CALLBACK_DEF( FT_UInt )
+  code_to_index8_12( TT_CMapTable*  charmap,
+                     FT_ULong       char_code );
+
+  FT_CALLBACK_DEF( FT_UInt )
+  code_to_index10( TT_CMapTable*  charmap,
+                   FT_ULong       char_code );
+
 
   /*************************************************************************/
   /*                                                                       */
@@ -79,19 +87,23 @@
                    TT_CMapTable*  cmap,
                    FT_Stream      stream )
   {
-    FT_Error   error;
-    FT_Memory  memory;
-    FT_UShort  num_SH, num_Seg, i;
+    FT_Error      error;
+    FT_Memory     memory;
+    FT_UShort     num_SH, num_Seg, i;
+    FT_ULong      j, n;
 
-    FT_UShort  u, l;
+    FT_UShort     u, l;
 
-    TT_CMap0*  cmap0;
-    TT_CMap2*  cmap2;
-    TT_CMap4*  cmap4;
-    TT_CMap6*  cmap6;
+    TT_CMap0*     cmap0;
+    TT_CMap2*     cmap2;
+    TT_CMap4*     cmap4;
+    TT_CMap6*     cmap6;
+    TT_CMap8_12*  cmap8_12;
+    TT_CMap10*    cmap10;
 
     TT_CMap2SubHeader*  cmap2sub;
     TT_CMap4Segment*    segments;
+    TT_CMapGroup*       groups;
 
 
     if ( cmap->loaded )
@@ -107,9 +119,10 @@
     case 0:
       cmap0 = &cmap->c.cmap0;
 
-      if ( ALLOC( cmap0->glyphIdArray, 256L )            ||
+      if ( READ_UShort( cmap0->language )         ||
+           ALLOC( cmap0->glyphIdArray, 256L )     ||
            FILE_Read( cmap0->glyphIdArray, 256L ) )
-         goto Fail;
+        goto Fail;
 
       cmap->get_index = code_to_index0;
       break;
@@ -121,9 +134,11 @@
       /* allocate subheader keys */
 
       if ( ALLOC_ARRAY( cmap2->subHeaderKeys, 256, FT_UShort ) ||
-           ACCESS_Frame( 512L )                                )
+           ACCESS_Frame( 2L + 512L )                           )
         goto Fail;
 
+      cmap2->language = GET_UShort();
+
       for ( i = 0; i < 256; i++ )
       {
         u = (FT_UShort)( GET_UShort() / 8 );
@@ -144,7 +159,10 @@
                         num_SH + 1,
                         TT_CMap2SubHeader )    ||
            ACCESS_Frame( ( num_SH + 1 ) * 8L ) )
+      {
+        FREE( cmap2->subHeaderKeys );
         goto Fail;
+      }
 
       cmap2sub = cmap2->subHeaders;
 
@@ -166,7 +184,11 @@
 
       if ( ALLOC_ARRAY( cmap2->glyphIdArray, l, FT_UShort ) ||
            ACCESS_Frame( l * 2L )                           )
+      {
+        FREE( cmap2->subHeaders );
+        FREE( cmap2->subHeaderKeys );
         goto Fail;
+      }
 
       for ( i = 0; i < l; i++ )
         cmap2->glyphIdArray[i] = GET_UShort();
@@ -181,9 +203,10 @@
 
       /* load header */
 
-      if ( ACCESS_Frame( 8L ) )
+      if ( ACCESS_Frame( 10L ) )
         goto Fail;
 
+      cmap4->language      = GET_UShort();
       cmap4->segCountX2    = GET_UShort();
       cmap4->searchRange   = GET_UShort();
       cmap4->entrySelector = GET_UShort();
@@ -226,24 +249,28 @@
 
       if ( ALLOC_ARRAY( cmap4->glyphIdArray, l, FT_UShort ) ||
            ACCESS_Frame( l * 2L )                           )
+      {
+        FREE( cmap4->segments );
         goto Fail;
+      }
 
       for ( i = 0; i < l; i++ )
         cmap4->glyphIdArray[i] = GET_UShort();
 
       FORGET_Frame();
 
-      cmap->get_index = code_to_index4;
-
       cmap4->last_segment = cmap4->segments;
+
+      cmap->get_index = code_to_index4;
       break;
 
     case 6:
       cmap6 = &cmap->c.cmap6;
 
-      if ( ACCESS_Frame( 4L ) )
+      if ( ACCESS_Frame( 6L ) )
         goto Fail;
 
+      cmap6->language   = GET_UShort();
       cmap6->firstCode  = GET_UShort();
       cmap6->entryCount = GET_UShort();
 
@@ -251,10 +278,8 @@
 
       l = cmap6->entryCount;
 
-      if ( ALLOC_ARRAY( cmap6->glyphIdArray,
-                        cmap6->entryCount,
-                        FT_Short )           ||
-           ACCESS_Frame( l * 2L )            )
+      if ( ALLOC_ARRAY( cmap6->glyphIdArray, l, FT_Short ) ||
+           ACCESS_Frame( l * 2L )                          )
         goto Fail;
 
       for ( i = 0; i < l; i++ )
@@ -264,6 +289,73 @@
       cmap->get_index = code_to_index6;
       break;
 
+    case 8:
+    case 12:
+      cmap8_12 = &cmap->c.cmap8_12;
+
+      if ( ACCESS_Frame( 8L ) )
+        goto Fail;
+
+      cmap->length       = GET_ULong();
+      cmap8_12->language = GET_ULong();
+
+      FORGET_Frame();
+
+      if ( cmap->format == 8 )
+        if ( FILE_Skip( 8192L ) )
+          goto Fail;
+
+      if ( READ_ULong( cmap8_12->nGroups ) )
+        goto Fail;
+
+      n = cmap8_12->nGroups;
+
+      if ( ALLOC_ARRAY( cmap8_12->groups, n, TT_CMapGroup ) ||
+           ACCESS_Frame( n * 3 * 4L )                       )
+        goto Fail;
+
+      groups = cmap8_12->groups;
+
+      for ( j = 0; j < n; j++ )
+      {
+        groups[j].startCharCode = GET_ULong();
+        groups[j].endCharCode   = GET_ULong();
+        groups[j].startGlyphID  = GET_ULong();
+      }
+
+      FORGET_Frame();
+
+      cmap8_12->last_group = cmap8_12->groups;
+
+      cmap->get_index = code_to_index8_12;
+      break;
+
+    case 10:
+      cmap10 = &cmap->c.cmap10;
+
+      if ( ACCESS_Frame( 16L ) )
+        goto Fail;
+
+      cmap->length          = GET_ULong();
+      cmap10->language      = GET_ULong();
+      cmap10->startCharCode = GET_ULong();
+      cmap10->numChars      = GET_ULong();
+
+      FORGET_Frame();
+
+      n = cmap10->numChars;
+
+      if ( ALLOC_ARRAY( cmap10->glyphs, n, FT_Short ) ||
+           ACCESS_Frame( n * 2L )                     )
+        goto Fail;
+
+      for ( j = 0; j < n; j++ )
+        cmap10->glyphs[j] = GET_UShort();
+
+      FORGET_Frame();
+      cmap->get_index = code_to_index10;
+      break;
+
     default:   /* corrupt character mapping table */
       return SFNT_Err_Invalid_CharMap_Format;
 
@@ -327,6 +419,17 @@
       cmap->c.cmap6.entryCount = 0;
       break;
 
+    case 8:
+    case 12:
+      FREE( cmap->c.cmap8_12.groups );
+      cmap->c.cmap8_12.nGroups = 0;
+      break;
+
+    case 10:
+      FREE( cmap->c.cmap10.glyphs );
+      cmap->c.cmap10.numChars = 0;
+      break;
+
     default:
       /* invalid table format, do nothing */
       ;
@@ -456,23 +559,23 @@
     cmap4    = &cmap->c.cmap4;
     result   = 0;
     segCount = cmap4->segCountX2 / 2;
-    seg4     = cmap4->segments;
-    limit    = seg4 + segCount;
+    limit    = cmap4->segments + segCount;
+
+    /* first, check against the last used segment */
 
-    /* check against the last segment */
     seg4 = cmap4->last_segment;
 
     /* the following is equivalent to performing two tests, as in         */
     /*                                                                    */
     /*  if ( charCode >= seg4->startCount && charCode <= seg4->endCount ) */
     /*                                                                    */
-    /* Yes, that's a bit strange, but it's faster, and the idea behind    */
-    /* the cache is to significantly speed up charcode to glyph index     */
+    /* This is a bit strange, but it is faster, and the idea behind the   */
+    /* cache is to significantly speed up charcode to glyph index         */
     /* conversion.                                                        */
 
-    if ( (FT_ULong)(charCode       - seg4->startCount) <
-         (FT_ULong)(seg4->endCount - seg4->startCount) )
-      goto Found;
+    if ( (FT_ULong)( charCode       - seg4->startCount ) <
+         (FT_ULong)( seg4->endCount - seg4->startCount ) )
+      goto Found1;
 
     for ( seg4 = cmap4->segments; seg4 < limit; seg4++ )
     {
@@ -487,9 +590,10 @@
     }
     return 0;
 
- Found:
+  Found:
     cmap4->last_segment = seg4;
 
+  Found1:
     /* if the idRangeOffset is 0, we can compute the glyph index */
     /* directly                                                  */
 
@@ -503,8 +607,8 @@
                           + ( seg4 - cmap4->segments )
                           - segCount );
 
-      if ( index1 < (FT_UInt)cmap4->numGlyphId       &&
-           cmap4->glyphIdArray[index1] != 0 )
+      if ( index1 < (FT_UInt)cmap4->numGlyphId &&
+           cmap4->glyphIdArray[index1] != 0    )
         result = ( cmap4->glyphIdArray[index1] + seg4->idDelta ) & 0xFFFF;
     }
 
@@ -536,11 +640,113 @@
 
 
     cmap6     = &cmap->c.cmap6;
-    result    = 0;
     charCode -= cmap6->firstCode;
 
     if ( charCode < (FT_UInt)cmap6->entryCount )
-      result =  cmap6->glyphIdArray[charCode];
+      result = cmap6->glyphIdArray[charCode];
+
+    return result;
+  }
+
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* <Function>                                                            */
+  /*    code_to_index8_12                                                  */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    Converts the (possibly 32bit) character code into a glyph index.   */
+  /*    Uses format 8 or 12.                                               */
+  /*                                                                       */
+  /* <Input>                                                               */
+  /*    charCode :: The wanted character code.                             */
+  /*    cmap8_12 :: A pointer to a cmap table in format 8 or 12.           */
+  /*                                                                       */
+  /* <Return>                                                              */
+  /*    Glyph index into the glyphs array.  0 if the glyph does not exist. */
+  /*                                                                       */
+  FT_CALLBACK_DEF( FT_UInt )
+  code_to_index8_12( TT_CMapTable*  cmap,
+                     FT_ULong       charCode )
+  {
+    TT_CMap8_12*  cmap8_12;
+    TT_CMapGroup  *group, *limit;
+
+
+    cmap8_12 = &cmap->c.cmap8_12;
+    limit    = cmap8_12->groups + cmap8_12->nGroups;
+
+    /* first, check against the last used group */
+
+    group = cmap8_12->last_group;
+
+    /* the following is equivalent to performing two tests, as in       */
+    /*                                                                  */
+    /*  if ( charCode >= group->startCharCode &&                        */
+    /*       charCode <= group->endCharCode   )                         */
+    /*                                                                  */
+    /* This is a bit strange, but it is faster, and the idea behind the */
+    /* cache is to significantly speed up charcode to glyph index       */
+    /* conversion.                                                      */
+
+    if ( (FT_ULong)( charCode           - group->startCharCode ) <
+         (FT_ULong)( group->endCharCode - group->startCharCode ) )
+      goto Found1;
+
+    for ( group = cmap8_12->groups; group < limit; group++ )
+    {
+      /* the ranges are sorted in increasing order.  If we are out of */
+      /* the range here, the char code isn't in the charmap, so exit. */
+
+      if ( charCode > group->endCharCode )
+        continue;
+
+      if ( charCode >= group->startCharCode )
+        goto Found;
+    }
+    return 0;
+
+  Found:
+    cmap8_12->last_group = group;
+
+  Found1:
+    return group->startGlyphID + (FT_UInt)( charCode - group->startCharCode );
+  }
+
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* <Function>                                                            */
+  /*    code_to_index10                                                    */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    Converts the (possibly 32bit) character code into a glyph index.   */
+  /*    Uses format 10.                                                    */
+  /*                                                                       */
+  /* <Input>                                                               */
+  /*    charCode :: The wanted character code.                             */
+  /*    cmap10   :: A pointer to a cmap table in format 10.                */
+  /*                                                                       */
+  /* <Return>                                                              */
+  /*    Glyph index into the glyphs array.  0 if the glyph does not exist. */
+  /*                                                                       */
+  FT_CALLBACK_DEF( FT_UInt )
+  code_to_index10( TT_CMapTable*  cmap,
+                   FT_ULong       charCode )
+  {
+    TT_CMap10*  cmap10;
+    FT_UInt     result = 0;
+
+
+    cmap10    = &cmap->c.cmap10;
+    charCode -= cmap10->startCharCode;
+
+    /* the overflow trick for comparison works here also since the number */
+    /* of glyphs (even if numChars is specified as ULong in the specs) in */
+    /* an OpenType font is limited to 64k                                 */
+
+    if ( charCode < cmap10->numChars )
+      result = cmap10->glyphs[charCode];
 
     return result;
   }
diff --git a/src/sfnt/ttload.c b/src/sfnt/ttload.c
index ab55342..6946636 100644
--- a/src/sfnt/ttload.c
+++ b/src/sfnt/ttload.c
@@ -840,11 +840,11 @@
         FT_FRAME_SHORT ( xMax_Extent ),
         FT_FRAME_SHORT ( caret_Slope_Rise ),
         FT_FRAME_SHORT ( caret_Slope_Run ),
+        FT_FRAME_SHORT ( caret_Offset ),
         FT_FRAME_SHORT ( Reserved[0] ),
         FT_FRAME_SHORT ( Reserved[1] ),
         FT_FRAME_SHORT ( Reserved[2] ),
         FT_FRAME_SHORT ( Reserved[3] ),
-        FT_FRAME_SHORT ( Reserved[4] ),
         FT_FRAME_SHORT ( metric_Data_Format ),
         FT_FRAME_USHORT( number_Of_HMetrics ),
       FT_FRAME_END
@@ -1144,7 +1144,6 @@
       FT_FRAME_START( 6 ),
         FT_FRAME_USHORT( format ),
         FT_FRAME_USHORT( length ),
-        FT_FRAME_USHORT( version ),
       FT_FRAME_END
     };
 
diff --git a/src/type1/t1driver.c b/src/type1/t1driver.c
index fbde5ec..40a1d38 100644
--- a/src/type1/t1driver.c
+++ b/src/type1/t1driver.c
@@ -70,6 +70,7 @@
     return T1_Err_Ok;
   }
 
+
   /*************************************************************************/
   /*                                                                       */
   /* <Function>                                                            */
@@ -81,6 +82,7 @@
   /*                                                                       */
   /* <Input>                                                               */
   /*    face       :: A handle to the source face object.                  */
+  /*                                                                       */
   /*    glyph_name :: The glyph name.                                      */
   /*                                                                       */
   /* <Return>                                                              */
@@ -90,15 +92,16 @@
   t1_get_name_index( T1_Face     face,
                      FT_String*  glyph_name )
   {
-    FT_UInt     i;
+    FT_Int      i;
     FT_String*  gname;
 
+
     for ( i = 0; i < face->type1.num_glyphs; i++ )
     {
       gname = face->type1.glyph_names[i];
 
       if ( !strcmp( glyph_name, gname ) )
-        return i;
+        return (FT_UInt)i;
     }
 
     return 0;