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