-
Notifications
You must be signed in to change notification settings - Fork 13
/
OpenType.spec
executable file
·1927 lines (1594 loc) · 63 KB
/
OpenType.spec
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
/**
This is the specification for OpenType fonts, based on the information
found at https://www.microsoft.com/typography/otspec/otff.htm and
linked pages for individual tables.
**/
Defining Collection SFNT {
// "private" collection
Collection _tableRecord {
ASCII[4] tag // four byte table name
ULONG checkSum // CheckSum for this table.
GLOBAL ULONG OFFSET offset TO VALUE(tag) // Offset from beginning of TrueType font file.
ULONG length // Length of this table.
}
LONG version // 0x00010000 for TTF , string 'OTTO' for CFF
USHORT numTables // Number of tables in this font
USHORT searchRange // (Maximum power of 2 <= numTables) x 16.
USHORT entrySelector // Log2(maximum power of 2 <= numTables).
USHORT rangeShift // NumTables x 16-searchRange.
_tableRecord[numTables] tableRecords // 16 byte table records
}
/**
Required tables:
cmap - Character to glyph mapping
head - Font header
hhea - Horizontal header
hmtx - Horizontal metrics
maxp - Maximum profile
name - Naming table
OS/2 - OS/2 and Windows specific metrics
post - PostScript information
**/
/**
* https://www.microsoft.com/typography/otspec/cmap.htm
*/
Collection cmap {
// "private" collection
Collection _subtable {
USHORT format
if(format==0) {
USHORT length
USHORT language
BYTE[256] glyphIdArray
}
if(format==2) {
// "private" collection
Collection _subHeaders {
USHORT firstCode
USHORT entryCount
SHORT idDelta
USHORT idRangeOffset
}
USHORT length
USHORT language
USHORT[256] subHeaderKeys
/* What is the value for these lengths? I don't understand the description in the official specification */
_subHeaders[0] subHeaders // Variable-length array of subHeader structures.
USHORT[0] glyphIndexArray // Variable-length array containing subarrays used for mapping the low byte of 2-byte characters.
}
if(format==4) {
USHORT length
USHORT language
USHORT segCountX2
USHORT searchRange
USHORT entrySelector
USHORT rangeShift
USHORT[segCountX2/2] endCount // the table encodes segCount as twice the value it really is...
RESERVED USHORT
USHORT[segCountX2/2] startCount
SHORT[segCountX2/2] idDelta
USHORT[segCountX2/2] idRangeOffset
// FIXME: ideally I don't want to see struct.length
// in the following array. It's in there right
// now as temporary solution to the problem
// of not having an AST =)
//
USHORT[(struct.length - (HERE - START))/2] glyphIdArray // this array runs until the end of the data block
}
if(format==6) {
USHORT length
USHORT language
USHORT firstCode
USHORT entryCount
USHORT[entryCount] glyphIdArray
}
if(format==8) {
// "private" collection
Collection _group {
ULONG startCharCode
ULONG endCharCode
ULONG startGlyphID
}
RESERVED USHORT
ULONG length
ULONG language
BYTE[8192] is32
ULONG nGroups
_group[nGroups] groups
}
if(format==10) {
RESERVED USHORT
ULONG length
ULONG language
ULONG startCharCode
ULONG numChars
USHORT[numChars] glyphs
}
if(format==12) {
// "private" collection
Collection _group {
ULONG startCharCode
ULONG endCharCode
ULONG startGlyphID
}
RESERVED USHORT
ULONG length
ULONG language
ULONG nGroups
_group[nGroups] groups
}
if(format==13) {
// "private" collection
Collection _group {
ULONG startCharCode
ULONG endCharCode
ULONG startGlyphID
}
RESERVED USHORT
ULONG length
ULONG language
ULONG nGroups
_group[nGroups] groups
}
if(format==14) {
// "private" collections
Collection _unicodeValueRanges {
UINT24 startUnicodeValue
BYTE additionalCount
}
Collection _defaultUVSTable {
ULONG numUnicodeValueRanges
_unicodeValueRanges[numUnicodeValueRanges] unicodeValueRanges
}
Collection _UVSMapping {
UINT24 unicodeValue
USHORT glyphID
}
Collection _nonDefaultUVSTable {
ULONG numUVSMappings
_UVSMapping[numUVSMappings] UVSMappings
}
Collection _varSelectorRecord {
UINT24 varSelector
IMMEDIATE ULONG OFFSET defaultUVSOffset TO _defaultUVSTable // Offset to Default UVS Table, from here. May be 0.
IMMEDIATE ULONG OFFSET nonDefaultUVSOffset TO _nonDefaultUVSTable // Offset to Non-Default UVS Table, from here. May be 0.
/* I don't actually know what happens here. The documentation is not clear enough */
}
ULONG length
ULONG numVarSelectorRecords
_varSelectorRecord[numVarSelectorRecords] varSelectorRecords
}
}
Collection _encodingRecord {
USHORT platformID
USHORT encodingID
RELATIVE ULONG OFFSET offset TO _subtable FROM OWNER.START // offset from beginning of table to the subtable for this encoding.
}
USHORT version
USHORT numTables
_encodingRecord[numTables] encodingRecords
}
/**
* https://www.microsoft.com/typography/otspec/head.htm
*/
Collection head {
LONG version
LONG fontRevision
ULONG checkSumAdjustment
ULONG magicNumber
if(magicNumber!=0x5F0F3CF5) {
TERMINATE magic number mismatch - this is not an OpenType font file, or at least not a legal one.
}
USHORT flags
USHORT unitsPerEm
LONG created
LONG modified
SHORT xMin
SHORT yMin
SHORT xMax
SHORT yMax
USHORT macStyle
USHORT lowestRecPPEM
SHORT fontDirectionHint // Deprecated, must be 2.
if(fontDirectionHint!=2) {
WARN fontDirectionHint has the wrong value: this record has been deprecated and should be set to 2
}
SHORT indexToLocFormat // 0 for USHORT offsets, 1 for ULONG offsets
SHORT glyphDataFormat
}
/**
* https://www.microsoft.com/typography/otspec/hhea.htm
*/
Collection hhea {
LONG version
SHORT Ascender
SHORT Descender
SHORT LineGap
USHORT advanceWidthMax
SHORT minLeftSideBearing
SHORT minRightSideBearing
SHORT xMaxExtent
SHORT caretSlopeRise
SHORT caretSlopeRun
SHORT caretOffset
RESERVED SHORT
RESERVED SHORT
RESERVED SHORT
RESERVED SHORT
SHORT metricDataFormat
USHORT numberOfHMetrics
}
/**
* https://www.microsoft.com/typography/otspec/hmtx.htm
*/
Collection hmtx {
// "private" collection
Collection _longHorMetric {
USHORT advanceWidth;
SHORT lsb;
}
_longHorMetric[hhea.numberOfHMetrics] hMetrics
SHORT[maxp.numGlyphs - hhea.numberOfHMetrics] leftSideBearing
}
/**
* https://www.microsoft.com/typography/otspec/maxp.htm
*/
Collection maxp {
LONG version
if(version==0x00005000) { // CFF
USHORT numGlyphs
}
if(version==0x00010000) { // TTF
USHORT numGlyphs
USHORT maxPoints
USHORT maxContours
USHORT maxCompositePoints
USHORT maxCompositeContours
USHORT maxZones
USHORT maxTwilightPoints
USHORT maxStorage
USHORT maxFunctionDefs
USHORT maxInstructionDefs
USHORT maxStackElements
USHORT maxSizeOfInstructions
USHORT maxComponentElements
USHORT maxComponentDepth
}
}
/**
* https://www.microsoft.com/typography/otspec/name.htm
*/
Collection name {
USHORT format
USHORT count
USHORT stringOffset
Collection _nameString {
ASCII[OWNER.length] nameString
}
Collection _nameRecord {
USHORT platformID
USHORT encodingID
USHORT languageID
USHORT nameID
USHORT length
RELATIVE USHORT OFFSET offset TO _nameString FROM OWNER.START+owner.stringOffset
}
_nameRecord[count] nameRecord
Collection _langTagRecord {
USHORT length
USHORT OFFSET offset RELATIVE TO OWNER.stringOffset // String offset from start of storage area (in bytes)
}
if(format==1) {
USHORT langTagCount
_langTagRecord[langTagCount] langTagRecord
}
}
/**
* https://www.microsoft.com/typography/otspec/os2.htm
*/
Collection OS_2 {
USHORT version
// https://www.microsoft.com/typography/otspec/os2ver0.htm
if(version==0x0000) {
SHORT xAvgCharWidth
USHORT usWeightClass
USHORT usWidthClass
USHORT fsType
SHORT ySubscriptXSize
SHORT ySubscriptYSize
SHORT ySubscriptXOffset
SHORT ySubscriptYOffset
SHORT ySuperscriptXSize
SHORT ySuperscriptYSize
SHORT ySuperscriptXOffset
SHORT ySuperscriptYOffset
SHORT yStrikeoutSize
SHORT yStrikeoutPosition
SHORT sFamilyClass
BYTE[10] panose
ULONG[4] ulCharRange //Bits 0-31
ASCII[4] achVendID
USHORT fsSelection
USHORT usFirstCharIndex
USHORT usLastCharIndex
SHORT sTypoAscender
SHORT sTypoDescender
SHORT sTypoLineGap
USHORT usWinAscent
USHORT usWinDescent
}
//https://www.microsoft.com/typography/otspec/os2ver1.htm
if(version==0x0001) {
SHORT xAvgCharWidth
USHORT usWeightClass
USHORT usWidthClass
USHORT fsType
SHORT ySubscriptXSize
SHORT ySubscriptYSize
SHORT ySubscriptXOffset
SHORT ySubscriptYOffset
SHORT ySuperscriptXSize
SHORT ySuperscriptYSize
SHORT ySuperscriptXOffset
SHORT ySuperscriptYOffset
SHORT yStrikeoutSize
SHORT yStrikeoutPosition
SHORT sFamilyClass
BYTE[10] panose
ULONG ulUnicodeRange1 // Bits 0-31
ULONG ulUnicodeRange2 // Bits 32-63
ULONG ulUnicodeRange3 // Bits 64-95
ULONG ulUnicodeRange4 // Bits 96-127
ASCII[4] achVendID
USHORT fsSelection
USHORT usFirstCharIndex
USHORT usLastCharIndex
SHORT sTypoAscender
SHORT sTypoDescender
SHORT sTypoLineGap
USHORT usWinAscent
USHORT usWinDescent
ULONG ulCodePageRange1 // Bits 0-31
ULONG ulCodePageRange2 // Bits 32-63
}
// https://www.microsoft.com/typography/otspec/os2ver2.htm
if(version==0x0002) {
SHORT xAvgCharWidth
USHORT usWeightClass
USHORT usWidthClass
USHORT fsType
SHORT ySubscriptXSize
SHORT ySubscriptYSize
SHORT ySubscriptXOffset
SHORT ySubscriptYOffset
SHORT ySuperscriptXSize
SHORT ySuperscriptYSize
SHORT ySuperscriptXOffset
SHORT ySuperscriptYOffset
SHORT yStrikeoutSize
SHORT yStrikeoutPosition
SHORT sFamilyClass
BYTE[10] panose
ULONG ulUnicodeRange1 // Bits 0-31
ULONG ulUnicodeRange2 // Bits 32-63
ULONG ulUnicodeRange3 // Bits 64-95
ULONG ulUnicodeRange4 // Bits 96-127
ASCII[4] achVendID
USHORT fsSelection
USHORT usFirstCharIndex
USHORT usLastCharIndex
SHORT sTypoAscender
SHORT sTypoDescender
SHORT sTypoLineGap
USHORT usWinAscent
USHORT usWinDescent
ULONG ulCodePageRange1 // Bits 0-31
ULONG ulCodePageRange2 // Bits 32-63
SHORT sxHeight
SHORT sCapHeight
USHORT usDefaultChar
USHORT usBreakChar
USHORT usMaxContext
}
// https://www.microsoft.com/typography/otspec/os2ver3.htm
if(version==0x0003) {
SHORT xAvgCharWidth
USHORT usWeightClass
USHORT usWidthClass
USHORT fsType
SHORT ySubscriptXSize
SHORT ySubscriptYSize
SHORT ySubscriptXOffset
SHORT ySubscriptYOffset
SHORT ySuperscriptXSize
SHORT ySuperscriptYSize
SHORT ySuperscriptXOffset
SHORT ySuperscriptYOffset
SHORT yStrikeoutSize
SHORT yStrikeoutPosition
SHORT sFamilyClass
BYTE[10] panose
ULONG ulUnicodeRange1 // Bits 0-31
ULONG ulUnicodeRange2 // Bits 32-63
ULONG ulUnicodeRange3 // Bits 64-95
ULONG ulUnicodeRange4 // Bits 96-127
ASCII[4] achVendID
USHORT fsSelection
USHORT usFirstCharIndex
USHORT usLastCharIndex
SHORT sTypoAscender
SHORT sTypoDescender
SHORT sTypoLineGap
USHORT usWinAscent
USHORT usWinDescent
ULONG ulCodePageRange1 // Bits 0-31
ULONG ulCodePageRange2 // Bits 32-63
SHORT sxHeight
SHORT sCapHeight
USHORT usDefaultChar
USHORT usBreakChar
USHORT usMaxContext
}
if(version==0x0004) {
SHORT xAvgCharWidth
USHORT usWeightClass
USHORT usWidthClass
USHORT fsType
SHORT ySubscriptXSize
SHORT ySubscriptYSize
SHORT ySubscriptXOffset
SHORT ySubscriptYOffset
SHORT ySuperscriptXSize
SHORT ySuperscriptYSize
SHORT ySuperscriptXOffset
SHORT ySuperscriptYOffset
SHORT yStrikeoutSize
SHORT yStrikeoutPosition
SHORT sFamilyClass
BYTE[10] panose
ULONG ulUnicodeRange1 // Bits 0-31
ULONG ulUnicodeRange2 // Bits 32-63
ULONG ulUnicodeRange3 // Bits 64-95
ULONG ulUnicodeRange4 // Bits 96-127
ASCII[4] achVendID
USHORT fsSelection
USHORT usFirstCharIndex
USHORT usLastCharIndex
SHORT sTypoAscender
SHORT sTypoDescender
SHORT sTypoLineGap
USHORT usWinAscent
USHORT usWinDescent
ULONG ulCodePageRange1 // Bits 0-31
ULONG ulCodePageRange2 // Bits 32-63
SHORT sxHeight
SHORT sCapHeight
USHORT usDefaultChar
USHORT usBreakChar
USHORT usMaxContext
}
}
// https://www.microsoft.com/typography/otspec/post.htm
Collection post {
ULONG version
ULONG italicAngle
SHORT underlinePosition
SHORT underlineThickness
ULONG isFixedPitch
ULONG minMemType42
ULONG maxMemType42
ULONG minMemType1
ULONG maxMemType1
if(version==0x00020000) {
USHORT numberOfGlyphs
//
// FIXME
// This is commented off because there is no transform for resolving RHS table.values
//
// if(numberOfGlyphs!=maxp.numGlyphs) {
// WARN post.numberOfGlyphs should be equal to maxp.numGlyphs, but this is not the case.
// }
//
USHORT[numberOfGlyphs] glyphNameIndex
if(numberOfGlyphs - 258 > 0) {
ASCII[numberOfGlyphs - 258] names
}
}
if(version==0x00025000) {
USHORT numberOfGlyphs
ASCII[numberOfGlyphs] offset
}
}
/**
Optional tables: TTF:
cvt - Control Value Table
fpgm - Font program
glyf - Glyph data
loca - Index to location
prep - CVT Program
**/
// http://www.microsoft.com/typography/otspec/cvt.htm
Collection cvt_ {
// FWORD[n] List of n values referenceable by instructions. n is the number of FWORD items that fit in the size of the table.
/**
Can this be done easily? how do we access the table record in the font header to find out the length of this table?
**/
}
// http://www.microsoft.com/typography/otspec/fpgm.htm
Collection fpgm {
// BYTE[n] Instructions // n is the number of BYTE items that fit in the size of the table.
/**
Can this be done easily? how do we access the table record in the font header to find out the length of this table?
**/
}
// http://www.microsoft.com/typography/otspec/glyf.htm
Collection glyf {
/*
Collection _glyfHeader {
SHORT numberOfContours
SHORT xMin
SHORT yMin
SHORT xMax
SHORT yMax
if(numberOfContours >= 0) {
USHORT[numberOfContours] endPtsOfContours
USHORT instructionLength
BYTE[instructionLength] instructions
BYTE flags[n]
BYTE or SHORT xCoordinates[ ] First coordinates relative to (0,0); others are relative to previous point.
BYTE or SHORT yCoordinates[ ]
}
if(numberOfContours < 0) {
}
}
// we probably do not want to read all this data in immediately
// _glyfHeader[maxp.numGlyphs] glyphs
*/
}
// http://www.microsoft.com/typography/otspec/loca.htm
Collection loca {
if(head.indexToLocFormat == 0) {
USHORT[maxp.numGlyphs+1] offsets
}
if(head.indexToLocFormat == 1) {
ULONG[maxp.numGlyphs+1] offsets
}
}
// http://www.microsoft.com/typography/otspec/prep.htm
Collection prep {
//BYTE[n] Set of instructions executed whenever point size or font or transformation change. n is the number of BYTE items that fit in the size of the table.
/**
Can this be done easily? how do we access the table record in the font header to find out the length of this table?
**/
}
/**
Optional tables: CFF and VORG
CFF - PostScript font program (compact font format)
VORG - Vertical Origin
**/
Collection CFF_ {}
Collection VORG {}
/**
Advanced typographic tables:
BASE - Baseline data
GDEF - Glyph definition data
GPOS - Glyph positioning data
GSUB - Glyph substitution data
JSTF - Justification data
See https://www.microsoft.com/typography/otspec/chapter2.htm
**/
Collection BASE {}
Collection GDEF {}
/**
OpenType Layout Common Table Formats
See https://www.microsoft.com/typography/OTSPEC/chapter2.htm
**/
Collection _ScriptList {
USHORT ScriptCount
Collection _ScriptRecord {
ASCII[4] ScriptTag
Collection _ScriptTable {
Collection _LangSysTable {
RESERVED USHORT // OFFSET LookupOrder NULL (reserved for an offset to a reordering table)
USHORT ReqFeatureIndex // Index of a feature required for this language system - if no required features = 0xFFFF
USHORT FeatureCount // Number of FeatureIndex values for this language system - excludes the required feature
USHORT[FeatureCount] FeatureIndex // Array of indices into the FeatureList - in arbitrary order
}
Collection _LangSysRecord {
ASCII[4] LangSysTag
// Offset to LangSys table, relative to the beginning of the Script table
RELATIVE USHORT OFFSET LangSys TO _LangSysTable FROM OWNER.START
}
RELATIVE USHORT OFFSET DefaultLangSys TO _LangSysTable FROM START
USHORT LangSysCount
_LangSysRecord[LangSysCount] LangSysRecords
}
// Offset to Script table, relative to the beginning of the ScriptList
RELATIVE USHORT OFFSET Script TO _ScriptTable FROM (OWNER.OWNER.START + OWNER.OWNER.ScriptList)
}
_ScriptRecord[ScriptCount] ScriptRecords
}
Collection _FeatureList {
USHORT FeatureCount // Number of FeatureRecords in this table
Collection _FeatureRecord {
ASCII[4] FeatureTag // 4-byte feature identification tag
Collection _FeatureTable {
RESERVED USHORT // OFFSET FeatureParams = NULL (reserved for offset to FeatureParams)
USHORT LookupCount // Number of LookupList indices for this feature
USHORT[LookupCount] LookupListIndex // Array of LookupList indices for this feature - zero-based (first lookup is LookupListIndex = 0)
}
// Offset to Feature table, relative to the beginning of the FeatureList
RELATIVE USHORT OFFSET Feature TO _FeatureTable FROM (OWNER.OWNER.START + OWNER.OWNER.FeatureList)
}
_FeatureRecord[FeatureCount] FeatureRecords // Array of FeatureRecords - zero-based (first feature has FeatureIndex = 0) - listed alphabetically by FeatureTag
}
// Used by: GPOS LookupType 2: Pair Adjustment Positioning Subtable
// Used by: GPOS LookupType 7: Contextual Positioning Subtables
// Used by: GPOS LookupType 8: Chaining Contextual Positioning Subtable
// Used by: GSUB LookupType 5: Contextual Substitution Subtable - This one is properly messed up
Collection _ClassDefTable {
USHORT ClassFormat
if(ClassFormat==1) {
USHORT StartGlyph
USHORT GlyphCount
USHORT[GlyphCount] ClassValueArray
}
if(ClassFormat==2) {
USHORT ClassRangeCount
Collection _ClassRangeRecord {
USHORT Start
USHORT End
USHORT Class
}
_ClassRangeRecord[RangeCount] ClassRangeRecord
}
}
Collection _CoverageTable {
USHORT CoverageFormat
if(CoverageFormat==1) {
USHORT GlyphCount
USHORT[GlyphCount] GlyphArray
}
if(CoverageFormat==2) {
USHORT RangeCount
Collection _RangeRecord {
USHORT Start
USHORT End
USHORT StartCoverageIndex
}
_RangeRecord[RangeCount] RangeRecords
}
}
/**
GPOS - The Glyph Positioning Table
See https://www.microsoft.com/typography/OTSPEC/gpos.htm
**/
Collection GPOS {
LONG Version
if(Version!=0x00010000) {
TERMINATE Unknown GPOS table version
}
LOCAL USHORT OFFSET ScriptList TO _ScriptList
LOCAL USHORT OFFSET FeatureList TO _FeatureList
Collection _LookupList {
USHORT LookupCount // Number of lookups in this table
USHORT[LookupCount] Lookup // Array of offsets to Lookup tables -from beginning of LookupList - zero based (first lookup is Lookup index = 0)
// Seen: LookupType 2
// Seen: LookupType 4
// Seen: LookupType 6
Collection _Lookuptable {
USHORT LookupType // GSUB-specific lookup types, explained below
USHORT LookupFlag // Lookup qualifiers
USHORT SubTableCount // Number of SubTables for this lookup
USHORT[SubTableCount] SubTable // Array of offsets to SubTables - from beginning of Lookup table
Collection _SubTable {
// shared by all subtables
USHORT PosFormat
// Anchor Table
// Seen: format=1
// Used by: GPOS LookupType 3: Cursive Attachment Positioning Subtable
// Used by: GPOS LookupType 4: MarkToBase Attachment Positioning Subtable
// Used by: GPOS LookupType 5: MarkToLigature Attachment Positioning Subtable
// Used by: GPOS LookupType 6: MarkToMark Attachment Positioning Subtable
// Used by: MarkArray
Collection _Anchor {
USHORT AnchorFormat
if(AnchorFormat==1) {
SHORT XCoordinate // Horizontal value-in design units
SHORT YCoordinate // Vertical value-in design units
}
if(AnchorFormat==2) {
SHORT XCoordinate // Horizontal value-in design units
SHORT YCoordinate // Vertical value-in design units
USHORT AnchorPoint // Index to glyph contour point
}
if(AnchorFormat==3) {
SHORT XCoordinate // Horizontal value-in design units
SHORT YCoordinate // Vertical value-in design units
USHORT XDeviceTable // Offset to Device table for X coordinate-from beginning of Anchor table (may be NULL)
USHORT YDeviceTable // Offset to Device table for Y coordinate-from beginning of Anchor table (may be NULL)
// XXX XXX Need _DeviceTable definitions
}
}
// Used by: GPOS LookupType 4: MarkToBase Attachment Positioning Subtable
// Used by: GPOS LookupType 5: MarkToLigature Attachment Positioning Subtable
// Used by: GPOS LookupType 6: MarkToMark Attachment Positioning Subtable
Collection _MarkArray {
USHORT MarkCount // Number of MarkRecords
Collection _MarkRecord {
USHORT Class // Class defined for this mark
// Offset to Anchor table-from beginning of MarkArray table
RELATIVE USHORT OFFSET MarkAnchor TO _Anchor FROM OWNER.START
}
_MarkRecord[MarkCount] MarkRecord // Array of MarkRecords-in Coverage order
}
// ==========================================
// LookupType 1: Single Adjustment Positioning Subtable
// ==========================================
// Not tested
if(OWNER.LookupType==1) {
// Offset to Coverage table, relative to the beginning of the Substitution table
RELATIVE USHORT OFFSET Coverage TO _CoverageTable FROM START
Collection _ValueRecord {
if(OWNER.ValueFormat&0x0001) {
SHORT XPlacement // Horizontal adjustment for placement-in design units
}
if(OWNER.ValueFormat&0x0002) {
SHORT YPlacement // Vertical adjustment for placement-in design units
}
if(OWNER.ValueFormat&0x0004) {
SHORT XAdvance // Horizontal adjustment for advance-in design units (only used for horizontal writing)
}
if(OWNER.ValueFormat&0x0008) {
SHORT YAdvance // Vertical adjustment for advance-in design units (only used for vertical writing)
}
if(OWNER.ValueFormat&0x0010) {
USHORT XPlaDevice // Offset to Device table for horizontal placement-measured from beginning of PosTable (may be NULL)
}
if(OWNER.ValueFormat&0x0020) {
USHORT YPlaDevice // Offset to Device table for vertical placement-measured from beginning of PosTable (may be NULL)
}
if(OWNER.ValueFormat&0x0040) {
USHORT XAdvDevice // Offset to Device table for horizontal advance-measured from beginning of PosTable (may be NULL)
}
if(OWNER.ValueFormat&0x0080) {
USHORT YAdvDevice // Offset to Device table for vertical advance-measured from beginning of PosTable (may be NULL)
}
}
if(PosFormat==1) {
// Defines the types of data in the ValueRecord
USHORT ValueFormat
// ValueRecord Value
_ValueRecord[1] Value
}
if(PosFormat==2) {
// Defines the types of data in the ValueRecord
USHORT ValueFormat
//Number of ValueRecords
USHORT ValueCount
// Array of ValueRecords-positioning values applied to glyphs
_ValueRecord[ValueCount] Value
}
}
// ============================================
// LookupType 2: Pair Adjustment Positioning Subtable
// ============================================
// Seen: type 2 format 1 ValueFormat2==3
// Not seen: type 2 format 2
if(OWNER.LookupType==2) {
RELATIVE USHORT OFFSET Coverage TO _CoverageTable FROM START
// =============================
// Format 1: Adjustments for glyph pairs
// =============================
if(PosFormat==1) {
// Defines the types of data in ValueRecord1-for the first glyph in the pair-may be zero (0)
USHORT ValueFormat1
// Defines the types of data in ValueRecord2-for the second glyph in the pair-may be zero (0)
USHORT ValueFormat2
// Number of PairSet tables
USHORT PairSetCount
// Array of offsets to PairSet tables-from beginning of PairPos subtable-ordered by Coverage Index
USHORT[PairSetCount] PairSetOffset
Collection _ValueRecord1 {
if(OWNER.OWNER.OWNER.ValueFormat1&0x0001) {
SHORT XPlacement // Horizontal adjustment for placement-in design units
}
if(OWNER.OWNER.OWNER.ValueFormat1&0x0002) {
SHORT YPlacement // Vertical adjustment for placement-in design units
}
if(OWNER.OWNER.OWNER.ValueFormat1&0x0004) {
SHORT XAdvance // Horizontal adjustment for advance-in design units (only used for horizontal writing)
}
if(OWNER.OWNER.OWNER.ValueFormat1&0x0008) {
SHORT YAdvance // Vertical adjustment for advance-in design units (only used for vertical writing)
}
if(OWNER.OWNER.OWNER.ValueFormat1&0x0010) {
USHORT XPlaDevice // Offset to Device table for horizontal placement-measured from beginning of PosTable (may be NULL)
}
if(OWNER.OWNER.OWNER.ValueFormat1&0x0020) {
USHORT YPlaDevice // Offset to Device table for vertical placement-measured from beginning of PosTable (may be NULL)
}
if(OWNER.OWNER.OWNER.ValueFormat1&0x0040) {
USHORT XAdvDevice // Offset to Device table for horizontal advance-measured from beginning of PosTable (may be NULL)
}
if(OWNER.OWNER.OWNER.ValueFormat1&0x0080) {
USHORT YAdvDevice // Offset to Device table for vertical advance-measured from beginning of PosTable (may be NULL)
}
}
Collection _ValueRecord2 {
if(OWNER.OWNER.OWNER.ValueFormat2&0x0001) {
SHORT XPlacement // Horizontal adjustment for placement-in design units
}
if(OWNER.OWNER.OWNER.ValueFormat2&0x0002) {
SHORT YPlacement // Vertical adjustment for placement-in design units
}
if(OWNER.OWNER.OWNER.ValueFormat2&0x0004) {
SHORT XAdvance // Horizontal adjustment for advance-in design units (only used for horizontal writing)
}
if(OWNER.OWNER.OWNER.ValueFormat2&0x0008) {
SHORT YAdvance // Vertical adjustment for advance-in design units (only used for vertical writing)
}
if(OWNER.OWNER.OWNER.ValueFormat2&0x0010) {
USHORT XPlaDevice // Offset to Device table for horizontal placement-measured from beginning of PosTable (may be NULL)
}
if(OWNER.OWNER.OWNER.ValueFormat2&0x0020) {
USHORT YPlaDevice // Offset to Device table for vertical placement-measured from beginning of PosTable (may be NULL)
}
if(OWNER.OWNER.OWNER.ValueFormat2&0x0040) {
USHORT XAdvDevice // Offset to Device table for horizontal advance-measured from beginning of PosTable (may be NULL)
}
if(OWNER.OWNER.OWNER.ValueFormat2&0x0080) {
USHORT YAdvDevice // Offset to Device table for vertical advance-measured from beginning of PosTable (may be NULL)
}
}
Collection _PairValueRecord {
USHORT SecondGlyph
_ValueRecord1[1] Value1
_ValueRecord2[1] Value2
}
Collection _PairSetTable {
USHORT PairValueCount
_PairValueRecord[PairValueCount] PairValueRecords
}
_PairSetTable[PairSetCount] PairSetOffsets OFFSET BY PairSetOffset RELATIVE TO START
}
// PairPosFormat2 subtable: Class pair adjustment
if(PosFormat==2) {
// Defines the types of data in ValueRecord1-for the first glyph in the pair-may be zero (0)
USHORT ValueFormat1