File: CompareFontTables.cpp

package info (click to toggle)
grcompiler 4.2-6
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 11,096 kB
  • ctags: 5,232
  • sloc: cpp: 45,565; sh: 4,451; ansic: 4,377; makefile: 188; xml: 175; perl: 127
file content (1360 lines) | stat: -rw-r--r-- 48,892 bytes parent folder | download | duplicates (4)
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
/*--------------------------------------------------------------------*//*:Ignore this sentence.
Copyright (C) 2007 SIL International. All rights reserved.

Distributable under the terms of either the Common Public License or the
GNU Lesser General Public License, as specified in the LICENSING.txt file.

File: CompareFontTables.cpp
Responsibility: Sharon Correll

Description:
    Methods to run the comparisons for the benchmark and test fonts.
-------------------------------------------------------------------------------*//*:End Ignore*/

#include "main.h"

//:>********************************************************************************************
//:>	Global variables
//:>********************************************************************************************

//:>********************************************************************************************
//:>	Functions
//:>********************************************************************************************

/*----------------------------------------------------------------------------------------------
	Compare the benchmark font against the newly created test font.
----------------------------------------------------------------------------------------------*/
int CompareFontTables(TestCase * ptcase, GrcRtFileFont * pfontBmark, GrcRtFileFont * pfontTest)
{
	bool fOk = false;

	int ec = 0; // error count

	// benchmark font buffers
	const gr::byte * pHeadTblB; const gr::byte * pCmapTblB; const gr::byte * pSileTblB; const gr::byte * pSilfTblB;
	const gr::byte * pFeatTblB; const gr::byte * pGlatTblB; const gr::byte * pGlocTblB; const gr::byte * pNameTblB; const gr::byte * pSillTblB;
	size_t cbHeadSzB, cbCmapSzB, /*cbSileSzB,*/ cbSilfSzB, cbFeatSzB, cbGlatSzB, cbGlocSzB, cbNameSzB, cbSillSzB;
	// test font buffers
	const gr::byte * pHeadTblT; const gr::byte * pCmapTblT; const gr::byte * pSileTblT; const gr::byte * pSilfTblT;
	const gr::byte * pFeatTblT; const gr::byte * pGlatTblT; const gr::byte * pGlocTblT; const gr::byte * pNameTblT; const gr::byte * pSillTblT;
	size_t cbHeadSzT, cbCmapSzT, /*cbSileSzT,*/ cbSilfSzT, cbFeatSzT, cbGlatSzT, cbGlocSzT, cbNameSzT, cbSillSzT;

	// head table
	try {
		pHeadTblB = static_cast<const gr::byte *> (pfontBmark->getTable(TtfUtil::TableIdTag(ktiHead), &cbHeadSzB));
		if (pHeadTblB == NULL)
			OutputError(ec, ptcase, "ERROR: benchmark font has empty head table");
		else
		{
			try {
				pHeadTblT = static_cast<const gr::byte *> (pfontTest->getTable(TtfUtil::TableIdTag(ktiHead), &cbHeadSzT));
				if (pHeadTblT == NULL)
					OutputError(ec, ptcase, "ERROR: test font has empty head table");
				else
				{
					if (cbHeadSzB != cbHeadSzT)
						OutputError(ec, ptcase, "ERROR: size of head tables do not match");
					if (TtfUtil::DesignUnits(pHeadTblB) != TtfUtil::DesignUnits(pHeadTblT))
						OutputError(ec, ptcase, "ERROR: design units do not match");
					if (TtfUtil::IsItalic(pHeadTblB) != TtfUtil::IsItalic(pHeadTblT))
						OutputError(ec, ptcase, "ERROR: italic flags do not match");
				}
			}
			catch (...)
			{
				OutputError(ec, ptcase, "ERROR, could not read test font head table");
				pHeadTblT = NULL;
			}
		}
	}
	catch (...)
	{
		OutputError(ec, ptcase, "ERROR: could not read benchmark font head table");
		pHeadTblB = NULL;
		pHeadTblT = NULL;
	}

	// TODO: handle Sile table.
	pSileTblB = NULL;
	pSileTblT = NULL;

	// cmap

	try {
		pCmapTblB = static_cast<const gr::byte *> (pfontBmark->getTable(TtfUtil::TableIdTag(ktiCmap), &cbCmapSzB));
		if (pCmapTblB == NULL)
			OutputError(ec, ptcase, "ERROR: benchmark font has empty cmap table");
		else
		{
			try {
				pCmapTblT = static_cast<const gr::byte *> (pfontTest->getTable(TtfUtil::TableIdTag(ktiCmap), &cbCmapSzT));
				if (pHeadTblT == NULL)
					OutputError(ec, ptcase, "ERROR: test font has empty cmap table");
				else
				{
					if (cbCmapSzB != cbCmapSzT)
						OutputError(ec, ptcase, "ERROR: size of cmap tables do not match");
					// TBD: do we need to test the contents of the cmap?
					// The Graphite compiler shouldn't be changing it.
				}
			}
			catch (...)
			{
				OutputError(ec, ptcase, "ERROR: could not read test font cmap table");
				pCmapTblT = NULL;
			}
		}
	}
	catch (...)
	{
		OutputError(ec, ptcase, "ERROR: could not read benchmark font cmap table");
		pCmapTblB = NULL;
		pCmapTblT = NULL;
	}

	// name

	// Currently the only stuff we're getting from the name table are our feature names,
	// so use the version from the Graphite font (not the base font if any).
	//////if (m_fUseSepBase)
	//////	pgg->SetupGraphics(&chrpOriginal);

	// name - need feature names later
	try {
        pNameTblB = static_cast<const gr::byte *> (pfontBmark->getTable(TtfUtil::TableIdTag(ktiName), &cbNameSzB));
		if (pNameTblB == NULL)
			OutputError(ec, ptcase, "ERROR: benchmark font has empty name table");
		else
		{
			try {
				pNameTblT = static_cast<const gr::byte *> (pfontTest->getTable(TtfUtil::TableIdTag(ktiName), &cbNameSzT));
				if (pNameTblT == NULL)
					OutputError(ec, ptcase, "ERROR: test font has empty name table");
				else
				{
					if (cbNameSzB != cbNameSzT)
						OutputError(ec, ptcase, "ERROR: size of name tables do not match");
				}
			}
			catch (...)
			{
				OutputError(ec, ptcase, "ERROR: could not read test font name table");
			}
		}
	}
	catch (...)
	{
		OutputError(ec, ptcase, "ERROR: could not read benchmark font name table");
	}

	/****
	Obtain font name from InitNew() now instead of reading from font file. InitNew should
	should have a correct font name passed to it since it should come from a font registered
	by GrFontInst.exe. This commented code could be use to verify name in font file matches.
	NOTE: if we ever use this code again, make sure we're using the base font name table,
	not the Graphite wrapper font name table.
	// find the font family name
	if (!TtfUtil::Get31EngFamilyInfo(vbName.Begin(), lnNameOff, lnNameSz))
	{	// use Name table which is Symbol encode instead
		// this could cause problems if a real Symbol writing system is used in the name table
		// however normally real Unicode values are used instead a Symbol writing system
		if (!TtfUtil::Get30EngFamilyInfo(vbName.Begin(), lnNameOff, lnNameSz))
		{
			ReturnResult(kresFail);
		}
		// test for Symbol writing system. first byte of Unicode id should be 0xF0
		if (vbName[lnNameOff + 1] == (unsigned char)0xF0) // 1 - Unicode id is big endian
			ReturnResult(kresFail);
	}
	if (!TtfUtil::SwapWString(vbName.Begin() + lnNameOff, lnNameSz / sizeof(utf16)))
		ReturnResult(kresFail);

	m_stuFaceName = std::wstring((utf16 *)(vbName.begin() + lnNameOff), lnNameSz / sizeof(utf16));
	****/

	// Silf
	try {
		if ((pSilfTblB = static_cast<const gr::byte *> (pfontBmark->getTable(TtfUtil::TableIdTag(ktiSilf), &cbSilfSzB))) == NULL)
			OutputError(ec, ptcase, "ERROR: benchmark font has empty Silf table");
		else
		{
			try {
				if ((pSilfTblT = static_cast<const gr::byte *> (pfontTest->getTable(TtfUtil::TableIdTag(ktiSilf), &cbSilfSzT))) == NULL)
					OutputError(ec, ptcase, "ERROR: test font has empty Silf table");
				else
				{
					if (cbSilfSzB != cbSilfSzT)
						OutputError(ec, ptcase, "ERROR: size of Silf tables do not match");
				}
			}
			catch (...)
			{
				OutputError(ec, ptcase, "ERROR: could not read test font Silf table");
				pSilfTblT = NULL;
			}
		}
	}
	catch (...)
	{
		OutputError(ec, ptcase, "ERROR: could not read benchmark font Silf table");
		pSilfTblB = NULL;
		pSilfTblT = NULL;
	}

	// Feat
	try {
		if ((pFeatTblB = static_cast<const gr::byte *> (pfontBmark->getTable(TtfUtil::TableIdTag(ktiFeat), &cbFeatSzB))) == NULL)
			OutputError(ec, ptcase, "ERROR: benchmark font has empty Feat table");
		else
		{
			try {
				if ((pFeatTblT = static_cast<const gr::byte *> (pfontTest->getTable(TtfUtil::TableIdTag(ktiFeat), &cbFeatSzT))) == NULL)
					OutputError(ec, ptcase, "ERROR: test font has empty Feat table");
				else
				{
					if (cbFeatSzB != cbFeatSzT)
						OutputError(ec, ptcase, "ERROR: size of Feat tables do not match");
				}
			}
			catch (...)
			{
				OutputError(ec, ptcase, "ERROR: could not read test font Feat table");
				pFeatTblT = NULL;
			}
		}
	}
	catch (...)
	{
		OutputError(ec, ptcase, "ERROR: could not read benchmark font Feat table");
		pFeatTblB = NULL;
		pFeatTblT = NULL;
	}


	// Glat
	try {
		if ((pGlatTblB = static_cast<const gr::byte *> (pfontBmark->getTable(TtfUtil::TableIdTag(ktiGlat), &cbGlatSzB))) == NULL)
			OutputError(ec, ptcase, "ERROR: benchmark font has empty Glat table");
		else
		{
			try {
				if ((pGlatTblT = static_cast<const gr::byte *> (pfontTest->getTable(TtfUtil::TableIdTag(ktiGlat), &cbGlatSzT))) == NULL)
					OutputError(ec, ptcase, "ERROR: test font has empty Glat table");
				else
				{
					if (cbGlatSzB != cbGlatSzT)
						OutputError(ec, ptcase, "ERROR: size of Glat tables do not match");
				}
			}
			catch (...)
			{
				OutputError(ec, ptcase, "ERROR: could not read test font Glat table");
				pGlocTblT = NULL;
			}
		}
	}
	catch (...)
	{
		OutputError(ec, ptcase, "ERROR: could not read benchmark font Glat table");
		pGlocTblB = NULL;
		pGlocTblT = NULL;
	}

	// Gloc
	try {
		if ((pGlocTblB = static_cast<const gr::byte *> (pfontBmark->getTable(TtfUtil::TableIdTag(ktiGloc), &cbGlocSzB))) == NULL)
			OutputError(ec, ptcase, "ERROR: benchmark font has empty Gloc table");
		else
		{
			try {
				if ((pGlocTblT = static_cast<const gr::byte *> (pfontTest->getTable(TtfUtil::TableIdTag(ktiGloc), &cbGlocSzT))) == NULL)
					OutputError(ec, ptcase, "ERROR: test font has empty Gloc table");
				else
				{
					if (cbGlatSzB != cbGlatSzT)
						OutputError(ec, ptcase, "ERROR: size of Gloc tables do not match");
				}
			}
			catch (...)
			{
				OutputError(ec, ptcase, "ERROR: could not read test font Gloc table");
				pGlatTblT = NULL;
			}
		}
	}
	catch (...)
	{
		OutputError(ec, ptcase, "ERROR: could not read benchmark font Gloc table");
		pGlatTblB = NULL;
		pGlatTblT = NULL;
	}

	// Sill
	try {
		pSillTblB = static_cast<const gr::byte *> (pfontBmark->getTable(TtfUtil::TableIdTag(ktiSill), &cbSillSzB));
		try {
			pSillTblT = static_cast<const gr::byte *> (pfontTest->getTable(TtfUtil::TableIdTag(ktiSill), &cbSillSzT));
			if (cbSillSzB != cbSillSzT)
				OutputError(ec, ptcase, "ERROR: size of Sill tables do not match");
		}
		catch (...)
		{
			OutputError(ec, ptcase, "ERROR: in attempting to read test font Sill table");
			pSillTblT = NULL;
		}
	}
	catch (...)
	{
		OutputError(ec, ptcase, "ERROR: in attempting to read benchmark font Sill table");
		pSillTblB = NULL;
		pSillTblT = NULL;
	}

	if (pSilfTblT == NULL)
		return ec;
	Assert(pSilfTblB);

	GrBufferIStream grstrmB, grstrmT;
	grstrmB.OpenBuffer((gr::byte *)pSilfTblB, cbSilfSzB);
	grstrmT.OpenBuffer((gr::byte *)pSilfTblT, cbSilfSzT);
	int chwMaxGlyphID;
	CompareSilfTables(ec, ptcase, grstrmB, grstrmT, &chwMaxGlyphID);
	grstrmB.Close();
	grstrmT.Close();

	if (chwMaxGlyphID == -1)
	{
		int ecBogus;
		OutputError(ecBogus, ptcase, "[Skipping Gloc and Glat tables since max glyph IDs do not match]");
	}
	else if (pGlatTblB && pGlocTblB && pGlatTblT && pGlocTblT)
	{
		GrBufferIStream grstrmGlatB, grstrmGlocB, grstrmGlatT, grstrmGlocT;
		grstrmGlatB.OpenBuffer((gr::byte *)pGlatTblB, cbGlatSzB);
		grstrmGlocB.OpenBuffer((gr::byte *)pGlocTblB, cbGlocSzB);
		grstrmGlatT.OpenBuffer((gr::byte *)pGlatTblT, cbGlatSzT);
		grstrmGlocT.OpenBuffer((gr::byte *)pGlocTblT, cbGlocSzT);
		CompareGlatAndGlocTables(ec, ptcase, chwMaxGlyphID, grstrmGlatB, grstrmGlocB, grstrmGlatT, grstrmGlocT);
		grstrmGlatB.Close();
		grstrmGlocB.Close();
		grstrmGlatT.Close();
		grstrmGlocT.Close();
	}

	if (pFeatTblB && pFeatTblT)
	{
		grstrmB.OpenBuffer((gr::byte *)pFeatTblB, cbFeatSzB);
		grstrmT.OpenBuffer((gr::byte *)pFeatTblT, cbFeatSzT);
		CompareFeatTables(ec, ptcase, grstrmB, grstrmT, (gr::byte*)pNameTblB, (gr::byte*)pNameTblT);
		grstrmB.Close();
		grstrmT.Close();
	}

	if (pSillTblB && pSillTblT)
	{
		grstrmB.OpenBuffer((gr::byte *)pSillTblB, cbSillSzB);
		grstrmT.OpenBuffer((gr::byte *)pSillTblT, cbSillSzT);
		CompareSillTables(ec, ptcase, grstrmB, grstrmT);
		grstrmB.Close();
		grstrmT.Close();
	}

	delete[] pHeadTblB;
	delete[] pHeadTblT;

	delete[] pCmapTblB;
	delete[] pCmapTblT;

	delete[] pNameTblB;
	delete[] pNameTblT;

	delete[] pSilfTblB;
	delete[] pSilfTblT;

	delete[] pFeatTblB;
	delete[] pFeatTblT;

	delete[] pGlatTblB;
	delete[] pGlatTblT;

	delete[] pGlocTblB;
	delete[] pGlocTblT;

	delete[] pSillTblB;
	delete[] pSillTblT;

	return ec;
}

