4e1957d2d121ac7f8596ad26812048d0cc786d3f
[m17n/libotf.git] / src / otf.h
1 /* BASIC */
2
3 #define OTF_ERROR_MEMORY        -1
4 #define OTF_ERROR_FILE          -2
5 #define OTF_ERROR_TABLE         -3
6 #define OTF_ERROR_CMAP_PROC     -4
7 #define OTF_ERROR_GDEF_PROC     -5
8 #define OTF_ERROR_GSUB_PROC     -6
9 #define OTF_ERROR_GPOS_PROC     -7
10
11 extern int otf_error;
12
13 typedef unsigned OTF_Tag;
14 typedef unsigned OTF_GlyphID;
15 typedef unsigned OTF_Offset;
16
17 typedef struct
18 {
19   unsigned high;
20   unsigned low;
21 } OTF_Fixed;
22
23 \f
24 /* COMMON */
25
26 /* ScriptList
27      ScriptRecord[]
28        ScriptTag
29      Script[]
30        DefaultLangSys
31        LangSysRecord[]
32          LangSysTag
33        LangSys[]
34          LookupOrder
35          ReqFeatureIndex
36          FeatureIndex[]
37
38   FeatureList
39     FeatureRecored[]
40       FeatureTag
41     Feature[]
42       FeatureParams
43       LookupListIndex[]
44
45   LookupList
46     LookupOffset[]
47     Lookup[]
48       LookupType
49       LookupFlag
50       SubTableOffset[]
51       SubTable[]
52 */
53
54
55 typedef struct OTF_ScriptRecord OTF_ScriptRecord;
56 typedef struct OTF_Script OTF_Script;
57
58 typedef struct
59 {
60   unsigned ScriptCount;
61   OTF_ScriptRecord *ScriptRecord;
62   OTF_Script *Script;
63 } OTF_ScriptList;
64
65 struct OTF_ScriptRecord
66 {
67   OTF_Tag ScriptTag;
68   OTF_Offset Script;
69 };
70
71 typedef struct
72 {
73   OTF_Offset LookupOrder;
74   unsigned ReqFeatureIndex;
75   unsigned FeatureCount;
76   unsigned *FeatureIndex;
77 } OTF_LangSys;
78
79 typedef struct
80 {
81   OTF_Tag LangSysTag;
82   OTF_Offset LangSys;
83 } OTF_LangSysRecord;
84
85 struct OTF_Script
86 {
87   OTF_Offset DefaultLangSysOffset;
88   OTF_LangSys DefaultLangSys;
89   unsigned LangSysCount;
90   OTF_LangSysRecord *LangSysRecord;
91   OTF_LangSys *LangSys;
92 };
93
94 typedef struct OTF_FeatureRecord OTF_FeatureRecord;
95 typedef struct OTF_Feature OTF_Feature;
96
97 typedef struct
98 {
99   unsigned FeatureCount;
100   OTF_FeatureRecord *FeatureRecord;
101   OTF_Feature *Feature;
102 } OTF_FeatureList;
103
104 struct OTF_FeatureRecord
105 {
106   OTF_Tag FeatureTag;
107   OTF_Offset Feature;
108 };
109
110 struct OTF_Feature
111 {
112   OTF_Offset FeatureParams;
113   unsigned LookupCount;
114   unsigned *LookupListIndex;
115 };
116
117 typedef struct OTF_Lookup OTF_Lookup;
118
119 typedef struct
120 {
121   unsigned LookupCount;
122   OTF_Offset *LookupOffset;
123   OTF_Lookup *Lookup;
124 } OTF_LookupList;
125
126 typedef struct OTF_LookupSubTable OTF_LookupSubTable;
127
128 struct OTF_Lookup
129 {
130   unsigned LookupType;
131   unsigned LookupFlag;
132   unsigned SubTableCount;
133   OTF_Offset *SubTableOffset;
134   OTF_LookupSubTable *SubTable;
135 };
136
137 enum OTF_LookupFlagBit
138   {
139     OTF_RightToLeft = 0x0001,
140     OTF_IgnoreBaseGlyphs = 0x0002,
141     OTF_IgnoreLigatures = 0x0004,
142     OTF_IgnoreMarks = 0x8000,
143     OTF_Reserved = 0x00F0,
144     OTF_MarkAttachmentType = 0xFF00
145   };
146     
147 typedef struct OTF_RangeRecord OTF_RangeRecord;
148
149 typedef struct
150 {
151   OTF_Offset offset;
152   unsigned CoverageFormat;
153   unsigned Count;
154   union {
155     OTF_GlyphID *GlyphArray;
156     OTF_RangeRecord *RangeRecord;
157   } table;
158 } OTF_Coverage;
159
160 struct OTF_RangeRecord
161 {
162   OTF_GlyphID Start;
163   OTF_GlyphID End;
164   unsigned StartCoverageIndex;
165 };
166
167 typedef struct OTF_ClassRangeRecord OTF_ClassRangeRecord;
168
169 typedef struct
170 {
171   OTF_Offset offset;
172   unsigned ClassFormat;
173   union {
174     struct {
175       OTF_GlyphID StartGlyph;
176       unsigned GlyphCount;
177       unsigned *ClassValueArray;
178     } f1;
179     struct {
180       unsigned ClassRangeCount;
181       OTF_ClassRangeRecord *ClassRangeRecord;
182     } f2;
183   } f;
184 } OTF_ClassDef;
185
186 struct OTF_ClassRangeRecord
187 {
188   OTF_GlyphID Start;
189   OTF_GlyphID End;
190   unsigned Class;
191 };
192
193 typedef struct
194 {
195   OTF_Offset offset;
196   unsigned StartSize;
197   unsigned EndSize;
198   unsigned DeltaFormat;
199   char *DeltaValue;
200 } OTF_DeviceTable;
201
202 \f
203 /* head */
204 typedef struct
205 {
206   OTF_Fixed TableVersionNumber;
207   OTF_Fixed fontRevision;
208   unsigned checkSumAdjustment;
209   unsigned magicNumber;
210   unsigned flags;
211   int unitsPerEm;
212 } OTF_head;
213
214 \f
215
216 /* GSUB */
217
218 typedef struct
219 {
220   int DeltaGlyphID;
221 } OTF_GSUB_Single1;
222
223 typedef struct
224 {
225   unsigned GlyphCount;
226   OTF_GlyphID *Substitute;
227 } OTF_GSUB_Single2;
228
229 typedef struct OTF_Sequence OTF_Sequence;
230
231 typedef struct
232 {
233   unsigned SequenceCount;
234   OTF_Sequence *Sequence;
235 } OTF_GSUB_Multiple1;
236
237 struct OTF_Sequence
238 {
239   OTF_Offset offset;
240   unsigned GlyphCount;
241   OTF_GlyphID *Substitute;
242 };
243
244 typedef struct OTF_AlternateSet OTF_AlternateSet;
245
246 typedef struct
247 {
248   unsigned AlternateSetCount;
249   OTF_AlternateSet *AlternateSet;
250 } OTF_GSUB_Alternate1;
251
252 struct OTF_AlternateSet
253 {
254   OTF_Offset offset;
255   unsigned GlyphCount;
256   OTF_GlyphID *Alternate;
257 };
258
259 typedef struct OTF_LigatureSet OTF_LigatureSet;
260 typedef struct OTF_Ligature OTF_Ligature;
261
262 typedef struct
263 {
264   unsigned LigSetCount;
265   OTF_LigatureSet *LigatureSet;
266 } OTF_GSUB_Ligature1;
267
268 struct OTF_LigatureSet
269 {
270   OTF_Offset offset;
271   unsigned LigatureCount;
272   OTF_Ligature *Ligature;
273 };
274
275 struct OTF_Ligature
276 {
277   OTF_Offset offset;
278   OTF_GlyphID LigGlyph;
279   unsigned CompCount;
280   OTF_GlyphID *Component;
281 };
282
283 typedef struct
284 {
285   unsigned SequenceIndex;
286   unsigned LookupListIndex;
287 } OTF_SubstLookupRecord;
288
289 typedef struct OTF_SubRuleSet OTF_SubRuleSet;
290
291 typedef struct
292 {
293   unsigned SubRuleSetCount;
294   OTF_SubRuleSet *SubRuleSet;
295 } OTF_GSUB_Context1;
296
297 typedef struct OTF_SubRule OTF_SubRule;
298
299 struct OTF_SubRuleSet
300 {
301   OTF_Offset offset;
302   unsigned SubRuleCount;
303   OTF_SubRule *SubRule;
304 };
305
306 struct OTF_SubRule
307 {
308   OTF_Offset offset;
309   unsigned GlyphCount;
310   unsigned SubstCount;
311   OTF_GlyphID *Input;
312   OTF_SubstLookupRecord *SubstLookupRecord;
313 };
314
315 typedef struct OTF_SubClassSet OTF_SubClassSet;
316
317 typedef struct
318 {
319   OTF_ClassDef ClassDef;
320   unsigned SubClassSetCount;
321   OTF_SubClassSet *SubClassSet;
322 } OTF_GSUB_Context2;
323
324 typedef struct OTF_SubClassRule OTF_SubClassRule;
325
326 struct OTF_SubClassSet
327 {
328   unsigned SubClassRuleCnt;
329   OTF_SubClassRule *SubClassRule;
330 };
331
332 struct OTF_SubClassRule
333 {
334   OTF_Offset offset;
335   unsigned GlyphCount;
336   unsigned SubstCount;
337   unsigned *Class;
338   OTF_SubstLookupRecord *SubstLookupRecord;
339 };
340
341 typedef struct
342 {
343   unsigned GlyphCount;
344   unsigned SubstCount;
345   OTF_Coverage *Coverage;
346   OTF_SubstLookupRecord *SubstLookupRecord;
347 } OTF_GSUB_Context3;
348
349 typedef struct OTF_ChainSubRuleSet OTF_ChainSubRuleSet;
350
351 typedef struct
352 {
353   unsigned ChainSubRuleSetCount;
354   OTF_ChainSubRuleSet *ChainSubRuleSet;
355 } OTF_GSUB_ChainContext1;
356
357 typedef struct OTF_ChainSubRule OTF_ChainSubRule;
358
359 struct OTF_ChainSubRuleSet
360 {
361   OTF_Offset offset;
362   unsigned ChainSubRuleCount;
363   OTF_ChainSubRule *ChainSubRule;
364 };
365
366 struct OTF_ChainSubRule
367 {
368   OTF_Offset offset;
369   unsigned BacktrackGlyphCount;
370   OTF_GlyphID *Backtrack;
371   unsigned InputGlyphCount;
372   OTF_GlyphID *Input;
373   unsigned LookaheadGlyphCount;
374   OTF_GlyphID *LookAhead;
375   unsigned SubstCount;
376   OTF_SubstLookupRecord *SubstLookupRecord;
377 };
378
379 typedef struct OTF_ChainSubClassSet OTF_ChainSubClassSet;
380
381 typedef struct
382 {
383   OTF_ClassDef Backtrack;
384   OTF_ClassDef Input;
385   OTF_ClassDef LookAhead;
386   unsigned ChainSubClassSetCnt;
387   OTF_ChainSubClassSet *ChainSubClassSet;
388 } OTF_GSUB_ChainContext2;
389
390 typedef struct OTF_ChainSubClassRule OTF_ChainSubClassRule;
391
392 struct OTF_ChainSubClassSet
393 {
394   OTF_Offset offset;
395   unsigned ChainSubClassRuleCnt;
396   OTF_ChainSubClassRule *ChainSubClassRule;
397 };
398
399 struct OTF_ChainSubClassRule
400 {
401   OTF_Offset offset;
402   unsigned BacktrackGlyphCount;
403   unsigned *Backtrack;
404   unsigned InputGlyphCount;
405   unsigned *Input;
406   unsigned LookaheadGlyphCount;
407   unsigned *LookAhead;
408   unsigned SubstCount;
409   OTF_SubstLookupRecord *SubstLookupRecord;
410 };
411
412
413 typedef struct
414 {
415   unsigned BacktrackGlyphCount;
416   OTF_Coverage *Backtrack;
417   unsigned InputGlyphCount;
418   OTF_Coverage *Input;
419   unsigned LookaheadGlyphCount;
420   OTF_Coverage *LookAhead;
421   unsigned SubstCount;
422   OTF_SubstLookupRecord *SubstLookupRecord;
423 } OTF_GSUB_ChainContext3;
424
425 typedef struct
426 {
427   unsigned ExtensionLookupType;
428   unsigned ExtentionOffset;
429 } OTF_GSUB_Extension1;
430
431 typedef struct
432 {
433   unsigned BacktrackGlyphCount;
434   OTF_Coverage *Backtrack;
435   unsigned LookaheadGlyphCount;
436   OTF_Coverage *LookAhead;
437   unsigned GlyphCount;
438   OTF_GlyphID *Substitute;
439 } OTF_GSUB_ReverseChainSingle1;
440
441 \f
442 /* GPOS */
443 enum OTF_ValueFormat
444   {
445     OTF_XPlacement = 0x0001,
446     OTF_YPlacement = 0x0002,
447     OTF_XAdvance = 0x0004,
448     OTF_YAdvance = 0x0008,
449     OTF_XPlaDevice = 0x0010,
450     OTF_YPlaDevice = 0x0020,
451     OTF_XAdvDevice = 0x0040,
452     OTF_YAdvDevice = 0x0080
453   };
454
455 typedef struct
456 {
457   int XPlacement;
458   int YPlacement;
459   int XAdvance;
460   int YAdvance;
461   OTF_DeviceTable XPlaDevice;
462   OTF_DeviceTable YPlaDevice;
463   OTF_DeviceTable XAdvDevice;
464   OTF_DeviceTable YAdvDevice;
465 } OTF_ValueRecord;
466
467 typedef struct
468 {
469   OTF_Offset offset;
470   unsigned AnchorFormat;
471   int XCoordinate;
472   int YCoordinate;
473   union {
474     union {
475       unsigned AnchorPoint;
476     } f1;
477     union {
478       OTF_DeviceTable XDeviceTable;
479       OTF_DeviceTable YDeviceTable;
480     } f2;
481   } f;
482 } OTF_Anchor;
483
484 typedef struct
485 {
486   unsigned Class;
487   OTF_Anchor MarkAnchor;
488 } OTF_MarkRecord;
489
490 typedef struct
491 {
492   OTF_Offset offset;
493   unsigned MarkCount;
494   OTF_MarkRecord *MarkRecord;
495 } OTF_MarkArray;
496
497 typedef struct
498 {
499   int dummy;
500 } OTF_GPOS_Single1;
501
502 typedef struct
503 {
504   int dummy;
505 } OTF_GPOS_Single2;
506
507 typedef struct
508 {
509   int dummy;
510 } OTF_GPOS_Pair1;
511
512 typedef struct
513 {
514   OTF_ValueRecord Value1;
515   OTF_ValueRecord Value2;
516 } OTF_Class2Record;
517
518 typedef struct
519 {
520   OTF_Class2Record *Class2Record;
521 } OTF_Class1Record;
522
523 typedef struct
524 {
525   unsigned ValueFormat1;
526   unsigned ValueFormat2;
527   OTF_ClassDef ClassDef1;
528   OTF_ClassDef ClassDef2;
529   unsigned Class1Count;
530   unsigned Class2Count;
531   OTF_Class1Record *Class1Record; /* size: <Class1Count> */
532 } OTF_GPOS_Pair2;
533
534 typedef struct
535 {
536   int dummy;
537 } OTF_GPOS_Cursive1;
538
539 typedef struct
540 {
541   OTF_Anchor *BaseAnchor;
542 } OTF_BaseRecord;
543
544 typedef struct
545 {
546   OTF_Offset offset;
547   unsigned BaseCount;
548   OTF_BaseRecord *BaseRecord;
549 } OTF_BaseArray;
550
551 typedef struct
552 {
553   OTF_Coverage BaseCoverage;
554   unsigned ClassCount;
555   OTF_MarkArray MarkArray;
556   OTF_BaseArray BaseArray;
557 } OTF_GPOS_MarkBase1;
558
559 typedef struct
560 {
561   int dummy;
562 } OTF_GPOS_MarkLig1;
563
564 typedef struct
565 {
566   int dummy;
567 } OTF_GPOS_MarkMark1;
568
569 typedef struct
570 {
571   int dummy;
572 } OTF_GPOS_Context1;
573
574 typedef struct
575 {
576   int dummy;
577 } OTF_GPOS_Context2;
578
579 typedef struct
580 {
581   int dummy;
582 } OTF_GPOS_Context3;
583
584 typedef struct
585 {
586   int dummy;
587 } OTF_GPOS_ChainContext1;
588
589 typedef struct
590 {
591   int dummy;
592 } OTF_GPOS_ChainContext2;
593
594 typedef struct
595 {
596   int dummy;
597 } OTF_GPOS_ChainContext3;
598
599 typedef struct
600 {
601   int dummy;
602 } OTF_GPOS_Extension1;
603
604
605 struct OTF_LookupSubTable
606 {
607   unsigned Format;
608   OTF_Coverage Coverage;
609   union {
610     union {                     /* GSUB */
611       /* LookupType 1 */
612       OTF_GSUB_Single1 single1;
613       OTF_GSUB_Single2 single2;
614       /* LookupType 2 */
615       OTF_GSUB_Multiple1 multiple1;
616       /* LookupType 3 */
617       OTF_GSUB_Alternate1 alternate1;
618       /* LookupType 4 */
619       OTF_GSUB_Ligature1 ligature1;
620       /* LookupType 5 */
621       OTF_GSUB_Context1 context1;
622       OTF_GSUB_Context2 context2;
623       OTF_GSUB_Context3 context3;
624       /* LookupType 6 */
625       OTF_GSUB_ChainContext1 chain_context1;
626       OTF_GSUB_ChainContext2 chain_context2;
627       OTF_GSUB_ChainContext3 chain_context3;
628       /* LookupType 7 */
629       OTF_GSUB_Extension1 extension1;
630       /* LookupType 8 */
631       OTF_GSUB_ReverseChainSingle1 reverse_chain_single1;
632     } gsub;
633
634     union {                     /* GPOS */
635       /* LookupType 1 */
636       OTF_GPOS_Single1 single1;
637       OTF_GPOS_Single2 single2;
638       /* LookupType 2 */
639       OTF_GPOS_Pair1 pair1;
640       OTF_GPOS_Pair2 pair2;
641       /* LookupType 3 */
642       OTF_GPOS_Cursive1 cursive1;
643       /* LookupType 4 */
644       OTF_GPOS_MarkBase1 mark_base1;
645       /* LookupType 5 */
646       OTF_GPOS_MarkLig1 mark_lig1;
647       /* LookupType 6 */
648       OTF_GPOS_MarkMark1 mark_mark1;
649       /* LookupType 7 */
650       OTF_GPOS_Context1 context1;
651       OTF_GPOS_Context2 context2;
652       OTF_GPOS_Context3 context3;
653       /* LookupType 8 */
654       OTF_GPOS_ChainContext1 chain_context1;
655       OTF_GPOS_ChainContext2 chain_context2;
656       OTF_GPOS_ChainContext3 chain_context3;
657       /* LookupType 9 */
658       OTF_GPOS_Extension1 extension1;
659     } gpos;
660   } sub;
661 };
662
663 \f
664 /* GSUB */
665
666 typedef struct
667 {
668   OTF_Fixed Version;
669   OTF_Offset ScriptList;
670   OTF_Offset FeatureList;
671   OTF_Offset LookupList;
672 } OTF_GSUBHeader;
673
674 typedef struct
675 {
676   OTF_GSUBHeader header;
677   OTF_ScriptList script_list;
678   OTF_FeatureList feature_list;
679   OTF_LookupList lookup_list;
680 } OTF_GSUB;
681
682 \f
683 typedef OTF_GSUBHeader OTF_GPOSHeader;
684
685 /* GPOS */
686 typedef struct
687 {
688   OTF_GPOSHeader header;
689   OTF_ScriptList script_list;
690   OTF_FeatureList feature_list;
691   OTF_LookupList lookup_list;
692 } OTF_GPOS;
693
694 \f
695 /* BASE */
696 typedef struct
697 {
698   int dummy;
699 } OTF_BASE;
700
701 \f
702 /* JSTF */
703 typedef struct
704 {
705   int dummy;
706 } OTF_JSTF;
707
708 \f
709 /* GDEF */
710 typedef struct
711 {
712   OTF_Fixed Version;
713   OTF_Offset GlyphClassDef;
714   OTF_Offset AttachList;
715   OTF_Offset LigCaretList;
716   OTF_Offset MarkAttachClassDef;
717 } OTF_GDEFHeader;
718
719 enum OTF_GlyphClassDef
720   {
721     OTF_GlyphClass0 = 0,
722     OTF_GlyphClassBase = 1,
723     OTF_GlyphClassLigature = 2,
724     OTF_GlyphClassMark = 3,
725     OTF_GlyphClassComponent = 4
726   };
727
728 typedef struct
729 {
730   OTF_Offset offset;
731   unsigned PointCount;
732   unsigned *PointIndex;
733 } OTF_AttachPoint;
734
735 typedef struct
736 {
737   OTF_Coverage Coverage;
738   unsigned GlyphCount;
739   OTF_AttachPoint *AttachPoint;
740 } OTF_AttachList;
741
742 typedef struct
743 {
744   OTF_Offset offset;
745   unsigned CaretValueFormat;    /* 1, 2, 3 */
746   union {
747     union {
748       int Coordinate;
749     } f1;
750     union {
751       unsigned CaretValuePoint;
752     } f2;
753     union {
754       int Coordinate;
755       OTF_DeviceTable DeviceTable;
756     } f3;
757   } f;
758 } OTF_CaretValue;
759
760 typedef struct
761 {
762   OTF_Offset offset;
763   unsigned CaretCount;
764   OTF_CaretValue *CaretValue;
765 } OTF_LigGlyph;
766
767 typedef struct
768 {
769   OTF_Coverage Coverage;
770   unsigned LigGlyphCount;
771   OTF_LigGlyph *LigGlyph;
772 } OTF_LigCaretList;
773
774 typedef struct
775 {
776   OTF_GDEFHeader header;
777   OTF_ClassDef glyph_class_def;
778   OTF_AttachList attach_list;
779   OTF_LigCaretList lig_caret_list;
780   OTF_ClassDef mark_attach_class_def;
781 } OTF_GDEF;
782
783 \f
784
785 /* cmap */
786
787 typedef struct
788 {
789   unsigned char glyphIdArray[256];
790 } OTF_EncodingSubtable0;
791
792 typedef struct
793 {
794   unsigned firstCode;
795   unsigned entryCount;
796   int idDelta;
797   unsigned idRangeOffset;
798 } OTF_cmapSubHeader;
799
800 typedef struct
801 {
802   unsigned subHeaderKeys[256];
803   OTF_cmapSubHeader *subHeaders;
804   unsigned *glyphIndexArray;
805 } OTF_EncodingSubtable2;
806
807 typedef struct
808 {
809   unsigned startCount;
810   unsigned endCount;
811   int idDelta;
812   unsigned idRangeOffset;
813 } OTF_cmapSegument;
814
815 typedef struct
816 {
817   unsigned segCountX2;
818   unsigned searchRange;
819   unsigned entrySelector;
820   unsigned rangeShift;
821   OTF_cmapSegument *segments;
822   int GlyphCount;
823   unsigned *glyphIdArray;
824 } OTF_EncodingSubtable4;
825
826 typedef struct
827 {
828   unsigned firstCode;
829   unsigned entryCount;
830   unsigned *glyphIdArray;
831 } OTF_EncodingSubtable6;
832
833 typedef struct
834 {
835   unsigned startCharCode;
836   unsigned endCharCode;
837   unsigned startGlyphID;
838 } OTF_cmapGroup;
839
840 typedef struct
841 {
842   unsigned char is32[8192];
843   unsigned nGroups;
844   OTF_cmapGroup *Groups;
845 } OTF_EncodingSubtable8;
846
847 typedef struct
848 {
849   unsigned startCharCode;
850   unsigned numChars;
851   unsigned *glyphs;
852 } OTF_EncodingSubtable10;
853
854 typedef struct
855 {
856   unsigned nGroups;
857   OTF_cmapGroup *Groups;
858 } OTF_EncodingSubtable12;
859
860 typedef struct
861 {
862   unsigned format;
863   unsigned length;
864   unsigned language;
865   union {
866     OTF_EncodingSubtable0 *f0;
867     OTF_EncodingSubtable2 *f2;
868     OTF_EncodingSubtable4 *f4;
869     OTF_EncodingSubtable6 *f6;
870     OTF_EncodingSubtable8 *f8;
871     OTF_EncodingSubtable10 *f10;
872     OTF_EncodingSubtable12 *f12;
873   }f;
874 } OTF_EncodingSubtable;
875
876 typedef struct
877 {
878   unsigned platformID;
879   unsigned encodingID;
880   unsigned offset;
881   OTF_EncodingSubtable subtable;
882 } OTF_EncodingRecord;
883
884 typedef struct
885 {
886   unsigned version;
887   unsigned numTables;
888   OTF_EncodingRecord *EncodingRecord;
889   OTF_EncodingRecord *Unicode;
890 } OTF_cmap;
891
892 \f
893 /* name */
894 typedef struct
895 {
896   int platformID;
897   int encodingID;
898   int languageID;
899   int nameID;
900   int length;
901   int offset;
902 } OTF_NameRecord;
903
904 #define OTF_max_nameID 20
905
906 typedef struct
907 {
908   int format;
909   int count;
910   int stringOffset;
911   OTF_NameRecord *nameRecord;
912   char *name[OTF_max_nameID + 1];
913 } OTF_name;
914
915 \f
916 /* OTF */
917 typedef struct
918 {
919   OTF_Fixed sfnt_version;
920   unsigned numTables;
921   unsigned searchRange;
922   unsigned enterSelector;
923   unsigned rangeShift;
924 } OTF_OffsetTable;
925
926 typedef struct
927 {
928   OTF_Tag tag;
929   unsigned checkSum;
930   unsigned offset;
931   unsigned length;
932 } OTF_TableDirectory;
933
934 typedef struct
935 {
936   char *filename;
937   OTF_OffsetTable offset_table;
938   OTF_TableDirectory *table_dirs;
939   OTF_head *head;
940   OTF_name *name;
941   OTF_cmap *cmap;
942   OTF_GDEF *gdef;
943   OTF_GSUB *gsub;
944   OTF_GPOS *gpos;
945   /* The following tables are not yet supported.  */
946   // OTF_BASE *base;
947   // OTF_JSTF *jstf;
948 } OTF;
949
950 typedef struct
951 {
952   /* Character code of the glyph.  This is the only member that a
953      client has to set before calling the OTF library function
954      otf_proc.  */
955   int c;
956
957   /* Glyph ID of the glyph.  */
958   OTF_GlyphID glyph_id;
959
960   /* GlyphClass of the glyph.  The value is extracted from the GDEF
961      table of OTF.  */
962   enum OTF_GlyphClassDef GlyphClass;
963
964   /* MarkAttachClassDef of the glyph.  The value is extracted from the
965      GDEF table.  */
966   unsigned MarkAttachClass;  
967
968   /* Positioning format type of the glyph.  The value is the same as
969      the LookupType of the GPOS's Lookup table that is used to decide
970      the positioning of the glyph.  */
971   int positioning_type;
972   union {
973     struct {
974       enum OTF_ValueFormat format;
975       OTF_ValueRecord *value;
976     } f1;
977     struct {
978       enum OTF_ValueFormat format;
979       OTF_ValueRecord *value;
980     } f2;
981     struct {
982       OTF_Anchor *entry_anchor;
983       OTF_Anchor *exit_anchor;
984     } f3;
985     struct {
986       OTF_Anchor *mark_anchor;
987       OTF_Anchor *base_anchor;
988     } f4;
989     struct {
990       OTF_Anchor *mark_anchor;
991       OTF_Anchor *ligature_anchor;
992     } f5;
993     struct {
994       OTF_Anchor *mark1_anchor;
995       OTF_Anchor *mark2_anchor;
996     } f6;
997   } f;
998 } OTF_Glyph;
999
1000 typedef struct
1001 {
1002   int size;
1003   int used;
1004   OTF_Glyph *glyphs;
1005 } OTF_GlyphString;
1006
1007
1008 extern OTF_Tag otf_tag (char *str);
1009
1010 extern OTF *otf_open (char *name);
1011 extern void otf_close (OTF *otf);
1012
1013 extern int otf_cmap (OTF *otf, OTF_GlyphString *gstring);
1014 extern int otf_gdef (OTF *otf, OTF_GlyphString *gstring);
1015 extern int otf_gsub (OTF *otf, OTF_Tag script_tag, OTF_Tag langsys_tag,
1016                      OTF_GlyphString *gstring);
1017 extern int otf_gpos (OTF *otf, OTF_Tag script_tag, OTF_Tag langsys_tag,
1018                      OTF_GlyphString *gstring);
1019
1020 extern int otf_lookup_cmap (OTF *otf, int c);