Commit 2e421319fc4bedef44218fc144b1186ea53df584

David Turner 2000-05-26T22:13:17

moved a lot of things from the TrueType driver to the SFNT module (whose interface has changed, by the way) This allows even more code re-use between TrueType and OpenType formats..

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
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
diff --git a/CHANGES b/CHANGES
index 8ec03ee..e7ffb23 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,5 +1,12 @@
 LATEST_CHANGES
 
+  - moved a lot of stuff from the TrueType driver to the SFNT module,
+    this allows greater code re-use between font drivers (e.g. TrueType,
+    OpenType, Compact-TrueType, etc..)
+
+  - added a tiny segment cache to the SFNT Charmap 4 decoder, in order
+    to minimally speed it up..
+
   - added support for Multiple Master fonts in "type1z". There is also
     a new file named <freetype/ftmm.h> which defines functions to
     manage them from client applications.
diff --git a/include/freetype/internal/autohint.h b/include/freetype/internal/autohint.h
index 4a995f8..277461b 100644
--- a/include/freetype/internal/autohint.h
+++ b/include/freetype/internal/autohint.h
@@ -149,6 +149,24 @@
                                                  FT_Face        face );
 
 
+ /***********************************************************************
+  *
+  * <FuncType>
+  *    FT_AutoHinter_Reset_Func
+  *
+  * <Description>
+  *    This function is used to recompute the global metrics in a given   
+  *    font. This is useful when global font data changes (e.g. multiple
+  *    masters fonts where blend coordinates change..)
+  *
+  * <Input>
+  *    hinter      :: handle to source auto-hinter
+  *    face        :: handle to the face.
+  *
+  *
+  */
+  typedef  FT_Error    (*FT_AutoHinter_Reset_Func)( FT_AutoHinter  hinter,
+                                                    FT_Face        face );
 
  /***********************************************************************
   *
@@ -189,6 +207,7 @@
   {
     FT_AutoHinter_Init_Func   init_autohinter;
     FT_AutoHinter_Done_Func   done_autohinter;
+    FT_AutoHinter_Reset_Func  reset_face;
     FT_AutoHinter_Load_Func   load_glyph;
 
     FT_AutoHinter_Get_Global_Func   get_global_hints;
diff --git a/include/freetype/internal/ftstream.h b/include/freetype/internal/ftstream.h
index ec9d331..02d3820 100644
--- a/include/freetype/internal/ftstream.h
+++ b/include/freetype/internal/ftstream.h
@@ -195,7 +195,12 @@ typedef struct FT_Frame_Field_
 
   BASE_DEF(void)      FT_Forget_Frame( FT_Stream  stream );
 
+  BASE_DEF(FT_Error)  FT_Extract_Frame( FT_Stream  stream,
+                                        FT_ULong   count,
+                                        FT_Byte*  *pbytes );
 
+  BASE_DEF(void)      FT_Release_Frame( FT_Stream  stream,
+                                        FT_Byte*  *pbytes );
 
   BASE_DEF(FT_Char)   FT_Get_Char( FT_Stream  stream );
 
@@ -233,13 +238,14 @@ typedef struct FT_Frame_Field_
 #define ACCESS_Frame( size )  \
           FT_SET_ERROR( FT_Access_Frame( stream, size ) )
 
-#define ACCESS_Compressed_Frame( size )  \
-          FT_SET_ERROR( FT_Access_Compressed_Frame( stream, size ) )
-
-
 #define FORGET_Frame() \
           FT_Forget_Frame( stream )
 
+#define EXTRACT_Frame( size, bytes ) \
+          FT_SET_ERROR( FT_Extract_Frame( stream, size, (FT_Byte**)&(bytes) ) )
+          
+#define RELEASE_Frame( bytes ) \
+          FT_Release_Frame( stream, (FT_Byte**)&(bytes) )
 
 #define FILE_Seek( position )  \
           FT_SET_ERROR( FT_Seek_Stream( stream, position ) )
diff --git a/include/freetype/internal/sfnt.h b/include/freetype/internal/sfnt.h
index d6dd15e..8c85a1a 100644
--- a/include/freetype/internal/sfnt.h
+++ b/include/freetype/internal/sfnt.h
@@ -26,6 +26,96 @@
   /*************************************************************************/
   /*                                                                       */
   /* <FuncType>                                                            */
+  /*    TT_Init_Face_Func                                                  */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    First part of the SFNT face object initialisation. This will       */
+  /*    find the face in a SFNT file or collection, and load its           */
+  /*    format tag in face->format_tag.                                    */
+  /*                                                                       */
+  /* <Input>                                                               */
+  /*    stream     :: The input stream.                                    */
+  /*    face       :: A handle to the target face object.                  */
+  /*    faceIndex  :: The index of the TrueType font, if we're opening a   */
+  /*                  collection.                                          */
+  /*    num_params :: number of additional parameters                      */
+  /*    params     :: optional additional parameters                       */
+  /*                                                                       */
+  /* <Return>                                                              */
+  /*    FreeType error code.  0 means success.                             */
+  /*                                                                       */
+  /* <Note>                                                                */
+  /*    The stream cursor must be at the font file's origin                */
+  /*    This function recognizes fonts embedded in a "TrueType collection" */
+  /*                                                                       */
+  /*    Once the format tag has been validated by the font driver, it      */
+  /*    should then call the TT_Load_Face_Func callback to read the rest   */
+  /*    of the SFNT tables in the object..                                 */
+  /*                                                                       */
+  typedef
+  FT_Error  (*TT_Init_Face_Func)( FT_Stream      stream,
+                                  TT_Face        face,
+                                  FT_Int         face_index,
+                                  FT_Int         num_params,
+                                  FT_Parameter*  params );
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* <FuncType>                                                            */
+  /*    TT_Load_Face_Func                                                  */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    Second part of the SFNT face object initialisation. This will      */
+  /*    load the common SFNT tables (head, OS/2, maxp, metrics, etc..)     */
+  /*    in the face object..                                               */
+  /*                                                                       */
+  /* <Input>                                                               */
+  /*    stream     :: The input stream.                                    */
+  /*    face       :: A handle to the target face object.                  */
+  /*    faceIndex  :: The index of the TrueType font, if we're opening a   */
+  /*                  collection.                                          */
+  /*    num_params :: number of additional parameters                      */
+  /*    params     :: optional additional parameters                       */
+  /*                                                                       */
+  /* <Return>                                                              */
+  /*    FreeType error code.  0 means success.                             */
+  /*                                                                       */
+  /* <Note>                                                                */
+  /*    This function must be called after TT_Init_Face_Func               */
+  /*                                                                       */
+  typedef
+  FT_Error  (*TT_Load_Face_Func)( FT_Stream      stream,
+                                  TT_Face        face,
+                                  FT_Int         face_index,
+                                  FT_Int         num_params,
+                                  FT_Parameter*  params );
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* <FuncType>                                                            */
+  /*    TT_Done_Face_Func                                                  */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    A callback used to delete the common SFNT data from a face.        */
+  /*                                                                       */
+  /* <Input>                                                               */
+  /*    face       :: A handle to the target face object.                  */
+  /*                                                                       */
+  /* <Note>                                                                */
+  /*    This function does NOT destroy the face object..                   */
+  /*                                                                       */
+  typedef
+  void    (*TT_Done_Face_Func)( TT_Face   face );
+
+
+  typedef
+  FTDriver_Interface  (*SFNT_Get_Interface_Func)( FT_Driver    driver,
+                                                  const char*  interface );
+
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* <FuncType>                                                            */
   /*    TT_Load_Format_Tag                                                 */
   /*                                                                       */
   /* <Description>                                                         */
