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