Commit d76fe5a1af5fb9a08b38d4d426688ee9cd34996b

Werner Lemberg 2007-08-08T06:38:06

* src/otvalid/otvbase.c, src/otvalid/otvcommn.c, src/otvalid/otvgdef.c, src/otvalid/otvgpos.c, src/otvalid/otvgsub.c, src/otvalid/otvjstf.c: s/FT_INVALID_DATA/FT_INVALID_FORMAT/ where appropriate. Reported by George. * include/freetype/internal/fttrace.h: Define `trace_otvmath'. * src/otvalid/rules.mk (OTV_DRV_SRC): Add otvmath.c. * docs/CHANGES: Updated. Add `MATH' validating support to otvalid module. * include/freetype/tttags.h (TTAG_MATH): New macro. * include/freetype/ftotval.h (FT_VALIDATE_MATH): New macro. (FT_VALIDATE_OT): Updated. * src/otvalid/otmath.c: New file. * src/otvalid/otvalid.c: Include otvmath.c. * src/otvalid/otvmod.c (otv_validate): Handle `MATH' table.

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
diff --git a/ChangeLog b/ChangeLog
index c5c8765..ffad12e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,29 @@
+2007-08-08  Werner Lemberg  <wl@gnu.org>
+
+	* src/otvalid/otvbase.c, src/otvalid/otvcommn.c,
+	src/otvalid/otvgdef.c, src/otvalid/otvgpos.c, src/otvalid/otvgsub.c,
+	src/otvalid/otvjstf.c: s/FT_INVALID_DATA/FT_INVALID_FORMAT/ where
+	appropriate.  Reported by George.
+
+	* include/freetype/internal/fttrace.h: Define `trace_otvmath'.
+
+	* src/otvalid/rules.mk (OTV_DRV_SRC): Add otvmath.c.
+
+	* docs/CHANGES: Updated.
+
+2007-08-08  George Williams  <gww@silcom.com>
+
+	Add `MATH' validating support to otvalid module.
+
+	* include/freetype/tttags.h (TTAG_MATH): New macro.
+	* include/freetype/ftotval.h (FT_VALIDATE_MATH): New macro.
+	(FT_VALIDATE_OT): Updated.
+
+	* src/otvalid/otmath.c: New file.
+
+	* src/otvalid/otvalid.c: Include otvmath.c.
+	* src/otvalid/otvmod.c (otv_validate): Handle `MATH' table.
+
 2007-08-04  Werner Lemberg  <wl@gnu.org>
 
 	* builds/unix/configure.raw: Add call to AC_LIBTOOL_WIN32_DLL. 
diff --git a/docs/CHANGES b/docs/CHANGES
index 1c42b86..7b98d58 100644
--- a/docs/CHANGES
+++ b/docs/CHANGES
@@ -7,6 +7,9 @@ CHANGES BETWEEN 2.3.6 and 2.3.5
       access to  those fields in a CID-keyed font.  The code  has been
       contributed by Derek Clegg.
 
+    - George Williams  contributed  code  to validate  the new  `MATH'
+      OpenType  table (within  the `otvalid'  module).  The  `ftvalid'
+      demo program has been extended accordingly.
 
 ======================================================================
 
diff --git a/include/freetype/ftotval.h b/include/freetype/ftotval.h
index 7c488fd..419190d 100644
--- a/include/freetype/ftotval.h
+++ b/include/freetype/ftotval.h
@@ -4,7 +4,7 @@
 /*                                                                         */
 /*    FreeType API for validating OpenType tables (specification).         */
 /*                                                                         */
-/*  Copyright 2004, 2005, 2006 by                                          */
+/*  Copyright 2004, 2005, 2006, 2007 by                                    */
 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
 /*                                                                         */
 /*  This file is part of the FreeType project, and may only be used,       */
@@ -86,8 +86,11 @@ FT_BEGIN_HEADER
   *    FT_VALIDATE_JSTF ::
   *      Validate JSTF table.
   *
+  *    FT_VALIDATE_MATH ::
+  *      Validate MATH table.
+  *
   *    FT_VALIDATE_OT ::
-  *      Validate all OpenType tables (BASE, GDEF, GPOS, GSUB, JSTF).
+  *      Validate all OpenType tables (BASE, GDEF, GPOS, GSUB, JSTF, MATH).
   *
   */
 #define FT_VALIDATE_BASE  0x0100
@@ -95,12 +98,14 @@ FT_BEGIN_HEADER
 #define FT_VALIDATE_GPOS  0x0400
 #define FT_VALIDATE_GSUB  0x0800
 #define FT_VALIDATE_JSTF  0x1000
+#define FT_VALIDATE_MATH  0x2000
 
 #define FT_VALIDATE_OT  FT_VALIDATE_BASE | \
                         FT_VALIDATE_GDEF | \
                         FT_VALIDATE_GPOS | \
                         FT_VALIDATE_GSUB | \
-                        FT_VALIDATE_JSTF
+                        FT_VALIDATE_JSTF | \
+                        FT_VALIDATE_MATH
 
   /* */
 
diff --git a/include/freetype/internal/fttrace.h b/include/freetype/internal/fttrace.h
index 81916fc..4d38a46 100644
--- a/include/freetype/internal/fttrace.h
+++ b/include/freetype/internal/fttrace.h
@@ -4,7 +4,7 @@
 /*                                                                         */
 /*    Tracing handling (specification only).                               */
 /*                                                                         */
-/*  Copyright 2002, 2004, 2005, 2006 by                                    */
+/*  Copyright 2002, 2004, 2005, 2006, 2007 by                              */
 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
 /*                                                                         */
 /*  This file is part of the FreeType project, and may only be used,       */
@@ -114,6 +114,7 @@ FT_TRACE_DEF( otvgdef )
 FT_TRACE_DEF( otvgpos )
 FT_TRACE_DEF( otvgsub )
 FT_TRACE_DEF( otvjstf )
+FT_TRACE_DEF( otvmath )
 
   /* TrueTypeGX/AAT validation components */
 FT_TRACE_DEF( gxvmodule )
diff --git a/include/freetype/tttags.h b/include/freetype/tttags.h
index e10244c..5a79008 100644
--- a/include/freetype/tttags.h
+++ b/include/freetype/tttags.h
@@ -4,7 +4,7 @@
 /*                                                                         */
 /*    Tags for TrueType and OpenType tables (specification only).          */
 /*                                                                         */
-/*  Copyright 1996-2001, 2004, 2005 by                                     */
+/*  Copyright 1996-2001, 2004, 2005, 2007 by                               */
 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
 /*                                                                         */
 /*  This file is part of the FreeType project, and may only be used,       */
@@ -67,6 +67,7 @@ FT_BEGIN_HEADER
 #define TTAG_lcar  FT_MAKE_TAG( 'l', 'c', 'a', 'r' )
 #define TTAG_loca  FT_MAKE_TAG( 'l', 'o', 'c', 'a' )
 #define TTAG_LTSH  FT_MAKE_TAG( 'L', 'T', 'S', 'H' )
+#define TTAG_MATH  FT_MAKE_TAG( 'M', 'A', 'T', 'H' )
 #define TTAG_maxp  FT_MAKE_TAG( 'm', 'a', 'x', 'p' )
 #define TTAG_META  FT_MAKE_TAG( 'M', 'E', 'T', 'A' )
 #define TTAG_MMFX  FT_MAKE_TAG( 'M', 'M', 'F', 'X' )
diff --git a/src/otvalid/otvalid.c b/src/otvalid/otvalid.c
index 2f85f60..d5c2b75 100644
--- a/src/otvalid/otvalid.c
+++ b/src/otvalid/otvalid.c
@@ -4,7 +4,7 @@
 /*                                                                         */
 /*    FreeType validator for OpenType tables (body only).                  */
 /*                                                                         */
-/*  Copyright 2004 by                                                      */
+/*  Copyright 2004, 2007 by                                                */
 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
 /*                                                                         */
 /*  This file is part of the FreeType project, and may only be used,       */
@@ -25,6 +25,7 @@
 #include "otvgpos.c"
 #include "otvgsub.c"
 #include "otvjstf.c"
+#include "otvmath.c"
 #include "otvmod.c"
 
 /* END */
diff --git a/src/otvalid/otvbase.c b/src/otvalid/otvbase.c
index 8ad2238..d742d2d 100644
--- a/src/otvalid/otvbase.c
+++ b/src/otvalid/otvbase.c
@@ -4,7 +4,7 @@
 /*                                                                         */
 /*    OpenType BASE table validation (body).                               */
 /*                                                                         */
-/*  Copyright 2004 by                                                      */
+/*  Copyright 2004, 2007 by                                                */
 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
 /*                                                                         */
 /*  This file is part of the FreeType project, and may only be used,       */
@@ -62,7 +62,7 @@
       break;
 
     default:
-      FT_INVALID_DATA;
+      FT_INVALID_FORMAT;
     }
 
     OTV_EXIT;