@@ -338,10 +428,17 @@
   {
     TT_Goto_Table_Func      goto_table;
 
+    TT_Init_Face_Func       init_face;
+    TT_Load_Face_Func       load_face;
+    TT_Done_Face_Func       done_face;
+    SFNT_Get_Interface_Func get_interface;
+    
     TT_Load_Any_Func        load_any;
     TT_Load_Format_Tag_Func load_format_tag;
     TT_Load_Directory_Func  load_directory;
 
+    /* these functions are called by "load_face" but they can also */
+    /* be called from external modules, if there is a need to      */
     TT_Load_Table_Func      load_header;
     TT_Load_Metrics_Func    load_metrics;
     TT_Load_Table_Func      load_charmaps;
diff --git a/include/freetype/internal/tttypes.h b/include/freetype/internal/tttypes.h
index a2df877..0510d1d 100644
--- a/include/freetype/internal/tttypes.h
+++ b/include/freetype/internal/tttypes.h
@@ -423,463 +423,6 @@
   } TT_Table;
 
 
-#if 0
-  /*************************************************************************/
-  /*                                                                       */
-  /* <Struct>                                                              */
-  /*    TT_Header                                                          */
-  /*                                                                       */
-  /* <Description>                                                         */
-  /*    A structure used to model a TrueType font header table.  All       */
-  /*    fields follow the TrueType specification.                          */
-  /*                                                                       */
-  typedef struct  TT_Header_
-  {
-    TT_Fixed   Table_Version;
-    TT_Fixed   Font_Revision;
-
-    TT_Long    CheckSum_Adjust;
-    TT_Long    Magic_Number;
-
-    TT_UShort  Flags;
-    TT_UShort  Units_Per_EM;
-
-    TT_Long    Created [2];
-    TT_Long    Modified[2];
-
-    TT_FWord   xMin;
-    TT_FWord   yMin;
-    TT_FWord   xMax;
-    TT_FWord   yMax;
-
-    TT_UShort  Mac_Style;
-    TT_UShort  Lowest_Rec_PPEM;
-
-    TT_Short   Font_Direction;
-    TT_Short   Index_To_Loc_Format;
-    TT_Short   Glyph_Data_Format;
-
-  } TT_Header;
-
-
-  /*************************************************************************/
-  /*                                                                       */
-  /* <Struct>                                                              */
-  /*    TT_HoriHeader                                                      */
-  /*                                                                       */
-  /* <Description>                                                         */
-  /*    A structure used to model a TrueType horizontal header, the `hhea' */
-  /*    table, as well as the corresponding horizontal metrics table,      */
-  /*    i.e., the `hmtx' table.                                            */
-  /*                                                                       */
-  /* <Fields>                                                              */
-  /*    Version                :: The table version.                       */
-  /*                                                                       */
-  /*    Ascender               :: The font's ascender, i.e., the distance  */
-  /*                              from the baseline to the top-most of all */
-  /*                              glyph points found in the font.          */
-  /*                                                                       */
-  /*                              This value is invalid in many fonts, as  */
-  /*                              it is usually set by the font designer,  */
-  /*                              and often reflects only a portion of the */
-  /*                              glyphs found in the font (maybe ASCII).  */
-  /*                                                                       */
-  /*                              You should use the `sTypoAscender' field */
-  /*                              of the OS/2 table instead if you want    */
-  /*                              the correct one.                         */
-  /*                                                                       */
-  /*    Descender              :: The font's descender, i.e., the distance */
-  /*                              from the baseline to the bottom-most of  */
-  /*                              all glyph points found in the font.  It  */
-  /*                              is negative.                             */
-  /*                                                                       */
-  /*                              This value is invalid in many fonts, as  */
-  /*                              it is usually set by the font designer,  */
-  /*                              and often reflects only a portion of the */
-  /*                              glyphs found in the font (maybe ASCII).  */
-  /*                                                                       */
-  /*                              You should use the `sTypoDescender'      */
-  /*                              field of the OS/2 table instead if you   */
-  /*                              want the correct one.                    */
-  /*                                                                       */
-  /*    Line_Gap               :: The font's line gap, i.e., the distance  */
-  /*                              to add to the ascender and descender to  */
-  /*                              get the BTB, i.e., the                   */
-  /*                              baseline-to-baseline distance for the    */
-  /*                              font.                                    */
-  /*                                                                       */
-  /*    advance_Width_Max      :: This field is the maximum of all advance */
-  /*                              widths found in the font.  It can be     */
-  /*                              used to compute the maximum width of an  */
-  /*                              arbitrary string of text.                */
-  /*                                                                       */
-  /*    min_Left_Side_Bearing  :: The minimum left side bearing of all     */
-  /*                              glyphs within the font.                  */
-  /*                                                                       */
-  /*    min_Right_Side_Bearing :: The minimum right side bearing of all    */
-  /*                              glyphs within the font.                  */
-  /*                                                                       */
-  /*    xMax_Extent            :: The maximum horizontal extent (i.e., the */
-  /*                              `width' of a glyph's bounding box) for   */
-  /*                              all glyphs in the font.                  */
-  /*                                                                       */
-  /*    caret_Slope_Rise       :: The rise coefficient of the cursor's     */
-  /*                              slope of the cursor (slope=rise/run).    */
-  /*                                                                       */
-  /*    caret_Slope_Run        :: The run coefficient of the cursor's      */
-  /*                              slope.                                   */
-  /*                                                                       */
-  /*    Reserved               :: 10 reserved bytes.                       */
-  /*                                                                       */
-  /*    metric_Data_Format     :: Always 0.                                */
-  /*                                                                       */
-  /*    number_Of_HMetrics     :: Number of HMetrics entries in the `hmtx' */
-  /*                              table -- this value can be smaller than  */
-  /*                              the total number of glyphs in the font.  */
-  /*                                                                       */
-  /*    long_metrics           :: A pointer into the `hmtx' table.         */
-  /*                                                                       */
-  /*    short_metrics          :: A pointer into the `hmtx' table.         */
-  /*                                                                       */
-  /* <Note>                                                                */
-  /*    IMPORTANT: The TT_HoriHeader and TT_VertHeader structures should   */
-  /*               be identical except for the names of their fields which */
-  /*               are different.                                          */
-  /*                                                                       */
-  /*               This ensures that a single function in the `ttload'     */
-  /*               module is able to read both the horizontal and vertical */
-  /*               headers.                                                */
-  /*                                                                       */
-  typedef struct  TT_HoriHeader_
-  {
-    TT_Fixed   Version;
-    TT_FWord   Ascender;
-    TT_FWord   Descender;
-    TT_FWord   Line_Gap;
-
-    TT_UFWord  advance_Width_Max;      /* advance width maximum */
-
-    TT_FWord   min_Left_Side_Bearing;  /* minimum left-sb       */
-    TT_FWord   min_Right_Side_Bearing; /* minimum right-sb      */
-    TT_FWord   xMax_Extent;            /* xmax extents          */
-    TT_FWord   caret_Slope_Rise;
-    TT_FWord   caret_Slope_Run;
-    TT_FWord   caret_Offset;
-
-    TT_Short   Reserved[4];
-
-    TT_Short   metric_Data_Format;
-    TT_UShort  number_Of_HMetrics;
-
-    /* The following fields are not defined by the TrueType specification */
-    /* but they're used to connect the metrics header to the relevant     */
-    /* `HMTX' table.                                                      */
-
-    void*      long_metrics;
-    void*      short_metrics;
-
-  } TT_HoriHeader;
-
-
-  /*************************************************************************/
-  /*                                                                       */
-  /* <Struct>                                                              */
-  /*    TT_VertHeader                                                      */
-  /*                                                                       */
-  /* <Description>                                                         */
-  /*    A structure used to model a TrueType vertical header, the `vhea'   */
-  /*    table, as well as the corresponding vertical metrics table, i.e.,  */
-  /*    the `vmtx' table.                                                  */
-  /*                                                                       */
-  /* <Fields>                                                              */
-  /*    Version                 :: The table version.                      */
-  /*                                                                       */
-  /*    Ascender                :: The font's ascender, i.e., the distance */
-  /*                               from the baseline to the top-most of    */
-  /*                               all glyph points found in the font.     */
-  /*                                                                       */
-  /*                               This value is invalid in many fonts, as */
-  /*                               it is usually set by the font designer, */
-  /*                               and often reflects only a portion of    */
-  /*                               the glyphs found in the font (maybe     */
-  /*                               ASCII).                                 */
-  /*                                                                       */
-  /*                               You should use the `sTypoAscender'      */
-  /*                               field of the OS/2 table instead if you  */
-  /*                               want the correct one.                   */
-  /*                                                                       */
-  /*    Descender               :: The font's descender, i.e., the         */
-  /*                               distance from the baseline to the       */
-  /*                               bottom-most of all glyph points found   */
-  /*                               in the font.  It is negative.           */
-  /*                                                                       */
-  /*                               This value is invalid in many fonts, as */
-  /*                               it is usually set by the font designer, */
-  /*                               and often reflects only a portion of    */
-  /*                               the glyphs found in the font (maybe     */
-  /*                               ASCII).                                 */
-  /*                                                                       */
-  /*                               You should use the `sTypoDescender'     */
-  /*                               field of the OS/2 table instead if you  */
-  /*                               want the correct one.                   */
-  /*                                                                       */
-  /*    Line_Gap                :: The font's line gap, i.e., the distance */
-  /*                               to add to the ascender and descender to */
-  /*                               get the BTB, i.e., the                  */
-  /*                               baseline-to-baseline distance for the   */
-  /*                               font.                                   */
-  /*                                                                       */
-  /*    advance_Height_Max      :: This field is the maximum of all        */
-  /*                               advance heights found in the font.  It  */
-  /*                               can be used to compute the maximum      */
-  /*                               height of an arbitrary string of text.  */
-  /*                                                                       */
-  /*    min_Top_Side_Bearing    :: The minimum top side bearing of all     */
-  /*                               glyphs within the font.                 */
-  /*                                                                       */
-  /*    min_Bottom_Side_Bearing :: The minimum bottom side bearing of all  */
-  /*                               glyphs within the font.                 */
-  /*                                                                       */
-  /*    yMax_Extent             :: The maximum vertical extent (i.e., the  */
-  /*                               `height' of a glyph's bounding box) for */
-  /*                               all glyphs in the font.                 */
-  /*                                                                       */
-  /*    caret_Slope_Rise        :: The rise coefficient of the cursor's    */
-  /*                               slope of the cursor (slope=rise/run).   */
-  /*                                                                       */
-  /*    caret_Slope_Run         :: The run coefficient of the cursor's     */
-  /*                               slope.                                  */
-  /*                                                                       */
-  /*    Reserved                :: 10 reserved bytes.                      */
-  /*                                                                       */
-  /*    metric_Data_Format      :: Always 0.                               */
-  /*                                                                       */
-  /*    number_Of_HMetrics      :: Number of VMetrics entries in the       */
-  /*                               `vmtx' table -- this value can be       */
-  /*                               smaller than the total number of glyphs */
-  /*                               in the font.                            */
-  /*                                                                       */
-  /*    long_metrics           :: A pointer into the `vmtx' table.         */
-  /*                                                                       */
-  /*    short_metrics          :: A pointer into the `vmtx' table.         */
-  /*                                                                       */
-  /* <Note>                                                                */
-  /*    IMPORTANT: The TT_HoriHeader and TT_VertHeader structures should   */
-  /*               be identical except for the names of their fields which */
-  /*               are different.                                          */
-  /*                                                                       */
-  /*               This ensures that a single function in the `ttload'     */
-  /*               module is able to read both the horizontal and vertical */
-  /*               headers.                                                */
-  /*                                                                       */
-  typedef struct TT_VertHeader_
-  {
-    TT_Fixed   Version;
-    TT_FWord   Ascender;
-    TT_FWord   Descender;
-    TT_FWord   Line_Gap;
-
-    TT_UFWord  advance_Height_Max;      /* advance height maximum */
-
-    TT_FWord   min_Top_Side_Bearing;    /* minimum left-sb or top-sb       */
-    TT_FWord   min_Bottom_Side_Bearing; /* minimum right-sb or bottom-sb   */
-    TT_FWord   yMax_Extent;             /* xmax or ymax extents            */
-    TT_FWord   caret_Slope_Rise;
-    TT_FWord   caret_Slope_Run;
-    TT_FWord   caret_Offset;
-
-    TT_Short   Reserved[4];
-
-    TT_Short   metric_Data_Format;
-    TT_UShort  number_Of_VMetrics;
-
-    /* The following fields are not defined by the TrueType specification */
-    /* but they're used to connect the metrics header to the relevant     */
-    /* `HMTX' or `VMTX' table.                                            */
-
-    void*      long_metrics;
-    void*      short_metrics;
-
-  } TT_VertHeader;
-
-
-  /*************************************************************************/
-  /*                                                                       */
-  /* <Struct>                                                              */
-  /*    TT_OS2                                                             */
-  /*                                                                       */
-  /* <Description>                                                         */
-  /*    A structure used to model a TrueType OS/2 table. This is the long  */
-  /*    table version.  All fields comply to the TrueType specification.   */
-  /*                                                                       */
-  /*    Note that we now support old Mac fonts which do not include an     */
-  /*    OS/2 table.  In this case, the `version' field is always set to    */
-  /*    0xFFFF.                                                            */
-  /*                                                                       */
-  typedef struct  TT_OS2_
-  {
-    TT_UShort  version;                /* 0x0001 - more or 0xFFFF */
-    TT_FWord   xAvgCharWidth;
-    TT_UShort  usWeightClass;
-    TT_UShort  usWidthClass;
-    TT_Short   fsType;
-    TT_FWord   ySubscriptXSize;
-    TT_FWord   ySubscriptYSize;
-    TT_FWord   ySubscriptXOffset;
-    TT_FWord   ySubscriptYOffset;
-    TT_FWord   ySuperscriptXSize;
-    TT_FWord   ySuperscriptYSize;
-    TT_FWord   ySuperscriptXOffset;
-    TT_FWord   ySuperscriptYOffset;
-    TT_FWord   yStrikeoutSize;
-    TT_FWord   yStrikeoutPosition;
-    TT_Short   sFamilyClass;
-
-    TT_Byte    panose[10];
-
-    TT_ULong   ulUnicodeRange1;        /* Bits 0-31   */
-    TT_ULong   ulUnicodeRange2;        /* Bits 32-63  */
-    TT_ULong   ulUnicodeRange3;        /* Bits 64-95  */
-    TT_ULong   ulUnicodeRange4;        /* Bits 96-127 */
-
-    TT_Char    achVendID[4];
-
-    TT_UShort  fsSelection;
-    TT_UShort  usFirstCharIndex;
-    TT_UShort  usLastCharIndex;
-    TT_Short   sTypoAscender;
-    TT_Short   sTypoDescender;
-    TT_Short   sTypoLineGap;
-    TT_UShort  usWinAscent;
-    TT_UShort  usWinDescent;
-
-    /* only version 1 tables: */
-
-    TT_ULong   ulCodePageRange1;       /* Bits 0-31   */
-    TT_ULong   ulCodePageRange2;       /* Bits 32-63  */
-
-  } TT_OS2;
-
-
-  /*************************************************************************/
-  /*                                                                       */
-  /* <Struct>                                                              */
-  /*    TT_Postscript                                                      */
-  /*                                                                       */
-  /* <Description>                                                         */
-  /*    A structure used to model a TrueType Postscript table.  All fields */
-  /*    comply to the TrueType table.  This structure does not reference   */
-  /*    the Postscript glyph names, which can be nevertheless accessed     */
-  /*    with the `ttpost' module.                                          */
-  /*                                                                       */
-  typedef struct  TT_Postscript_
-  {
-    TT_Fixed  FormatType;
-    TT_Fixed  italicAngle;
-    TT_FWord  underlinePosition;
-    TT_FWord  underlineThickness;
-    TT_ULong  isFixedPitch;
-    TT_ULong  minMemType42;
-    TT_ULong  maxMemType42;
-    TT_ULong  minMemType1;
-    TT_ULong  maxMemType1;
-
-    /* Glyph names follow in the file, but we don't   */
-    /* load them by default.  See the ttpost.c file.  */
-
-  } TT_Postscript;
-
-
-  /*************************************************************************/
-  /*                                                                       */
-  /* <Struct>                                                              */
-  /*    TT_MaxProfile                                                      */
-  /*                                                                       */
-  /* <Description>                                                         */
-  /*    The maximum profile is a table containing many max values which    */
-  /*    can be used to pre-allocate arrays.  This ensures that no memory   */
-  /*    allocation occurs during a glyph load.                             */
-  /*                                                                       */
-  /* <Fields>                                                              */
-  /*    version               :: The version number.                       */
-  /*                                                                       */
-  /*    numGlyphs             :: The number of glyphs in this TrueType     */
-  /*                             font.                                     */
-  /*                                                                       */
-  /*    maxPoints             :: The maximum number of points in a         */
-  /*                             non-composite TrueType glyph.  See also   */
-  /*                             the structure element                     */
-  /*                             `maxCompositePoints'.                     */
-  /*                                                                       */
-  /*    maxContours           :: The maximum number of contours in a       */
-  /*                             non-composite TrueType glyph.  See also   */
-  /*                             the structure element                     */
-  /*                             `maxCompositeContours'.                   */
-  /*                                                                       */
-  /*    maxCompositePoints    :: The maximum number of points in a         */
-  /*                             composite TrueType glyph.  See also the   */
-  /*                             structure element `maxPoints'.            */
-  /*                                                                       */
-  /*    maxCompositeContours  :: The maximum number of contours in a       */
-  /*                             composite TrueType glyph.  See also the   */
-  /*                             structure element `maxContours'.          */
-  /*                                                                       */
-  /*    maxZones              :: The maximum number of zones used for      */
-  /*                             glyph hinting.                            */
-  /*                                                                       */
-  /*    maxTwilightPoints     :: The maximum number of points in the       */
-  /*                             twilight zone used for glyph hinting.     */
-  /*                                                                       */
-  /*    maxStorage            :: The maximum number of elements in the     */
-  /*                             storage area used for glyph hinting.      */
-  /*                                                                       */
-  /*    maxFunctionDefs       :: The maximum number of function            */
-  /*                             definitions in the TrueType bytecode for  */
-  /*                             this font.                                */
-  /*                                                                       */
-  /*    maxInstructionDefs    :: The maximum number of instruction         */
-  /*                             definitions in the TrueType bytecode for  */
-  /*                             this font.                                */
-  /*                                                                       */
-  /*    maxStackElements      :: The maximum number of stack elements used */
-  /*                             during bytecode interpretation.           */
-  /*                                                                       */
-  /*    maxSizeOfInstructions :: The maximum number of TrueType opcodes    */
-  /*                             used for glyph hinting.                   */
-  /*                                                                       */
-  /*    maxComponentElements  :: An obscure value related to composite     */
-  /*                             glyphs definitions.                       */
-  /*                                                                       */
-  /*    maxComponentDepth     :: An obscure value related to composite     */
-  /*                             glyphs definitions.  Probably the maximum */
-  /*                             number of simple glyphs in a composite.   */
-  /*                                                                       */
-  /* <Note>                                                                */
-  /*    This structure is only used during font loading.                   */
-  /*                                                                       */
-  typedef struct  TT_MaxProfile_
-  {
-    TT_Fixed   version;
-    TT_UShort  numGlyphs;
-    TT_UShort  maxPoints;
-    TT_UShort  maxContours;
-    TT_UShort  maxCompositePoints;
-    TT_UShort  maxCompositeContours;
-    TT_UShort  maxZones;
-    TT_UShort  maxTwilightPoints;
-    TT_UShort  maxStorage;
-    TT_UShort  maxFunctionDefs;
-    TT_UShort  maxInstructionDefs;
-    TT_UShort  maxStackElements;
-    TT_UShort  maxSizeOfInstructions;
-    TT_UShort  maxComponentElements;
-    TT_UShort  maxComponentDepth;
-
-  } TT_MaxProfile;
-
-
-#endif
-
   /*************************************************************************/
   /*                                                                       */
   /* <Struct>                                                              */
