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