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