@@ -1657,7 +1200,9 @@
     TT_CMap4Segment*  segments;
     TT_UShort*        glyphIdArray;
     TT_UShort         numGlyphId;   /* control value */
-
+    
+    TT_CMap4Segment*  last_segment;  /* last used segment, this is a small  */
+                                     /* cache to potentially increase speed */
   } TT_CMap4;
 
 
@@ -2063,6 +1608,15 @@
     /* used to hook the debugger for the `ttdebug' utility..      */
     TT_Interpreter     interpreter;
 
+    /***********************************************************************/
+    /*                                                                     */
+    /* Other tables or fields. This is used by derivative formats like     */
+    /* OpenType.                                                           */
+    /*                                                                     */
+    /***********************************************************************/
+
+    void*              other;
+
   } TT_FaceRec;
 
 
diff --git a/src/base/ftstream.c b/src/base/ftstream.c
index 2179ba1..6c3cc6d 100644
--- a/src/base/ftstream.c
+++ b/src/base/ftstream.c
@@ -121,6 +121,37 @@
   }
 
 
+  BASE_FUNC(FT_Error)  FT_Extract_Frame( FT_Stream  stream,
+                                         FT_ULong   count,
+                                         FT_Byte*  *pbytes )
+  {
+    FT_Error  error;
+    
+    error = FT_Access_Frame( stream, count );
+    if (!error)
+    {
+      *pbytes = (FT_Byte*)stream->cursor;
+        
+      /* equivalent to FT_Forget_Frame, with no memory block release */
+      stream->cursor = 0;
+      stream->limit  = 0;
+    }
+    return error;
+  }                                         
+
+
+  BASE_FUNC(void)    FT_Release_Frame( FT_Stream  stream,
+                                       FT_Byte*  *pbytes )
+  {
+    if (stream->read)
+    {
+      FT_Memory  memory = stream->memory;
+      FREE( *pbytes );
+    }
+    *pbytes = 0;
+  }
+
+
 
   BASE_FUNC(FT_Error)  FT_Access_Frame( FT_Stream  stream,
                                         FT_ULong   count )