/*----------------------------------------------------------------------------------------------
	Compare the Silf tables of the benchmark and the test fonts.
----------------------------------------------------------------------------------------------*/
void CompareSilfTables(int & ec, TestCase * ptcase, GrIStream & grstrmB, GrIStream & grstrmT,
	int * pchwMaxGlyphID)
{
	int fxdSilfVersionB = ReadVersion(grstrmB);
	int fxdSilfVersionT = ReadVersion(grstrmT);

	Assert(fxdSilfVersionB <= kSilfVersion);
	if (fxdSilfVersionT > kSilfVersion)
	{
		OutputError(ec, ptcase, "ERROR: Unknown Silf table version in test font");
		return;
	}

	if (fxdSilfVersionB >= 0x00030000)
		 // compiler version
		grstrmB.ReadIntFromFont();
	if (fxdSilfVersionT >= 0x00030000)
		grstrmT.ReadIntFromFont();

	//	number of tables
	unsigned short cSubTablesB = grstrmB.ReadUShortFromFont();
	Assert(cSubTablesB == 1);	// for now
	Assert(cSubTablesB <= kMaxSubTablesInFont);
	unsigned short cSubTablesT = grstrmT.ReadUShortFromFont();
	if (cSubTablesT < 1)
	{
		OutputError(ec, ptcase, "ERROR: Silf table has no subtable");
		return;
	}
	if (cSubTablesT > 1)
		OutputError(ec, ptcase, "ERROR: Silf table has greater than 1 subtable");

    if (fxdSilfVersionB >= 0x00020000)
		// reserved
		grstrmB.ReadShortFromFont();
	if (fxdSilfVersionT >= 0x00020000)
		grstrmT.ReadShortFromFont();

	//	subtable offsets
	int nSubTableOffsetsB[kMaxSubTablesInFont];
	int nSubTableOffsetsT[kMaxSubTablesInFont];
	int i;
	for (i = 0; i < cSubTablesB; i++)
		nSubTableOffsetsB[i] = grstrmB.ReadIntFromFont();
	for (i = 0; i < cSubTablesT; i++)
		nSubTableOffsetsT[i] = grstrmT.ReadIntFromFont();
	grstrmB.SetPositionInFont(nSubTableOffsetsB[0]);
	grstrmT.SetPositionInFont(nSubTableOffsetsT[0]);

	//	Now we are at the beginning of the desired sub-table.

	//	Get the position of the start of the table.
	long lSubTableStartB, lSubTableStartT;
	grstrmB.GetPositionInFont(&lSubTableStartB);
	grstrmT.GetPositionInFont(&lSubTableStartT);

	//	rule version
	int fxdRuleVersionB = (fxdSilfVersionB >= 0x00030000) ? ReadVersion(grstrmB) : fxdSilfVersionB;
	int fxdRuleVersionT = (fxdSilfVersionT >= 0x00030000) ? ReadVersion(grstrmT) : fxdSilfVersionT;

	long lPassBlockPosB = -1;
	long lPseudosPosB = -1;
	if (fxdSilfVersionB >= 0x00030000)
	{
		lPassBlockPosB = grstrmB.ReadUShortFromFont() + lSubTableStartB;
		lPseudosPosB = grstrmB.ReadUShortFromFont() + lSubTableStartB;
	}
	long lPassBlockPosT = -1;
	long lPseudosPosT = -1;
	if (fxdSilfVersionT >= 0x00030000)
	{
		lPassBlockPosT = grstrmT.ReadUShortFromFont() + lSubTableStartT;
		lPseudosPosT = grstrmT.ReadUShortFromFont() + lSubTableStartT;
	}

	//	maximum glyph ID
	*pchwMaxGlyphID = grstrmB.ReadUShortFromFont();
	if (grstrmT.ReadUShortFromFont() != *pchwMaxGlyphID)
	{
		OutputError(ec, ptcase, "ERROR: Silf table - maxiumum glyph ID");
		*pchwMaxGlyphID = -1;
	}

	//	extra ascent
	if (grstrmB.ReadShortFromFont() != grstrmT.ReadShortFromFont())
		OutputError(ec, ptcase, "ERROR: Silf table - extra ascent");
	// extra descent
	if (grstrmB.ReadShortFromFont() != grstrmT.ReadShortFromFont())
		OutputError(ec, ptcase, "ERROR: Silf table - extra descent");

	//	number of passes
	gr::byte cPasses = grstrmB.ReadByteFromFont();
	if (cPasses != grstrmT.ReadByteFromFont())
		OutputError(ec, ptcase, "ERROR: Silf table - number of passes");
	//	index of first substitution pass
	gr::byte ipassSub1 = grstrmB.ReadByteFromFont();
	if (ipassSub1 != grstrmT.ReadByteFromFont())
		OutputError(ec, ptcase, "ERROR: Silf table - first substitution pass");
	//	index of first positioning pass
	gr::byte ipassPos1 = grstrmB.ReadByteFromFont();
	if (ipassPos1 != grstrmT.ReadByteFromFont())
		OutputError(ec, ptcase, "ERROR: Silf table - first positioning pass");
	//	index of first justification pass
	gr::byte ipassJust1 = grstrmB.ReadByteFromFont();
	if (ipassJust1 != grstrmT.ReadByteFromFont())
		OutputError(ec, ptcase, "ERROR: Silf table - first justification pass");
	//	index of first reordered pass, or 0xFF if no reordering
	gr::byte ipassReordered1 = grstrmB.ReadByteFromFont();
	if (ipassReordered1 != grstrmT.ReadByteFromFont())
		OutputError(ec, ptcase, "ERROR: Silf table - first reordered pass");

	//	line-break flag
	if (grstrmB.ReadByteFromFont() != grstrmT.ReadByteFromFont())
		OutputError(ec, ptcase, "ERROR: Silf table - line-break flag");

	//	range of possible cross-line-boundary contextualization
	if (grstrmB.ReadByteFromFont() != grstrmT.ReadByteFromFont())
		OutputError(ec, ptcase, "ERROR: Silf table - pre LB context");
	if (grstrmB.ReadByteFromFont() != grstrmT.ReadByteFromFont())
		OutputError(ec, ptcase, "ERROR: Silf table - post LB context");

	//	actual glyph ID for pseudo-glyph (ID of bogus attribute)
long posB; grstrmB.GetPositionInFont(&posB);
WriteToLog("benchmark position = ", posB, "; ");
long posT; grstrmT.GetPositionInFont(&posT);
WriteToLog("test font position = ", posT, "; ");
gr::byte tempB = grstrmB.ReadByteFromFont();
WriteToLog("next byte B = ", tempB, "; ");
gr::byte tempT = grstrmT.ReadByteFromFont();
WriteToLog("next byte T = ", tempT, "\n");
if (tempB != tempT)
	////if (grstrmB.ReadByteFromFont() != grstrmT.ReadByteFromFont())
		OutputError(ec, ptcase, "ERROR: Silf table - actual-for-pseudo attr");
	//	breakweight
	if (grstrmB.ReadByteFromFont() != grstrmT.ReadByteFromFont())
		OutputError(ec, ptcase, "ERROR: Silf table - breakweight attr");
	//	directionality
	if (grstrmB.ReadByteFromFont() != grstrmT.ReadByteFromFont())
		OutputError(ec, ptcase, "ERROR: Silf table - directionality attr");

	if (fxdSilfVersionB >= 0x00020000 && fxdSilfVersionT >= 0x00020000)
	{
		// reserved
		grstrmB.ReadByteFromFont();
		grstrmB.ReadByteFromFont();

		grstrmT.ReadByteFromFont();
		grstrmT.ReadByteFromFont();

		//	justification levels
		int cJLevels = grstrmB.ReadByteFromFont();
		if (cJLevels != grstrmT.ReadByteFromFont())
		{
			OutputError(ec, ptcase, "ERROR: Silf table - justification levels");
			return;
		}
		for (int i = 0; i < cJLevels; i++)
		{
			//	justification glyph attribute IDs
			if (grstrmB.ReadByteFromFont() != grstrmT.ReadByteFromFont())
				OutputError(ec, ptcase, "ERROR: Silf table - stretch", i);
			if (grstrmB.ReadByteFromFont() != grstrmT.ReadByteFromFont())
				OutputError(ec, ptcase, "ERROR: Silf table - shrink", i);
			if (grstrmB.ReadByteFromFont() != grstrmT.ReadByteFromFont())
				OutputError(ec, ptcase, "ERROR: Silf table - step", i);
			if (grstrmB.ReadByteFromFont() != grstrmT.ReadByteFromFont())
				OutputError(ec, ptcase, "ERROR: Silf table - weight", i);
			grstrmB.ReadByteFromFont(); // runto
			grstrmT.ReadByteFromFont();
			// reserved
			grstrmB.ReadByteFromFont();
			grstrmB.ReadByteFromFont();
			grstrmB.ReadByteFromFont();

			grstrmT.ReadByteFromFont();
			grstrmT.ReadByteFromFont();
			grstrmT.ReadByteFromFont();
		}
	}
	else if (fxdSilfVersionB >= 0x00020000)
	{
		// reserved
		grstrmB.ReadByteFromFont();
		grstrmB.ReadByteFromFont();
		//	justification levels
		int cJLevels = grstrmB.ReadByteFromFont();
		if (cJLevels > 0)
			OutputError(ec, ptcase, "ERROR: Silf table - missing justification data");
		gr::byte rgb[8];
		for (int i = 0; i < cJLevels; i++)
			grstrmB.ReadBlockFromFont(rgb, 8);
	}
	else if (fxdSilfVersionT >= 0x00020000)
	{
		// reserved
		grstrmB.ReadByteFromFont();
		grstrmB.ReadByteFromFont();
		//	justification levels
		int cJLevels = grstrmB.ReadByteFromFont();
		if (cJLevels > 0)
			OutputError(ec, ptcase, "ERROR: Silf table - justification data found but not expected");
		gr::byte rgb[8];
		for (int i = 0; i < cJLevels; i++)
			grstrmB.ReadBlockFromFont(rgb, 8);
	}

	//	number of component attributes
	if (grstrmB.ReadUShortFromFont() != grstrmT.ReadUShortFromFont())
		OutputError(ec, ptcase, "ERROR: Silf table - number of components");

	//	number of user-defined slot attributes
	if (grstrmB.ReadByteFromFont() != grstrmT.ReadByteFromFont())
		OutputError(ec, ptcase, "ERROR: Silf table - number of user-defined slot attributes");

	//	max number of ligature components per glyph
	if (grstrmB.ReadByteFromFont() != grstrmT.ReadByteFromFont())
		OutputError(ec, ptcase, "ERROR: Silf table - max number of ligature components");

	//	directions supported
	if (grstrmB.ReadByteFromFont() != grstrmT.ReadByteFromFont())
		OutputError(ec, ptcase, "ERROR: Silf table - supported directions");

	//	reserved
	grstrmB.ReadByteFromFont();
	grstrmB.ReadByteFromFont();
	grstrmB.ReadByteFromFont();
	grstrmT.ReadByteFromFont();
	grstrmT.ReadByteFromFont();
	grstrmT.ReadByteFromFont();

	//	critical features
	if (fxdSilfVersionB >= 0x00020000 && fxdSilfVersionT >= 0x00020000)
	{
		// reserved
		grstrmB.ReadByteFromFont();
		grstrmT.ReadByteFromFont();
		// critical features
		if (grstrmB.ReadByteFromFont() != grstrmT.ReadByteFromFont())
			OutputError(ec, ptcase, "ERROR: Silf table - critical features");
		// reserved
		grstrmB.ReadByteFromFont();
		grstrmT.ReadByteFromFont();
	}
	else if (fxdSilfVersionB >= 0x00020000)
	{
		grstrmB.ReadByteFromFont();
		if (grstrmB.ReadByteFromFont() != 0)
			OutputError(ec, ptcase, "ERROR: Silf table - critical features not equal to zero");
		grstrmB.ReadByteFromFont();
	}
	else if (fxdSilfVersionT >= 0x00020000)
	{
		grstrmT.ReadByteFromFont();
		if (grstrmT.ReadByteFromFont() != 0)
			OutputError(ec, ptcase, "ERROR: Silf table - critical features found but not expected");
		grstrmT.ReadByteFromFont();
	}

	//	rendering behaviors
	int cBehaviorsB = grstrmB.ReadByteFromFont();
	int cBehaviorsT = grstrmT.ReadByteFromFont();
	if (cBehaviorsB != cBehaviorsT)
		OutputError(ec, ptcase, "ERROR: Silf table - rendering behaviors");
	for (i = 0; i < cBehaviorsB; i++)
		grstrmB.ReadUShortFromFont();
	for (i = 0; i < cBehaviorsT; i++)
		grstrmT.ReadUShortFromFont();

	//	linebreak glyph ID
	if (grstrmB.ReadUShortFromFont() != grstrmT.ReadUShortFromFont())
		OutputError(ec, ptcase, "ERROR: Silf table - linebreak glyph ID");

	//	Jump to the beginning of the pass offset block, if we have this information.
	if (fxdSilfVersionB >= 0x00030000)
		grstrmB.SetPositionInFont(lPassBlockPosB);
	else
		//	Otherwise assume that's where we are!
		Assert(lPassBlockPosB == -1);

	if (fxdSilfVersionT >= 0x00030000)
		grstrmT.SetPositionInFont(lPassBlockPosT);
	else
		Assert(lPassBlockPosT == -1);

	//	offsets to passes, relative to the start of this subtable;
	//	note that we read (cPasses + 1) of these
	int rgnPassOffsets[kMaxPasses];
	bool fPassesOk = true;
	for (i = 0; i <= cPasses; i++)
	{
		rgnPassOffsets[i] = grstrmB.ReadIntFromFont();
		if (rgnPassOffsets[i] != grstrmT.ReadIntFromFont())
		{
			OutputError(ec, ptcase, "ERROR: Silf table - pass offsets", i);
			fPassesOk = false;
		}
	}

	//	Jump to the beginning of the pseudo-glyph info block, if we have this information.
	if (fxdSilfVersionB >= 0x00030000)
		grstrmB.SetPositionInFont(lPseudosPosB);
	else
		//	Otherwise assume that's where we are!
		Assert(lPseudosPosB == -1);

	if (fxdSilfVersionT >= 0x00030000)
		grstrmT.SetPositionInFont(lPseudosPosT);
	else
		Assert(lPseudosPosT == -1);

	//	number of pseudo-glyphs and search constants
	int cpsd = grstrmB.ReadUShortFromFont();
	if (cpsd != grstrmT.ReadUShortFromFont())
		OutputError(ec, ptcase, "ERROR: Silf table - pseudo search count");
	if (grstrmB.ReadUShortFromFont() != grstrmT.ReadUShortFromFont())
		OutputError(ec, ptcase, "ERROR: Silf table - pseudo search increment");
	if (grstrmB.ReadUShortFromFont() != grstrmT.ReadUShortFromFont())
		OutputError(ec, ptcase, "ERROR: Silf table - pseudo search loop");
	if (grstrmB.ReadUShortFromFont() != grstrmT.ReadUShortFromFont())
		OutputError(ec, ptcase, "ERROR: Silf table - pseudo search start");

	//	unicode-to-pseudo map
	for (i = 0; i < cpsd; i++)
	{
		int unicodeB, unicodeT;
		if (fxdSilfVersionB <= 0x00010000)
			unicodeB = grstrmB.ReadUShortFromFont();
		else
			unicodeB = grstrmB.ReadIntFromFont();
		if (fxdSilfVersionT <= 0x00010000)
			unicodeT = grstrmT.ReadUShortFromFont();
		else
			unicodeT = grstrmT.ReadIntFromFont();
		if (unicodeB != unicodeT)
			OutputError(ec, ptcase, "ERROR: Silf table - unicode for pseudo", i);

		if (grstrmB.ReadUShortFromFont() != grstrmT.ReadUShortFromFont())
			OutputError(ec, ptcase, "ERROR: Silf table = pseudo value", i);
	}

	CompareClassMaps(ec, ptcase, grstrmB, grstrmT);

	if (fPassesOk)
		ComparePasses(ec, ptcase, grstrmB, grstrmT,
			fxdSilfVersionB, fxdSilfVersionT, cPasses,
			lSubTableStartB, lSubTableStartT, rgnPassOffsets);
}