@@ -297,7 +297,7 @@
     OTV_LIMIT_CHECK( 6 );
 
     if ( FT_NEXT_ULONG( p ) != 0x10000UL )      /* Version */
-      FT_INVALID_DATA;
+      FT_INVALID_FORMAT;
 
     table_size = 6;
 
diff --git a/src/otvalid/otvcommn.c b/src/otvalid/otvcommn.c
index d94e4f3..36c4c5e 100644
--- a/src/otvalid/otvcommn.c
+++ b/src/otvalid/otvcommn.c
@@ -4,7 +4,7 @@
 /*                                                                         */
 /*    OpenType common tables validation (body).                            */
 /*                                                                         */
-/*  Copyright 2004, 2005, 2006 by                                          */
+/*  Copyright 2004, 2005, 2006, 2007 by                                    */
 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
 /*                                                                         */
 /*  This file is part of the FreeType project, and may only be used,       */
@@ -291,7 +291,10 @@
     EndSize     = FT_NEXT_USHORT( p );
     DeltaFormat = FT_NEXT_USHORT( p );
 
-    if ( DeltaFormat < 1 || DeltaFormat > 3 || EndSize < StartSize )
+    if ( DeltaFormat < 1 || DeltaFormat > 3 )
+      FT_INVALID_FORMAT;
+
+    if ( EndSize < StartSize )
       FT_INVALID_DATA;
 
     count = EndSize - StartSize + 1;