@@ -194,7 +225,6 @@
     if (stream->read)
     {
       FT_Memory  memory = stream->memory;
-
       FREE( stream->base );
     }
     stream->cursor = 0;
diff --git a/src/sfnt/rules.mk b/src/sfnt/rules.mk
index 0969c35..212f383 100644
--- a/src/sfnt/rules.mk
+++ b/src/sfnt/rules.mk
@@ -38,12 +38,14 @@ ifndef SFNT_INCLUDE
                   $(SFNT_DIR_)ttcmap.c   \
                   $(SFNT_DIR_)ttsbit.c   \
                   $(SFNT_DIR_)ttpost.c   \
+                  $(SFNT_DIR_)sfobjs.c   \
                   $(SFNT_DIR_)sfdriver.c
 
 
   # driver headers
   #
   SFNT_DRV_H := $(BASE_H)              \
+                $(SFNT_DIR_)sfobjs.h   \
                 $(SFNT_DIR_)ttload.h   \
                 $(SFNT_DIR_)ttsbit.h   \
                 $(SFNT_DIR_)ttcmap.h   \
diff --git a/src/sfnt/sfdriver.c b/src/sfnt/sfdriver.c
index 3c6b889..c76a8db 100644
--- a/src/sfnt/sfdriver.c
+++ b/src/sfnt/sfdriver.c
@@ -5,11 +5,52 @@
 #include <ttsbit.h>
 #include <ttpost.h>
 #include <ttcmap.h>