/*----------------------------------------------------------------------------------------------
	Compare the class tables.
----------------------------------------------------------------------------------------------*/
void CompareClassMaps(int & ec, TestCase * ptcase, GrIStream & grstrmB, GrIStream & grstrmT)
{
	// number of classes
	int cClasses = grstrmB.ReadUShortFromFont();
	if (cClasses != grstrmT.ReadUShortFromFont())
	{
		OutputError(ec, ptcase, "ERROR: class map - number of classes");
		return;
	}

	// number of linearly stored classes
	int cClassesLinear = grstrmB.ReadUShortFromFont();
	if (cClassesLinear != grstrmT.ReadUShortFromFont())
	{
		OutputError(ec, ptcase, "ERROR: class map - number of linear classes");
		return;
	}

	// offsets
	data16 * wOffsets = new data16[cClasses + 1];
	bool fOffsetsOk = true;
	for (int i = 0; i <= cClasses; i++)
	{
		wOffsets[i] = grstrmB.ReadUShortFromFont();
		if (wOffsets[i] != grstrmT.ReadUShortFromFont())
		{
			OutputError(ec, ptcase, "ERROR: class map - offset", i);
			fOffsetsOk = false;
		}
	}
	if (!fOffsetsOk)
	{
		delete[] wOffsets;
		return;
	}

	int iClass = 0;
	int ibOffset = 4 + (2 * (cClasses + 1));
	while (iClass < cClasses)
	{
		bool fLinear = (iClass < cClassesLinear);
		if (fLinear)
		{
			int cGlyphs = (wOffsets[iClass + 1] - wOffsets[iClass]) >> 1; // divided by 2
			for (int ig = 0; ig < cGlyphs; ig++)
			{
				if (grstrmB.ReadUShortFromFont() != grstrmT.ReadUShortFromFont())
					OutputError(ec, ptcase, "ERROR: class map - glyph of class", iClass);
				ibOffset += 2; // 2 bytes
			}
		}
		else
		{
			int cGlyphs = grstrmB.ReadUShortFromFont();
			if (cGlyphs != grstrmT.ReadUShortFromFont())
			{
				OutputError(ec, ptcase, "ERROR: class map - number of glyphs in class", iClass);
				return;
			}
			if (grstrmB.ReadUShortFromFont() != grstrmT.ReadUShortFromFont())
				OutputError(ec, ptcase, "ERROR: Silf table - class search increment", iClass);
			if (grstrmB.ReadUShortFromFont() != grstrmT.ReadUShortFromFont())
				OutputError(ec, ptcase, "ERROR: Silf table - class search loop", iClass);
			if (grstrmB.ReadUShortFromFont() != grstrmT.ReadUShortFromFont())
				OutputError(ec, ptcase, "ERROR: Silf table - class search start", iClass);
			ibOffset += 8;
			for (int ig = 0; ig < cGlyphs; ig++)
			{
				if (grstrmB.ReadUShortFromFont() != grstrmT.ReadUShortFromFont())
					OutputError(ec, ptcase, "ERROR: Silf table - glyph ID in class", iClass);
				if (grstrmB.ReadUShortFromFont() != grstrmT.ReadUShortFromFont())
					OutputError(ec, ptcase, "ERROR: Silf table - glyph index in class", iClass);
				ibOffset += 4;
			}
		}
		iClass++;
		Assert(ibOffset == wOffsets[iClass]);
	}

	delete[] wOffsets;
}

