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