+#include <sfobjs.h>
+
+  static
+  void*  get_sfnt_table( TT_Face  face, FT_Sfnt_Tag  tag )
+  {
+    void*  table;
+
+    switch (tag)
+    {
+      case ft_sfnt_head: table = &face->header; break;
+      case ft_sfnt_hhea: table = &face->horizontal; break;
+      case ft_sfnt_vhea: table = (face->vertical_info ? &face->vertical : 0 ); break;
+      case ft_sfnt_os2:  table = (face->os2.version == 0xFFFF ? 0 : &face->os2 ); break;
+      case ft_sfnt_post: table = &face->postscript; break;
+      case ft_sfnt_maxp: table = &face->max_profile; break;
+	  case ft_sfnt_pclt: table = face->pclt.Version ? &face->pclt : 0 ; break;
+
+      default:
+        table = 0;
+    }
+    return table;
+  }
+
+
+  static
+  FTDriver_Interface  SFNT_Get_Interface( FT_Driver    driver,
+                                          const char*  interface )
+  {
+    UNUSED(driver);
+
+    if (strcmp(interface,"get_sfnt")==0)
+      return (FTDriver_Interface)get_sfnt_table;
+
+    return 0;
+  }
+
 
   static const SFNT_Interface  sfnt_interface =
   {
     TT_Goto_Table,
 
+    SFNT_Init_Face,
+    SFNT_Load_Face,
+    SFNT_Done_Face,
+    SFNT_Get_Interface,
+
     TT_Load_Any,
     TT_Load_Format_Tag,
     TT_Load_Directory,
diff --git a/src/sfnt/sfnt.c b/src/sfnt/sfnt.c
index 319659a..445cd6c 100644
--- a/src/sfnt/sfnt.c
+++ b/src/sfnt/sfnt.c
@@ -2,6 +2,7 @@
 
 #include <ttload.c>
 #include <ttcmap.c>
+#include <sfobjs.c>
 
 #ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
 #include <ttsbit.c>
diff --git a/src/sfnt/ttcmap.c b/src/sfnt/ttcmap.c
index 08bee12..83cb2bd 100644
--- a/src/sfnt/ttcmap.c
+++ b/src/sfnt/ttcmap.c
@@ -214,6 +214,8 @@
       FORGET_Frame();
 
       cmap->get_index = code_to_index4;
+      
+      cmap4->last_segment = cmap4->segments;
       break;
 
     case 6:
@@ -438,35 +440,45 @@
     seg4     = cmap4->segments;
     limit    = seg4 + segCount;
 
-    for ( ; seg4 < limit; seg4++, segCount-- )
-    {
-      if ( charCode <= seg4->endCount )
-      {
-        /* the ranges are sorted in increasing order, if we're out of  */
-        /* the range here, the char code isn't in the charmap, so exit */
-        if ( charCode < seg4->startCount )
-          break;
-
-        /* when the idRangeOffset is 0, we can compute the glyph index */
-        /* directly..                                                  */
-        if ( seg4->idRangeOffset == 0 )
-          result = (charCode + seg4->idDelta) & 0xFFFF;
-        else
-        /* otherwise, we must use the glyphIdArray to do it            */
-        {
-          index1 = seg4->idRangeOffset/2 + (charCode - seg4->startCount)
-                   - segCount;
+    /* check against the last segment */
+    seg4 = cmap4->last_segment;
+    if ( (TT_ULong)(charCode       - seg4->startCount) <
+         (TT_ULong)(seg4->endCount - seg4->startCount) )
+      goto Found;
 
-          if ( index1 < cmap4->numGlyphId       &&
-               cmap4->glyphIdArray[index1] != 0 )
-          {
-            result = (cmap4->glyphIdArray[index1] + seg4->idDelta) & 0xFFFF;
-          }
-        }
+    for ( seg4 = cmap4->segments; seg4 < limit; seg4++, segCount-- )
+    {
+      /* the ranges are sorted in increasing order, if we're out of  */
+      /* the range here, the char code isn't in the charmap, so exit */
+      if ( charCode > seg4->endCount )
         break;
-      }
+        
+      if ( charCode >= seg4->startCount )
+        goto Found;
     }
+    return 0;
+
+ Found:    
+    cmap4->last_segment = seg4;
+    
+    /* when the idRangeOffset is 0, we can compute the glyph index */
+    /* directly..                                                  */
+    
+    if ( seg4->idRangeOffset == 0 )
+      result = (charCode + seg4->idDelta) & 0xFFFF;
+      
+    else
+    /* otherwise, we must use the glyphIdArray to do it            */
+    {
+      index1 = seg4->idRangeOffset/2 + (charCode - seg4->startCount)
+               - segCount;
 
+      if ( index1 < cmap4->numGlyphId       &&
+           cmap4->glyphIdArray[index1] != 0 )
+      {
+        result = (cmap4->glyphIdArray[index1] + seg4->idDelta) & 0xFFFF;
+      }
+    }
     return result;
   }
 
diff --git a/src/truetype/ttdriver.c b/src/truetype/ttdriver.c
index 1e8318a..44d1f24 100644
--- a/src/truetype/ttdriver.c
+++ b/src/truetype/ttdriver.c
@@ -43,270 +43,6 @@
   /*************************************************************************/
 
 
- /******************************************************************
-  *
-  * <Function>
-  *    find_encoding
-  *
-  * <Description>
-  *    return the FT_Encoding corresponding to a given
-  *    (platform_id,encoding_id) pair, as found in TrueType charmaps
-  *
-  * <Input>
-  *   platform_id ::
-  *   encoding_id ::
-  *
-  * <Return>
-  *   the corresponding FT_Encoding tag. ft_encoding_none by default
-  *
-  *****************************************************************/
-
-  static
-  FT_Encoding   find_encoding( int  platform_id,
-                               int  encoding_id )
-  {
-    typedef struct  TEncoding
-    {
-      int          platform_id;
-      int          encoding_id;
-      FT_Encoding  encoding;
-
-    } TEncoding;
-
-    static
-    const TEncoding   tt_encodings[] =
-    {
-      { TT_PLATFORM_ISO,                         -1, ft_encoding_unicode },
-
-      { TT_PLATFORM_APPLE_UNICODE,               -1, ft_encoding_unicode },
-
-      { TT_PLATFORM_MACINTOSH,      TT_MAC_ID_ROMAN, ft_encoding_apple_roman },
-
-      { 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_BIG_5,      ft_encoding_big5 }
-    };
-
-    const TEncoding  *cur, *limit;
-
-    cur   = tt_encodings;
-    limit = cur + sizeof(tt_encodings)/sizeof(tt_encodings[0]);
-
-    for ( ; cur < limit; cur++ )
-    {
-      if (cur->platform_id == platform_id)
-      {
-        if (cur->encoding_id == encoding_id ||
-            cur->encoding_id == -1          )
-          return cur->encoding;
-      }
-    }
-    return ft_encoding_none;
-  }
-
-
-
-
-  /*************************************************************************/
-  /*                                                                       */
-  /* <Function>                                                            */
-  /*    Init_Face                                                          */
-  /*                                                                       */
-  /* <Description>                                                         */
-  /*    A driver method used to initialize a new TrueType face object.     */
-  /*                                                                       */
-  /* <Input>                                                               */
-  /*    resource       :: A handle to the source resource.                 */
-  /*                                                                       */
-  /*    typeface_index :: An index of the face in the font resource.  Used */
-  /*                      to access individual faces in font collections.  */
-  /*                                                                       */
-  /* <InOut>                                                               */
-  /*    face           :: A handle to the face object.                     */
-  /*                                                                       */
-  /* <Return>                                                              */
-  /*    FreeType error code.  0 means success.                             */
-  /*                                                                       */
-  /* <Note>                                                                */
-  /*    The `typeface_index' parameter field will be set to -1 if the      */
-  /*    engine only wants to test the format of the resource.  This means  */
-  /*    that font drivers should simply check the font format, then return */
-  /*    immediately with an error code of 0 (meaning success).  The field  */
-  /*    `num_faces' should be set.                                         */
-  /*                                                                       */
-  /*    Done_Face() will be called subsequently, whatever the result was.  */
-  /*                                                                       */
-  static
-  TT_Error  Init_Face( FT_Stream      stream,
-                       TT_Face        face,
-                       FT_Int         typeface_index,
-                       FT_Int         num_params,
-                       FT_Parameter*  params )
-  {
-    TT_Error     error;
-
-    /* initialize the TrueType face object */
-    error = TT_Init_Face( stream, face, typeface_index, num_params, params );
-
-    /* now set up root fields */
-    if ( !error && typeface_index >= 0 )
-    {
-      FT_Face     root = &face->root;
-      FT_Int      flags;
-      TT_CharMap  charmap;
-      TT_Int      n;
-      FT_Memory   memory;
-
-      memory = root->memory;
-
-      /*****************************************************************/
-      /*                                                               */
-      /* Compute face flags.                                           */
-      /*                                                               */
-      flags = FT_FACE_FLAG_SCALABLE  |    /* scalable outlines */
-              FT_FACE_FLAG_SFNT      |    /* SFNT file format  */
-              FT_FACE_FLAG_HORIZONTAL;    /* horizontal data   */
-
-      /* fixed width font ? */
-      if ( face->postscript.isFixedPitch )
-        flags |= FT_FACE_FLAG_FIXED_WIDTH;
-
-      /* vertical information ? */
-      if ( face->vertical_info )
-        flags |= FT_FACE_FLAG_VERTICAL;
-
-      /* kerning available ? */
-      if ( face->kern_pairs )
-        flags |= FT_FACE_FLAG_KERNING;
-
-      root->face_flags = flags;
-
-      /*****************************************************************/
-      /*                                                               */
-      /* Compute style flags.                                          */
-      /*                                                               */
-      flags = 0;
-
-      if ( face->os2.version != 0xFFFF )
-      {
-        /* We have an OS/2 table, use the `fsSelection' field */
-        if ( face->os2.fsSelection & 1 )
-          flags |= FT_STYLE_FLAG_ITALIC;
-
-        if ( face->os2.fsSelection & 32 )
-          flags |= FT_STYLE_FLAG_BOLD;
-      }
-      else
-      {
-        /* This is an old Mac font, use the header field */
-        if ( face->header.Mac_Style & 1 )
-          flags |= FT_STYLE_FLAG_BOLD;
-
-        if ( face->header.Mac_Style & 2 )
-          flags |= FT_STYLE_FLAG_ITALIC;
-      }
-
-      face->root.style_flags = flags;
-
-      /*****************************************************************/
-      /*                                                               */
-      /* Polish the charmaps.                                          */
-      /*                                                               */
-      /*   Try to set the charmap encoding according to the platform & */
-      /*   encoding ID of each charmap.                                */
-      /*                                                               */
-      charmap            = face->charmaps;
-      root->num_charmaps = face->num_charmaps;
-
-      /* allocate table of pointers */
-      if ( ALLOC_ARRAY( root->charmaps, root->num_charmaps, FT_CharMap ) )
-        return error;
-
-      for ( n = 0; n < root->num_charmaps; n++, charmap++ )
-      {
-        FT_Int  platform = charmap->cmap.platformID;
-        FT_Int  encoding = charmap->cmap.platformEncodingID;
-
-        charmap->root.face        = (FT_Face)face;
-        charmap->root.platform_id = platform;
-        charmap->root.encoding_id = encoding;
-        charmap->root.encoding    = find_encoding(platform,encoding);
-
-        /* now, set root->charmap with a unicode charmap wherever available */
-        if (!root->charmap && charmap->root.encoding == ft_encoding_unicode)
-          root->charmap = (FT_CharMap)charmap;
-
-        root->charmaps[n] = (FT_CharMap)charmap;
-      }
-
-#ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
-      if ( face->num_sbit_strikes )
-      {
-       face->root.num_fixed_sizes = face->num_sbit_strikes;
-       if ( ALLOC_ARRAY( face->root.available_sizes,
-                         face->num_sbit_strikes,
-                         FT_Bitmap_Size ) )
-         return error;
-
-       for ( n = 0 ; n < face->num_sbit_strikes ; n++ )
-       {
-         face->root.available_sizes[n].width =
-           face->sbit_strikes[n].x_ppem;
-         face->root.available_sizes[n].height =
-           face->sbit_strikes[n].y_ppem;
-       }
-      }
-      else
-#else
-      {
-       root->num_fixed_sizes = 0;
-       root->available_sizes = 0;
-      }
-#endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */
-
-      /*****************************************************************/
-      /*                                                               */
-      /*  Set up metrics.                                              */
-      /*                                                               */
-      root->bbox.xMin    = face->header.xMin;
-      root->bbox.yMin    = face->header.yMin;
-      root->bbox.xMax    = face->header.xMax;
-      root->bbox.yMax    = face->header.yMax;
-      root->units_per_EM = face->header.Units_Per_EM;
-
-      /* The ascender/descender/height are computed from the OS/2 table   */
-      /* when found.  Otherwise, they're taken from the horizontal header */
-      if ( face->os2.version != 0xFFFF )
-      {
-        root->ascender  =  face->os2.sTypoAscender;
-        root->descender = -face->os2.sTypoDescender;
-        root->height    =  root->ascender + root->descender +
-                           face->os2.sTypoLineGap;
-      }
-      else
-      {
-        root->ascender  = face->horizontal.Ascender;
-        root->descender = face->horizontal.Descender;
-        root->height    = root->ascender + root->descender +
-                          face->horizontal.Line_Gap;
-      }
-
-      root->max_advance_width  = face->horizontal.advance_Width_Max;
-
-      root->max_advance_height = root->height;
-      if ( face->vertical_info )
-        root->max_advance_height = face->vertical.advance_Height_Max;
-
-      root->underline_position  = face->postscript.underlinePosition;
-      root->underline_thickness = face->postscript.underlineThickness;
-
-      /* root->max_points      - already set up */
-      /* root->max_contours    - already set up */
-
-    }
-    return error;
-  }
-
 
 #undef  PAIR_TAG
 #define PAIR_TAG( left, right )  ( ((TT_ULong)left << 16) | (TT_ULong)right )
@@ -639,35 +375,18 @@
 
 
   static
-  void*  tt_get_sfnt_table( TT_Face  face, FT_Sfnt_Tag  tag )
+  FTDriver_Interface  tt_get_interface( TT_Driver  driver, const char* interface )
   {
-    void*  table;
-
-    switch (tag)
+    FT_Driver        sfntd = FT_Get_Driver( driver->root.library, "sfnt" );
+    SFNT_Interface*  sfnt;
+    
+    /* only return the default interface from the SFNT module */
+    if (sfntd)
     {
-      case ft_sfnt_head: table = &face->header; break;
-      case ft_sfnt_hhea: table = &face->horizontal; break;
-      case ft_sfnt_vhea: table = (face->vertical_info ? &face->vertical : 0 ); break;
-      case ft_sfnt_os2:  table = (face->os2.version == 0xFFFF ? 0 : &face->os2 ); break;
-      case ft_sfnt_post: table = &face->postscript; break;
-      case ft_sfnt_maxp: table = &face->max_profile; break;
-	  case ft_sfnt_pclt: table = face->pclt.Version ? &face->pclt : 0 ; break;
-
-      default:
-        table = 0;
+      sfnt = (SFNT_Interface*)(sfntd->interface.format_interface);
+      if (sfnt)
+        return sfnt->get_interface( (FT_Driver)driver, interface );
     }
-    return table;
-  }
-
-
-  static
-  FTDriver_Interface  tt_get_interface( TT_Driver  driver, const char* interface )
-  {
-    UNUSED(driver);
-
-    if (strcmp(interface,"get_sfnt")==0)
-      return (FTDriver_Interface)tt_get_sfnt_table;
-
     return 0;
   }
 
@@ -691,7 +410,7 @@
     (FTDriver_doneDriver)        TT_Done_Driver,
     (FTDriver_getInterface)      tt_get_interface,
 
-    (FTDriver_initFace)          Init_Face,
+    (FTDriver_initFace)          TT_Init_Face,
     (FTDriver_doneFace)          TT_Done_Face,
     (FTDriver_getKerning)        Get_Kerning,
 
diff --git a/src/truetype/ttobjs.c b/src/truetype/ttobjs.c
index 8f2a60d..a3b97c0 100644
--- a/src/truetype/ttobjs.c
+++ b/src/truetype/ttobjs.c
@@ -45,95 +45,6 @@
   /*************************************************************************/
 
 
-  /*************************************************************************/
-  /*                                                                       */
-  /* <Function>                                                            */
-  /*    Get_Name                                                           */
-  /*                                                                       */
-  /* <Description>                                                         */
-  /*    Returns a given ENGLISH name record in ASCII.                      */
-  /*                                                                       */
-  /* <Input>                                                               */
-  /*    face   :: A handle to the source face object.                      */
-  /*                                                                       */
-  /*    nameid :: The name id of the name record to return.                */
-  /*                                                                       */
-  /* <Return>                                                              */
-  /*    Char string.  NULL if no name is present.                          */
-  /*                                                                       */
-  static
-  FT_String*  Get_Name( TT_Face    face,
-                        TT_UShort  nameid )
-  {
-    FT_Memory    memory = face->root.memory;
-    TT_UShort    n;
-    TT_NameRec*  rec;
-    TT_Bool      wide_chars = 1;
-
-    /* first pass, look for a given name record */
-    rec = face->name_table.names;
-    for ( n = 0; n < face->name_table.numNameRecords; n++, rec++ )
-    {
-      if ( rec->nameID == nameid )
-      {
-        /* found the name - now create an ASCII string from it */
-        TT_Bool  found = 0;
-
-        /* Test for Microsoft English language */
-        if ( rec->platformID == TT_PLATFORM_MICROSOFT &&
-             rec->encodingID <= TT_MS_ID_UNICODE_CS   &&
-             (rec->languageID & 0x3FF) == 0x009 )
-          found = 1;
-
-        /* Test for Apple Unicode encoding */
-        else if ( rec->platformID == TT_PLATFORM_APPLE_UNICODE )
-          found = 1;
-
-        /* Test for Apple Roman */
-        else if ( rec->platformID == TT_PLATFORM_MACINTOSH &&
-                  rec->languageID == TT_MAC_ID_ROMAN       )
-        {
-          found      = 1;
-          wide_chars = 0;
-        }
-
-        /* Found a Unicode Name */
-        if ( found )
-        {
-          TT_String*  string;
-          TT_UInt     len;
-
-          if ( wide_chars )
-          {
-            TT_UInt   m;
-
-            len = (TT_UInt)rec->stringLength / 2;
-            if ( MEM_Alloc( string, len + 1 ) )
-              return NULL;
-
-            for ( m = 0; m < len; m ++ )
-              string[m] = rec->string[2*m + 1];
-          }
-          else
-          {
-            len = rec->stringLength;
-            if ( MEM_Alloc( string, len + 1 ) )
-              return NULL;
-
-            MEM_Copy( string, rec->string, len );
-          }
-
-          string[len] = '\0';
-          return string;
-        }
-      }
-    }
-    return NULL;
-  }
-
-
-#undef  LOAD_
-#define LOAD_(x)   ( (error = sfnt->load_##x( face, stream )) != TT_Err_Ok )
 
 
   /*************************************************************************/
@@ -160,126 +71,51 @@
                           FT_Parameter*  params )
   {
     TT_Error           error;
-    TT_ULong           format_tag;
+    FT_Driver          sfnt_driver;
     SFNT_Interface*    sfnt;
-    PSNames_Interface* psnames;
 
-    /* for now, parameters are unused */
-    UNUSED(num_params);
-    UNUSED(params);
+    sfnt_driver = FT_Get_Driver( face->root.driver->library, "sfnt" );
+    if (!sfnt_driver) goto Bad_Format;
 
-    sfnt = (SFNT_Interface*)face->sfnt;
-    if (!sfnt)
-    {
-      /* look-up the SFNT driver */
-      FT_Driver  sfnt_driver;
-
-      sfnt_driver = FT_Get_Driver( face->root.driver->library, "sfnt" );
-      if (!sfnt_driver)
-        return FT_Err_Invalid_File_Format;
-
-      sfnt = (SFNT_Interface*)(sfnt_driver->interface.format_interface);
-      if (!sfnt)
-        return FT_Err_Invalid_File_Format;
-
-      face->sfnt       = sfnt;
-      face->goto_table = sfnt->goto_table;
-    }
-
-    psnames = (PSNames_Interface*)face->psnames;
-    if (!psnames)
-    {
-      /* look-up the PSNames driver */
-      FT_Driver  psnames_driver;
-
-      psnames_driver = FT_Get_Driver( face->root.driver->library, "psnames" );
-      if (psnames_driver)
-        face->psnames = (PSNames_Interface*)
-                            (psnames_driver->interface.format_interface);
-    }
+    sfnt = (SFNT_Interface*)(sfnt_driver->interface.format_interface);
+    if (!sfnt) goto Bad_Format;
 
     /* create input stream from resource */
     if ( FILE_Seek(0) )
       goto Exit;
 
     /* check that we have a valid TrueType file */
-    error = sfnt->load_format_tag( face, stream, face_index, &format_tag );
+    error = sfnt->init_face( stream, face, face_index, num_params, params );
     if (error) goto Exit;
 
     /* We must also be able to accept Mac/GX fonts, as well as OT ones */
-    if ( format_tag != 0x00010000 &&    /* MS fonts  */
-         format_tag != TTAG_true  )     /* Mac fonts */
+    if ( face->format_tag != 0x00010000 &&    /* MS fonts  */
+         face->format_tag != TTAG_true  )     /* Mac fonts */
     {
       FT_TRACE2(( "[not a valid TTF font]" ));
-      error = FT_Err_Unknown_File_Format;
-      goto Exit;
+      goto Bad_Format;
     }
 
-    /* store format tag */
-    face->format_tag = format_tag;
-	
-    /* Load font directory */
-    error = sfnt->load_directory( face, stream, face_index );
-    if ( error ) goto Exit;
-
-    face->root.num_faces = face->ttc_header.DirCount;
-    if ( face->root.num_faces < 1 )
-      face->root.num_faces = 1;
-
     /* If we're performing a simple font format check, exit immediately */
     if ( face_index < 0 )
       return TT_Err_Ok;
 
-    /* Load tables */
-
-    if ( LOAD_( header )        ||
-         LOAD_( max_profile )   ||
-
-         (error = sfnt->load_metrics( face, stream, 0 )) != TT_Err_Ok  ||
-         /* load the `hhea' & `hmtx' tables at once */
-
-         (error = sfnt->load_metrics( face, stream, 1 )) != TT_Err_Ok ||
-         /* try to load the `vhea' & `vmtx' at once if present */
-
-         LOAD_( charmaps )      ||
-         LOAD_( names )         ||
-         LOAD_( os2 )           ||
-         LOAD_( psnames )       )
-     goto Exit;
-
-    /* the optional tables */
-
-    /* embedded bitmap support. */
-#ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
-    if (sfnt->load_sbits && LOAD_(sbits)) goto Exit;
-#endif
-
-    if ( LOAD_( hdmx )          ||
-         LOAD_( gasp )          ||
-         LOAD_( kerning )       ||
-		 LOAD_( pclt )          ||
-
-         (error = TT_Load_Locations( face, stream )) != TT_Err_Ok ||
-         (error = TT_Load_CVT      ( face, stream )) != TT_Err_Ok ||
-         (error = TT_Load_Programs ( face, stream )) != TT_Err_Ok )
-
-      goto Exit;
-
-#ifdef TT_CONFIG_OPTION_EXTEND_ENGINE
-    if ( ( error = TT_Extension_Create( face ) ) != TT_Err_Ok )
-      goto Exit;
-#endif
-
-    face->root.family_name = Get_Name( face, TT_NAME_ID_FONT_FAMILY );
-    face->root.style_name  = Get_Name( face, TT_NAME_ID_FONT_SUBFAMILY );
+    /* Load font directory */
+    error = sfnt->load_face( stream, face, face_index, num_params, params );
+    if ( error ) goto Exit;
 
+    error = TT_Load_Locations( face, stream ) ||
+            TT_Load_CVT      ( face, stream ) ||
+            TT_Load_Programs ( face, stream );
   Exit:
     return error;
+     
+  Bad_Format:
+    error = FT_Err_Unknown_File_Format;
+    goto Exit;
   }
 
 