/*----------------------------------------------------------------------------------------------
	Compare the class tables.
----------------------------------------------------------------------------------------------*/
void ComparePasses(int & ec, TestCase * ptcase, GrIStream & grstrmB, GrIStream & grstrmT,
   int fxdSilfVersionB, int fxdSilfVersionT, int cPasses,
   int lSubTableStartB, int lSubTableStartT, int * prgnPassOffsets)
{
	for (int iPass = 0; iPass < cPasses; iPass++)
	{
		int nOffsetB = lSubTableStartB + prgnPassOffsets[iPass];
		int nOffsetT = lSubTableStartT + prgnPassOffsets[iPass];

		long lPassInfoStart;
		grstrmB.GetPositionInFont(&lPassInfoStart);
		if (lPassInfoStart != nOffsetB)
			grstrmB.SetPositionInFont(nOffsetB);
		grstrmT.GetPositionInFont(&lPassInfoStart);
		if (lPassInfoStart != nOffsetT)
			grstrmT.SetPositionInFont(nOffsetT);

		//	flags
		if (grstrmB.ReadByteFromFont() != grstrmT.ReadByteFromFont())
			OutputError(ec, ptcase, "ERROR: pass", iPass, " - flags");

		//	MaxRuleLoop
		if (grstrmB.ReadByteFromFont() != grstrmT.ReadByteFromFont())
			OutputError(ec, ptcase, "ERROR: pass", iPass, " - MaxRuleLoop");

		//	max rule context
		if (grstrmB.ReadByteFromFont() != grstrmT.ReadByteFromFont())
			OutputError(ec, ptcase, "ERROR: pass", iPass, " - max rule context");

		//	MaxBackup
		if (grstrmB.ReadByteFromFont() != grstrmT.ReadByteFromFont())
			OutputError(ec, ptcase, "ERROR: pass", iPass, " - MaxBackup");

		//	number of rules
		int crul = grstrmB.ReadShortFromFont();
		if (crul != grstrmT.ReadShortFromFont())
		{
			OutputError(ec, ptcase, "ERROR: pass", iPass, " - number of rules");
			return;
		}

		//	offset to pass constraint code, relative to start of subtable
		int nPConstraintOffsetB = 0;
		long lFsmPosB = -1;
		if (fxdSilfVersionB >= 0x00020000)
		{
			if (fxdSilfVersionB >= 0x00030000)
				lFsmPosB = grstrmB.ReadUShortFromFont() + nOffsetB; // offset to row info
			else
				grstrmB.ReadShortFromFont();	// pad bytes
			nPConstraintOffsetB = grstrmB.ReadIntFromFont();
		}
		int nPConstraintOffsetT = 0;
		long lFsmPosT = -1;
		if (fxdSilfVersionT >= 0x00020000)
		{
			if (fxdSilfVersionT >= 0x00030000)
				lFsmPosT = grstrmT.ReadUShortFromFont() + nOffsetT; // offset to row info
			else
				grstrmT.ReadShortFromFont();	// pad bytes
			nPConstraintOffsetT = grstrmT.ReadIntFromFont();
		}

		//	offset to rule constraint code, relative to start of subtable
		//int nConstraintOffset = grstrmB.ReadIntFromFont();
		grstrmB.ReadIntFromFont();
		grstrmT.ReadIntFromFont();
		//	offset to action code, relative to start of subtable
		//int nActionOffset = grstrmB.ReadIntFromFont();
		grstrmB.ReadIntFromFont();
		grstrmT.ReadIntFromFont();
		//	offset to debug strings; 0 if stripped
		//int nDebugOffset = grstrmB.ReadIntFromFont();
		grstrmB.ReadIntFromFont();
		grstrmT.ReadIntFromFont();

		//	Jump to beginning of FSM, if we have this information.
		if (fxdSilfVersionB >= 0x00030000)
			grstrmB.SetPositionInFont(lFsmPosB);
		else
			// Otherwise assume that's where we are!
			Assert(lFsmPosB == -1);
		if (fxdSilfVersionT >= 0x00030000)
			grstrmT.SetPositionInFont(lFsmPosT);
		else
			// Otherwise assume that's where we are!
			Assert(lFsmPosT == -1);

		int cFsmCells = CompareFsmTables(ec, ptcase, grstrmB, grstrmT, fxdSilfVersionB, fxdSilfVersionT, iPass);

		//	rule sort keys
		int irul;
		for (irul = 0; irul < crul; irul++)
		{
			if (grstrmB.ReadUShortFromFont() != grstrmT.ReadUShortFromFont())
				OutputError(ec, ptcase, "ERROR: pass", iPass, ", rule sort key", irul);
		}

		//	rule pre-mod-context item counts
		for (irul = 0; irul < crul; irul++)
		{
			if (grstrmB.ReadByteFromFont() != grstrmT.ReadByteFromFont())
				OutputError(ec, ptcase, "ERROR: pass", iPass, ", rule pre-mod-context", irul);
		}

		//	constraint offset for pass-level constraints
		int cbPassConstraintsB, cbPassConstraintsT = 0;
		if (fxdSilfVersionB >= 0x00020000)
		{
			grstrmB.ReadByteFromFont();
			cbPassConstraintsB = grstrmB.ReadUShortFromFont();				
		}
		if (fxdSilfVersionB >= 0x00020000)
		{
			grstrmT.ReadByteFromFont();
			cbPassConstraintsT = grstrmT.ReadUShortFromFont();
		}
		if (cbPassConstraintsB != cbPassConstraintsT)
			OutputError(ec, ptcase, "ERROR: pass", iPass, ", pass-level constraint offset");

		//	constraint and action offsets for rules
		data16 cbConstraints;
		for (irul = 0; irul <= crul; irul++)
		{
			cbConstraints = grstrmB.ReadUShortFromFont(); // save the last item, it gives the total
			if (cbConstraints != grstrmT.ReadUShortFromFont())
				OutputError(ec, ptcase, "ERROR: pass", iPass, ", rule constraint offset", irul);
		}
		data16 cbActions;
		for (irul = 0; irul <= crul; irul++)
		{
			cbActions = grstrmB.ReadUShortFromFont(); // save the last item, it gives the total
			if (cbActions != grstrmT.ReadUShortFromFont())
				OutputError(ec, ptcase, "ERROR: pass", iPass, ", rule action offset", irul);
		}

		// FSM cells
		for (int iCell = 0; iCell < cFsmCells; iCell++)
		{
			if (grstrmB.ReadShortFromFont() != grstrmT.ReadShortFromFont())
				OutputError(ec, ptcase, "ERROR: pass", iPass, ", FSM cell", iCell);
		}

		if (fxdSilfVersionB >= 0x00020000)
			// reserved - pad byte
			grstrmB.ReadByteFromFont();
		if (fxdSilfVersionT >= 0x00020000)
			// reserved - pad byte
			grstrmT.ReadByteFromFont();

		gr::byte * pbB;
		gr::byte * pbT;
		int ib;

		//	Constraint and action blocks
		int cb = cbPassConstraintsB;
		gr::byte * prgbPConstraintBlockB = new gr::byte[cb];
		gr::byte * prgbPConstraintBlockT = new gr::byte[cb];
		grstrmB.ReadBlockFromFont(prgbPConstraintBlockB, cb);
		grstrmT.ReadBlockFromFont(prgbPConstraintBlockT, cb);
		for (ib = 0, pbB = prgbPConstraintBlockB, pbT = prgbPConstraintBlockT;
			ib < cb;
			ib++, pbB++, pbT++)
		{
			if (*pbB != *pbT)
				OutputError(ec, ptcase, "ERROR: pass", iPass, ", pass constraint byte", ib);
		}
		delete[] prgbPConstraintBlockB;
		delete[] prgbPConstraintBlockT;

		cb = cbConstraints;
		gr::byte * prgbConstraintBlockB = new gr::byte[cb];
		gr::byte * prgbConstraintBlockT = new gr::byte[cb];
		grstrmB.ReadBlockFromFont(prgbConstraintBlockB, cb);
		grstrmT.ReadBlockFromFont(prgbConstraintBlockT, cb);
		for (ib = 0, pbB = prgbConstraintBlockB, pbT = prgbConstraintBlockT;
			ib < cb;
			ib++, pbB++, pbT++)
		{
			if (*pbB != *pbT)
				OutputError(ec, ptcase, "ERROR: pass", iPass, ", rule constraint byte", ib);
		}
		delete[] prgbConstraintBlockB;
		delete[] prgbConstraintBlockT;

		cb = cbActions;
		gr::byte * prgbActionBlockB = new gr::byte[cb];
		gr::byte * prgbActionBlockT = new gr::byte[cb];
		grstrmB.ReadBlockFromFont(prgbActionBlockB, cb);
		grstrmT.ReadBlockFromFont(prgbActionBlockT, cb);
		for (ib = 0, pbB = prgbActionBlockB, pbT = prgbActionBlockT;
			ib < cb;
			ib++, pbB++, pbT++)
		{
			if (*pbB != *pbT)
				OutputError(ec, ptcase, "ERROR: pass", iPass, ", action byte", ib);
		}
		delete[] prgbActionBlockB;
		delete[] prgbActionBlockT;
	}
}