diff --git a/src/otvalid/otvgdef.c b/src/otvalid/otvgdef.c
index 7d24902..e4c32a0 100644
--- a/src/otvalid/otvgdef.c
+++ b/src/otvalid/otvgdef.c
@@ -4,7 +4,7 @@
 /*                                                                         */
 /*    OpenType GDEF table validation (body).                               */
 /*                                                                         */
-/*  Copyright 2004, 2005 by                                                */
+/*  Copyright 2004, 2005, 2007 by                                          */
 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
 /*                                                                         */
 /*  This file is part of the FreeType project, and may only be used,       */
@@ -126,7 +126,7 @@
       break;
 
     default:
-      FT_INVALID_DATA;
+      FT_INVALID_FORMAT;
     }
 
     OTV_EXIT;
diff --git a/src/otvalid/otvgpos.c b/src/otvalid/otvgpos.c
index ed34705..af8269a 100644
--- a/src/otvalid/otvgpos.c
+++ b/src/otvalid/otvgpos.c
@@ -4,7 +4,7 @@
 /*                                                                         */
 /*    OpenType GPOS table validation (body).                               */
 /*                                                                         */
-/*  Copyright 2002, 2004, 2005, 2006 by                                    */
+/*  Copyright 2002, 2004, 2005, 2006, 2007 by                              */
 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
 /*                                                                         */
 /*  This file is part of the FreeType project, and may only be used,       */
@@ -191,7 +191,7 @@
 #endif
 
     if ( format >= 0x100 )
-      FT_INVALID_DATA;
+      FT_INVALID_FORMAT;
 
     for ( count = 4; count > 0; count-- )
     {
@@ -294,7 +294,7 @@
       break;
 
     default:
-      FT_INVALID_DATA;
+      FT_INVALID_FORMAT;
     }
 
     OTV_EXIT;
@@ -409,7 +409,7 @@
       break;
 
     default:
-      FT_INVALID_DATA;
+      FT_INVALID_FORMAT;
     }
 
     OTV_EXIT;
@@ -558,7 +558,7 @@
       break;
 
     default:
-      FT_INVALID_DATA;
+      FT_INVALID_FORMAT;
     }
 
     OTV_EXIT;
@@ -629,7 +629,7 @@
       break;
 
     default:
-      FT_INVALID_DATA;
+      FT_INVALID_FORMAT;
     }
 
     OTV_EXIT;
@@ -670,7 +670,7 @@
       break;
 
     default:
-      FT_INVALID_DATA;
+      FT_INVALID_FORMAT;
     }
 
     OTV_EXIT;
@@ -711,7 +711,7 @@
       break;
 
     default:
-      FT_INVALID_DATA;
+      FT_INVALID_FORMAT;
     }
 
     OTV_EXIT;
@@ -752,7 +752,7 @@
       break;
 
     default:
-      FT_INVALID_DATA;
+      FT_INVALID_FORMAT;
     }
 
     OTV_EXIT;
@@ -811,7 +811,7 @@
       break;
 
     default:
-      FT_INVALID_DATA;
+      FT_INVALID_FORMAT;
     }
 
     OTV_EXIT;
@@ -872,7 +872,7 @@
       break;
 
     default:
-      FT_INVALID_DATA;
+      FT_INVALID_FORMAT;
     }
 
     OTV_EXIT;
@@ -925,7 +925,7 @@
       break;
 
     default:
-      FT_INVALID_DATA;
+      FT_INVALID_FORMAT;
     }
 
     OTV_EXIT;
@@ -989,7 +989,7 @@
     OTV_LIMIT_CHECK( 10 );
 
     if ( FT_NEXT_ULONG( p ) != 0x10000UL )      /* Version */
-      FT_INVALID_DATA;
+      FT_INVALID_FORMAT;
 
     ScriptList  = FT_NEXT_USHORT( p );
     FeatureList = FT_NEXT_USHORT( p );
diff --git a/src/otvalid/otvgsub.c b/src/otvalid/otvgsub.c
index 91dae0b..9412bda 100644
--- a/src/otvalid/otvgsub.c
+++ b/src/otvalid/otvgsub.c
@@ -4,7 +4,7 @@
 /*                                                                         */
 /*    OpenType GSUB table validation (body).                               */
 /*                                                                         */
-/*  Copyright 2004, 2005 by                                                */
+/*  Copyright 2004, 2005, 2007 by                                          */
 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
 /*                                                                         */
 /*  This file is part of the FreeType project, and may only be used,       */
@@ -103,7 +103,7 @@
       break;
 
     default:
-      FT_INVALID_DATA;
+      FT_INVALID_FORMAT;
     }
 
     OTV_EXIT;
@@ -144,7 +144,7 @@
       break;
 
     default:
-      FT_INVALID_DATA;
+      FT_INVALID_FORMAT;
     }
 
     OTV_EXIT;
@@ -185,7 +185,7 @@
       break;
 
     default:
-      FT_INVALID_DATA;
+      FT_INVALID_FORMAT;
     }
 
     OTV_EXIT;
@@ -259,7 +259,7 @@
       break;
 
     default:
-      FT_INVALID_DATA;
+      FT_INVALID_FORMAT;
     }
 
     OTV_EXIT;
@@ -318,7 +318,7 @@
       break;
 
     default:
-      FT_INVALID_DATA;
+      FT_INVALID_FORMAT;
     }
 
     OTV_EXIT;
@@ -379,7 +379,7 @@
       break;
 
     default:
-      FT_INVALID_DATA;
+      FT_INVALID_FORMAT;
     }
 
     OTV_EXIT;
@@ -434,7 +434,7 @@
       break;
 
     default:
-      FT_INVALID_DATA;
+      FT_INVALID_FORMAT;
     }
 
     OTV_EXIT;
@@ -509,7 +509,7 @@
       break;
 
     default:
-      FT_INVALID_DATA;
+      FT_INVALID_FORMAT;
     }
 
     OTV_EXIT;
@@ -560,7 +560,7 @@
     OTV_LIMIT_CHECK( 10 );
 
     if ( FT_NEXT_ULONG( p ) != 0x10000UL )      /* Version */
-      FT_INVALID_DATA;
+      FT_INVALID_FORMAT;
 
     ScriptList  = FT_NEXT_USHORT( p );
     FeatureList = FT_NEXT_USHORT( p );
diff --git a/src/otvalid/otvjstf.c b/src/otvalid/otvjstf.c
index 80b8dd6..a616a23 100644
--- a/src/otvalid/otvjstf.c
+++ b/src/otvalid/otvjstf.c
@@ -4,7 +4,7 @@
 /*                                                                         */
 /*    OpenType JSTF table validation (body).                               */
 /*                                                                         */
-/*  Copyright 2004 by                                                      */
+/*  Copyright 2004, 2007 by                                                */
 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
 /*                                                                         */
 /*  This file is part of the FreeType project, and may only be used,       */
@@ -222,7 +222,7 @@
     OTV_LIMIT_CHECK( 6 );
 
     if ( FT_NEXT_ULONG( p ) != 0x10000UL )      /* Version */
-      FT_INVALID_DATA;
+      FT_INVALID_FORMAT;
 
     JstfScriptCount = FT_NEXT_USHORT( p );
 
