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