/*----------------------------------------------------------------------------------------------
	Compare the FSM tables.
----------------------------------------------------------------------------------------------*/
int CompareFsmTables(int & ec, TestCase * ptcase,
	GrIStream & grstrmB, GrIStream & grstrmT,
	int fxdSilfVersionB, int fxdSilfVersionT, int iPass)
{
	//	number of FSM states
	int crow = grstrmB.ReadShortFromFont();
	if (crow != grstrmT.ReadShortFromFont())
		OutputError(ec, ptcase, "ERROR: pass FSM", iPass, " - number of FSM states");
	//	number of transitional states
	int crowTransitional = grstrmB.ReadShortFromFont();
	if (crowTransitional != grstrmT.ReadShortFromFont())
		OutputError(ec, ptcase, "ERROR: pass FSM", iPass, " - number of FSM transitional states");
	//	number of success states
	int crowSuccess = grstrmB.ReadShortFromFont();
	if (crowSuccess != grstrmT.ReadShortFromFont())
		OutputError(ec, ptcase, "ERROR: pass FSM", iPass, " - number of FSM success states");
	int crowFinal = crow - crowTransitional;
	int crowNonAcpt = crow - crowSuccess;

	//	number of columns
	int ccol = grstrmB.ReadShortFromFont();
	if (ccol != grstrmT.ReadShortFromFont())
		OutputError(ec, ptcase, "ERROR: pass FSM", iPass, " - number of FSM columns");

	// Sanity check
	Assert(crowTransitional <= crow && crowSuccess <= crow);

	//	number of FSM glyph ranges and search constants
	int cmcr = grstrmB.ReadShortFromFont();
	if (cmcr != grstrmT.ReadShortFromFont())
		OutputError(ec, ptcase, "ERROR: pass FSM", iPass, " - # of glyph ranges");
	if (grstrmB.ReadShortFromFont() != grstrmT.ReadShortFromFont())
		OutputError(ec, ptcase, "ERROR: pass FSM", iPass, " - glyph range search increment");
	if (grstrmB.ReadShortFromFont() != grstrmT.ReadShortFromFont())
		OutputError(ec, ptcase, "ERROR: pass FSM", iPass, " - glyph range search loop");
	if (grstrmB.ReadShortFromFont() != grstrmT.ReadShortFromFont())
		OutputError(ec, ptcase, "ERROR: pass FSM", iPass, " - glyph range search start");

	for (int imcr = 0; imcr < cmcr; imcr++)
	{
		if (grstrmB.ReadUShortFromFont() != grstrmT.ReadUShortFromFont())
			OutputError(ec, ptcase, "ERROR: pass FSM", iPass, " - glyph range first", imcr);
		if (grstrmB.ReadUShortFromFont() != grstrmT.ReadUShortFromFont())
			OutputError(ec, ptcase, "ERROR: pass FSM", iPass, " - glyph range last", imcr);
		if (grstrmB.ReadUShortFromFont() != grstrmT.ReadUShortFromFont())
			OutputError(ec, ptcase, "ERROR: pass FSM", iPass, " - glyph range column", imcr);
	}

	// rule map and offsets (extra item at end gives final offset, ie, total)
	int crulInMap;
	int i;
	for (i = 0; i < (crowSuccess + 1); i++)
	{
		crulInMap = grstrmB.ReadUShortFromFont();	// last offset functions as the total length of the rule list
		if (crulInMap != grstrmT.ReadUShortFromFont())
			OutputError(ec, ptcase, "ERROR: pass FSM", iPass, " - rule map offset", i);
	}

	for (i = 0; i < crulInMap; i++)
	{
		if (grstrmB.ReadUShortFromFont() != grstrmT.ReadUShortFromFont())
			OutputError(ec, ptcase, "ERROR: pass FSM", iPass, " - rule map item", i);
	}

	//	min rule pre-context number of items
	int critMinRulePreContext = grstrmB.ReadByteFromFont();
	if (critMinRulePreContext != grstrmT.ReadByteFromFont())
		OutputError(ec, ptcase, "ERROR: pass FSM", iPass, " - min rule pre-context", i);
	int critMaxRulePreContext = grstrmB.ReadByteFromFont();
	if (critMaxRulePreContext != grstrmT.ReadByteFromFont())
		OutputError(ec, ptcase, "ERROR: pass FSM", iPass, " - max rule pre-context", i);

	Assert(critMinRulePreContext <= kMaxSlotsPerRule);
	Assert(critMaxRulePreContext <= kMaxSlotsPerRule);

	int cStartStates = critMaxRulePreContext - critMinRulePreContext + 1;

	//	start states
	for (int ic = 0; ic < cStartStates;	ic++)
	{
		if (grstrmB.ReadShortFromFont() != grstrmT.ReadShortFromFont())
			OutputError(ec, ptcase, "ERROR: pass FSM", iPass, " - start state", ic);
	}

	return (crow - crowFinal) * ccol;
}

