1 /* otf.h -- Header file for the OTF (OpenType font) library.
4 by AIST (National Institute of Advanced Industrial Science and Technology)
5 Registration Number H14PRO???
7 This file is part of the OTF library.
9 The OTF library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License as
11 published by the Free Software Foundation; either version 2, or (at
12 your option) any later version.
14 The OTF library is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with the OTF library; see the file COPYING. If not, write to
21 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
30 (1) Structures for OTF Layout tables and OTF itself
35 (1-5) Structures common to GDEF, GSUB, and GPOS
37 (1-7) Structures for ScriptList, FeatureList, and LookupList
38 (1-8) Structures common to GSUB and GPOS
41 (1-11) Structure for OTF
43 (2) APIs for reading OTF
48 (3) APIs for driving OTF
49 (3-1) Structure for glyph string
50 (3-2) OTF_drive_cmap()
51 (3-3) OTF_drive_gdef()
52 (3-4) OTF_drive_gsub()
53 (3-5) OTF_drive_gpos()
54 (3-6) OTF_drive_tables()
56 (4) APIs for error handling
60 (5) APIs miscellaneous
65 /*** (1) Structures for OTF Layout tables and OTF itself */
67 /*** (1-1) Basic types */
69 typedef unsigned OTF_Tag;
70 typedef unsigned OTF_GlyphID;
71 typedef unsigned OTF_Offset;
80 /*** (1-2) "head" table */
84 OTF_Fixed TableVersionNumber;
85 OTF_Fixed fontRevision;
86 unsigned checkSumAdjustment;
93 /*** (1-3) "name" table */
105 #define OTF_max_nameID 23
112 OTF_NameRecord *nameRecord;
113 char *name[OTF_max_nameID + 1];
117 /*** (1-4) "cmap" table */
121 unsigned char glyphIdArray[256];
122 } OTF_EncodingSubtable0;
129 unsigned idRangeOffset;
134 unsigned subHeaderKeys[256];
135 OTF_cmapSubHeader *subHeaders;
136 unsigned *glyphIndexArray;
137 } OTF_EncodingSubtable2;
144 unsigned idRangeOffset;
150 unsigned searchRange;
151 unsigned entrySelector;
153 OTF_cmapSegument *segments;
155 unsigned *glyphIdArray;
156 } OTF_EncodingSubtable4;
162 unsigned *glyphIdArray;
163 } OTF_EncodingSubtable6;
167 unsigned startCharCode;
168 unsigned endCharCode;
169 unsigned startGlyphID;
174 unsigned char is32[8192];
176 OTF_cmapGroup *Groups;
177 } OTF_EncodingSubtable8;
181 unsigned startCharCode;
184 } OTF_EncodingSubtable10;
189 OTF_cmapGroup *Groups;
190 } OTF_EncodingSubtable12;
198 OTF_EncodingSubtable0 *f0;
199 OTF_EncodingSubtable2 *f2;
200 OTF_EncodingSubtable4 *f4;
201 OTF_EncodingSubtable6 *f6;
202 OTF_EncodingSubtable8 *f8;
203 OTF_EncodingSubtable10 *f10;
204 OTF_EncodingSubtable12 *f12;
206 } OTF_EncodingSubtable;
213 OTF_EncodingSubtable subtable;
214 } OTF_EncodingRecord;
220 OTF_EncodingRecord *EncodingRecord;
221 OTF_EncodingRecord *Unicode;
225 /*** (1-5) Structures common to GDEF, GSUB, GPOS */
231 unsigned StartCoverageIndex;
237 unsigned CoverageFormat;
240 OTF_GlyphID *GlyphArray;
241 OTF_RangeRecord *RangeRecord;
250 unsigned DeltaFormat;
259 } OTF_ClassRangeRecord;
264 unsigned ClassFormat;
267 OTF_GlyphID StartGlyph;
269 unsigned *ClassValueArray;
272 unsigned ClassRangeCount;
273 OTF_ClassRangeRecord *ClassRangeRecord;
279 /*** (1-6) "GDEF" table */
284 OTF_Offset GlyphClassDef;
285 OTF_Offset AttachList;
286 OTF_Offset LigCaretList;
287 OTF_Offset MarkAttachClassDef;
290 enum OTF_GlyphClassDef
293 OTF_GlyphClassBase = 1,
294 OTF_GlyphClassLigature = 2,
295 OTF_GlyphClassMark = 3,
296 OTF_GlyphClassComponent = 4
303 unsigned *PointIndex;
308 OTF_Coverage Coverage;
310 OTF_AttachPoint *AttachPoint;
316 unsigned CaretValueFormat; /* 1, 2, or 3 */
322 unsigned CaretValuePoint;
326 OTF_DeviceTable DeviceTable;
335 OTF_CaretValue *CaretValue;
340 OTF_Coverage Coverage;
341 unsigned LigGlyphCount;
342 OTF_LigGlyph *LigGlyph;
347 OTF_GDEFHeader header;
348 OTF_ClassDef glyph_class_def;
349 OTF_AttachList attach_list;
350 OTF_LigCaretList lig_caret_list;
351 OTF_ClassDef mark_attach_class_def;
355 /*** (1-7) Structures for ScriptList, FeatureList, and LookupList */
357 /*** The structure hierarchy
384 SubTable.gsub[] or SubTable.gpos[]
390 OTF_Offset LookupOrder;
391 unsigned ReqFeatureIndex;
392 unsigned FeatureCount;
393 unsigned *FeatureIndex;
406 OTF_Offset DefaultLangSysOffset;
407 OTF_LangSys DefaultLangSys;
408 unsigned LangSysCount;
409 OTF_LangSysRecord *LangSysRecord;
410 OTF_LangSys *LangSys;
416 unsigned ScriptCount;
424 OTF_Offset FeatureParams;
425 unsigned LookupCount;
426 unsigned *LookupListIndex;
432 unsigned FeatureCount;
433 OTF_Feature *Feature;
436 typedef struct OTF_LookupSubTableGSUB OTF_LookupSubTableGSUB;
437 typedef struct OTF_LookupSubTableGPOS OTF_LookupSubTableGPOS;
439 enum OTF_LookupFlagBit
441 OTF_RightToLeft = 0x0001,
442 OTF_IgnoreBaseGlyphs = 0x0002,
443 OTF_IgnoreLigatures = 0x0004,
444 OTF_IgnoreMarks = 0x8000,
445 OTF_Reserved = 0x00F0,
446 OTF_MarkAttachmentType = 0xFF00
454 unsigned SubTableCount;
455 OTF_Offset *SubTableOffset;
457 OTF_LookupSubTableGSUB *gsub;
458 OTF_LookupSubTableGPOS *gpos;
465 unsigned LookupCount;
470 /*** (1-8) Structures common to GSUB and GPOS */
472 /* For SubstLookupRecord (GSUB) and PosLookupRecord (GPOS). */
476 unsigned SequenceIndex;
477 unsigned LookupListIndex;
484 unsigned LookupCount;
485 OTF_GlyphID *Input; /* [<GlyphCount> - 1] */
486 OTF_LookupRecord *LookupRecord; /* [<LookupCount>] */
493 OTF_Rule *Rule; /* [<RuleCount>] */
500 unsigned LookupCount;
501 unsigned *Class; /* [<GlyphCount> - 1] */
502 OTF_LookupRecord *LookupRecord; /* [<LookupCount>] */
508 unsigned ClassRuleCnt;
509 OTF_ClassRule *ClassRule; /* [<ClassRuleCnt>] */
515 unsigned BacktrackGlyphCount;
516 OTF_GlyphID *Backtrack;
517 unsigned InputGlyphCount;
519 unsigned LookaheadGlyphCount;
520 OTF_GlyphID *LookAhead;
521 unsigned LookupCount;
522 OTF_LookupRecord *LookupRecord;
528 unsigned ChainRuleCount;
529 OTF_ChainRule *ChainRule;
535 unsigned BacktrackGlyphCount;
537 unsigned InputGlyphCount;
539 unsigned LookaheadGlyphCount;
541 unsigned LookupCount;
542 OTF_LookupRecord *LookupRecord;
543 } OTF_ChainClassRule;
548 unsigned ChainClassRuleCnt;
549 OTF_ChainClassRule *ChainClassRule;
553 /* Common to OTF_GSUB/GPOS_Context1/2/3. */
557 unsigned RuleSetCount;
558 OTF_RuleSet *RuleSet; /* [<RuleSetCount>] */
563 OTF_ClassDef ClassDef;
564 unsigned ClassSetCnt;
565 OTF_ClassSet *ClassSet; /* [<ClassSetCnt>] */
571 unsigned LookupCount;
572 OTF_Coverage *Coverage; /* [<GlyphCount>] */
573 OTF_LookupRecord *LookupRecord; /* [<LookupCount>] */
577 /* Common to OTF_GSUB/GPOS_ChainContext1/2/3. */
581 unsigned ChainRuleSetCount;
582 OTF_ChainRuleSet *ChainRuleSet;
587 OTF_ClassDef BacktrackClassDef;
588 OTF_ClassDef InputClassDef;
589 OTF_ClassDef LookaheadClassDef;
590 unsigned ChainClassSetCnt;
591 OTF_ChainClassSet *ChainClassSet;
596 unsigned BacktrackGlyphCount;
597 OTF_Coverage *Backtrack;
598 unsigned InputGlyphCount;
600 unsigned LookaheadGlyphCount;
601 OTF_Coverage *LookAhead;
602 unsigned LookupCount;
603 OTF_LookupRecord *LookupRecord;
606 /* Common to OTF_GSUB/GPOS. */
611 OTF_ScriptList ScriptList;
612 OTF_FeatureList FeatureList;
613 OTF_LookupList LookupList;
616 /*** (1-9) "GSUB" table */
626 OTF_GlyphID *Substitute;
629 typedef struct OTF_Sequence OTF_Sequence;
633 unsigned SequenceCount;
634 OTF_Sequence *Sequence;
635 } OTF_GSUB_Multiple1;
641 OTF_GlyphID *Substitute;
644 typedef struct OTF_AlternateSet OTF_AlternateSet;
648 unsigned AlternateSetCount;
649 OTF_AlternateSet *AlternateSet;
650 } OTF_GSUB_Alternate1;
652 struct OTF_AlternateSet
656 OTF_GlyphID *Alternate;
659 typedef struct OTF_LigatureSet OTF_LigatureSet;
660 typedef struct OTF_Ligature OTF_Ligature;
664 unsigned LigSetCount;
665 OTF_LigatureSet *LigatureSet;
666 } OTF_GSUB_Ligature1;
668 struct OTF_LigatureSet
671 unsigned LigatureCount;
672 OTF_Ligature *Ligature;
678 OTF_GlyphID LigGlyph;
680 OTF_GlyphID *Component;
683 typedef OTF_Context1 OTF_GSUB_Context1;
685 typedef OTF_Context2 OTF_GSUB_Context2;
687 typedef OTF_Context3 OTF_GSUB_Context3;
689 typedef OTF_ChainContext1 OTF_GSUB_ChainContext1;
691 typedef OTF_ChainContext2 OTF_GSUB_ChainContext2;
693 typedef OTF_ChainContext3 OTF_GSUB_ChainContext3;
697 unsigned ExtensionLookupType;
698 unsigned ExtentionOffset;
699 } OTF_GSUB_Extension1;
703 unsigned BacktrackGlyphCount;
704 OTF_Coverage *Backtrack;
705 unsigned LookaheadGlyphCount;
706 OTF_Coverage *LookAhead;
708 OTF_GlyphID *Substitute;
709 } OTF_GSUB_ReverseChainSingle1;
711 struct OTF_LookupSubTableGSUB
714 OTF_Coverage Coverage;
717 OTF_GSUB_Single1 single1;
718 OTF_GSUB_Single2 single2;
720 OTF_GSUB_Multiple1 multiple1;
722 OTF_GSUB_Alternate1 alternate1;
724 OTF_GSUB_Ligature1 ligature1;
726 OTF_GSUB_Context1 context1;
727 OTF_GSUB_Context2 context2;
728 OTF_GSUB_Context3 context3;
730 OTF_GSUB_ChainContext1 chain_context1;
731 OTF_GSUB_ChainContext2 chain_context2;
732 OTF_GSUB_ChainContext3 chain_context3;
734 OTF_GSUB_Extension1 extension1;
736 OTF_GSUB_ReverseChainSingle1 reverse_chain_single1;
740 typedef OTF_GSUB_GPOS OTF_GSUB;
742 /*** (1-10) "GPOS" table */
746 OTF_XPlacement = 0x0001,
747 OTF_YPlacement = 0x0002,
748 OTF_XAdvance = 0x0004,
749 OTF_YAdvance = 0x0008,
750 OTF_XPlaDevice = 0x0010,
751 OTF_YPlaDevice = 0x0020,
752 OTF_XAdvDevice = 0x0040,
753 OTF_YAdvDevice = 0x0080
762 OTF_DeviceTable XPlaDevice;
763 OTF_DeviceTable YPlaDevice;
764 OTF_DeviceTable XAdvDevice;
765 OTF_DeviceTable YAdvDevice;
771 unsigned AnchorFormat;
776 unsigned AnchorPoint;
779 OTF_DeviceTable XDeviceTable;
780 OTF_DeviceTable YDeviceTable;
788 OTF_Anchor MarkAnchor;
795 OTF_MarkRecord *MarkRecord;
800 unsigned ValueFormat;
801 OTF_ValueRecord Value;
806 unsigned ValueFormat;
808 OTF_ValueRecord *Value; /* [<ValueCount>] */
818 OTF_ValueRecord Value1;
819 OTF_ValueRecord Value2;
824 OTF_Class2Record *Class2Record;
829 unsigned ValueFormat1;
830 unsigned ValueFormat2;
831 OTF_ClassDef ClassDef1;
832 OTF_ClassDef ClassDef2;
833 unsigned Class1Count;
834 unsigned Class2Count;
835 OTF_Class1Record *Class1Record; /* size: <Class1Count> */
852 OTF_AnchorRecord *AnchorRecord;
857 OTF_Coverage BaseCoverage;
859 OTF_MarkArray MarkArray;
860 OTF_AnchorArray BaseArray;
861 } OTF_GPOS_MarkBase1;
870 OTF_Coverage Mark2Coverage;
872 OTF_MarkArray Mark1Array;
873 OTF_AnchorArray Mark2Array;
874 } OTF_GPOS_MarkMark1;
876 typedef OTF_Context1 OTF_GPOS_Context1;
878 typedef OTF_Context2 OTF_GPOS_Context2;
880 typedef OTF_Context3 OTF_GPOS_Context3;
882 typedef OTF_ChainContext1 OTF_GPOS_ChainContext1;
884 typedef OTF_ChainContext2 OTF_GPOS_ChainContext2;
886 typedef OTF_ChainContext3 OTF_GPOS_ChainContext3;
891 } OTF_GPOS_Extension1;
894 struct OTF_LookupSubTableGPOS
897 OTF_Coverage Coverage;
900 OTF_GPOS_Single1 single1;
901 OTF_GPOS_Single2 single2;
903 OTF_GPOS_Pair1 pair1;
904 OTF_GPOS_Pair2 pair2;
906 OTF_GPOS_Cursive1 cursive1;
908 OTF_GPOS_MarkBase1 mark_base1;
910 OTF_GPOS_MarkLig1 mark_lig1;
912 OTF_GPOS_MarkMark1 mark_mark1;
914 OTF_GPOS_Context1 context1;
915 OTF_GPOS_Context2 context2;
916 OTF_GPOS_Context3 context3;
918 OTF_GPOS_ChainContext1 chain_context1;
919 OTF_GPOS_ChainContext2 chain_context2;
920 OTF_GPOS_ChainContext3 chain_context3;
922 OTF_GPOS_Extension1 extension1;
926 typedef OTF_GSUB_GPOS OTF_GPOS;
928 /*** (1-11) Structure for OTF */
932 OTF_Fixed sfnt_version;
934 unsigned searchRange;
935 unsigned enterSelector;
946 } OTF_TableDirectory;
948 typedef struct OTF_InternalData OTF_InternalData;
953 OTF_OffsetTable offset_table;
954 OTF_TableDirectory *table_dirs;
961 /* The following tables are not yet supported. */
964 OTF_InternalData *internal_data;
968 /*** (2) APIs for reading OTF */
970 /*** (2-1) otf_open () */
975 The OTF_open() function reads the OpenType font file whose name is
976 $NAME, and return a pointer to the structure of type OTF.
978 It setups these member of the structure OTF:
979 filename, offset_table, table_dirs
981 If the file can't be read or the file contains invalid data, NULL
982 is returned, and the variable OTF_error is set to one of the
989 See also OTF_get_table() and OTF_close(). */
991 extern OTF *OTF_open (char *name);
994 /*** (2-2) OTF_close () */
999 The OTF_close() function closes the OpenType font pointed by $OTF
1000 which must be what the OTF_open() returned.
1002 See also OTF_open(). */
1004 extern void OTF_close (OTF *otf);
1007 /*** (2-3) OTF_get_table () */
1010 Get OpenType font table
1012 The OTF_get_table() function setups one of the OTF tables
1013 specified by $NAME in the structure pointed by $OTF.
1015 $NAME must be one of "head", "name", "cmap", "GDEF", "GSUB", and
1016 "GPOS", and a member of the same name is setup.
1018 If the table is successfully setup, return 0. Otherwise, return
1019 -1, and set the variable OTF_error to OTF_ERROR_TABLE.
1021 See also OTF_open(). */
1023 extern int OTF_get_table (OTF *otf, char *name);
1026 /*** (3) APIs for driving OTF */
1028 /*** (3-1) Structure for glyph string */
1031 The structure OTF_Glyph contains information about each glyph in
1032 the structure OTF_GlyphString. */
1036 /* Character code of the glyph. This is the only member that a
1037 client has to set before calling the function
1041 /* Glyph ID of the glyph. */
1042 OTF_GlyphID glyph_id;
1044 /* GlyphClass of the glyph. The value is extracted from the GDEF
1046 enum OTF_GlyphClassDef GlyphClass;
1048 /* MarkAttachClassDef of the glyph. The value is extracted from the
1050 unsigned MarkAttachClass;
1052 /* Positioning format type of the glyph. The value specifies how
1053 the glyph positioning information is encoded in the member <f>.
1054 If the value is N, the union member fN, is used. If the value is
1055 zero, the glyph has no positioning information, i.e. it should be
1056 drawn at the normal position. */
1057 int positioning_type;
1060 enum OTF_ValueFormat format;
1061 OTF_ValueRecord *value;
1064 enum OTF_ValueFormat format;
1065 OTF_ValueRecord *value;
1068 OTF_Anchor *entry_anchor;
1069 OTF_Anchor *exit_anchor;
1072 OTF_Anchor *mark_anchor;
1073 OTF_Anchor *base_anchor;
1076 OTF_Anchor *mark_anchor;
1077 OTF_Anchor *ligature_anchor;
1080 OTF_Anchor *mark1_anchor;
1081 OTF_Anchor *mark2_anchor;
1087 The structure OTF_GlyphString contains an array of glyphs (type
1088 OTF_Glyph). It is used as arguments of otf_drive_XXX(). */
1092 /* How many glyphs are allocated at the memory pointed by the member
1095 /* How many glyphs contains valid information. */
1097 /* Array of glyphs. It must be allocated by malloc(). The
1098 functions otf_drive_XXX() may reallocate it and increase the
1099 members <size> and <used>. */
1104 /*** (3-2) OTF_drive_cmap() */
1107 Process glyph string by cmap table.
1109 The OTF_drive_cmap() function looks up the cmap table of OpenType
1110 font $OTF, and setup the member <glyhph_id> of all glhphs in the
1111 glyph string $GSTRING. */
1113 extern int OTF_drive_cmap (OTF *otf, OTF_GlyphString *gstring);
1115 /*** (3-3) OTF_drive_gdef() */
1118 Process glyph string by GDEF table.
1120 The OTF_drive_gdef() function looks up the GDEF table of OpenType
1121 font $OTF, and setup members <GlyphClass> and <MarkAttachClass> of
1122 all glhphs in the glyph string $GSTRING. */
1124 extern int OTF_drive_gdef (OTF *otf, OTF_GlyphString *gstring);
1127 /*** (3-4) OTF_drive_gsub() */
1130 Process glyph string by GSUB table.
1132 The OTF_drive_gsub() function looks up the GSUB table of OpenType
1133 font $OTF, and by using features the font has for script $SCRIPT
1134 and language system $LANGSYS, update member <glyphs> of the glyph
1135 string $GSTRING. It may substitute, delete, insert glyphs in that
1138 extern int OTF_drive_gsub (OTF *otf, OTF_GlyphString *gstring,
1139 char *script, char *language, char *features);
1141 /*** (3-5) OTF_drive_gpos() */
1144 Process glyph string by GPOS table.
1146 The OTF_drive_gdef() function looks up the GPOS table of $OTF of
1147 OpenType font $OTF, and by using features the font has for script
1148 $SCRIPT and language system $LANGSYS, setup members
1149 <positioning_type> and <f> of all glhphs in the glyph string
1152 extern int OTF_drive_gpos (OTF *otf, OTF_GlyphString *gstring,
1153 char *script, char *language, char *features);
1155 /*** (3-6) OTF_drive_tables() */
1158 Process glyph string by cmap, GDEF, GSUB, and GPOS tables.
1160 The OTF_drive_tables() function calls OTF_drive_cmap(),
1161 OTF_drive_gdef(), OTF_drive_gsub(), and OTF_drive_gpos() in this
1162 order, and update the glyphs string GSTRING. */
1164 extern int OTF_drive_tables (OTF *otf, OTF_GlyphString *gstring,
1165 char *script, char *language,
1166 char *gsub_features, char *gpos_features);
1169 /*** (4) APIs for error handling ***/
1171 /*** (4-1) Error codes ***/
1174 Global variable holding an error code.
1176 The variable OTF_error is set to one of OTF_ERROR_XXX macros when
1177 an error is detected in the OTF library. */
1178 extern int OTF_error;
1181 Memory allocation error
1183 This error indicates that the library couldn't allocate
1185 #define OTF_ERROR_MEMORY 1
1190 This error indicates that the library fails in opening, reading,
1191 or seeking an OTF file. */
1192 #define OTF_ERROR_FILE 2
1195 Invalid table contents
1197 This error indicates that an OTF file contains invalid data. */
1198 #define OTF_ERROR_TABLE 3
1203 See the function otf_drive_cmap() for more detail. */
1204 #define OTF_ERROR_CMAP_DRIVE 4
1209 See the function OTF_drive_gdef() for more detail. */
1210 #define OTF_ERROR_GDEF_DRIVE 5
1215 See the function OTF_drive_gsub() for more detail. */
1216 #define OTF_ERROR_GSUB_DRIVE 6
1221 See the function OTF_drive_gpos() for more detail. */
1222 #define OTF_ERROR_GPOS_DRIVE 7
1225 /*** (4-2) OTF_perror() */
1228 Print an OTF error message
1230 The OTF_perror() function produces a message on the standard error
1231 output, describing the last error encountered during a call to the
1232 OTF library function. If $PREFIX is not NULL, is is printed
1233 first, followed by a colon and a blank. Then the message and a
1236 extern void OTF_perror (char *prefix);
1239 /*** (5) APIs miscellaneous ***/
1242 Return OTF tag of a specified name string.
1244 The OTF_tag() function returns OTF tag of name $NAME. If $NAME is
1245 NULL, return 0. Otherwise, $NAME must be at least 4-byte length.
1246 Only the first 4 characters are took into an account. */
1248 extern OTF_Tag OTF_tag (char *name);
1251 Convert OTF tag to name string.
1253 The OTF_tag_name() function converts OTF tag $TAG to a 5-byte name
1254 string (including the terminating NULL), and store it in $NAME.
1255 At least 5-byte space must be at $NAME. */
1257 extern void OTF_tag_name (OTF_Tag tag, char *name);
1260 #endif /* not _OTF_H_ */