Commit 72f5ff5bbb6f3467baf13e4c014f3f50479e3b96

Werner Lemberg 2013-07-31T22:49:29

[autofit] Introduce `writing systems'. This patch adds a new top level to the auto-hinter's script class hierarchy. It defines `writing systems' which can contain multiple scripts. For example, the `latin' writing system (in file `aflatin.c') is able to support scripts like Latin, Cyrillic, Armenian, etc., which can be handled similarly. Scripts are now named using four-letter OpenType tags. * src/autofit/aftypes.h (AF_ScriptClassRec): Move relevant members to... (AF_WritingSystemClassRec): This new structure. It holds pointers to functions which can be shared among related scripts. (AF_WritingSystem): New enumeration. (AF_Script): Revised values using four-letter tags. (AF_DEFINE_WRITING_SYSTEM_CLASS): New macro. (AF_DEFINE_SCRIPT_CLASS): Updated. * src/autofit/afglobal.c (af_writing_system_classes): New global, constant array. (af_script_classes): Updated. (af_face_globals_free): Updated. Remove assertion. (af_face_globals_get_metrics): Updated. * src/autofit/afglobal.h (AF_SCRIPT_FALLBACK) [!AF_CONFIG_OPTION_CJK]: Handle this case. * src/autofit/afloader.c (af_loader_load_g, af_loader_load_glyph): Updated. * src/autofit/afpic.c (autofit_module_class_pic_init): Updated; initialize structures for both writing systems and scripts. * src/autofit/afpic.h: Updated. (AF_WRITING_SYSTEM_CLASSES_GET): New macro. * src/autofit/afcjk.c (af_cjk_writing_system_class): New writing system. (af_cjk_uniranges): Renamed to... (af_hani_uniranges): This. (af_cjk_script_class): Reduced and renamed to... (af_hani_script_class): This. * src/autofit/afcjk.h: Updated. * src/autofit/afdummy.c (af_dummy_writing_system_class): New writing system. (af_dummy_script_class): Reduced and renamed to... (af_dflt_script_class): This. * src/autofit/afdummy.h: Updated. * src/autofit/afindic.c (af_indic_writing_system_class): New writing system. (af_indic_uniranges): Renamed to... (af_deva_uniranges): This. (af_indic_script_class): Reduced and renamed to... (af_deva_script_class): This. * src/autofit/afcjk.h: Updated. * src/autofit/aflatin.c (af_latin_writing_system_class): New writing system. (af_latin_uniranges): Renamed to... (af_latn_uniranges): This. (af_latin_script_class): Reduced and renamed to... (af_latn_script_class): This. * src/autofit/aflatin.h: Updated. * src/autofit/aflatin2.c (af_latin2_writing_system_class): New writing system. (af_latin2_uniranges): Renamed to... (af_ltn2_uniranges): This. Synchronize ranges with `latin'. (af_latin2_script_class): Reduced and renamed to... (af_ltn2_script_class): This. * src/autofit/aflatin2.h: Updated.

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
diff --git a/ChangeLog b/ChangeLog
index f9e643b..8de2ab8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,85 @@
 2013-07-30  Werner Lemberg  <wl@gnu.org>
 
+	[autofit] Introduce `writing systems'.
+
+	This patch adds a new top level to the auto-hinter's script class
+	hierarchy.  It defines `writing systems' which can contain multiple
+	scripts.
+
+	For example, the `latin' writing system (in file `aflatin.c') is
+	able to support scripts like Latin, Cyrillic, Armenian, etc., which
+	can be handled similarly.
+
+	Scripts are now named using four-letter OpenType tags.
+
+	* src/autofit/aftypes.h (AF_ScriptClassRec): Move relevant members
+	to...
+	(AF_WritingSystemClassRec): This new structure.  It holds pointers
+	to functions which can be shared among related scripts.
+	(AF_WritingSystem): New enumeration.
+	(AF_Script): Revised values using four-letter tags.
+	(AF_DEFINE_WRITING_SYSTEM_CLASS): New macro.
+	(AF_DEFINE_SCRIPT_CLASS): Updated.
+
+	* src/autofit/afglobal.c (af_writing_system_classes): New global,
+	constant array.
+	(af_script_classes): Updated.
+	(af_face_globals_free): Updated.
+	Remove assertion.
+	(af_face_globals_get_metrics): Updated.
+
+	* src/autofit/afglobal.h (AF_SCRIPT_FALLBACK)
+	[!AF_CONFIG_OPTION_CJK]: Handle this case.
+
+	* src/autofit/afloader.c (af_loader_load_g, af_loader_load_glyph):
+	Updated.
+
+	* src/autofit/afpic.c (autofit_module_class_pic_init): Updated;
+	initialize structures for both writing systems and scripts.
+	* src/autofit/afpic.h: Updated.
+	(AF_WRITING_SYSTEM_CLASSES_GET): New macro.
+
+	* src/autofit/afcjk.c (af_cjk_writing_system_class): New writing
+	system.
+	(af_cjk_uniranges): Renamed to...
+	(af_hani_uniranges): This.
+	(af_cjk_script_class): Reduced and renamed to...
+	(af_hani_script_class): This.
+	* src/autofit/afcjk.h: Updated.
+
+	* src/autofit/afdummy.c (af_dummy_writing_system_class): New writing
+	system.
+	(af_dummy_script_class): Reduced and renamed to...
+	(af_dflt_script_class): This.
+	* src/autofit/afdummy.h: Updated.
+
+	* src/autofit/afindic.c (af_indic_writing_system_class): New writing
+	system.
+	(af_indic_uniranges): Renamed to...
+	(af_deva_uniranges): This.
+	(af_indic_script_class): Reduced and renamed to...
+	(af_deva_script_class): This.
+	* src/autofit/afcjk.h: Updated.
+
+	* src/autofit/aflatin.c (af_latin_writing_system_class): New writing
+	system.
+	(af_latin_uniranges): Renamed to...
+	(af_latn_uniranges): This.
+	(af_latin_script_class): Reduced and renamed to...
+	(af_latn_script_class): This.
+	* src/autofit/aflatin.h: Updated.
+
+	* src/autofit/aflatin2.c (af_latin2_writing_system_class): New
+	writing system.
+	(af_latin2_uniranges): Renamed to...
+	(af_ltn2_uniranges): This.
+	Synchronize ranges with `latin'.
+	(af_latin2_script_class): Reduced and renamed to...
+	(af_ltn2_script_class): This.
+	* src/autofit/aflatin2.h: Updated.
+
+2013-07-30  Werner Lemberg  <wl@gnu.org>
+
 	[autofit] Variable renaming.
 
 	* src/autofit/aftypes.h (AF_ScriptMetricsRec):
diff --git a/src/autofit/afcjk.c b/src/autofit/afcjk.c
index 1dbf1c2..cb53083 100644
--- a/src/autofit/afcjk.c
+++ b/src/autofit/afcjk.c
@@ -2192,9 +2192,28 @@
   /*************************************************************************/
 
 
+  AF_DEFINE_WRITING_SYSTEM_CLASS(
+    af_cjk_writing_system_class,
+
+    AF_WRITING_SYSTEM_CJK,
+
+    sizeof ( AF_CJKMetricsRec ),
+
+    (AF_Script_InitMetricsFunc) af_cjk_metrics_init,
+    (AF_Script_ScaleMetricsFunc)af_cjk_metrics_scale,
+    (AF_Script_DoneMetricsFunc) NULL,
+
+    (AF_Script_InitHintsFunc)   af_cjk_hints_init,
+    (AF_Script_ApplyHintsFunc)  af_cjk_hints_apply
+  )
+
+
   /* this corresponds to Unicode 6.0 */
 
-  static const AF_Script_UniRangeRec  af_cjk_uniranges[] =
+  /* XXX: this should probably fine tuned to differentiate better between */
+  /*      scripts...                                                      */
+
+  static const AF_Script_UniRangeRec  af_hani_uniranges[] =
   {
     AF_UNIRANGE_REC(  0x1100UL,  0x11FFUL ),  /* Hangul Jamo                             */
     AF_UNIRANGE_REC(  0x2E80UL,  0x2EFFUL ),  /* CJK Radicals Supplement                 */
@@ -2232,45 +2251,41 @@
   };
 
 
-  AF_DEFINE_SCRIPT_CLASS( af_cjk_script_class,
-    AF_SCRIPT_CJK,
-    af_cjk_uniranges,
-    0x7530, /* 田 */
+#else /* !AF_CONFIG_OPTION_CJK */
+
+  AF_DEFINE_WRITING_SYSTEM_CLASS(
+    af_cjk_writing_system_class,
+
+    AF_WRITING_SYSTEM_CJK,
 
     sizeof ( AF_CJKMetricsRec ),
 
-    (AF_Script_InitMetricsFunc) af_cjk_metrics_init,
-    (AF_Script_ScaleMetricsFunc)af_cjk_metrics_scale,
+    (AF_Script_InitMetricsFunc) NULL,
+    (AF_Script_ScaleMetricsFunc)NULL,
     (AF_Script_DoneMetricsFunc) NULL,
 
-    (AF_Script_InitHintsFunc)   af_cjk_hints_init,
-    (AF_Script_ApplyHintsFunc)  af_cjk_hints_apply
+    (AF_Script_InitHintsFunc)   NULL,
+    (AF_Script_ApplyHintsFunc)  NULL
   )
 
-#else /* !AF_CONFIG_OPTION_CJK */
 
-  static const AF_Script_UniRangeRec  af_cjk_uniranges[] =
+  static const AF_Script_UniRangeRec  af_hani_uniranges[] =
   {
     AF_UNIRANGE_REC( 0UL, 0UL )
   };
 
+#endif /* !AF_CONFIG_OPTION_CJK */
 
-  AF_DEFINE_SCRIPT_CLASS( af_cjk_script_class,
-    AF_SCRIPT_CJK,
-    af_cjk_uniranges,
-    0,
 
-    sizeof ( AF_CJKMetricsRec ),
+  AF_DEFINE_SCRIPT_CLASS(
+    af_hani_script_class,
 
-    (AF_Script_InitMetricsFunc) NULL,
-    (AF_Script_ScaleMetricsFunc)NULL,
-    (AF_Script_DoneMetricsFunc) NULL,
+    AF_SCRIPT_HANI,
+    AF_WRITING_SYSTEM_CJK,
 
-    (AF_Script_InitHintsFunc)   NULL,
-    (AF_Script_ApplyHintsFunc)  NULL
+    af_hani_uniranges,
+    0x7530 /* 田 */
   )
 
-#endif /* !AF_CONFIG_OPTION_CJK */
-
 
 /* END */
diff --git a/src/autofit/afcjk.h b/src/autofit/afcjk.h
index ab816f2..44f718b 100644
--- a/src/autofit/afcjk.h
+++ b/src/autofit/afcjk.h
@@ -4,7 +4,7 @@
 /*                                                                         */
 /*    Auto-fitter hinting routines for CJK script (specification).         */
 /*                                                                         */
-/*  Copyright 2006, 2007, 2011, 2012 by                                    */
+/*  Copyright 2006, 2007, 2011-2013 by                                     */
 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
 /*                                                                         */
 /*  This file is part of the FreeType project, and may only be used,       */
@@ -26,9 +26,15 @@
 FT_BEGIN_HEADER
 
 
-  /* the CJK-specific script class */
+  /* the CJK-specific writing system */
+
+  AF_DECLARE_WRITING_SYSTEM_CLASS( af_cjk_writing_system_class )
+
+
+  /* the CJK-specific script classes */
+
+  AF_DECLARE_SCRIPT_CLASS( af_hani_script_class )
 
-  AF_DECLARE_SCRIPT_CLASS( af_cjk_script_class )
 
   /* CJK (global) metrics management */
 
diff --git a/src/autofit/afdummy.c b/src/autofit/afdummy.c
index 2294455..d559bfe 100644
--- a/src/autofit/afdummy.c
+++ b/src/autofit/afdummy.c
@@ -43,10 +43,10 @@
   }
 
 
-  AF_DEFINE_SCRIPT_CLASS( af_dummy_script_class,
-    AF_SCRIPT_DUMMY,
-    NULL,
-    0,
+  AF_DEFINE_WRITING_SYSTEM_CLASS(
+    af_dummy_writing_system_class,
+
+    AF_WRITING_SYSTEM_DUMMY,
 
     sizeof ( AF_ScriptMetricsRec ),
 
@@ -59,4 +59,15 @@
   )
 
 
+  AF_DEFINE_SCRIPT_CLASS(
+    af_dflt_script_class,
+
+    AF_SCRIPT_DFLT,
+    AF_WRITING_SYSTEM_DUMMY,
+
+    NULL,
+    '\0'
+  )
+
+
 /* END */
diff --git a/src/autofit/afdummy.h b/src/autofit/afdummy.h
index 95d8f8c..bc34ddd 100644
--- a/src/autofit/afdummy.h
+++ b/src/autofit/afdummy.h
@@ -5,7 +5,7 @@
 /*    Auto-fitter dummy routines to be used if no hinting should be        */
 /*    performed (specification).                                           */
 /*                                                                         */
-/*  Copyright 2003-2005, 2011 by                                           */
+/*  Copyright 2003-2005, 2011, 2013 by                                     */
 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
 /*                                                                         */
 /*  This file is part of the FreeType project, and may only be used,       */
@@ -25,11 +25,13 @@
 
 FT_BEGIN_HEADER
 
- /*  A dummy script metrics class used when no hinting should
-  *  be performed.  This is the default for non-latin glyphs!
+ /*  A dummy writing system and script class used when no hinting should be
+  *  performed.
   */
 
-  AF_DECLARE_SCRIPT_CLASS( af_dummy_script_class )
+  AF_DECLARE_WRITING_SYSTEM_CLASS( af_dummy_writing_system_class )
+
+  AF_DECLARE_SCRIPT_CLASS( af_dflt_script_class )
 
 /* */
 
diff --git a/src/autofit/afglobal.c b/src/autofit/afglobal.c
index b89d10c..f5d7bb4 100644
--- a/src/autofit/afglobal.c
+++ b/src/autofit/afglobal.c
@@ -31,19 +31,36 @@
 
 #ifndef FT_CONFIG_OPTION_PIC
 
+  /* when updating this table, don't forget to update                  */
+  /* AF_WRITING_SYSTEM_CLASSES_COUNT and autofit_module_class_pic_init */
+
+  /* populate this list when you add new writing systems */
+  static AF_WritingSystemClass const  af_writing_system_classes[] =
+  {
+    &af_dummy_writing_system_class,
+    &af_latin_writing_system_class,
+    &af_cjk_writing_system_class,
+    &af_indic_writing_system_class,
+#ifdef FT_OPTION_AUTOFIT2
+    &af_latin2_writing_system_class,
+#endif
+    NULL  /* do not remove */
+  };
+
+
   /* when updating this table, don't forget to update          */
   /* AF_SCRIPT_CLASSES_COUNT and autofit_module_class_pic_init */
 
   /* populate this list when you add new scripts */
   static AF_ScriptClass const  af_script_classes[] =
   {
-    &af_dummy_script_class,
+    &af_dflt_script_class, /* XXX */
+    &af_latn_script_class,
+    &af_hani_script_class,
+    &af_deva_script_class,
 #ifdef FT_OPTION_AUTOFIT2
-    &af_latin2_script_class,
+    &af_ltn2_script_class,
 #endif
-    &af_latin_script_class,
-    &af_cjk_script_class,
-    &af_indic_script_class,
     NULL  /* do not remove */
   };
 
@@ -206,13 +223,14 @@
       {
         if ( globals->metrics[nn] )
         {
-          AF_ScriptClass  script_class = AF_SCRIPT_CLASSES_GET[nn];
-
+          AF_ScriptClass         script_class =
+            AF_SCRIPT_CLASSES_GET[nn];
+          AF_WritingSystemClass  writing_system_class =
+            AF_WRITING_SYSTEM_CLASSES_GET[script_class->writing_system];
 
-          FT_ASSERT( globals->metrics[nn]->script_class == script_class );
 
-          if ( script_class->script_metrics_done )
-            script_class->script_metrics_done( globals->metrics[nn] );
+          if ( writing_system_class->script_metrics_done )
+            writing_system_class->script_metrics_done( globals->metrics[nn] );
 
           FT_FREE( globals->metrics[nn] );
         }
@@ -235,11 +253,14 @@
   {
     AF_ScriptMetrics  metrics = NULL;
     FT_UInt           gidx;
-    AF_ScriptClass    script_class;
-    FT_UInt           script     = options & 15;
-    const FT_Offset   script_max = sizeof ( AF_SCRIPT_CLASSES_GET ) /
-                                     sizeof ( AF_SCRIPT_CLASSES_GET[0] );
-    FT_Error          error      = FT_Err_Ok;
+
+    AF_WritingSystemClass  writing_system_class;
+    AF_ScriptClass         script_class;
+
+    FT_UInt          script     = options & 15;
+    const FT_Offset  script_max = sizeof ( AF_SCRIPT_CLASSES_GET ) /
+                                    sizeof ( AF_SCRIPT_CLASSES_GET[0] );
+    FT_Error         error      = FT_Err_Ok;
 
 
     if ( gindex >= (FT_ULong)globals->glyph_count )
@@ -252,7 +273,9 @@
     if ( gidx == 0 || gidx + 1 >= script_max )
       gidx = globals->glyph_scripts[gindex] & AF_SCRIPT_NONE;
 
-    script_class = AF_SCRIPT_CLASSES_GET[gidx];
+    script_class         = AF_SCRIPT_CLASSES_GET[gidx];
+    writing_system_class = AF_WRITING_SYSTEM_CLASSES_GET
+                             [script_class->writing_system];
     if ( script == 0 )
       script = script_class->script;
 
@@ -263,19 +286,20 @@
       FT_Memory  memory = globals->face->memory;
 
 
-      if ( FT_ALLOC( metrics, script_class->script_metrics_size ) )
+      if ( FT_ALLOC( metrics, writing_system_class->script_metrics_size ) )
         goto Exit;
 
       metrics->script_class = script_class;
       metrics->globals      = globals;
 
-      if ( script_class->script_metrics_init )
+      if ( writing_system_class->script_metrics_init )
       {
-        error = script_class->script_metrics_init( metrics, globals->face );
+        error = writing_system_class->script_metrics_init( metrics,
+                                                           globals->face );
         if ( error )
         {
-          if ( script_class->script_metrics_done )
-            script_class->script_metrics_done( metrics );
+          if ( writing_system_class->script_metrics_done )
+            writing_system_class->script_metrics_done( metrics );
 
           FT_FREE( metrics );
           goto Exit;
diff --git a/src/autofit/afglobal.h b/src/autofit/afglobal.h
index 2e24900..8034536 100644
--- a/src/autofit/afglobal.h
+++ b/src/autofit/afglobal.h
@@ -5,7 +5,7 @@
 /*    Auto-fitter routines to compute global hinting values                */
 /*    (specification).                                                     */
 /*                                                                         */
-/*  Copyright 2003-2005, 2007, 2009, 2011-2012 by                          */
+/*  Copyright 2003-2005, 2007, 2009, 2011-2013 by                          */
 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
 /*                                                                         */
 /*  This file is part of the FreeType project, and may only be used,       */
@@ -34,7 +34,11 @@ FT_BEGIN_HEADER
    */
 
   /* index of fallback script in `af_script_classes' */
-#define AF_SCRIPT_FALLBACK  2
+#ifdef AF_CONFIG_OPTION_CJK
+#define AF_SCRIPT_FALLBACK  2  /* hani */
+#else
+#define AF_SCRIPT_FALLBACK  0  /* dflt */
+#endif
   /* a bit mask indicating an uncovered glyph        */
 #define AF_SCRIPT_NONE      0x7F
   /* if this flag is set, we have an ASCII digit     */
@@ -55,8 +59,8 @@ FT_BEGIN_HEADER
 
 
   /*
-   *  Note that glyph_scripts[] is used to map each glyph into
-   *  an index into the `af_script_classes' array.
+   *  Note that glyph_scripts[] maps each glyph to an index into the
+   *  `af_script_classes' array.
    *
    */
   typedef struct  AF_FaceGlobalsRec_
diff --git a/src/autofit/afindic.c b/src/autofit/afindic.c
index 8c24972..5dfe404 100644
--- a/src/autofit/afindic.c
+++ b/src/autofit/afindic.c
@@ -97,26 +97,10 @@
   /*************************************************************************/
 
 
-  static const AF_Script_UniRangeRec  af_indic_uniranges[] =
-  {
-#if 0
-    AF_UNIRANGE_REC( 0x0100UL, 0xFFFFUL ),  /* why this? */
-#endif
-    AF_UNIRANGE_REC( 0x0900UL, 0x0DFFUL),    /* Indic Range */
-    AF_UNIRANGE_REC( 0x0F00UL, 0x0FFFUL),    /* Tibetan */
-    AF_UNIRANGE_REC( 0x1900UL, 0x194FUL),    /* Limbu */
-    AF_UNIRANGE_REC( 0x1B80UL, 0x1BBFUL),    /* Sundanese */
-    AF_UNIRANGE_REC( 0x1C80UL, 0x1CDFUL),    /* Meetei Mayak */
-    AF_UNIRANGE_REC( 0xA800UL, 0xA82FUL),    /* Syloti Nagri */
-    AF_UNIRANGE_REC( 0x11800UL, 0x118DFUL),  /* Sharada */
-    AF_UNIRANGE_REC(      0UL,      0UL)
-  };
-
+  AF_DEFINE_WRITING_SYSTEM_CLASS(
+    af_indic_writing_system_class,
 
-  AF_DEFINE_SCRIPT_CLASS( af_indic_script_class,
-    AF_SCRIPT_INDIC,
-    af_indic_uniranges,
-    'o', /* XXX */
+    AF_WRITING_SYSTEM_INDIC,
 
     sizeof ( AF_CJKMetricsRec ),
 
@@ -128,18 +112,28 @@
     (AF_Script_ApplyHintsFunc)  af_indic_hints_apply
   )
 
-#else /* !AF_CONFIG_OPTION_INDIC */
+  /* XXX: this should probably fine tuned to differentiate better between */
+  /*      scripts...                                                      */
 
-  static const AF_Script_UniRangeRec  af_indic_uniranges[] =
+  static const AF_Script_UniRangeRec  af_deva_uniranges[] =
   {
-    { 0, 0 }
+    AF_UNIRANGE_REC(  0x0900UL,  0x0DFFUL ),  /* Indic Range  */
+    AF_UNIRANGE_REC(  0x0F00UL,  0x0FFFUL ),  /* Tibetan      */
+    AF_UNIRANGE_REC(  0x1900UL,  0x194FUL ),  /* Limbu        */
+    AF_UNIRANGE_REC(  0x1B80UL,  0x1BBFUL ),  /* Sundanese    */
+    AF_UNIRANGE_REC(  0x1C80UL,  0x1CDFUL ),  /* Meetei Mayak */
+    AF_UNIRANGE_REC(  0xA800UL,  0xA82FUL ),  /* Syloti Nagri */
+    AF_UNIRANGE_REC( 0x11800UL, 0x118DFUL ),  /* Sharada      */
+    AF_UNIRANGE_REC(       0UL,       0UL )
   };
 
 
-  AF_DEFINE_SCRIPT_CLASS( af_indic_script_class,
-    AF_SCRIPT_INDIC,
-    af_indic_uniranges,
-    0,
+#else /* !AF_CONFIG_OPTION_INDIC */
+
+  AF_DEFINE_WRITING_SYSTEM_CLASS(
+    af_indic_writing_system_class,
+
+    AF_WRITING_SYSTEM_INDIC,
 
     sizeof ( AF_CJKMetricsRec ),
 
@@ -151,7 +145,24 @@
     (AF_Script_ApplyHintsFunc)  NULL
   )
 
+
+  static const AF_Script_UniRangeRec  af_deva_uniranges[] =
+  {
+    AF_UNIRANGE_REC( 0UL, 0UL )
+  };
+
 #endif /* !AF_CONFIG_OPTION_INDIC */
 
 
+  AF_DEFINE_SCRIPT_CLASS(
+    af_deva_script_class,
+
+    AF_SCRIPT_DEVA,
+    AF_WRITING_SYSTEM_INDIC,
+
+    af_deva_uniranges,
+    'o' /* XXX */
+  )
+
+
 /* END */
diff --git a/src/autofit/afindic.h b/src/autofit/afindic.h
index c252cf2..db38e96 100644
--- a/src/autofit/afindic.h
+++ b/src/autofit/afindic.h
@@ -4,7 +4,7 @@
 /*                                                                         */
 /*    Auto-fitter hinting routines for Indic scripts (specification).      */
 /*                                                                         */
-/*  Copyright 2007, 2012 by                                                */
+/*  Copyright 2007, 2012, 2013 by                                          */
 /*  Rahul Bhalerao <rahul.bhalerao@redhat.com>, <b.rahul.pm@gmail.com>.    */
 /*                                                                         */
 /*  This file is part of the FreeType project, and may only be used,       */
@@ -25,9 +25,14 @@
 FT_BEGIN_HEADER
 
 
-  /* the Indic-specific script class */
+  /* the `indic' writing system */
 
-  AF_DECLARE_SCRIPT_CLASS( af_indic_script_class )
+  AF_DECLARE_WRITING_SYSTEM_CLASS( af_indic_writing_system_class )
+
+
+  /* the indic-specific script classes */
+
+  AF_DECLARE_SCRIPT_CLASS( af_deva_script_class )
 
 
 /* */
diff --git a/src/autofit/aflatin.c b/src/autofit/aflatin.c
index 4488348..b7f1a09 100644
--- a/src/autofit/aflatin.c
+++ b/src/autofit/aflatin.c
@@ -2448,10 +2448,26 @@
   /*************************************************************************/
 
 
+  AF_DEFINE_WRITING_SYSTEM_CLASS(
+    af_latin_writing_system_class,
+
+    AF_WRITING_SYSTEM_LATIN,
+
+    sizeof ( AF_LatinMetricsRec ),
+
+    (AF_Script_InitMetricsFunc) af_latin_metrics_init,
+    (AF_Script_ScaleMetricsFunc)af_latin_metrics_scale,
+    (AF_Script_DoneMetricsFunc) NULL,
+
+    (AF_Script_InitHintsFunc)   af_latin_hints_init,
+    (AF_Script_ApplyHintsFunc)  af_latin_hints_apply
+  )
+
+
   /* XXX: this should probably fine tuned to differentiate better between */
   /*      scripts...                                                      */
 
-  static const AF_Script_UniRangeRec  af_latin_uniranges[] =
+  static const AF_Script_UniRangeRec  af_latn_uniranges[] =
   {
     AF_UNIRANGE_REC(  0x0020UL,  0x007FUL ),  /* Basic Latin (no control chars) */
     AF_UNIRANGE_REC(  0x00A0UL,  0x00FFUL ),  /* Latin-1 Supplement (no control chars) */
@@ -2485,19 +2501,14 @@
   };
 
 
-  AF_DEFINE_SCRIPT_CLASS( af_latin_script_class,
-    AF_SCRIPT_LATIN,
-    af_latin_uniranges,
-    'o',
-
-    sizeof ( AF_LatinMetricsRec ),
+  AF_DEFINE_SCRIPT_CLASS(
+    af_latn_script_class,
 
-    (AF_Script_InitMetricsFunc) af_latin_metrics_init,
-    (AF_Script_ScaleMetricsFunc)af_latin_metrics_scale,
-    (AF_Script_DoneMetricsFunc) NULL,
+    AF_SCRIPT_LATN,
+    AF_WRITING_SYSTEM_LATIN,
 
-    (AF_Script_InitHintsFunc)   af_latin_hints_init,
-    (AF_Script_ApplyHintsFunc)  af_latin_hints_apply
+    af_latn_uniranges,
+    'o'
   )
 
 
diff --git a/src/autofit/aflatin.h b/src/autofit/aflatin.h
index d9170b3..07c3141 100644
--- a/src/autofit/aflatin.h
+++ b/src/autofit/aflatin.h
@@ -4,7 +4,7 @@
 /*                                                                         */
 /*    Auto-fitter hinting routines for latin script (specification).       */
 /*                                                                         */
-/*  Copyright 2003-2007, 2009, 2011-2012 by                                */
+/*  Copyright 2003-2007, 2009, 2011-2013 by                                */
 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
 /*                                                                         */
 /*  This file is part of the FreeType project, and may only be used,       */
@@ -24,10 +24,20 @@
 
 FT_BEGIN_HEADER
 
+  /* the `latin' writing system */
 
-  /* the latin-specific script class */
+  AF_DECLARE_WRITING_SYSTEM_CLASS( af_latin_writing_system_class )
 
-  AF_DECLARE_SCRIPT_CLASS( af_latin_script_class )
+
+  /* the latin-specific script classes */
+
+  AF_DECLARE_SCRIPT_CLASS( af_latn_script_class )  /* XXX */
+#if 0
+  AF_DECLARE_SCRIPT_CLASS( af_armn_script_class )
+  AF_DECLARE_SCRIPT_CLASS( af_cyrl_script_class )
+  AF_DECLARE_SCRIPT_CLASS( af_grek_script_class )
+  AF_DECLARE_SCRIPT_CLASS( af_hebr_script_class )
+#endif
 
 
   /* constants are given with units_per_em == 2048 in mind */
diff --git a/src/autofit/aflatin2.c b/src/autofit/aflatin2.c
index 0544301..cea3fdb 100644
--- a/src/autofit/aflatin2.c
+++ b/src/autofit/aflatin2.c
@@ -2380,18 +2380,10 @@
   /*************************************************************************/
 
 
-  static const AF_Script_UniRangeRec  af_latin2_uniranges[] =
-  {
-    AF_UNIRANGE_REC( 32UL,  127UL ),    /* TODO: Add new Unicode ranges here! */
-    AF_UNIRANGE_REC( 160UL, 255UL ),
-    AF_UNIRANGE_REC( 0UL,   0UL )
-  };
+  AF_DEFINE_WRITING_SYSTEM_CLASS(
+    af_latin2_writing_system_class,
 
-
-  AF_DEFINE_SCRIPT_CLASS( af_latin2_script_class,
-    AF_SCRIPT_LATIN2,
-    af_latin2_uniranges,
-    'o',
+    AF_WRITING_SYSTEM_LATIN2,
 
     sizeof ( AF_LatinMetricsRec ),
 
@@ -2404,4 +2396,52 @@
   )
 
 
+  /* XXX: this should probably fine tuned to differentiate better between */
+  /*      scripts...                                                      */
+
+  static const AF_Script_UniRangeRec  af_ltn2_uniranges[] =
+  {
+    AF_UNIRANGE_REC(  0x0020UL,  0x007FUL ),  /* Basic Latin (no control chars) */
+    AF_UNIRANGE_REC(  0x00A0UL,  0x00FFUL ),  /* Latin-1 Supplement (no control chars) */
+    AF_UNIRANGE_REC(  0x0100UL,  0x017FUL ),  /* Latin Extended-A */
+    AF_UNIRANGE_REC(  0x0180UL,  0x024FUL ),  /* Latin Extended-B */
+    AF_UNIRANGE_REC(  0x0250UL,  0x02AFUL ),  /* IPA Extensions */
+    AF_UNIRANGE_REC(  0x02B0UL,  0x02FFUL ),  /* Spacing Modifier Letters */
+    AF_UNIRANGE_REC(  0x0300UL,  0x036FUL ),  /* Combining Diacritical Marks */
+    AF_UNIRANGE_REC(  0x0370UL,  0x03FFUL ),  /* Greek and Coptic */
+    AF_UNIRANGE_REC(  0x0400UL,  0x04FFUL ),  /* Cyrillic */
+    AF_UNIRANGE_REC(  0x0500UL,  0x052FUL ),  /* Cyrillic Supplement */
+    AF_UNIRANGE_REC(  0x1D00UL,  0x1D7FUL ),  /* Phonetic Extensions */
+    AF_UNIRANGE_REC(  0x1D80UL,  0x1DBFUL ),  /* Phonetic Extensions Supplement */
+    AF_UNIRANGE_REC(  0x1DC0UL,  0x1DFFUL ),  /* Combining Diacritical Marks Supplement */
+    AF_UNIRANGE_REC(  0x1E00UL,  0x1EFFUL ),  /* Latin Extended Additional */
+    AF_UNIRANGE_REC(  0x1F00UL,  0x1FFFUL ),  /* Greek Extended */
+    AF_UNIRANGE_REC(  0x2000UL,  0x206FUL ),  /* General Punctuation */
+    AF_UNIRANGE_REC(  0x2070UL,  0x209FUL ),  /* Superscripts and Subscripts */
+    AF_UNIRANGE_REC(  0x20A0UL,  0x20CFUL ),  /* Currency Symbols */
+    AF_UNIRANGE_REC(  0x2150UL,  0x218FUL ),  /* Number Forms */
+    AF_UNIRANGE_REC(  0x2460UL,  0x24FFUL ),  /* Enclosed Alphanumerics */
+    AF_UNIRANGE_REC(  0x2C60UL,  0x2C7FUL ),  /* Latin Extended-C */
+    AF_UNIRANGE_REC(  0x2DE0UL,  0x2DFFUL ),  /* Cyrillic Extended-A */
+    AF_UNIRANGE_REC(  0x2E00UL,  0x2E7FUL ),  /* Supplemental Punctuation */
+    AF_UNIRANGE_REC(  0xA640UL,  0xA69FUL ),  /* Cyrillic Extended-B */
+    AF_UNIRANGE_REC(  0xA720UL,  0xA7FFUL ),  /* Latin Extended-D */
+    AF_UNIRANGE_REC(  0xFB00UL,  0xFB06UL ),  /* Alphab. Present. Forms (Latin Ligs) */
+    AF_UNIRANGE_REC( 0x1D400UL, 0x1D7FFUL ),  /* Mathematical Alphanumeric Symbols */
+    AF_UNIRANGE_REC( 0x1F100UL, 0x1F1FFUL ),  /* Enclosed Alphanumeric Supplement */
+    AF_UNIRANGE_REC(       0UL,       0UL )
+  };
+
+
+  AF_DEFINE_SCRIPT_CLASS(
+    af_ltn2_script_class,
+
+    AF_SCRIPT_LTN2,
+    AF_WRITING_SYSTEM_LATIN2,
+
+    af_ltn2_uniranges,
+    'o'
+  )
+
+
 /* END */
diff --git a/src/autofit/aflatin2.h b/src/autofit/aflatin2.h
index cbfa395..f7f6d8d 100644
--- a/src/autofit/aflatin2.h
+++ b/src/autofit/aflatin2.h
@@ -4,7 +4,7 @@
 /*                                                                         */
 /*    Auto-fitter hinting routines for latin script (specification).       */
 /*                                                                         */
-/*  Copyright 2003-2007, 2012 by                                           */
+/*  Copyright 2003-2007, 2012, 2013 by                                     */
 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
 /*                                                                         */
 /*  This file is part of the FreeType project, and may only be used,       */
@@ -25,9 +25,21 @@
 FT_BEGIN_HEADER
 
 
-  /* the latin-specific script class */
+  /* the `latin' writing system */
+
+  AF_DECLARE_WRITING_SYSTEM_CLASS( af_latin2_writing_system_class )
+
+
+  /* the latin-specific script classes */
+
+  AF_DECLARE_SCRIPT_CLASS( af_ltn2_script_class )  /* XXX */
+#if 0
+  AF_DECLARE_SCRIPT_CLASS( af_arm2_script_class )
+  AF_DECLARE_SCRIPT_CLASS( af_cyr2_script_class )
+  AF_DECLARE_SCRIPT_CLASS( af_grk2_script_class )
+  AF_DECLARE_SCRIPT_CLASS( af_hbr2_script_class )
+#endif
 
-  AF_DECLARE_SCRIPT_CLASS( af_latin2_script_class )
 
 /* */
 
diff --git a/src/autofit/afloader.c b/src/autofit/afloader.c
index 1ce5a98..fa5a4c4 100644
--- a/src/autofit/afloader.c
+++ b/src/autofit/afloader.c
@@ -180,10 +180,20 @@
 
       /* now load the slot image into the auto-outline and run the */
       /* automatic hinting process                                 */
-      if ( metrics->script_class->script_hints_apply )
-        metrics->script_class->script_hints_apply( hints,
-                                                   &gloader->current.outline,
-                                                   metrics );
+      {
+#ifdef FT_CONFIG_OPTION_PIC
+        AF_FaceGlobals         globals              = loader->globals;
+#endif
+        AF_WritingSystemClass  writing_system_class =
+                                 AF_WRITING_SYSTEM_CLASSES_GET
+                                   [metrics->script_class->writing_system];
+
+
+        if ( writing_system_class->script_hints_apply )
+          writing_system_class->script_hints_apply( hints,
+                                                    &gloader->current.outline,
+                                                    metrics );
+      }
 
       /* we now need to adjust the metrics according to the change in */
       /* width/positioning that occurred during the hinting process   */
@@ -519,33 +529,41 @@
     if ( !error )
     {
       AF_ScriptMetrics  metrics;
-      FT_UInt           options = 0;
+      FT_UInt           options = AF_SCRIPT_DFLT;
 
 
 #ifdef FT_OPTION_AUTOFIT2
-      /* XXX: undocumented hook to activate the latin2 hinter */
+      /* XXX: undocumented hook to activate the latin2 writing system */
       if ( load_flags & ( 1UL << 20 ) )
-        options = 2;
+        options = AF_SCRIPT_LTN2;
 #endif
 
       error = af_face_globals_get_metrics( loader->globals, gindex,
                                            options, &metrics );
       if ( !error )
       {
+#ifdef FT_CONFIG_OPTION_PIC
+        AF_FaceGlobals         globals              = loader->globals;
+#endif
+        AF_WritingSystemClass  writing_system_class =
+                                 AF_WRITING_SYSTEM_CLASSES_GET
+                                   [metrics->script_class->writing_system];
+
+
         loader->metrics = metrics;
 
-        if ( metrics->script_class->script_metrics_scale )
-          metrics->script_class->script_metrics_scale( metrics, &scaler );
+        if ( writing_system_class->script_metrics_scale )
+          writing_system_class->script_metrics_scale( metrics, &scaler );
         else
           metrics->scaler = scaler;
 
         load_flags |=  FT_LOAD_NO_SCALE | FT_LOAD_IGNORE_TRANSFORM;
         load_flags &= ~FT_LOAD_RENDER;
 
-        if ( metrics->script_class->script_hints_init )
+        if ( writing_system_class->script_hints_init )
         {
-          error = metrics->script_class->script_hints_init( &loader->hints,
-                                                            metrics );
+          error = writing_system_class->script_hints_init( &loader->hints,
+                                                           metrics );
           if ( error )
             goto Exit;
         }
diff --git a/src/autofit/afpic.c b/src/autofit/afpic.c
index 45e1448..f19dfd2 100644
--- a/src/autofit/afpic.c
+++ b/src/autofit/afpic.c
@@ -100,27 +100,47 @@
 
     FT_Init_Class_af_service_properties( &container->af_service_properties );
 
-    for ( ss = 0 ; ss < AF_SCRIPT_CLASSES_REC_COUNT ; ss++ )
-    {
+    for ( ss = 0; ss < AF_WRITING_SYSTEM_CLASSES_REC_COUNT; ss++ )
+      container->af_writing_system_classes[ss] =
+        &container->af_writing_system_classes_rec[ss];
+    container->af_writing_system_classes
+      [AF_WRITING_SYSTEM_CLASSES_COUNT - 1] = NULL;
+
+    for ( ss = 0; ss < AF_SCRIPT_CLASSES_REC_COUNT; ss++ )
       container->af_script_classes[ss] =
         &container->af_script_classes_rec[ss];
-    }
-    container->af_script_classes[AF_SCRIPT_CLASSES_COUNT - 1] = NULL;
+    container->af_script_classes
+      [AF_SCRIPT_CLASSES_COUNT - 1] = NULL;
 
     /* add call to initialization function when you add new scripts */
+    /* or writing systems                                           */
     ss = 0;
-    FT_Init_Class_af_dummy_script_class(
-      &container->af_script_classes_rec[ss++] );
+    FT_Init_Class_af_dummy_writing_system_class(
+      &container->af_writing_system_classes_rec[ss++] );
+    FT_Init_Class_af_latin_writing_system_class(
+      &container->af_writing_system_classes_rec[ss++] );
+    FT_Init_Class_af_cjk_writing_system_class(
+      &container->af_writing_system_classes_rec[ss++] );
+    FT_Init_Class_af_indic_writing_system_class(
+      &container->af_writing_system_classes_rec[ss++] );
 #ifdef FT_OPTION_AUTOFIT2
-    FT_Init_Class_af_latin2_script_class(
-      &container->af_script_classes_rec[ss++] );
+    FT_Init_Class_af_latin2_writing_system_class(
+      &container->af_writing_system_classes_rec[ss++] );
 #endif
-    FT_Init_Class_af_latin_script_class(
+
+    ss = 0;
+    FT_Init_Class_af_dflt_script_class(
+      &container->af_script_classes_rec[ss++] );
+    FT_Init_Class_af_latn_script_class(
       &container->af_script_classes_rec[ss++] );
-    FT_Init_Class_af_cjk_script_class(
+    FT_Init_Class_af_hani_script_class(
       &container->af_script_classes_rec[ss++] );
-    FT_Init_Class_af_indic_script_class(
+    FT_Init_Class_af_deva_script_class(
       &container->af_script_classes_rec[ss++] );
+#ifdef FT_OPTION_AUTOFIT2
+    FT_Init_Class_af_ltn2_script_class(
+      &container->af_script_classes_rec[ss++] );
+#endif
 
     FT_Init_Class_af_autofitter_interface(
       library, &container->af_autofitter_interface );
diff --git a/src/autofit/afpic.h b/src/autofit/afpic.h
index 0acf803..22b0abe 100644
--- a/src/autofit/afpic.h
+++ b/src/autofit/afpic.h
@@ -4,7 +4,7 @@
 /*                                                                         */
 /*    The FreeType position independent code services for autofit module.  */
 /*                                                                         */
-/*  Copyright 2009, 2011-2012 by                                           */
+/*  Copyright 2009, 2011-2013 by                                           */
 /*  Oran Agra and Mickey Gabel.                                            */
 /*                                                                         */
 /*  This file is part of the FreeType project, and may only be used,       */
@@ -27,11 +27,12 @@ FT_BEGIN_HEADER
 
 #ifndef FT_CONFIG_OPTION_PIC
 
-#define AF_SERVICES_GET            af_services
-#define AF_SERVICE_PROPERTIES_GET  af_service_properties
+#define AF_SERVICES_GET                af_services
+#define AF_SERVICE_PROPERTIES_GET      af_service_properties
 
-#define AF_SCRIPT_CLASSES_GET      af_script_classes
-#define AF_INTERFACE_GET           af_autofitter_interface
+#define AF_WRITING_SYSTEM_CLASSES_GET  af_writing_system_classes
+#define AF_SCRIPT_CLASSES_GET          af_script_classes
+#define AF_INTERFACE_GET               af_autofitter_interface
 
 #else /* FT_CONFIG_OPTION_PIC */
 
@@ -40,15 +41,20 @@ FT_BEGIN_HEADER
 
 #include "aftypes.h"
 
-  /* increase these when you add new scripts, */
-  /* and update autofit_module_class_pic_init */
+  /* increase these when you add new scripts or writing systems, */
+  /* and update autofit_module_class_pic_init                    */
 #ifdef FT_OPTION_AUTOFIT2
-#define AF_SCRIPT_CLASSES_COUNT  6
+#define AF_WRITING_SYSTEM_CLASSES_COUNT  6
+#define AF_SCRIPT_CLASSES_COUNT          6
 #else
-#define AF_SCRIPT_CLASSES_COUNT  5
+#define AF_WRITING_SYSTEM_CLASSES_COUNT  5
+#define AF_SCRIPT_CLASSES_COUNT          5
 #endif
 
-#define AF_SCRIPT_CLASSES_REC_COUNT  ( AF_SCRIPT_CLASSES_COUNT - 1 )
+#define AF_SCRIPT_CLASSES_REC_COUNT  \
+          ( AF_SCRIPT_CLASSES_COUNT - 1 )
+#define AF_WRITING_SYSTEM_CLASSES_REC_COUNT  \
+          ( AF_WRITING_SYSTEM_CLASSES_COUNT - 1 )
 
 
   typedef struct  AFModulePIC_
@@ -56,8 +62,16 @@ FT_BEGIN_HEADER
     FT_ServiceDescRec*          af_services;
     FT_Service_PropertiesRec    af_service_properties;
 
-    AF_ScriptClass              af_script_classes[AF_SCRIPT_CLASSES_COUNT];
-    AF_ScriptClassRec           af_script_classes_rec[AF_SCRIPT_CLASSES_REC_COUNT];
+    AF_WritingSystemClass       af_writing_system_classes
+                                  [AF_WRITING_SYSTEM_CLASSES_COUNT];
+    AF_WritingSystemClassRec    af_writing_system_classes_rec
+                                  [AF_WRITING_SYSTEM_CLASSES_REC_COUNT];
+
+    AF_ScriptClass              af_script_classes
+                                  [AF_SCRIPT_CLASSES_COUNT];
+    AF_ScriptClassRec           af_script_classes_rec
+                                  [AF_SCRIPT_CLASSES_REC_COUNT];
+
     FT_AutoHinter_InterfaceRec  af_autofitter_interface;
 
   } AFModulePIC;
@@ -71,6 +85,8 @@ FT_BEGIN_HEADER
 #define AF_SERVICE_PROPERTIES_GET  \
           ( GET_PIC( library )->af_service_properties )
 
+#define AF_WRITING_SYSTEM_CLASSES_GET  \
+          ( GET_PIC( FT_FACE_LIBRARY( globals->face ) )->af_writing_system_classes )
 #define AF_SCRIPT_CLASSES_GET  \
           ( GET_PIC( FT_FACE_LIBRARY( globals->face ) )->af_script_classes )
 #define AF_INTERFACE_GET  \
diff --git a/src/autofit/aftypes.h b/src/autofit/aftypes.h
index cc415ee..85f0feb 100644
--- a/src/autofit/aftypes.h
+++ b/src/autofit/aftypes.h
@@ -4,7 +4,7 @@
 /*                                                                         */
 /*    Auto-fitter types (specification only).                              */
 /*                                                                         */
-/*  Copyright 2003-2009, 2011-2012 by                                      */
+/*  Copyright 2003-2009, 2011-2013 by                                      */
 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
 /*                                                                         */
 /*  This file is part of the FreeType project, and may only be used,       */
@@ -20,15 +20,12 @@
    *
    *  The auto-fitter is a complete rewrite of the old auto-hinter.
    *  Its main feature is the ability to differentiate between different
-   *  scripts in order to apply language-specific rules.
+   *  writing systems in order to apply script-specific rules.
    *
    *  The code has also been compartmentized into several entities that
    *  should make algorithmic experimentation easier than with the old
    *  code.
    *
-   *  Finally, we get rid of the Catharon license, since this code is
-   *  released under the FreeType one.
-   *
    *************************************************************************/
 
 
@@ -201,52 +198,17 @@ extern void*  _af_debug_hints;
   /*************************************************************************/
   /*************************************************************************/
   /*****                                                               *****/
-  /*****                       S C R I P T S                           *****/
+  /*****                 S C R I P T   M E T R I C S                   *****/
   /*****                                                               *****/
   /*************************************************************************/
   /*************************************************************************/
 
-  /*
-   *  The list of known scripts.  Each different script corresponds to the
-   *  following information:
-   *
-   *   - A set of Unicode ranges to test whether the face supports the
-   *     script.
-   *
-   *   - A specific global analyzer that will compute global metrics
-   *     specific to the script.
-   *
-   *   - A specific glyph analyzer that will compute segments and
-   *     edges for each glyph covered by the script.
-   *
-   *   - A specific grid-fitting algorithm that will distort the
-   *     scaled glyph outline according to the results of the glyph
-   *     analyzer.
-   *
-   *  Note that a given analyzer and/or grid-fitting algorithm can be
-   *  used by more than one script.
-   */
+  /* This is the main structure which combines writing systems and script */
+  /* data (for a given face object, see below).                           */
 
-  typedef enum  AF_Script_
-  {
-    AF_SCRIPT_DUMMY = 0,
-    AF_SCRIPT_LATIN = 1,
-    AF_SCRIPT_CJK   = 2,
-    AF_SCRIPT_INDIC = 3,
-#ifdef FT_OPTION_AUTOFIT2
-    AF_SCRIPT_LATIN2 = 4,
-#endif
-
-    /* add new scripts here.  Don't forget to update the list in */
-    /* `afglobal.c'.                                             */
-
-    AF_SCRIPT_MAX   /* do not remove */
-
-  } AF_Script;
-
-
-  typedef struct AF_ScriptClassRec_ const*  AF_ScriptClass;
-  typedef struct AF_FaceGlobalsRec_*        AF_FaceGlobals;
+  typedef struct AF_WritingSystemClassRec_ const*  AF_WritingSystemClass;
+  typedef struct AF_ScriptClassRec_ const*         AF_ScriptClass;
+  typedef struct AF_FaceGlobalsRec_*               AF_FaceGlobals;
 
   typedef struct  AF_ScriptMetricsRec_
   {
@@ -284,23 +246,55 @@ extern void*  _af_debug_hints;
                                AF_ScriptMetrics  metrics );
 
 
-  typedef struct  AF_Script_UniRangeRec_
+  /*************************************************************************/
+  /*************************************************************************/
+  /*****                                                               *****/
+  /*****                W R I T I N G   S Y S T E M S                  *****/
+  /*****                                                               *****/
+  /*************************************************************************/
+  /*************************************************************************/
+
+  /*
+   *  In FreeType, a writing system consists of multiple scripts which can
+   *  be handled similarly *in a typographical way*; the relationship is not
+   *  based on history.  For example, both the Greek and the unrelated
+   *  Armenian scripts share the same features like ascender, descender,
+   *  x-height, etc.  Essentially, a writing system is covered by a
+   *  submodule of the auto-fitter; it contains
+   *
+   *  - a specific global analyzer which computes global metrics specific to
+   *    the script (based on script-specific characters to identify ascender
+   *    height, x-height, etc.),
+   *
+   *  - a specific glyph analyzer that computes segments and edges for each
+   *    glyph covered by the script,
+   *
+   *  - a specific grid-fitting algorithm that distorts the scaled glyph
+   *    outline according to the results of the glyph analyzer.
+   */
+
+  /* The list of known writing systems. */
+  typedef enum  AF_WritingSystem_
   {
-    FT_UInt32  first;
-    FT_UInt32  last;
+    AF_WRITING_SYSTEM_DUMMY = 0,
+    AF_WRITING_SYSTEM_LATIN = 1,
+    AF_WRITING_SYSTEM_CJK   = 2,
+    AF_WRITING_SYSTEM_INDIC = 3,
+#ifdef FT_OPTION_AUTOFIT2
+    AF_WRITING_SYSTEM_LATIN2 = 4,
+#endif
 
-  } AF_Script_UniRangeRec;
+    /* Add new writing systems here.  Don't forget to update */
+    /* the list in `afglobal.c'.                             */
 
-#define AF_UNIRANGE_REC( a, b ) { (FT_UInt32)(a), (FT_UInt32)(b) }
+    AF_WRITING_SYSTEM_MAX   /* do not remove */
 
-  typedef const AF_Script_UniRangeRec  *AF_Script_UniRange;
+  } AF_WritingSystem;
 
 
-  typedef struct  AF_ScriptClassRec_
+  typedef struct  AF_WritingSystemClassRec_
   {
-    AF_Script           script;
-    AF_Script_UniRange  script_uni_ranges; /* last must be { 0, 0 }        */
-    FT_UInt32           standard_char;     /* for default width and height */
+    AF_WritingSystem  writing_system;
 
     FT_Offset                   script_metrics_size;
     AF_Script_InitMetricsFunc   script_metrics_init;
@@ -310,59 +304,166 @@ extern void*  _af_debug_hints;
     AF_Script_InitHintsFunc     script_hints_init;
     AF_Script_ApplyHintsFunc    script_hints_apply;
 
+  } AF_WritingSystemClassRec;
+
+
+  /*************************************************************************/
+  /*************************************************************************/
+  /*****                                                               *****/
+  /*****                        S C R I P T S                          *****/
+  /*****                                                               *****/
+  /*************************************************************************/
+  /*************************************************************************/
+
+  /*
+   *  Each script is associated with a set of Unicode ranges which gets used
+   *  to test whether the font face supports the script.  It also references
+   *  the writing system it belongs to.
+   *
+   *  We use four-letter script tags from the OpenType specification.
+   */
+
+  /* The list of known scripts. */
+  typedef enum  AF_Script_
+  {
+    AF_SCRIPT_DFLT = 0,
+    AF_SCRIPT_LATN = 1,
+    AF_SCRIPT_HANI = 2,
+    AF_SCRIPT_DEVA = 3,
+#ifdef FT_OPTION_AUTOFIT2
+    AF_SCRIPT_LTN2 = 4,
+#endif
+
+    /* Add new scripts here.  Don't forget to update */
+    /* the list in `afglobal.c'.                     */
+
+    AF_SCRIPT_MAX   /* do not remove */
+
+  } AF_Script;
+
+
+  typedef struct  AF_Script_UniRangeRec_
+  {
+    FT_UInt32  first;
+    FT_UInt32  last;
+
+  } AF_Script_UniRangeRec;
+
+#define AF_UNIRANGE_REC( a, b ) { (FT_UInt32)(a), (FT_UInt32)(b) }
+
+  typedef const AF_Script_UniRangeRec*  AF_Script_UniRange;
+
+
+  typedef struct  AF_ScriptClassRec_
+  {
+    AF_Script         script;
+    AF_WritingSystem  writing_system;
+
+    AF_Script_UniRange  script_uni_ranges; /* last must be { 0, 0 }        */
+    FT_UInt32           standard_char;     /* for default width and height */
+
   } AF_ScriptClassRec;
 
 
   /* Declare and define vtables for classes */
 #ifndef FT_CONFIG_OPTION_PIC
 
+#define AF_DECLARE_WRITING_SYSTEM_CLASS( writing_system_class ) \
+  FT_CALLBACK_TABLE const AF_WritingSystemClassRec              \
+  writing_system_class;
+
+#define AF_DEFINE_WRITING_SYSTEM_CLASS(                  \
+          writing_system_class,                          \
+          system,                                        \
+          m_size,                                        \
+          m_init,                                        \
+          m_scale,                                       \
+          m_done,                                        \
+          h_init,                                        \
+          h_apply )                                      \
+  FT_CALLBACK_TABLE_DEF                                  \
+  const AF_WritingSystemClassRec  writing_system_class = \
+  {                                                      \
+    system,                                              \
+                                                         \
+    m_size,                                              \
+                                                         \
+    m_init,                                              \
+    m_scale,                                             \
+    m_done,                                              \
+                                                         \
+    h_init,                                              \
+    h_apply                                              \
+  };
+
+
 #define AF_DECLARE_SCRIPT_CLASS( script_class ) \
   FT_CALLBACK_TABLE const AF_ScriptClassRec     \
   script_class;
 
-#define AF_DEFINE_SCRIPT_CLASS( script_class, script_, ranges, def_char,   \
-                                m_size,                                    \
-                                m_init, m_scale, m_done, h_init, h_apply ) \
-  FT_CALLBACK_TABLE_DEF const AF_ScriptClassRec  script_class =            \
-  {                                                                        \
-    script_,                                                               \
-    ranges,                                                                \
-    def_char,                                                              \
-                                                                           \
-    m_size,                                                                \
-                                                                           \
-    m_init,                                                                \
-    m_scale,                                                               \
-    m_done,                                                                \
-                                                                           \
-    h_init,                                                                \
-    h_apply                                                                \
+#define AF_DEFINE_SCRIPT_CLASS(           \
+          script_class,                   \
+          script_,                        \
+          writing_system_,                \
+          ranges,                         \
+          std_char )                      \
+  FT_CALLBACK_TABLE_DEF                   \
+  const AF_ScriptClassRec  script_class = \
+  {                                       \
+    script_,                              \
+    writing_system_,                      \
+    ranges,                               \
+    std_char                              \
   };
 
 #else /* FT_CONFIG_OPTION_PIC */
 
+#define AF_DECLARE_WRITING_SYSTEM_CLASS( writing_system_class )            \
+  FT_LOCAL( void )                                                         \
+  FT_Init_Class_ ## writing_system_class( AF_WritingSystemClassRec*  ac );
+
+#define AF_DEFINE_WRITING_SYSTEM_CLASS(                                   \
+          writing_system_class,                                           \
+          system,                                                         \
+          m_size,                                                         \
+          m_init,                                                         \
+          m_scale,                                                        \
+          m_done,                                                         \
+          h_init,                                                         \
+          h_apply )                                                       \
+  FT_LOCAL_DEF( void )                                                    \
+  FT_Init_Class_ ## writing_system_class( AF_WritingSystemClassRec*  ac ) \
+  {                                                                       \
+    ac->writing_system       = system;                                    \
+                                                                          \
+    ac->script_metrics_size  = m_size;                                    \
+                                                                          \
+    ac->script_metrics_init  = m_init;                                    \
+    ac->script_metrics_scale = m_scale;                                   \
+    ac->script_metrics_done  = m_done;                                    \
+                                                                          \
+    ac->script_hints_init    = h_init;                                    \
+    ac->script_hints_apply   = h_apply;                                   \
+  }
+
+
 #define AF_DECLARE_SCRIPT_CLASS( script_class )             \
   FT_LOCAL( void )                                          \
   FT_Init_Class_ ## script_class( AF_ScriptClassRec*  ac );
 
-#define AF_DEFINE_SCRIPT_CLASS( script_class, script_, ranges, def_char,   \
-                                m_size,                                    \
-                                m_init, m_scale, m_done, h_init, h_apply ) \
-  FT_LOCAL_DEF( void )                                                     \
-  FT_Init_Class_ ## script_class( AF_ScriptClassRec*  ac )                 \
-  {                                                                        \
-    ac->script               = script_;                                    \
-    ac->script_uni_ranges    = ranges;                                     \
-    ac->default_char         = def_char;                                   \
-                                                                           \
-    ac->script_metrics_size  = m_size;                                     \
-                                                                           \
-    ac->script_metrics_init  = m_init;                                     \
-    ac->script_metrics_scale = m_scale;                                    \
-    ac->script_metrics_done  = m_done;                                     \
-                                                                           \
-    ac->script_hints_init    = h_init;                                     \
-    ac->script_hints_apply   = h_apply;                                    \
+#define AF_DEFINE_SCRIPT_CLASS(                            \
+          script_class,                                    \
+          script_,                                         \
+          writing_system_,                                 \
+          ranges,                                          \
+          std_char )                                       \
+  FT_LOCAL_DEF( void )                                     \
+  FT_Init_Class_ ## script_class( AF_ScriptClassRec*  ac ) \
+  {                                                        \
+    ac->script            = script_;                       \
+    ac->writing_system    = writing_system_;               \
+    ac->script_uni_ranges = ranges;                        \
+    ac->standard_char     = std_char;                      \
   }
 
 #endif /* FT_CONFIG_OPTION_PIC */