/*----------------------------------------------------------------------------------------------
	Compare the Glat and Gloc tables.
----------------------------------------------------------------------------------------------*/
void CompareGlatAndGlocTables(int & ec, TestCase * ptcase, int wMaxGlyphID,
	GrIStream & grstrmGlatB, GrIStream & grstrmGlocB,
	GrIStream & grstrmGlatT, GrIStream & grstrmGlocT)
{
	Assert(ReadVersion(grstrmGlatB) == 0x00010000);
	Assert(ReadVersion(grstrmGlocB) == 0x00010000);
	if (ReadVersion(grstrmGlatT) != 0x00010000)
	{
		OutputError(ec, ptcase, "ERROR: unknown Glat table version");
		return;
	}
	if (ReadVersion(grstrmGlocT) != 0x00010000)
	{
		OutputError(ec, ptcase, "ERROR: unknown Gloc table version");
		return;
	}

	// flag bits
	data16 wFlagsB = grstrmGlocB.ReadUShortFromFont();
	data16 wFlagsT = grstrmGlocT.ReadUShortFromFont();
	if (wFlagsB != wFlagsT)
		OutputError(ec, ptcase, "ERROR: Gloc table flags do not match");
	bool fLongFormatB = wFlagsB & 0x0001;
	bool fLongFormatT = wFlagsT & 0x0001;

	// number of attributes
	data16 cAttribs = grstrmGlocB.ReadUShortFromFont();
	if (cAttribs != grstrmGlocT.ReadUShortFromFont())
	{
		OutputError(ec, ptcase, "ERROR: Gloc table - number of attributes");
		return;
	}

	// offsets and attribute values
	int nOffsetB = fLongFormatB ? grstrmGlocB.ReadIntFromFont() : grstrmGlocB.ReadUShortFromFont();
	int nOffsetT = fLongFormatT ? grstrmGlocT.ReadIntFromFont() : grstrmGlocT.ReadUShortFromFont();
	if (fLongFormatB == fLongFormatT && nOffsetB != nOffsetT)
		OutputErrorWithValues(ec, ptcase, "ERROR: Gloc table - offset", 0, nOffsetB, nOffsetT);
	int iAttrEntry = 0;
	int cbGlatOffset = 4; // read version
	for (int wGlyphID = 1; wGlyphID < wMaxGlyphID; wGlyphID++)
	{
		int nOffsetBnext = fLongFormatB ? grstrmGlocB.ReadIntFromFont() : grstrmGlocB.ReadUShortFromFont();
		while (cbGlatOffset < nOffsetBnext)
		{
			int nAttrNumB = grstrmGlatB.ReadByteFromFont();
			int nAttrNumT = grstrmGlatT.ReadByteFromFont();
			if (nAttrNumB != nAttrNumT)
			{
				OutputError(ec, ptcase, "ERROR: Glat table - glyph", wGlyphID, ", attr entry first attr", iAttrEntry);
				return;
			}
			int cAttrsB = grstrmGlatB.ReadByteFromFont();
			int cAttrsT = grstrmGlatT.ReadByteFromFont();
			if (cAttrsB != cAttrsT)
			{
				OutputError(ec, ptcase, "ERROR: Glat table - glyph", wGlyphID, ", attr entry # of attrs", iAttrEntry);
				return;
			}
			cbGlatOffset += 2; // 2 bytes
			for (int iAttr = 0; iAttr < cAttrsB; iAttr++)
			{
				int nValueB = grstrmGlatB.ReadShortFromFont();
				int nValueT = grstrmGlatT.ReadShortFromFont();
				if (nValueB != nValueT)
                {
					OutputError(ec, ptcase, "ERROR: Glat table - glyph", wGlyphID, ", attr value", nAttrNumB+iAttr);
                    OutputError(ec, ptcase, "   Values: ", nValueB, " -> ", nValueT);
                }
				cbGlatOffset += 2; // 2 bytes
			}
			iAttrEntry++;
		}
		// Go on to next glyph ID.
		nOffsetB = nOffsetBnext;
		nOffsetT = fLongFormatT ? grstrmGlocT.ReadIntFromFont() : grstrmGlocT.ReadUShortFromFont();
		if (fLongFormatB == fLongFormatT && nOffsetB != nOffsetT)
			OutputErrorWithValues(ec, ptcase, "ERROR: Gloc table - offset", wGlyphID, nOffsetB, nOffsetT);
	}
}

