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