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