diff --git a/src/otvalid/otvmath.c b/src/otvalid/otvmath.c
new file mode 100644
index 0000000..e853575
--- /dev/null
+++ b/src/otvalid/otvmath.c
@@ -0,0 +1,426 @@
+/***************************************************************************/
+/*                                                                         */
+/*  otvmath.c                                                              */
+/*                                                                         */
+/*    OpenType MATH table validation (body).                               */
+/*                                                                         */
+/*  Copyright 2007 by                                                      */
+/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
+/*                                                                         */
+/*  Written by George Williams.                                            */
+/*                                                                         */
+/*  This file is part of the FreeType project, and may only be used,       */
+/*  modified, and distributed under the terms of the FreeType project      */
+/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
+/*  this file you indicate that you have read the license and              */
+/*  understand and accept it fully.                                        */
+/*                                                                         */
+/***************************************************************************/
+
+
+#include "otvalid.h"
+#include "otvcommn.h"
+#include "otvgpos.h"
+
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* The macro FT_COMPONENT is used in trace mode.  It is an implicit      */
+  /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log  */
+  /* messages during execution.                                            */
+  /*                                                                       */
+#undef  FT_COMPONENT
+#define FT_COMPONENT  trace_otvmath
+
+
+
+  /*************************************************************************/
+  /*************************************************************************/
+  /*****                                                               *****/
+  /*****                  MATH TYPOGRAPHIC CONSTANTS                   *****/
+  /*****                                                               *****/
+  /*************************************************************************/
+  /*************************************************************************/
+
+  static void
+  otv_MathConstants_validate( FT_Bytes       table,
+                              OTV_Validator  valid )
+  {
+    FT_Bytes  p = table;
+    FT_UInt   i;
+    FT_UInt   table_size;
+
+    OTV_OPTIONAL_TABLE( DeviceTableOffset );
+
+
+    OTV_NAME_ENTER( "MathConstants" );
+
+    /* 57 constants, 52 have device tables */
+    OTV_LIMIT_CHECK( 2 * ( 57 + 52 ) );
+    table_size = 2 * ( 57 + 52 );
+
+    p += 4 * 2;                 /* First 4 constants have no device tables */
+    for ( i = 0; i < 52; ++i )
+    {
+      p += 2;                                            /* skip the value */
+      OTV_OPTIONAL_OFFSET( DeviceTableOffset );
+      OTV_SIZE_CHECK( DeviceTableOffset );
+      if ( DeviceTableOffset )
+        otv_Device_validate( table + DeviceTableOffset, valid );
+    }
+
+    OTV_EXIT;
+  }
+
+
+  /*************************************************************************/
+  /*************************************************************************/
+  /*****                                                               *****/
+  /*****                   MATH ITALICS CORRECTION                     *****/
+  /*****                 MATH TOP ACCENT ATTACHMENT                    *****/
+  /*****                                                               *****/
+  /*************************************************************************/
+  /*************************************************************************/
+
+  static void
+  otv_MathItalicsCorrectionInfo_validate( FT_Bytes       table,
+                                          OTV_Validator  valid,
+                                          FT_Int         isItalic )
+  {
+    FT_Bytes  p = table;
+    FT_UInt   i, cnt, table_size ;
+
+    OTV_OPTIONAL_TABLE( Coverage );
+    OTV_OPTIONAL_TABLE( DeviceTableOffset );
+
+
+    OTV_NAME_ENTER( isItalic ? "MathItalicsCorrectionInfo"
+                             : "MathTopAccentAttachment" );
+
+    OTV_LIMIT_CHECK( 4 );
+
+    OTV_OPTIONAL_OFFSET( Coverage );
+    cnt = FT_NEXT_USHORT( p );
+
+    OTV_LIMIT_CHECK( 4 * cnt );
+    table_size = 4 + 4 * cnt;
+
+    OTV_SIZE_CHECK( Coverage );
+    otv_Coverage_validate( table + Coverage, valid );
+
+    for ( i = 0; i < cnt; ++i )
+    {
+      p += 2;                                            /* Skip the value */
+      OTV_OPTIONAL_OFFSET( DeviceTableOffset );
+      OTV_SIZE_CHECK( DeviceTableOffset );
+      if ( DeviceTableOffset )
+        otv_Device_validate( table + DeviceTableOffset, valid );
+    }
+
+    OTV_EXIT;
+  }
+
+
+  /*************************************************************************/
+  /*************************************************************************/
+  /*****                                                               *****/
+  /*****                           MATH KERNING                        *****/
+  /*****                                                               *****/
+  /*************************************************************************/
+  /*************************************************************************/
+
+  static void
+  otv_MathKern_validate( FT_Bytes       table,
+                         OTV_Validator  valid )
+  {
+    FT_Bytes  p = table;
+    FT_UInt   i, cnt, table_size;
+
+    OTV_OPTIONAL_TABLE( DeviceTableOffset );
+
+
+    /* OTV_NAME_ENTER( "MathKern" );*/
+
+    OTV_LIMIT_CHECK( 2 );
+
+    cnt = FT_NEXT_USHORT( p );
+
+    OTV_LIMIT_CHECK( 4 * cnt + 2 );
+    table_size = 4 + 4 * cnt;
+
+    /* Heights */
+    for ( i = 0; i < cnt; ++i )
+    {
+      p += 2;                                            /* Skip the value */
+      OTV_OPTIONAL_OFFSET( DeviceTableOffset );
+      OTV_SIZE_CHECK( DeviceTableOffset );
+      if ( DeviceTableOffset )
+        otv_Device_validate( table + DeviceTableOffset, valid );
+    }
+
+    /* One more Kerning value */
+    for ( i = 0; i < cnt + 1; ++i )
+    {
+      p += 2;                                            /* Skip the value */
+      OTV_OPTIONAL_OFFSET( DeviceTableOffset );
+      OTV_SIZE_CHECK( DeviceTableOffset );
+      if ( DeviceTableOffset )
+        otv_Device_validate( table + DeviceTableOffset, valid );
+    }
+
+    OTV_EXIT;
+  }
+
+
+  static void
+  otv_MathKernInfo_validate( FT_Bytes       table,
+                             OTV_Validator  valid )
+  {
+    FT_Bytes  p = table;
+    FT_UInt   i, j, cnt, table_size;
+
+    OTV_OPTIONAL_TABLE( Coverage );
+    OTV_OPTIONAL_TABLE( MKRecordOffset );
+
+
+    OTV_NAME_ENTER( "MathKernInfo" );
+
+    OTV_LIMIT_CHECK( 4 );
+
+    OTV_OPTIONAL_OFFSET( Coverage );
+    cnt = FT_NEXT_USHORT( p );
+
+    OTV_LIMIT_CHECK( 8 * cnt );
+    table_size = 4 + 8 * cnt;
+
+    OTV_SIZE_CHECK( Coverage );
+    otv_Coverage_validate( table + Coverage, valid );
+
+    for ( i = 0; i < cnt; ++i )
+    {
+      for ( j = 0; j < 4; ++j )
+      {
+        OTV_OPTIONAL_OFFSET( MKRecordOffset );
+        OTV_SIZE_CHECK( MKRecordOffset );
+        if ( MKRecordOffset )
+          otv_MathKern_validate( table + MKRecordOffset, valid );
+      }
+    }
+
+    OTV_EXIT;
+  }
+
+
+  /*************************************************************************/
+  /*************************************************************************/
+  /*****                                                               *****/
+  /*****                         MATH GLYPH INFO                       *****/
+  /*****                                                               *****/
+  /*************************************************************************/
+  /*************************************************************************/
+
+  static void
+  otv_MathGlyphInfo_validate( FT_Bytes       table,
+                              OTV_Validator  valid )
+  {
+    FT_Bytes  p = table;
+    FT_UInt   MathItalicsCorrectionInfo, MathTopAccentAttachment;
+    FT_UInt   ExtendedShapeCoverage, MathKernInfo;
+
+
+    OTV_NAME_ENTER( "MathGlyphInfo" );
+
+    OTV_LIMIT_CHECK( 8 );
+
+    MathItalicsCorrectionInfo = FT_NEXT_USHORT( p );
+    MathTopAccentAttachment   = FT_NEXT_USHORT( p );
+    ExtendedShapeCoverage     = FT_NEXT_USHORT( p );
+    MathKernInfo              = FT_NEXT_USHORT( p );
+
+    if ( MathItalicsCorrectionInfo )
+      otv_MathItalicsCorrectionInfo_validate(
+        table + MathItalicsCorrectionInfo, valid, TRUE );
+
+    /* Italic correction and Top Accent Attachment have the same format */
+    if ( MathTopAccentAttachment )
+      otv_MathItalicsCorrectionInfo_validate(
+        table + MathTopAccentAttachment, valid, FALSE );
+
+    if ( ExtendedShapeCoverage ) {
+      OTV_NAME_ENTER( "ExtendedShapeCoverage" );
+      otv_Coverage_validate( table + ExtendedShapeCoverage, valid );
+      OTV_EXIT;
+    }
+
+    if ( MathKernInfo )
+      otv_MathKernInfo_validate( table + MathKernInfo, valid );
+
+    OTV_EXIT;
+  }
+
+
+  /*************************************************************************/
+  /*************************************************************************/
+  /*****                                                               *****/
+  /*****                    MATH GLYPH CONSTRUCTION                    *****/
+  /*****                                                               *****/
+  /*************************************************************************/
+  /*************************************************************************/
+
+  static void
+  otv_GlyphAssembly_validate( FT_Bytes       table,
+                              OTV_Validator  valid )
+  {
+    FT_Bytes  p = table;
+    FT_UInt   pcnt, table_size;
+
+    OTV_OPTIONAL_TABLE( DeviceTableOffset );
+
+
+    /* OTV_NAME_ENTER( "GlyphAssembly" ); */
+
+    OTV_LIMIT_CHECK( 6 );
+
+    p += 2;                           /* Skip the Italics Correction value */
+    OTV_OPTIONAL_OFFSET( DeviceTableOffset );
+    pcnt = FT_NEXT_USHORT( p );
+
+    OTV_LIMIT_CHECK( 8 * pcnt );
+    table_size = 6 + 8 * pcnt;
+
+    OTV_SIZE_CHECK( DeviceTableOffset );
+    if ( DeviceTableOffset )
+      otv_Device_validate( table + DeviceTableOffset, valid );
+
+    /* OTV_EXIT; */
+  }
+
+
+  static void
+  otv_MathGlyphConstruction_validate( FT_Bytes       table,
+                                      OTV_Validator  valid )
+  {
+    FT_Bytes  p = table;
+    FT_UInt   vcnt, table_size;
+
+    OTV_OPTIONAL_TABLE( GlyphAssembly );
+
+
+    /* OTV_NAME_ENTER( "MathGlyphConstruction" ); */
+
+    OTV_LIMIT_CHECK( 4 );
+
+    OTV_OPTIONAL_OFFSET( GlyphAssembly );
+    vcnt = FT_NEXT_USHORT( p );
+
+    OTV_LIMIT_CHECK( 4 * vcnt );
+    table_size = 4 + 4 * vcnt;
+
+    OTV_SIZE_CHECK( GlyphAssembly );
+    if ( GlyphAssembly )
+      otv_GlyphAssembly_validate( table+GlyphAssembly, valid );
+
+    /* OTV_EXIT; */
+  }
+
+
+  static void
+  otv_MathVariants_validate( FT_Bytes       table,
+                             OTV_Validator  valid )
+  {
+    FT_Bytes  p = table;
+    FT_UInt   vcnt, hcnt, i, table_size;
+
+    OTV_OPTIONAL_TABLE( VCoverage );
+    OTV_OPTIONAL_TABLE( HCoverage );
+    OTV_OPTIONAL_TABLE( Offset );
+
+
+    OTV_NAME_ENTER( "MathVariants" );
+
+    OTV_LIMIT_CHECK( 10 );
+
+    p += 2;                       /* Skip the MinConnectorOverlap constant */
+    OTV_OPTIONAL_OFFSET( VCoverage );
+    OTV_OPTIONAL_OFFSET( HCoverage );
+    vcnt = FT_NEXT_USHORT( p );
+    hcnt = FT_NEXT_USHORT( p );
+
+    OTV_LIMIT_CHECK( 2 * vcnt + 2 * hcnt );
+    table_size = 10 + 2 * vcnt + 2 * hcnt;
+
+    OTV_SIZE_CHECK( VCoverage );
+    if ( VCoverage )
+      otv_Coverage_validate( table + VCoverage, valid );
+
+    OTV_SIZE_CHECK( HCoverage );
+    if ( HCoverage )
+      otv_Coverage_validate( table + HCoverage, valid );
+
+    for ( i = 0; i < vcnt; ++i )
+    {
+      OTV_OPTIONAL_OFFSET( Offset );
+      OTV_SIZE_CHECK( Offset );
+      otv_MathGlyphConstruction_validate( table + Offset, valid );
+    }
+
+    for ( i = 0; i < hcnt; ++i )
+    {
+      OTV_OPTIONAL_OFFSET( Offset );
+      OTV_SIZE_CHECK( Offset );
+      otv_MathGlyphConstruction_validate( table + Offset, valid );
+    }
+
+    OTV_EXIT;
+  }
+
+
+  /*************************************************************************/
+  /*************************************************************************/
+  /*****                                                               *****/
+  /*****                          MATH TABLE                           *****/
+  /*****                                                               *****/
+  /*************************************************************************/
+  /*************************************************************************/
+
+  /* sets valid->glyph_count */
+
+  FT_LOCAL_DEF( void )
+  otv_MATH_validate( FT_Bytes      table,
+                     FT_UInt       glyph_count,
+                     FT_Validator  ftvalid )
+  {
+    OTV_ValidatorRec  validrec;
+    OTV_Validator     valid = &validrec;
+    FT_Bytes          p     = table;
+    FT_UInt           MathConstants, MathGlyphInfo, MathVariants;
+
+
+    valid->root = ftvalid;
+
+    FT_TRACE3(( "validating MATH table\n" ));
+    OTV_INIT;
+
+    OTV_LIMIT_CHECK( 10 );
+
+    if ( FT_NEXT_ULONG( p ) != 0x10000UL )      /* Version */
+      FT_INVALID_FORMAT;
+
+    MathConstants = FT_NEXT_USHORT( p );
+    MathGlyphInfo = FT_NEXT_USHORT( p );
+    MathVariants  = FT_NEXT_USHORT( p );
+
+    valid->glyph_count = glyph_count;
+
+    otv_MathConstants_validate( table + MathConstants,
+                                valid );
+    otv_MathGlyphInfo_validate( table + MathGlyphInfo,
+                                valid );
+    otv_MathVariants_validate ( table + MathVariants,
+                                valid );
+
+    FT_TRACE4(( "\n" ));
+  }
+
+
+/* END */
diff --git a/src/otvalid/otvmod.c b/src/otvalid/otvmod.c
index 157272f..c280299 100644
--- a/src/otvalid/otvmod.c
+++ b/src/otvalid/otvmod.c
@@ -4,7 +4,7 @@
 /*                                                                         */
 /*    FreeType's OpenType validation module implementation (body).         */
 /*                                                                         */
