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