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