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