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) API for reading OTF
47 (2-4) OTF_check_table()
49 (3) API for driving OTF
50 (3-1) Structure for glyph string
51 (3-2) OTF_drive_cmap()
52 (3-3) OTF_drive_gdef()
53 (3-4) OTF_drive_gsub()
54 (3-5) OTF_drive_gpos()
55 (3-6) OTF_drive_tables()
57 (4) API for error handling
66 /*** (1) Structures for OTF Layout tables and OTF itself */
68 /*** (1-1) Basic types */
70 typedef unsigned OTF_Tag;
71 typedef unsigned OTF_GlyphID;
72 typedef unsigned OTF_Offset;
81 /*** (1-2) "head" table */
85 OTF_Fixed TableVersionNumber;
86 OTF_Fixed fontRevision;
87 unsigned checkSumAdjustment;
94 /*** (1-3) "name" table */
106 #define OTF_max_nameID 23
113 OTF_NameRecord *nameRecord;
114 char *name[OTF_max_nameID + 1];
118 /*** (1-4) "cmap" table */
122 unsigned char glyphIdArray[256];
123 } OTF_EncodingSubtable0;
130 unsigned idRangeOffset;
135 unsigned subHeaderKeys[256];
136 OTF_cmapSubHeader *subHeaders;
137 unsigned *glyphIndexArray;
138 } OTF_EncodingSubtable2;
145 unsigned idRangeOffset;
151 unsigned searchRange;
152 unsigned entrySelector;
154 OTF_cmapSegument *segments;
156 unsigned *glyphIdArray;
157 } OTF_EncodingSubtable4;
163 unsigned *glyphIdArray;
164 } OTF_EncodingSubtable6;
168 unsigned startCharCode;
169 unsigned endCharCode;
170 unsigned startGlyphID;
175 unsigned char is32[8192];
177 OTF_cmapGroup *Groups;
178 } OTF_EncodingSubtable8;
182 unsigned startCharCode;
185 } OTF_EncodingSubtable10;
190 OTF_cmapGroup *Groups;
191 } OTF_EncodingSubtable12;
199 OTF_EncodingSubtable0 *f0;
200 OTF_EncodingSubtable2 *f2;
201 OTF_EncodingSubtable4 *f4;
202 OTF_EncodingSubtable6 *f6;
203 OTF_EncodingSubtable8 *f8;
204 OTF_EncodingSubtable10 *f10;
205 OTF_EncodingSubtable12 *f12;
207 } OTF_EncodingSubtable;
214 OTF_EncodingSubtable subtable;
215 } OTF_EncodingRecord;
221 OTF_EncodingRecord *EncodingRecord;
222 OTF_EncodingRecord *Unicode;
226 /*** (1-5) Structures common to GDEF, GSUB, GPOS */
232 unsigned StartCoverageIndex;
238 unsigned CoverageFormat;
241 OTF_GlyphID *GlyphArray;
242 OTF_RangeRecord *RangeRecord;
251 unsigned DeltaFormat;
260 } OTF_ClassRangeRecord;
265 unsigned ClassFormat;
268 OTF_GlyphID StartGlyph;
270 unsigned *ClassValueArray;
273 unsigned ClassRangeCount;
274 OTF_ClassRangeRecord *ClassRangeRecord;
280 /*** (1-6) "GDEF" table */
285 OTF_Offset GlyphClassDef;
286 OTF_Offset AttachList;
287 OTF_Offset LigCaretList;
288 OTF_Offset MarkAttachClassDef;
291 enum OTF_GlyphClassDef
294 OTF_GlyphClassBase = 1,
295 OTF_GlyphClassLigature = 2,
296 OTF_GlyphClassMark = 3,
297 OTF_GlyphClassComponent = 4
304 unsigned *PointIndex;
309 OTF_Coverage Coverage;
311 OTF_AttachPoint *AttachPoint;
317 unsigned CaretValueFormat; /* 1, 2, or 3 */
323 unsigned CaretValuePoint;
327 OTF_DeviceTable DeviceTable;
336 OTF_CaretValue *CaretValue;
341 OTF_Coverage Coverage;
342 unsigned LigGlyphCount;
343 OTF_LigGlyph *LigGlyph;
348 OTF_GDEFHeader header;
349 OTF_ClassDef glyph_class_def;
350 OTF_AttachList attach_list;
351 OTF_LigCaretList lig_caret_list;
352 OTF_ClassDef mark_attach_class_def;
356 /*** (1-7) Structures for ScriptList, FeatureList, and LookupList */
358 /*** The structure hierarchy
385 SubTable.gsub[] or SubTable.gpos[]
391 OTF_Offset LookupOrder;
392 unsigned ReqFeatureIndex;
393 unsigned FeatureCount;
394 unsigned *FeatureIndex;
407 OTF_Offset DefaultLangSysOffset;
408 OTF_LangSys DefaultLangSys;
409 unsigned LangSysCount;
410 OTF_LangSysRecord *LangSysRecord;
411 OTF_LangSys *LangSys;
417 unsigned ScriptCount;
425 OTF_Offset FeatureParams;
426 unsigned LookupCount;
427 unsigned *LookupListIndex;
433 unsigned FeatureCount;
434 OTF_Feature *Feature;
437 typedef struct OTF_LookupSubTableGSUB OTF_LookupSubTableGSUB;
438 typedef struct OTF_LookupSubTableGPOS OTF_LookupSubTableGPOS;
440 enum OTF_LookupFlagBit
442 OTF_RightToLeft = 0x0001,
443 OTF_IgnoreBaseGlyphs = 0x0002,
444 OTF_IgnoreLigatures = 0x0004,
445 OTF_IgnoreMarks = 0x8000,
446 OTF_Reserved = 0x00F0,
447 OTF_MarkAttachmentType = 0xFF00
455 unsigned SubTableCount;
456 OTF_Offset *SubTableOffset;
458 OTF_LookupSubTableGSUB *gsub;
459 OTF_LookupSubTableGPOS *gpos;
466 unsigned LookupCount;
471 /*** (1-8) Structures common to GSUB and GPOS */
473 /* For SubstLookupRecord (GSUB) and PosLookupRecord (GPOS). */
477 unsigned SequenceIndex;
478 unsigned LookupListIndex;
485 unsigned LookupCount;
486 OTF_GlyphID *Input; /* [<GlyphCount> - 1] */
487 OTF_LookupRecord *LookupRecord; /* [<LookupCount>] */
494 OTF_Rule *Rule; /* [<RuleCount>] */
501 unsigned LookupCount;
502 unsigned *Class; /* [<GlyphCount> - 1] */
503 OTF_LookupRecord *LookupRecord; /* [<LookupCount>] */
509 unsigned ClassRuleCnt;
510 OTF_ClassRule *ClassRule; /* [<ClassRuleCnt>] */
516 unsigned BacktrackGlyphCount;
517 OTF_GlyphID *Backtrack;
518 unsigned InputGlyphCount;
520 unsigned LookaheadGlyphCount;
521 OTF_GlyphID *LookAhead;
522 unsigned LookupCount;
523 OTF_LookupRecord *LookupRecord;
529 unsigned ChainRuleCount;
530 OTF_ChainRule *ChainRule;
536 unsigned BacktrackGlyphCount;
538 unsigned InputGlyphCount;
540 unsigned LookaheadGlyphCount;
542 unsigned LookupCount;
543 OTF_LookupRecord *LookupRecord;
544 } OTF_ChainClassRule;
549 unsigned ChainClassRuleCnt;
550 OTF_ChainClassRule *ChainClassRule;
554 /* Common to OTF_GSUB/GPOS_Context1/2/3. */
558 unsigned RuleSetCount;
559 OTF_RuleSet *RuleSet; /* [<RuleSetCount>] */
564 OTF_ClassDef ClassDef;
565 unsigned ClassSetCnt;
566 OTF_ClassSet *ClassSet; /* [<ClassSetCnt>] */
572 unsigned LookupCount;
573 OTF_Coverage *Coverage; /* [<GlyphCount>] */
574 OTF_LookupRecord *LookupRecord; /* [<LookupCount>] */
578 /* Common to OTF_GSUB/GPOS_ChainContext1/2/3. */
582 unsigned ChainRuleSetCount;
583 OTF_ChainRuleSet *ChainRuleSet;
588 OTF_ClassDef BacktrackClassDef;
589 OTF_ClassDef InputClassDef;
590 OTF_ClassDef LookaheadClassDef;
591 unsigned ChainClassSetCnt;
592 OTF_ChainClassSet *ChainClassSet;
597 unsigned BacktrackGlyphCount;
598 OTF_Coverage *Backtrack;
599 unsigned InputGlyphCount;
601 unsigned LookaheadGlyphCount;
602 OTF_Coverage *LookAhead;
603 unsigned LookupCount;
604 OTF_LookupRecord *LookupRecord;
607 /* Common to OTF_GSUB/GPOS. */
612 OTF_ScriptList ScriptList;
613 OTF_FeatureList FeatureList;
614 OTF_LookupList LookupList;
617 /*** (1-9) "GSUB" table */
627 OTF_GlyphID *Substitute;
630 typedef struct OTF_Sequence OTF_Sequence;
634 unsigned SequenceCount;
635 OTF_Sequence *Sequence;
636 } OTF_GSUB_Multiple1;
642 OTF_GlyphID *Substitute;
645 typedef struct OTF_AlternateSet OTF_AlternateSet;
649 unsigned AlternateSetCount;
650 OTF_AlternateSet *AlternateSet;
651 } OTF_GSUB_Alternate1;
653 struct OTF_AlternateSet
657 OTF_GlyphID *Alternate;
660 typedef struct OTF_LigatureSet OTF_LigatureSet;
661 typedef struct OTF_Ligature OTF_Ligature;
665 unsigned LigSetCount;
666 OTF_LigatureSet *LigatureSet;
667 } OTF_GSUB_Ligature1;
669 struct OTF_LigatureSet
672 unsigned LigatureCount;
673 OTF_Ligature *Ligature;
679 OTF_GlyphID LigGlyph;
681 OTF_GlyphID *Component;
684 typedef OTF_Context1 OTF_GSUB_Context1;
686 typedef OTF_Context2 OTF_GSUB_Context2;
688 typedef OTF_Context3 OTF_GSUB_Context3;
690 typedef OTF_ChainContext1 OTF_GSUB_ChainContext1;
692 typedef OTF_ChainContext2 OTF_GSUB_ChainContext2;
694 typedef OTF_ChainContext3 OTF_GSUB_ChainContext3;
698 unsigned ExtensionLookupType;
699 unsigned ExtentionOffset;
700 } OTF_GSUB_Extension1;
704 unsigned BacktrackGlyphCount;
705 OTF_Coverage *Backtrack;
706 unsigned LookaheadGlyphCount;
707 OTF_Coverage *LookAhead;
709 OTF_GlyphID *Substitute;
710 } OTF_GSUB_ReverseChainSingle1;
712 struct OTF_LookupSubTableGSUB
715 OTF_Coverage Coverage;
718 OTF_GSUB_Single1 single1;
719 OTF_GSUB_Single2 single2;
721 OTF_GSUB_Multiple1 multiple1;
723 OTF_GSUB_Alternate1 alternate1;
725 OTF_GSUB_Ligature1 ligature1;
727 OTF_GSUB_Context1 context1;
728 OTF_GSUB_Context2 context2;
729 OTF_GSUB_Context3 context3;
731 OTF_GSUB_ChainContext1 chain_context1;
732 OTF_GSUB_ChainContext2 chain_context2;
733 OTF_GSUB_ChainContext3 chain_context3;
735 OTF_GSUB_Extension1 extension1;
737 OTF_GSUB_ReverseChainSingle1 reverse_chain_single1;
741 typedef OTF_GSUB_GPOS OTF_GSUB;
743 /*** (1-10) "GPOS" table */
747 OTF_XPlacement = 0x0001,
748 OTF_YPlacement = 0x0002,
749 OTF_XAdvance = 0x0004,
750 OTF_YAdvance = 0x0008,
751 OTF_XPlaDevice = 0x0010,
752 OTF_YPlaDevice = 0x0020,
753 OTF_XAdvDevice = 0x0040,
754 OTF_YAdvDevice = 0x0080
763 OTF_DeviceTable XPlaDevice;
764 OTF_DeviceTable YPlaDevice;
765 OTF_DeviceTable XAdvDevice;
766 OTF_DeviceTable YAdvDevice;
772 unsigned AnchorFormat;
777 unsigned AnchorPoint;
780 OTF_DeviceTable XDeviceTable;
781 OTF_DeviceTable YDeviceTable;
789 OTF_Anchor MarkAnchor;
796 OTF_MarkRecord *MarkRecord;
801 unsigned ValueFormat;
802 OTF_ValueRecord Value;
807 unsigned ValueFormat;
809 OTF_ValueRecord *Value; /* [<ValueCount>] */
819 OTF_ValueRecord Value1;
820 OTF_ValueRecord Value2;
825 OTF_Class2Record *Class2Record;
830 unsigned ValueFormat1;
831 unsigned ValueFormat2;
832 OTF_ClassDef ClassDef1;
833 OTF_ClassDef ClassDef2;
834 unsigned Class1Count;
835 unsigned Class2Count;
836 OTF_Class1Record *Class1Record; /* size: <Class1Count> */
853 OTF_AnchorRecord *AnchorRecord;
858 OTF_Coverage BaseCoverage;
860 OTF_MarkArray MarkArray;
861 OTF_AnchorArray BaseArray;
862 } OTF_GPOS_MarkBase1;
871 OTF_Coverage Mark2Coverage;
873 OTF_MarkArray Mark1Array;
874 OTF_AnchorArray Mark2Array;
875 } OTF_GPOS_MarkMark1;
877 typedef OTF_Context1 OTF_GPOS_Context1;
879 typedef OTF_Context2 OTF_GPOS_Context2;
881 typedef OTF_Context3 OTF_GPOS_Context3;
883 typedef OTF_ChainContext1 OTF_GPOS_ChainContext1;
885 typedef OTF_ChainContext2 OTF_GPOS_ChainContext2;
887 typedef OTF_ChainContext3 OTF_GPOS_ChainContext3;
892 } OTF_GPOS_Extension1;
895 struct OTF_LookupSubTableGPOS
898 OTF_Coverage Coverage;
901 OTF_GPOS_Single1 single1;
902 OTF_GPOS_Single2 single2;
904 OTF_GPOS_Pair1 pair1;
905 OTF_GPOS_Pair2 pair2;
907 OTF_GPOS_Cursive1 cursive1;
909 OTF_GPOS_MarkBase1 mark_base1;
911 OTF_GPOS_MarkLig1 mark_lig1;
913 OTF_GPOS_MarkMark1 mark_mark1;
915 OTF_GPOS_Context1 context1;
916 OTF_GPOS_Context2 context2;
917 OTF_GPOS_Context3 context3;
919 OTF_GPOS_ChainContext1 chain_context1;
920 OTF_GPOS_ChainContext2 chain_context2;
921 OTF_GPOS_ChainContext3 chain_context3;
923 OTF_GPOS_Extension1 extension1;
927 typedef OTF_GSUB_GPOS OTF_GPOS;
929 /*** (1-11) Structure for OTF */
933 OTF_Fixed sfnt_version;
935 unsigned searchRange;
936 unsigned enterSelector;
947 } OTF_TableDirectory;
949 typedef struct OTF_InternalData OTF_InternalData;
954 OTF_OffsetTable offset_table;
955 OTF_TableDirectory *table_dirs;
962 /* The following tables are not yet supported. */
965 OTF_InternalData *internal_data;
969 /*** (2) API for reading OTF */
971 /*** (2-1) otf_open () */
976 The OTF_open() function reads the OpenType font file whose name is
977 $NAME, and return a pointer to the structure of type OTF.
979 It setups these member of the structure OTF:
980 filename, offset_table, table_dirs
982 If the file can't be read or the file contains invalid data, NULL
983 is returned, and the variable OTF_error is set to one of the
990 See also OTF_get_table() and OTF_close(). */
992 extern OTF *OTF_open (char *name);
995 /*** (2-2) OTF_close () */
1000 The OTF_close() function closes the OpenType font $OTF which must
1001 be what the OTF_open() function returned.
1003 See also OTF_open(). */
1005 extern void OTF_close (OTF *otf);
1008 /*** (2-3) OTF_get_table () */
1011 Get OpenType font table
1013 The OTF_get_table() function setups one of the OTF table specified
1014 by $NAME in the OpenType font $OTF.
1016 $NAME must be one of "head", "name", "cmap", "GDEF", "GSUB", and
1017 "GPOS", and a member of the same name is setup.
1019 If the table is successfully setup, return 0. Otherwise, return
1020 -1, and set the variable OTF_error to OTF_ERROR_TABLE.
1022 See also OTF_open(). */
1024 extern int OTF_get_table (OTF *otf, char *name);
1026 /*** (2-4) OTF_check_table () */
1029 Check the existence of OpenType font table
1031 The OTF_check_table() function checks if the the OTF table
1032 specified by $NAME exists in OpenType font $OTF.
1034 If the table exists, return 0, else return -1.
1036 See also OTF_open(). */
1038 extern int OTF_check_table (OTF *otf, char *name);
1041 /*** (3) API for driving OTF */
1043 /*** (3-1) Structure for glyph string */
1046 The structure OTF_Glyph contains information about each glyph in
1047 the structure OTF_GlyphString. */
1051 /* Character code of the glyph. This is the only member that a
1052 client has to set before calling the function
1056 /* Glyph ID of the glyph. */
1057 OTF_GlyphID glyph_id;
1059 /* GlyphClass of the glyph. The value is extracted from the GDEF
1061 enum OTF_GlyphClassDef GlyphClass;
1063 /* MarkAttachClassDef of the glyph. The value is extracted from the
1065 unsigned MarkAttachClass;
1067 /* Positioning format type of the glyph. The value specifies how
1068 the glyph positioning information is encoded in the member <f>.
1069 If the value is N, the union member fN, is used. If the value is
1070 zero, the glyph has no positioning information, i.e. it should be
1071 drawn at the normal position. */
1072 int positioning_type;
1075 enum OTF_ValueFormat format;
1076 OTF_ValueRecord *value;
1079 enum OTF_ValueFormat format;
1080 OTF_ValueRecord *value;
1083 OTF_Anchor *entry_anchor;
1084 OTF_Anchor *exit_anchor;
1087 OTF_Anchor *mark_anchor;
1088 OTF_Anchor *base_anchor;
1091 OTF_Anchor *mark_anchor;
1092 OTF_Anchor *ligature_anchor;
1095 OTF_Anchor *mark1_anchor;
1096 OTF_Anchor *mark2_anchor;
1102 The structure OTF_GlyphString contains an array of glyphs (type
1103 OTF_Glyph). It is used as arguments of otf_drive_XXX(). */
1107 /* How many glyphs are allocated at the memory pointed by the member
1110 /* How many glyphs contains valid information. */
1112 /* Array of glyphs. It must be allocated by malloc(). The
1113 functions otf_drive_XXX() may reallocate it and increase the
1114 members <size> and <used>. */
1119 /*** (3-2) OTF_drive_cmap() */
1122 Process glyph string by cmap table.
1124 The OTF_drive_cmap() function looks up the cmap table of OpenType
1125 font $OTF, and setup the member <glyhph_id> of all glhphs in the
1126 glyph string $GSTRING. */
1128 extern int OTF_drive_cmap (OTF *otf, OTF_GlyphString *gstring);
1130 /*** (3-3) OTF_drive_gdef() */
1133 Process glyph string by GDEF table.
1135 The OTF_drive_gdef() function looks up the GDEF table of OpenType
1136 font $OTF, and setup members <GlyphClass> and <MarkAttachClass> of
1137 all glhphs in the glyph string $GSTRING. */
1139 extern int OTF_drive_gdef (OTF *otf, OTF_GlyphString *gstring);
1142 /*** (3-4) OTF_drive_gsub() */
1145 Process glyph string by GSUB table.
1147 The OTF_drive_gsub() function looks up the GSUB table of OpenType
1148 font $OTF, and by using features the font has for script $SCRIPT
1149 and language system $LANGSYS, update member <glyphs> of the glyph
1150 string $GSTRING. It may substitute, delete, insert glyphs in that
1153 extern int OTF_drive_gsub (OTF *otf, OTF_GlyphString *gstring,
1154 char *script, char *language, char *features);
1156 /*** (3-5) OTF_drive_gpos() */
1159 Process glyph string by GPOS table.
1161 The OTF_drive_gdef() function looks up the GPOS table of $OTF of
1162 OpenType font $OTF, and by using features the font has for script
1163 $SCRIPT and language system $LANGSYS, setup members
1164 <positioning_type> and <f> of all glhphs in the glyph string
1167 extern int OTF_drive_gpos (OTF *otf, OTF_GlyphString *gstring,
1168 char *script, char *language, char *features);
1170 /*** (3-6) OTF_drive_tables() */
1173 Process glyph string by cmap, GDEF, GSUB, and GPOS tables.
1175 The OTF_drive_tables() function calls OTF_drive_cmap(),
1176 OTF_drive_gdef(), OTF_drive_gsub(), and OTF_drive_gpos() in this
1177 order, and update the glyphs string GSTRING. */
1179 extern int OTF_drive_tables (OTF *otf, OTF_GlyphString *gstring,
1180 char *script, char *language,
1181 char *gsub_features, char *gpos_features);
1184 /*** (4) API for error handling ***/
1186 /*** (4-1) Error codes ***/
1189 Global variable holding an error code.
1191 The variable OTF_error is set to one of OTF_ERROR_XXX macros when
1192 an error is detected in the OTF library. */
1193 extern int OTF_error;
1196 Memory allocation error
1198 This error indicates that the library couldn't allocate
1200 #define OTF_ERROR_MEMORY 1
1205 This error indicates that the library fails in opening, reading,
1206 or seeking an OTF file. */
1207 #define OTF_ERROR_FILE 2
1210 Invalid table contents
1212 This error indicates that an OTF file contains invalid data. */
1213 #define OTF_ERROR_TABLE 3
1218 See the function otf_drive_cmap() for more detail. */
1219 #define OTF_ERROR_CMAP_DRIVE 4
1224 See the function OTF_drive_gdef() for more detail. */
1225 #define OTF_ERROR_GDEF_DRIVE 5
1230 See the function OTF_drive_gsub() for more detail. */
1231 #define OTF_ERROR_GSUB_DRIVE 6
1236 See the function OTF_drive_gpos() for more detail. */
1237 #define OTF_ERROR_GPOS_DRIVE 7
1240 /*** (4-2) OTF_perror() */
1243 Print an OTF error message
1245 The OTF_perror() function produces a message on the standard error
1246 output, describing the last error encountered during a call to the
1247 OTF library function. If $PREFIX is not NULL, is is printed
1248 first, followed by a colon and a blank. Then the message and a
1251 extern void OTF_perror (char *prefix);
1254 /*** (5) API miscellaneous ***/
1257 Return OTF tag of a specified name string.
1259 The OTF_tag() function returns OTF tag of name $NAME. If $NAME is
1260 NULL, return 0. Otherwise, $NAME must be at least 4-byte length.
1261 Only the first 4 characters are took into an account. */
1263 extern OTF_Tag OTF_tag (char *name);
1266 Convert OTF tag to name string.
1268 The OTF_tag_name() function converts OTF tag $TAG to a 5-byte name
1269 string (including the terminating NULL), and store it in $NAME.
1270 At least 5-byte space must be at $NAME. */
1272 extern void OTF_tag_name (OTF_Tag tag, char *name);
1275 #endif /* not _OTF_H_ */