-/*  Copyright 2004, 2005, 2006 by                                          */
+/*  Copyright 2004, 2005, 2006, 2007 by                                    */
 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
 /*                                                                         */
 /*  This file is part of the FreeType project, and may only be used,       */
@@ -79,12 +79,14 @@
     FT_Byte* volatile         gpos;
     FT_Byte* volatile         gsub;
     FT_Byte* volatile         jstf;
+    FT_Byte* volatile         math;
     FT_ULong                  len_base, len_gdef, len_gpos, len_gsub, len_jstf;
+    FT_ULong                  len_math;
     FT_ValidatorRec volatile  valid;
 
 
-    base     = gdef     = gpos     = gsub     = jstf     = NULL;
-    len_base = len_gdef = len_gpos = len_gsub = len_jstf = 0;
+    base     = gdef     = gpos     = gsub     = jstf     = math     = NULL;
+    len_base = len_gdef = len_gpos = len_gsub = len_jstf = len_math = 0;
 
     /* load tables */
 
@@ -123,6 +125,13 @@
         goto Exit;
     }
 
+    if ( ot_flags & FT_VALIDATE_MATH )
+    {
+      error = otv_load_table( face, TTAG_MATH, &math, &len_math );
+      if ( error )
+        goto Exit;
+    }
+
     /* validate tables */
 
     if ( base )