-#undef LOAD_
-
 
   /*************************************************************************/
   /*                                                                       */
@@ -295,94 +131,27 @@
   LOCAL_DEF
   void  TT_Done_Face( TT_Face  face )
   {
-    TT_UShort  n;
     FT_Memory  memory = face->root.memory;
+    FT_Stream  stream = face->root.stream;
 
     SFNT_Interface*  sfnt = face->sfnt;
 
     if (sfnt)
-    {
-      /* destroy the postscript names table if it is supported */
-      if (sfnt->free_psnames)
-        sfnt->free_psnames( face );
-
-      /* destroy the embedded bitmaps table if it is supported */
-      if (sfnt->free_sbits)
-        sfnt->free_sbits( face );
-    }
-
-    /* freeing the kerning table */
-    FREE( face->kern_pairs );
-    face->num_kern_pairs = 0;
-
-    /* freeing the collection table */
-    FREE( face->ttc_header.TableDirectory );
-    face->ttc_header.DirCount = 0;
-
-    /* freeing table directory */
-    FREE( face->dir_tables );
-    face->num_tables = 0;
+      sfnt->done_face(face);
 
     /* freeing the locations table */
     FREE( face->glyph_locations );
     face->num_locations = 0;
 
-    /* freeing the character mapping tables */
-    if (sfnt && sfnt->load_charmaps )
-    {
-      for ( n = 0; n < face->num_charmaps; n++ )
-        sfnt->free_charmap( face, &face->charmaps[n].cmap );
-    }
-
-    FREE( face->charmaps );
-    face->num_charmaps = 0;
-
-    FREE( face->root.charmaps );
-    face->root.num_charmaps = 0;
-    face->root.charmap      = 0;
-
     /* freeing the CVT */
     FREE( face->cvt );
     face->cvt_size = 0;
 
-    /* freeing the horizontal metrics */
-    FREE( face->horizontal.long_metrics );
-    FREE( face->horizontal.short_metrics );
-
-    /* freeing the vertical ones, if any */
-    if ( face->vertical_info )
-    {
-      FREE( face->vertical.long_metrics  );
-      FREE( face->vertical.short_metrics );
-      face->vertical_info = 0;
-    }
-
     /* freeing the programs */
-    FREE( face->font_program );
-    FREE( face->cvt_program );
+    RELEASE_Frame( face->font_program );
+    RELEASE_Frame( face->cvt_program );
     face->font_program_size = 0;
     face->cvt_program_size  = 0;
-
-    /* freeing the gasp table */
-    FREE( face->gasp.gaspRanges );
-    face->gasp.numRanges = 0;
-
-    /* freeing the name table */
-    sfnt->free_names( face );
-
-    /* freeing the hdmx table */
-    sfnt->free_hdmx( face );
-
-    /* freeing family and style name */
-    FREE( face->root.family_name );
-    FREE( face->root.style_name );
-
-    /* freeing sbit size table */
-    face->root.num_fixed_sizes = 0;
-    if ( face->root.available_sizes )
-      FREE( face->root.available_sizes );
-
-    face->sfnt = 0;
   }
 
 
