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