/*----------------------------------------------------------------------------------------------
	Compare the Feat tables.
----------------------------------------------------------------------------------------------*/
void CompareFeatTables(int & ec, TestCase * ptcase, GrIStream & grstrmB, GrIStream & grstrmT,
	const gr::byte * pNameTblB, const gr::byte * pNameTblT)
{
	int fxdVersionB = ReadVersion(grstrmB);
	int fxdVersionT = ReadVersion(grstrmT);
    Assert(fxdVersionB <= kFeatVersion);
	if (fxdVersionT > kFeatVersion)
	{
		OutputError(ec, ptcase, "ERROR: Feat table - unknown version number");
		return;
	}
	
	//	number of features
	int cfeatB = grstrmB.ReadUShortFromFont();
	int cfeatT = grstrmT.ReadUShortFromFont();
	Assert(cfeatB <= kMaxFeatures);
	if (cfeatB != cfeatT)
		OutputError(ec, ptcase, "ERROR: Feat table - number of features");

	//	reserved
	grstrmB.ReadUShortFromFont();
	grstrmT.ReadUShortFromFont();
	grstrmB.ReadIntFromFont();
	grstrmT.ReadIntFromFont();
	
	int cfset = 0;
	int ifeat;
	for (ifeat = 0; ifeat < min(cfeatB, cfeatT); ifeat++)
	{
		//	ID
		featid nIdB, nIdT;
		if (fxdVersionB >= 0x00020000)
			nIdB = (unsigned int)grstrmB.ReadIntFromFont();
		else
			nIdB = grstrmB.ReadUShortFromFont();
		if (fxdVersionT >= 0x00020000)
			nIdT = (unsigned int)grstrmT.ReadIntFromFont();
		else
			nIdT = grstrmT.ReadUShortFromFont();
		if (nIdB != nIdT)
			OutputError(ec, ptcase, "ERROR: Feat table - feature ID", ifeat);

		//	number of settings
		data16 cfsetThis = grstrmB.ReadUShortFromFont();
		if (cfsetThis != grstrmT.ReadUShortFromFont())
			OutputError(ec, ptcase, "ERROR: Feat table - feature", ifeat, ", number of settings");
		cfset += cfsetThis;

		if (fxdVersionB >= 0x00020000)
			grstrmB.ReadShortFromFont(); // pad bytes
		if (fxdVersionT >= 0x00020000)
			grstrmT.ReadShortFromFont();

		//	offset to settings list
		grstrmB.ReadIntFromFont();
		grstrmT.ReadIntFromFont();

		//	flags
		if (grstrmB.ReadUShortFromFont() != grstrmT.ReadUShortFromFont())
			OutputError(ec, ptcase, "ERROR: Feat table - feature", ifeat, ", flags");

		//	index into name table of UI label
		unsigned int nStrOffsetB = grstrmB.ReadShortFromFont();
		unsigned int nStrOffsetT = grstrmT.ReadShortFromFont();
		std::wstring strB = StringFromNameTable(pNameTblB, 1033, nStrOffsetB);
		std::wstring strT = StringFromNameTable(pNameTblT, 1033, nStrOffsetT);
		if (wcscmp(strB.c_str(), strT.c_str()) != 0)
			OutputError(ec, ptcase, "ERROR: Feat table - label for feature", ifeat);
	}

	if (cfeatB != cfeatT)
		return;

	// setttings
	for (int ifset = 0; ifset < cfset; ifset++)
	{
		if (grstrmB.ReadShortFromFont() != grstrmT.ReadShortFromFont())
			OutputError(ec, ptcase, "ERROR: Feat table - value for setting", ifset);

		// name table offsets
		unsigned int nStrOffsetB = grstrmB.ReadUShortFromFont();
		unsigned int nStrOffsetT = grstrmT.ReadUShortFromFont();
		std::wstring strB = StringFromNameTable(pNameTblB, 1033, nStrOffsetB);
		std::wstring strT = StringFromNameTable(pNameTblT, 1033, nStrOffsetT);
		if (wcscmp(strB.c_str(), strT.c_str()) != 0)
			OutputError(ec, ptcase, "ERROR: Feat table - label for setting", ifset);
	}
}

