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