@@ -175,6 +184,16 @@
         goto Exit;
     }
 
+    if ( math )
+    {
+      ft_validator_init( &valid, math, math + len_math, FT_VALIDATE_DEFAULT );
+      if ( ft_setjmp( valid.jump_buffer ) == 0 )
+        otv_MATH_validate( math, face->num_glyphs, &valid );
+      error = valid.error;
+      if ( error )
+        goto Exit;
+    }
+
     *ot_base = (FT_Bytes)base;
     *ot_gdef = (FT_Bytes)gdef;
     *ot_gpos = (FT_Bytes)gpos;
@@ -192,6 +211,12 @@
       FT_FREE( gsub );
       FT_FREE( jstf );
     }
+    {
+      FT_Memory  memory = FT_FACE_MEMORY( face );
+
+
+      FT_FREE( math );                 /* Can't return this as API is frozen */
+    }
 
     return error;
   }
diff --git a/src/otvalid/rules.mk b/src/otvalid/rules.mk
index 48f1233..53bd41e 100644
--- a/src/otvalid/rules.mk
+++ b/src/otvalid/rules.mk
@@ -3,7 +3,7 @@
 #
 
 
-# Copyright 2004 by
+# Copyright 2004, 2007 by
 # David Turner, Robert Wilhelm, and Werner Lemberg.
 #
 # This file is part of the FreeType project, and may only be used, modified,
@@ -31,14 +31,15 @@ OTV_DRV_SRC := $(OTV_DIR)/otvbase.c  \
                $(OTV_DIR)/otvgpos.c  \
                $(OTV_DIR)/otvgsub.c  \
                $(OTV_DIR)/otvjstf.c  \
+               $(OTV_DIR)/otvmath.c  \
                $(OTV_DIR)/otvmod.c
 
 # OTV driver headers
 #
-OTV_DRV_H := $(OTV_DIR)/otvalid.h \
-             $(OTV_DIR)/otverror.h  \
+OTV_DRV_H := $(OTV_DIR)/otvalid.h  \
              $(OTV_DIR)/otvcommn.h \
-             $(OTV_DIR)/otvgpos.h \
+             $(OTV_DIR)/otverror.h \
+             $(OTV_DIR)/otvgpos.h  \
              $(OTV_DIR)/otvmod.h