/*----------------------------------------------------------------------------------------------
	Compare the Sill tables.
----------------------------------------------------------------------------------------------*/
void CompareSillTables(int & ec, TestCase * ptcase, GrIStream & grstrmB, GrIStream & grstrmT)
{
	ReadVersion(grstrmB);
	ReadVersion(grstrmT);

	// number of languages
	int clangB = grstrmB.ReadUShortFromFont();
	int clangT = grstrmT.ReadUShortFromFont();
	if (clangB != clangT)
		OutputError(ec, ptcase, "ERROR: Sill table - number of languages");
	
	// search constants
	if (grstrmB.ReadUShortFromFont() != grstrmT.ReadUShortFromFont())
		OutputError(ec, ptcase, "ERROR: Sill table - search increment");
	if (grstrmB.ReadUShortFromFont() != grstrmT.ReadUShortFromFont())
		OutputError(ec, ptcase, "ERROR: Sill table - search loop");
	if (grstrmB.ReadUShortFromFont() != grstrmT.ReadUShortFromFont())
		OutputError(ec, ptcase, "ERROR: Sill table - search start");

	int cSettings = 0;
	for (int ilang = 0; ilang <= std::min(clangB, clangT); ilang++)
	{
		if (grstrmB.ReadIntFromFont() != grstrmT.ReadIntFromFont())
			OutputError(ec, ptcase, "ERROR: Sill table - language code", ilang);
		int c = grstrmB.ReadUShortFromFont();
		if (c!= grstrmT.ReadUShortFromFont())
			OutputError(ec, ptcase, "ERROR: Sill table - number of settings", ilang);
		cSettings += c;
		if (grstrmB.ReadUShortFromFont() != grstrmT.ReadUShortFromFont())
			OutputError(ec, ptcase, "ERROR: Sill table - offset", ilang);
	}

	if (clangB != clangT)
		return;

	for (int iSetting = 0; iSetting < cSettings; iSetting++)
	{
		if (grstrmB.ReadIntFromFont() != grstrmT.ReadIntFromFont()) // should be unsigned, but oh well
			OutputError(ec, ptcase, "ERROR: Sill table - feature ID", iSetting);
		if (grstrmB.ReadShortFromFont() != grstrmT.ReadShortFromFont())
			OutputError(ec, ptcase, "ERROR: Sill table - default value", iSetting);
		// pad bytes
		grstrmB.ReadShortFromFont();
		grstrmT.ReadShortFromFont();
	}
}

/*----------------------------------------------------------------------------------------------
	Reinterpret the version number from a font table.
----------------------------------------------------------------------------------------------*/
int ReadVersion(GrIStream & grstrm)
{
	int fxdVersion = grstrm.ReadIntFromFont();

	if (fxdVersion < 0x00010000)
		fxdVersion = 0x00010000; // kludge for bug with which some fonts were generated

	return fxdVersion;
}