diff --git a/src/truetype/ttpload.c b/src/truetype/ttpload.c
index 56d61cc..e0fe0f5 100644
--- a/src/truetype/ttpload.c
+++ b/src/truetype/ttpload.c
@@ -199,10 +199,8 @@
                               FT_Stream  stream )
   {
     TT_Error   error;
-    FT_Memory  memory = stream->memory;
     TT_ULong   table_len;
 
-
     FT_TRACE2(( "Font program " ));
 
     /* The font program is optional */
@@ -216,12 +214,7 @@
     else
     {
       face->font_program_size = table_len;
-
-      if ( ALLOC( face->font_program,
-                  face->font_program_size ) ||
-
-           FILE_Read( (void*)face->font_program,
-                      face->font_program_size )   )
+      if ( EXTRACT_Frame( table_len, face->font_program ) )
         goto Exit;
 
       FT_TRACE2(( "loaded, %12d bytes\n", face->font_program_size ));
@@ -241,14 +234,8 @@
     else
     {
       face->cvt_program_size = table_len;
-
-      if ( ALLOC( face->cvt_program,
-                  face->cvt_program_size )           ||
-
-           FILE_Read( (void*)face->cvt_program,
-                      face->cvt_program_size ) )
-        return error;
-
+      if ( EXTRACT_Frame( table_len, face->cvt_program ) )
+        goto Exit;
       FT_TRACE2(( "loaded, %12d bytes\n", face->cvt_program_size ));
     }
 
diff --git a/src/type1/module.mk b/src/type1/module.mk
index 0acc599..5b057b7 100644
--- a/src/type1/module.mk
+++ b/src/type1/module.mk
@@ -2,5 +2,5 @@ make_module_list: add_type1_driver
 
 add_type1_driver:
 	$(OPEN_DRIVER)t1_driver_interface$(CLOSE_DRIVER)
-	$(ECHO_DRIVER)type1     $(ECHO_DRIVER_DESC) Postscript font files with extension *.pfa or *.pfb $(ECHO_DRIVER_DONE)
+	$(ECHO_DRIVER)type1     $(ECHO_DRIVER_DESC)Postscript font files with extension *.pfa or *.pfb$(ECHO_DRIVER_DONE)