bd0704dc9f8c95f5cae2c6d67f1b473573d30331
[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   OTF_EncodingRecord *Unicode;
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 ExtentionOffset;
700 } OTF_GSUB_Extension1;
701
702 typedef struct
703 {
704   unsigned BacktrackGlyphCount;
705   OTF_Coverage *Backtrack;
706   unsigned LookaheadGlyphCount;
707   OTF_Coverage *LookAhead;
708   unsigned GlyphCount;
709   OTF_GlyphID *Substitute;
710 } OTF_GSUB_ReverseChainSingle1;
711
712 struct OTF_LookupSubTableGSUB
713 {
714   unsigned Format;
715   OTF_Coverage Coverage;
716   union {
717     /* LookupType 1 */
718     OTF_GSUB_Single1 single1;
719     OTF_GSUB_Single2 single2;
720     /* LookupType 2 */
721     OTF_GSUB_Multiple1 multiple1;
722     /* LookupType 3 */
723     OTF_GSUB_Alternate1 alternate1;
724     /* LookupType 4 */
725     OTF_GSUB_Ligature1 ligature1;
726     /* LookupType 5 */
727     OTF_GSUB_Context1 context1;
728     OTF_GSUB_Context2 context2;
729     OTF_GSUB_Context3 context3;
730     /* LookupType 6 */
731     OTF_GSUB_ChainContext1 chain_context1;
732     OTF_GSUB_ChainContext2 chain_context2;
733     OTF_GSUB_ChainContext3 chain_context3;
734     /* LookupType 7 */
735     OTF_GSUB_Extension1 extension1;
736     /* LookupType 8 */
737     OTF_GSUB_ReverseChainSingle1 reverse_chain_single1;
738   } u;
739 };
740
741 typedef OTF_GSUB_GPOS OTF_GSUB;
742
743 /*** (1-10) "GPOS" table */
744
745 enum OTF_ValueFormat
746   {
747     OTF_XPlacement = 0x0001,
748     OTF_YPlacement = 0x0002,
749     OTF_XAdvance = 0x0004,
750     OTF_YAdvance = 0x0008,
751     OTF_XPlaDevice = 0x0010,
752     OTF_YPlaDevice = 0x0020,
753     OTF_XAdvDevice = 0x0040,
754     OTF_YAdvDevice = 0x0080
755   };
756
757 typedef struct
758 {
759   int XPlacement;
760   int YPlacement;
761   int XAdvance;
762   int YAdvance;
763   OTF_DeviceTable XPlaDevice;
764   OTF_DeviceTable YPlaDevice;
765   OTF_DeviceTable XAdvDevice;
766   OTF_DeviceTable YAdvDevice;
767 } OTF_ValueRecord;
768
769 typedef struct
770 {
771   OTF_Offset offset;
772   unsigned AnchorFormat;
773   int XCoordinate;
774   int YCoordinate;
775   union {
776     union {
777       unsigned AnchorPoint;
778     } f1;
779     union {
780       OTF_DeviceTable XDeviceTable;
781       OTF_DeviceTable YDeviceTable;
782     } f2;
783   } f;
784 } OTF_Anchor;
785
786 typedef struct
787 {
788   unsigned Class;
789   OTF_Anchor MarkAnchor;
790 } OTF_MarkRecord;
791
792 typedef struct
793 {
794   OTF_Offset offset;
795   unsigned MarkCount;
796   OTF_MarkRecord *MarkRecord;
797 } OTF_MarkArray;
798
799 typedef struct
800 {
801   unsigned ValueFormat;
802   OTF_ValueRecord Value;  
803 } OTF_GPOS_Single1;
804
805 typedef struct
806 {
807   unsigned ValueFormat;
808   unsigned ValueCount;
809   OTF_ValueRecord *Value;       /* [<ValueCount>] */
810 } OTF_GPOS_Single2;
811
812 typedef struct
813 {
814   int dummy;
815 } OTF_GPOS_Pair1;
816
817 typedef struct
818 {
819   OTF_ValueRecord Value1;
820   OTF_ValueRecord Value2;
821 } OTF_Class2Record;
822
823 typedef struct
824 {
825   OTF_Class2Record *Class2Record;
826 } OTF_Class1Record;
827
828 typedef struct
829 {
830   unsigned ValueFormat1;
831   unsigned ValueFormat2;
832   OTF_ClassDef ClassDef1;
833   OTF_ClassDef ClassDef2;
834   unsigned Class1Count;
835   unsigned Class2Count;
836   OTF_Class1Record *Class1Record; /* size: <Class1Count> */
837 } OTF_GPOS_Pair2;
838
839 typedef struct
840 {
841   int dummy;
842 } OTF_GPOS_Cursive1;
843
844 typedef struct
845 {
846   OTF_Anchor *Anchor;
847 } OTF_AnchorRecord;
848
849 typedef struct
850 {
851   OTF_Offset offset;
852   unsigned Count;
853   OTF_AnchorRecord *AnchorRecord;
854 } OTF_AnchorArray;
855
856 typedef struct
857 {
858   OTF_Coverage BaseCoverage;
859   unsigned ClassCount;
860   OTF_MarkArray MarkArray;
861   OTF_AnchorArray BaseArray;
862 } OTF_GPOS_MarkBase1;
863
864 typedef struct
865 {
866   int dummy;
867 } OTF_GPOS_MarkLig1;
868
869 typedef struct
870 {
871   OTF_Coverage Mark2Coverage;
872   unsigned ClassCount;
873   OTF_MarkArray Mark1Array;
874   OTF_AnchorArray Mark2Array;
875 } OTF_GPOS_MarkMark1;
876
877 typedef OTF_Context1 OTF_GPOS_Context1;
878
879 typedef OTF_Context2 OTF_GPOS_Context2;
880
881 typedef OTF_Context3 OTF_GPOS_Context3;
882
883 typedef OTF_ChainContext1 OTF_GPOS_ChainContext1;
884
885 typedef OTF_ChainContext2 OTF_GPOS_ChainContext2;
886
887 typedef OTF_ChainContext3 OTF_GPOS_ChainContext3;
888
889 typedef struct
890 {
891   int dummy;
892 } OTF_GPOS_Extension1;
893
894
895 struct OTF_LookupSubTableGPOS
896 {
897   unsigned Format;
898   OTF_Coverage Coverage;
899   union {
900     /* LookupType 1 */
901     OTF_GPOS_Single1 single1;
902     OTF_GPOS_Single2 single2;
903     /* LookupType 2 */
904     OTF_GPOS_Pair1 pair1;
905     OTF_GPOS_Pair2 pair2;
906     /* LookupType 3 */
907     OTF_GPOS_Cursive1 cursive1;
908     /* LookupType 4 */
909     OTF_GPOS_MarkBase1 mark_base1;
910     /* LookupType 5 */
911     OTF_GPOS_MarkLig1 mark_lig1;
912     /* LookupType 6 */
913     OTF_GPOS_MarkMark1 mark_mark1;
914     /* LookupType 7 */
915     OTF_GPOS_Context1 context1;
916     OTF_GPOS_Context2 context2;
917     OTF_GPOS_Context3 context3;
918     /* LookupType 8 */
919     OTF_GPOS_ChainContext1 chain_context1;
920     OTF_GPOS_ChainContext2 chain_context2;
921     OTF_GPOS_ChainContext3 chain_context3;
922     /* LookupType 9 */
923     OTF_GPOS_Extension1 extension1;
924   } u;
925 };
926
927 typedef OTF_GSUB_GPOS OTF_GPOS;
928
929 /*** (1-11) Structure for OTF */
930
931 typedef struct
932 {
933   OTF_Fixed sfnt_version;
934   unsigned numTables;
935   unsigned searchRange;
936   unsigned enterSelector;
937   unsigned rangeShift;
938 } OTF_OffsetTable;
939
940 typedef struct
941 {
942   OTF_Tag tag;
943   char name[5];
944   unsigned checkSum;
945   unsigned offset;
946   unsigned length;
947 } OTF_TableDirectory;
948
949 typedef struct OTF_InternalData  OTF_InternalData;
950
951 typedef struct
952 {
953   char *filename;
954   OTF_OffsetTable offset_table;
955   OTF_TableDirectory *table_dirs;
956   OTF_head *head;
957   OTF_name *name;
958   OTF_cmap *cmap;
959   OTF_GDEF *gdef;
960   OTF_GSUB *gsub;
961   OTF_GPOS *gpos;
962   /* The following tables are not yet supported.  */
963   // OTF_BASE *base;
964   // OTF_JSTF *jstf;
965   OTF_InternalData *internal_data;
966 } OTF;
967
968 \f
969 /*** (2) API for reading OTF */
970
971 /*** (2-1) otf_open () */
972
973 /***
974     Open OpenType font
975
976     The OTF_open() function reads the OpenType font file whose name is
977     $NAME, and return a pointer to the structure of type OTF.
978
979     It setups these member of the structure OTF:
980         filename, offset_table, table_dirs
981
982     If the file can't be read or the file contains invalid data, NULL
983     is returned, and the variable OTF_error is set to one of the
984     following values.
985
986         OTF_ERROR_MEMORY
987         OTF_ERROR_FILE
988         OTF_ERROR_TABLE
989
990     See also OTF_get_table() and OTF_close().  */
991
992 extern OTF *OTF_open (char *name);
993
994
995 /*** (2-2) OTF_close () */
996
997 /***
998     Close OpenType font
999
1000     The OTF_close() function closes the OpenType font $OTF which must
1001     be what the OTF_open() function returned.
1002
1003     See also OTF_open().  */
1004
1005 extern void OTF_close (OTF *otf);
1006
1007
1008 /*** (2-3) OTF_get_table () */
1009
1010 /***
1011     Get OpenType font table
1012
1013     The OTF_get_table() function setups one of the OTF table specified
1014     by $NAME in the OpenType font $OTF.
1015
1016     $NAME must be one of "head", "name", "cmap", "GDEF", "GSUB", and
1017     "GPOS", and a member of the same name is setup.
1018
1019     If the table is successfully setup, return 0.  Otherwise, return
1020     -1, and set the variable OTF_error to OTF_ERROR_TABLE.
1021
1022     See also OTF_open().  */
1023
1024 extern int OTF_get_table (OTF *otf, char *name);
1025
1026 /*** (2-4) OTF_check_table () */
1027
1028 /***
1029     Check the existence of OpenType font table
1030
1031     The OTF_check_table() function checks if the the OTF table
1032     specified by $NAME exists in OpenType font $OTF.
1033
1034     If the table exists, return 0, else return -1.
1035
1036     See also OTF_open().  */
1037
1038 extern int OTF_check_table (OTF *otf, char *name);
1039
1040
1041 /*** (3) API for driving OTF */
1042
1043 /*** (3-1) Structure for glyph string */
1044
1045 /***
1046     The structure OTF_Glyph contains information about each glyph in
1047     the structure OTF_GlyphString.  */
1048
1049 typedef struct
1050 {
1051   /* Character code of the glyph.  This is the only member that a
1052      client has to set before calling the function
1053      OTF_drive_XXX().  */
1054   int c;
1055
1056   /* Glyph ID of the glyph.  */
1057   OTF_GlyphID glyph_id;
1058
1059   /* GlyphClass of the glyph.  The value is extracted from the GDEF
1060      table.  */
1061   enum OTF_GlyphClassDef GlyphClass;
1062
1063   /* MarkAttachClassDef of the glyph.  The value is extracted from the
1064      GDEF table.  */
1065   unsigned MarkAttachClass;  
1066
1067   /* Positioning format type of the glyph.  The value specifies how
1068      the glyph positioning information is encoded in the member <f>.
1069      If the value is N, the union member fN, is used.  If the value is
1070      zero, the glyph has no positioning information, i.e. it should be
1071      drawn at the normal position.  */
1072   int positioning_type;
1073   union {
1074     struct {
1075       enum OTF_ValueFormat format;
1076       OTF_ValueRecord *value;
1077     } f1;
1078     struct {
1079       enum OTF_ValueFormat format;
1080       OTF_ValueRecord *value;
1081     } f2;
1082     struct {
1083       OTF_Anchor *entry_anchor;
1084       OTF_Anchor *exit_anchor;
1085     } f3;
1086     struct {
1087       OTF_Anchor *mark_anchor;
1088       OTF_Anchor *base_anchor;
1089     } f4;
1090     struct {
1091       OTF_Anchor *mark_anchor;
1092       OTF_Anchor *ligature_anchor;
1093     } f5;
1094     struct {
1095       OTF_Anchor *mark1_anchor;
1096       OTF_Anchor *mark2_anchor;
1097     } f6;
1098   } f;
1099 } OTF_Glyph;
1100
1101 /***
1102     The structure OTF_GlyphString contains an array of glyphs (type
1103     OTF_Glyph).  It is used as arguments of otf_drive_XXX().  */
1104
1105 typedef struct
1106 {
1107   /* How many glyphs are allocated at the memory pointed by the member
1108       <glyphs>.  */
1109   int size;
1110   /* How many glyphs contains valid information.  */
1111   int used;
1112   /* Array of glyphs.  It must be allocated by malloc().  The
1113      functions otf_drive_XXX() may reallocate it and increase the
1114      members <size> and <used>.  */
1115   OTF_Glyph *glyphs;
1116 } OTF_GlyphString;
1117
1118
1119 /*** (3-2) OTF_drive_cmap() */
1120
1121 /***
1122     Process glyph string by cmap table.
1123
1124     The OTF_drive_cmap() function looks up the cmap table of OpenType
1125     font $OTF, and setup the member <glyhph_id> of all glhphs in the
1126     glyph string $GSTRING.  */
1127
1128 extern int OTF_drive_cmap (OTF *otf, OTF_GlyphString *gstring);
1129
1130 /*** (3-3) OTF_drive_gdef() */
1131
1132 /***
1133     Process glyph string by GDEF table.
1134
1135     The OTF_drive_gdef() function looks up the GDEF table of OpenType
1136     font $OTF, and setup members <GlyphClass> and <MarkAttachClass> of
1137     all glhphs in the glyph string $GSTRING.  */
1138
1139 extern int OTF_drive_gdef (OTF *otf, OTF_GlyphString *gstring);
1140
1141
1142 /*** (3-4) OTF_drive_gsub() */
1143
1144 /***
1145     Process glyph string by GSUB table.
1146
1147     The OTF_drive_gsub() function looks up the GSUB table of OpenType
1148     font $OTF, and by using features the font has for script $SCRIPT
1149     and language system $LANGSYS, update member <glyphs> of the glyph
1150     string $GSTRING.  It may substitute, delete, insert glyphs in that
1151     array.  */
1152
1153 extern int OTF_drive_gsub (OTF *otf, OTF_GlyphString *gstring,
1154                            char *script, char *language, char *features);
1155
1156 /*** (3-5) OTF_drive_gpos() */
1157
1158 /***
1159     Process glyph string by GPOS table.
1160
1161     The OTF_drive_gdef() function looks up the GPOS table of $OTF of
1162     OpenType font $OTF, and by using features the font has for script
1163     $SCRIPT and language system $LANGSYS, setup members
1164     <positioning_type> and <f> of all glhphs in the glyph string
1165     $GSTRING.  */
1166
1167 extern int OTF_drive_gpos (OTF *otf, OTF_GlyphString *gstring,
1168                            char *script, char *language, char *features);
1169
1170 /*** (3-6) OTF_drive_tables() */
1171
1172 /***
1173     Process glyph string by cmap, GDEF, GSUB, and GPOS tables.
1174
1175     The OTF_drive_tables() function calls OTF_drive_cmap(),
1176     OTF_drive_gdef(), OTF_drive_gsub(), and OTF_drive_gpos() in this
1177     order, and update the glyphs string GSTRING.  */
1178
1179 extern int OTF_drive_tables (OTF *otf, OTF_GlyphString *gstring,
1180                              char *script, char *language,
1181                              char *gsub_features, char *gpos_features);
1182
1183
1184 /*** (4) API for error handling ***/
1185
1186 /*** (4-1) Error codes ***/
1187
1188 /***
1189     Global variable holding an error code.
1190
1191     The variable OTF_error is set to one of OTF_ERROR_XXX macros when
1192     an error is detected in the OTF library.  */
1193 extern int OTF_error;
1194
1195 /***
1196     Memory allocation error
1197
1198     This error indicates that the library couldn't allocate
1199     memory.  */
1200 #define OTF_ERROR_MEMORY        1
1201
1202 /***
1203     File error
1204
1205     This error indicates that the library fails in opening, reading,
1206     or seeking an OTF file.  */
1207 #define OTF_ERROR_FILE          2
1208
1209 /***
1210     Invalid table contents
1211
1212     This error indicates that an OTF file contains invalid data.  */
1213 #define OTF_ERROR_TABLE         3
1214
1215 /***
1216     CMAP driving error
1217
1218     See the function otf_drive_cmap() for more detail.  */
1219 #define OTF_ERROR_CMAP_DRIVE    4
1220
1221 /***
1222     GDEF driving error
1223
1224     See the function OTF_drive_gdef() for more detail.  */
1225 #define OTF_ERROR_GDEF_DRIVE    5
1226
1227 /***
1228     GSUB driving error
1229
1230     See the function OTF_drive_gsub() for more detail.  */
1231 #define OTF_ERROR_GSUB_DRIVE    6
1232
1233 /***
1234     GPOS driving error
1235
1236     See the function OTF_drive_gpos() for more detail.  */
1237 #define OTF_ERROR_GPOS_DRIVE    7
1238
1239
1240 /*** (4-2) OTF_perror() */
1241
1242 /***
1243     Print an OTF error message
1244
1245     The OTF_perror() function produces a message on the standard error
1246     output, describing the last error encountered during a call to the
1247     OTF library function.  If $PREFIX is not NULL, is is printed
1248     first, followed by a colon and a blank.  Then the message and a
1249     newline.  */
1250
1251 extern void OTF_perror (char *prefix);
1252
1253
1254 /*** (5) API miscellaneous ***/
1255
1256 /***
1257     Return OTF tag of a specified name string.
1258
1259     The OTF_tag() function returns OTF tag of name $NAME.  If $NAME is
1260     NULL, return 0.  Otherwise, $NAME must be at least 4-byte length.
1261     Only the first 4 characters are took into an account.  */
1262
1263 extern OTF_Tag OTF_tag (char *name);
1264
1265 /***
1266     Convert OTF tag to name string.
1267
1268     The OTF_tag_name() function converts OTF tag $TAG to a 5-byte name
1269     string (including the terminating NULL), and store it in $NAME.
1270     At least 5-byte space must be at $NAME.  */
1271
1272 extern void OTF_tag_name (OTF_Tag tag, char *name);
1273
1274
1275 #endif /* not _OTF_H_ */