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 tables and OTF itself
35 (1-5) Structures common to GDEF, GSUB, and GPOS
37 (1-7) Structures for ScriptList, FeatureList, and LookupList
40 (1-9) Structure for OTF
42 (2) APIs for reading OTF
47 (3) APIs for driving OTF
48 (3-1) Structure for glyph string
49 (3-2) OTF_drive_cmap()
50 (3-3) OTF_drive_gdef()
51 (3-4) OTF_drive_gsub()
52 (3-5) OTF_drive_gpos()
53 (3-6) OTF_drive_tables()
55 (4) APIs for error handling
59 (5) APIs miscellaneous
63 /*** (1) Structures for OTF tables and OTF itself */
65 /*** (1-1) Basic types */
67 typedef unsigned OTF_Tag;
68 typedef unsigned OTF_GlyphID;
69 typedef unsigned OTF_Offset;
78 /*** (1-2) "head" table */
82 OTF_Fixed TableVersionNumber;
83 OTF_Fixed fontRevision;
84 unsigned checkSumAdjustment;
91 /*** (1-3) "name" table */
103 #define OTF_max_nameID 23
110 OTF_NameRecord *nameRecord;
111 char *name[OTF_max_nameID + 1];
115 /*** (1-4) "cmap" table */
119 unsigned char glyphIdArray[256];
120 } OTF_EncodingSubtable0;
127 unsigned idRangeOffset;
132 unsigned subHeaderKeys[256];
133 OTF_cmapSubHeader *subHeaders;
134 unsigned *glyphIndexArray;
135 } OTF_EncodingSubtable2;
142 unsigned idRangeOffset;
148 unsigned searchRange;
149 unsigned entrySelector;
151 OTF_cmapSegument *segments;
153 unsigned *glyphIdArray;
154 } OTF_EncodingSubtable4;
160 unsigned *glyphIdArray;
161 } OTF_EncodingSubtable6;
165 unsigned startCharCode;
166 unsigned endCharCode;
167 unsigned startGlyphID;
172 unsigned char is32[8192];
174 OTF_cmapGroup *Groups;
175 } OTF_EncodingSubtable8;
179 unsigned startCharCode;
182 } OTF_EncodingSubtable10;
187 OTF_cmapGroup *Groups;
188 } OTF_EncodingSubtable12;
196 OTF_EncodingSubtable0 *f0;
197 OTF_EncodingSubtable2 *f2;
198 OTF_EncodingSubtable4 *f4;
199 OTF_EncodingSubtable6 *f6;
200 OTF_EncodingSubtable8 *f8;
201 OTF_EncodingSubtable10 *f10;
202 OTF_EncodingSubtable12 *f12;
204 } OTF_EncodingSubtable;
211 OTF_EncodingSubtable subtable;
212 } OTF_EncodingRecord;
218 OTF_EncodingRecord *EncodingRecord;
219 OTF_EncodingRecord *Unicode;
223 /*** (1-5) Structures common to GDEF, GSUB, GPOS */
229 unsigned StartCoverageIndex;
235 unsigned CoverageFormat;
238 OTF_GlyphID *GlyphArray;
239 OTF_RangeRecord *RangeRecord;
248 unsigned DeltaFormat;
257 } OTF_ClassRangeRecord;
262 unsigned ClassFormat;
265 OTF_GlyphID StartGlyph;
267 unsigned *ClassValueArray;
270 unsigned ClassRangeCount;
271 OTF_ClassRangeRecord *ClassRangeRecord;
277 /*** (1-6) "GDEF" table */
282 OTF_Offset GlyphClassDef;
283 OTF_Offset AttachList;
284 OTF_Offset LigCaretList;
285 OTF_Offset MarkAttachClassDef;
288 enum OTF_GlyphClassDef
291 OTF_GlyphClassBase = 1,
292 OTF_GlyphClassLigature = 2,
293 OTF_GlyphClassMark = 3,
294 OTF_GlyphClassComponent = 4
301 unsigned *PointIndex;
306 OTF_Coverage Coverage;
308 OTF_AttachPoint *AttachPoint;
314 unsigned CaretValueFormat; /* 1, 2, or 3 */
320 unsigned CaretValuePoint;
324 OTF_DeviceTable DeviceTable;
333 OTF_CaretValue *CaretValue;
338 OTF_Coverage Coverage;
339 unsigned LigGlyphCount;
340 OTF_LigGlyph *LigGlyph;
345 OTF_GDEFHeader header;
346 OTF_ClassDef glyph_class_def;
347 OTF_AttachList attach_list;
348 OTF_LigCaretList lig_caret_list;
349 OTF_ClassDef mark_attach_class_def;
353 /*** (1-7) Structures for ScriptList, FeatureList, and LookupList */
355 /*** The structure hierarchy
382 SubTable.gsub[] or SubTable.gpos[]
388 OTF_Offset LookupOrder;
389 unsigned ReqFeatureIndex;
390 unsigned FeatureCount;
391 unsigned *FeatureIndex;
404 OTF_Offset DefaultLangSysOffset;
405 OTF_LangSys DefaultLangSys;
406 unsigned LangSysCount;
407 OTF_LangSysRecord *LangSysRecord;
408 OTF_LangSys *LangSys;
414 unsigned ScriptCount;
422 OTF_Offset FeatureParams;
423 unsigned LookupCount;
424 unsigned *LookupListIndex;
430 unsigned FeatureCount;
431 OTF_Feature *Feature;
434 typedef struct OTF_LookupSubTableGSUB OTF_LookupSubTableGSUB;
435 typedef struct OTF_LookupSubTableGPOS OTF_LookupSubTableGPOS;
437 enum OTF_LookupFlagBit
439 OTF_RightToLeft = 0x0001,
440 OTF_IgnoreBaseGlyphs = 0x0002,
441 OTF_IgnoreLigatures = 0x0004,
442 OTF_IgnoreMarks = 0x8000,
443 OTF_Reserved = 0x00F0,
444 OTF_MarkAttachmentType = 0xFF00
452 unsigned SubTableCount;
453 OTF_Offset *SubTableOffset;
455 OTF_LookupSubTableGSUB *gsub;
456 OTF_LookupSubTableGPOS *gpos;
463 unsigned LookupCount;
467 /*** (1-8) "GSUB" table */
477 OTF_GlyphID *Substitute;
480 typedef struct OTF_Sequence OTF_Sequence;
484 unsigned SequenceCount;
485 OTF_Sequence *Sequence;
486 } OTF_GSUB_Multiple1;
492 OTF_GlyphID *Substitute;
495 typedef struct OTF_AlternateSet OTF_AlternateSet;
499 unsigned AlternateSetCount;
500 OTF_AlternateSet *AlternateSet;
501 } OTF_GSUB_Alternate1;
503 struct OTF_AlternateSet
507 OTF_GlyphID *Alternate;
510 typedef struct OTF_LigatureSet OTF_LigatureSet;
511 typedef struct OTF_Ligature OTF_Ligature;
515 unsigned LigSetCount;
516 OTF_LigatureSet *LigatureSet;
517 } OTF_GSUB_Ligature1;
519 struct OTF_LigatureSet
522 unsigned LigatureCount;
523 OTF_Ligature *Ligature;
529 OTF_GlyphID LigGlyph;
531 OTF_GlyphID *Component;
536 unsigned SequenceIndex;
537 unsigned LookupListIndex;
540 typedef struct OTF_RuleSet OTF_RuleSet;
544 unsigned SubRuleSetCount;
545 OTF_RuleSet *SubRuleSet; /* [<SubRuleSetCount>] */
548 typedef struct OTF_Rule OTF_Rule;
554 OTF_Rule *Rule; /* [<RuleCount>] */
561 unsigned LookupCount;
562 OTF_GlyphID *Input; /* [<GlyphCount> - 1] */
563 OTF_LookupRecord *LookupRecord; /* [<LookupCount>] */
566 typedef struct OTF_ClassSet OTF_ClassSet;
570 OTF_ClassDef ClassDef;
571 unsigned SubClassSetCnt;
572 OTF_ClassSet *SubClassSet; /* [<ClassSetCnt>] */
575 typedef struct OTF_ClassRule OTF_ClassRule;
580 unsigned ClassRuleCnt;
581 OTF_ClassRule *ClassRule; /* [<ClassRuleCnt>] */
588 unsigned LookupCount;
589 unsigned *Class; /* [<GlyphCount> - 1] */
590 OTF_LookupRecord *LookupRecord; /* [<LookupCount>] */
597 OTF_Coverage *Coverage;
598 OTF_LookupRecord *LookupRecord;
601 typedef struct OTF_ChainRuleSet OTF_ChainRuleSet;
605 unsigned ChainSubRuleSetCount;
606 OTF_ChainRuleSet *ChainSubRuleSet;
607 } OTF_GSUB_ChainContext1;
609 typedef struct OTF_ChainRule OTF_ChainRule;
611 struct OTF_ChainRuleSet
614 unsigned ChainRuleCount;
615 OTF_ChainRule *ChainRule;
621 unsigned BacktrackGlyphCount;
622 OTF_GlyphID *Backtrack;
623 unsigned InputGlyphCount;
625 unsigned LookaheadGlyphCount;
626 OTF_GlyphID *LookAhead;
627 unsigned LookupCount;
628 OTF_LookupRecord *LookupRecord;
631 typedef struct OTF_ChainClassSet OTF_ChainClassSet;
635 OTF_ClassDef Backtrack;
637 OTF_ClassDef LookAhead;
638 unsigned ChainSubClassSetCnt;
639 OTF_ChainClassSet *ChainSubClassSet;
640 } OTF_GSUB_ChainContext2;
642 typedef struct OTF_ChainClassRule OTF_ChainClassRule;
644 struct OTF_ChainClassSet
647 unsigned ChainClassRuleCnt;
648 OTF_ChainClassRule *ChainClassRule;
651 struct OTF_ChainClassRule
654 unsigned BacktrackGlyphCount;
656 unsigned InputGlyphCount;
658 unsigned LookaheadGlyphCount;
660 unsigned LookupCount;
661 OTF_LookupRecord *LookupRecord;
667 unsigned BacktrackGlyphCount;
668 OTF_Coverage *Backtrack;
669 unsigned InputGlyphCount;
671 unsigned LookaheadGlyphCount;
672 OTF_Coverage *LookAhead;
674 OTF_LookupRecord *LookupRecord;
675 } OTF_GSUB_ChainContext3;
679 unsigned ExtensionLookupType;
680 unsigned ExtentionOffset;
681 } OTF_GSUB_Extension1;
685 unsigned BacktrackGlyphCount;
686 OTF_Coverage *Backtrack;
687 unsigned LookaheadGlyphCount;
688 OTF_Coverage *LookAhead;
690 OTF_GlyphID *Substitute;
691 } OTF_GSUB_ReverseChainSingle1;
693 struct OTF_LookupSubTableGSUB
696 OTF_Coverage Coverage;
699 OTF_GSUB_Single1 single1;
700 OTF_GSUB_Single2 single2;
702 OTF_GSUB_Multiple1 multiple1;
704 OTF_GSUB_Alternate1 alternate1;
706 OTF_GSUB_Ligature1 ligature1;
708 OTF_GSUB_Context1 context1;
709 OTF_GSUB_Context2 context2;
710 OTF_GSUB_Context3 context3;
712 OTF_GSUB_ChainContext1 chain_context1;
713 OTF_GSUB_ChainContext2 chain_context2;
714 OTF_GSUB_ChainContext3 chain_context3;
716 OTF_GSUB_Extension1 extension1;
718 OTF_GSUB_ReverseChainSingle1 reverse_chain_single1;
725 OTF_ScriptList ScriptList;
726 OTF_FeatureList FeatureList;
727 OTF_LookupList LookupList;
730 /*** (1-8) "GPOS" table */
734 OTF_XPlacement = 0x0001,
735 OTF_YPlacement = 0x0002,
736 OTF_XAdvance = 0x0004,
737 OTF_YAdvance = 0x0008,
738 OTF_XPlaDevice = 0x0010,
739 OTF_YPlaDevice = 0x0020,
740 OTF_XAdvDevice = 0x0040,
741 OTF_YAdvDevice = 0x0080
750 OTF_DeviceTable XPlaDevice;
751 OTF_DeviceTable YPlaDevice;
752 OTF_DeviceTable XAdvDevice;
753 OTF_DeviceTable YAdvDevice;
759 unsigned AnchorFormat;
764 unsigned AnchorPoint;
767 OTF_DeviceTable XDeviceTable;
768 OTF_DeviceTable YDeviceTable;
776 OTF_Anchor MarkAnchor;
783 OTF_MarkRecord *MarkRecord;
788 unsigned ValueFormat;
789 OTF_ValueRecord Value;
794 unsigned ValueFormat;
796 OTF_ValueRecord *Value; /* [<ValueCount>] */
806 OTF_ValueRecord Value1;
807 OTF_ValueRecord Value2;
812 OTF_Class2Record *Class2Record;
817 unsigned ValueFormat1;
818 unsigned ValueFormat2;
819 OTF_ClassDef ClassDef1;
820 OTF_ClassDef ClassDef2;
821 unsigned Class1Count;
822 unsigned Class2Count;
823 OTF_Class1Record *Class1Record; /* size: <Class1Count> */
840 OTF_AnchorRecord *AnchorRecord;
845 OTF_Coverage BaseCoverage;
847 OTF_MarkArray MarkArray;
848 OTF_AnchorArray BaseArray;
849 } OTF_GPOS_MarkBase1;
858 OTF_Coverage Mark2Coverage;
860 OTF_MarkArray Mark1Array;
861 OTF_AnchorArray Mark2Array;
862 } OTF_GPOS_MarkMark1;
867 unsigned PosRuleSetCount;
868 OTF_RuleSet *PosRuleSet;
873 OTF_ClassDef ClassDef;
874 unsigned PosClassSetCnt;
875 OTF_ClassSet *PosClassSet;
882 OTF_Coverage *Coverage; /* [<GlyphCount>] */
883 OTF_LookupRecord *LookupRecord; /* [<PosCount>] */
888 unsigned ChainPosRuleSetCount;
889 OTF_ChainRuleSet *ChainPosRuleSet;
890 } OTF_GPOS_ChainContext1;
894 OTF_ClassDef Backtrack;
896 OTF_ClassDef LookAhead;
897 unsigned ChainPosClassSetCnt;
898 OTF_ChainClassSet *ChainPosClassSet;
899 } OTF_GPOS_ChainContext2;
903 unsigned BacktrackGlyphCount;
904 OTF_Coverage *Backtrack;
905 unsigned InputGlyphCount;
907 unsigned LookaheadGlyphCount;
908 OTF_Coverage *LookAhead;
910 OTF_LookupRecord *LookupRecord;
911 } OTF_GPOS_ChainContext3;
916 } OTF_GPOS_Extension1;
919 struct OTF_LookupSubTableGPOS
922 OTF_Coverage Coverage;
925 OTF_GPOS_Single1 single1;
926 OTF_GPOS_Single2 single2;
928 OTF_GPOS_Pair1 pair1;
929 OTF_GPOS_Pair2 pair2;
931 OTF_GPOS_Cursive1 cursive1;
933 OTF_GPOS_MarkBase1 mark_base1;
935 OTF_GPOS_MarkLig1 mark_lig1;
937 OTF_GPOS_MarkMark1 mark_mark1;
939 OTF_GPOS_Context1 context1;
940 OTF_GPOS_Context2 context2;
941 OTF_GPOS_Context3 context3;
943 OTF_GPOS_ChainContext1 chain_context1;
944 OTF_GPOS_ChainContext2 chain_context2;
945 OTF_GPOS_ChainContext3 chain_context3;
947 OTF_GPOS_Extension1 extension1;
954 OTF_ScriptList ScriptList;
955 OTF_FeatureList FeatureList;
956 OTF_LookupList LookupList;
959 /*** (1-9) Structure for OTF */
963 OTF_Fixed sfnt_version;
965 unsigned searchRange;
966 unsigned enterSelector;
977 } OTF_TableDirectory;
979 typedef struct OTF_InternalData OTF_InternalData;
984 OTF_OffsetTable offset_table;
985 OTF_TableDirectory *table_dirs;
992 /* The following tables are not yet supported. */
995 OTF_InternalData *internal_data;
999 /*** (2) APIs for reading OTF */
1001 /*** (2-1) otf_open () */
1006 The OTF_open() function reads the OpenType font file whose name is
1007 $NAME, and return a pointer to the structure of type OTF.
1009 It setups these member of the structure OTF:
1010 filename, offset_table, table_dirs
1012 If the file can't be read or the file contains invalid data, NULL
1013 is returned, and the variable OTF_error is set to one of the
1020 See also OTF_get_table() and OTF_close(). */
1022 extern OTF *OTF_open (char *name);
1025 /*** (2-2) OTF_close () */
1030 The OTF_close() function closes the OpenType font pointed by $OTF
1031 which must be what the OTF_open() returned.
1033 See also OTF_open(). */
1035 extern void OTF_close (OTF *otf);
1038 /*** (2-3) OTF_get_table () */
1041 Get OpenType font table
1043 The OTF_get_table() function setups one of the OTF tables
1044 specified by $NAME in the structure pointed by $OTF.
1046 $NAME must be one of "head", "name", "cmap", "GDEF", "GSUB", and
1047 "GPOS", and a member of the same name is setup.
1049 If the table is successfully setup, return 0. Otherwise, return
1050 -1, and set the variable OTF_error to OTF_ERROR_TABLE.
1052 See also OTF_open(). */
1054 extern int OTF_get_table (OTF *otf, char *name);
1057 /*** (3) APIs for driving OTF */
1059 /*** (3-1) Structure for glyph string */
1062 The structure OTF_Glyph contains information about each glyph in
1063 the structure OTF_GlyphString. */
1067 /* Character code of the glyph. This is the only member that a
1068 client has to set before calling the function
1072 /* Glyph ID of the glyph. */
1073 OTF_GlyphID glyph_id;
1075 /* GlyphClass of the glyph. The value is extracted from the GDEF
1077 enum OTF_GlyphClassDef GlyphClass;
1079 /* MarkAttachClassDef of the glyph. The value is extracted from the
1081 unsigned MarkAttachClass;
1083 /* Positioning format type of the glyph. The value specifies how
1084 the glyph positioning information is encoded in the member <f>.
1085 If the value is N, the union member fN, is used. If the value is
1086 zero, the glyph has no positioning information, i.e. it should be
1087 drawn at the normal position. */
1088 int positioning_type;
1091 enum OTF_ValueFormat format;
1092 OTF_ValueRecord *value;
1095 enum OTF_ValueFormat format;
1096 OTF_ValueRecord *value;
1099 OTF_Anchor *entry_anchor;
1100 OTF_Anchor *exit_anchor;
1103 OTF_Anchor *mark_anchor;
1104 OTF_Anchor *base_anchor;
1107 OTF_Anchor *mark_anchor;
1108 OTF_Anchor *ligature_anchor;
1111 OTF_Anchor *mark1_anchor;
1112 OTF_Anchor *mark2_anchor;
1118 The structure OTF_GlyphString contains an array of glyphs (type
1119 OTF_Glyph). It is used as arguments of otf_drive_XXX(). */
1123 /* How many glyphs are allocated at the memory pointed by the member
1126 /* How many glyphs contains valid information. */
1128 /* Array of glyphs. It must be allocated by malloc(). The
1129 functions otf_drive_XXX() may reallocate it and increase the
1130 members <size> and <used>. */
1135 /*** (3-2) OTF_drive_cmap() */
1138 Process glyph string by cmap table.
1140 The OTF_drive_cmap() function looks up the cmap table of OpenType
1141 font $OTF, and setup the member <glyhph_id> of all glhphs in the
1142 glyph string $GSTRING. */
1144 extern int OTF_drive_cmap (OTF *otf, OTF_GlyphString *gstring);
1146 /*** (3-3) OTF_drive_gdef() */
1149 Process glyph string by GDEF table.
1151 The OTF_drive_gdef() function looks up the GDEF table of OpenType
1152 font $OTF, and setup members <GlyphClass> and <MarkAttachClass> of
1153 all glhphs in the glyph string $GSTRING. */
1155 extern int OTF_drive_gdef (OTF *otf, OTF_GlyphString *gstring);
1158 /*** (3-4) OTF_drive_gsub() */
1161 Process glyph string by GSUB table.
1163 The OTF_drive_gsub() function looks up the GSUB table of OpenType
1164 font $OTF, and by using features the font has for script $SCRIPT
1165 and language system $LANGSYS, update member <glyphs> of the glyph
1166 string $GSTRING. It may substitute, delete, insert glyphs in that
1169 extern int OTF_drive_gsub (OTF *otf, OTF_GlyphString *gstring,
1170 char *script, char *language, char *features);
1172 /*** (3-5) OTF_drive_gpos() */
1175 Process glyph string by GPOS table.
1177 The OTF_drive_gdef() function looks up the GPOS table of $OTF of
1178 OpenType font $OTF, and by using features the font has for script
1179 $SCRIPT and language system $LANGSYS, setup members
1180 <positioning_type> and <f> of all glhphs in the glyph string
1183 extern int OTF_drive_gpos (OTF *otf, OTF_GlyphString *gstring,
1184 char *script, char *language, char *features);
1186 /*** (3-6) OTF_drive_tables() */
1189 Process glyph string by cmap, GDEF, GSUB, and GPOS tables.
1191 The OTF_drive_tables() function calls OTF_drive_cmap(),
1192 OTF_drive_gdef(), OTF_drive_gsub(), and OTF_drive_gpos() in this
1193 order, and update the glyphs string GSTRING. */
1195 extern int OTF_drive_tables (OTF *otf, OTF_GlyphString *gstring,
1196 char *script, char *language,
1197 char *gsub_features, char *gpos_features);
1200 /*** (4) APIs for error handling ***/
1202 /*** (4-1) Error codes ***/
1205 Global variable holding an error code.
1207 The variable OTF_error is set to one of OTF_ERROR_XXX macros when
1208 an error is detected in the OTF library. */
1209 extern int OTF_error;
1212 Memory allocation error
1214 This error indicates that the library couldn't allocate
1216 #define OTF_ERROR_MEMORY 1
1221 This error indicates that the library fails in opening, reading,
1222 or seeking an OTF file. */
1223 #define OTF_ERROR_FILE 2
1226 Invalid table contents
1228 This error indicates that an OTF file contains invalid data. */
1229 #define OTF_ERROR_TABLE 3
1234 See the function otf_drive_cmap() for more detail. */
1235 #define OTF_ERROR_CMAP_DRIVE 4
1240 See the function OTF_drive_gdef() for more detail. */
1241 #define OTF_ERROR_GDEF_DRIVE 5
1246 See the function OTF_drive_gsub() for more detail. */
1247 #define OTF_ERROR_GSUB_DRIVE 6
1252 See the function OTF_drive_gpos() for more detail. */
1253 #define OTF_ERROR_GPOS_DRIVE 7
1256 /*** (4-2) OTF_perror() */
1259 Print an OTF error message
1261 The OTF_perror() function produces a message on the standard error
1262 output, describing the last error encountered during a call to the
1263 OTF library function. If $PREFIX is not NULL, is is printed
1264 first, followed by a colon and a blank. Then the message and a
1267 extern void OTF_perror (char *prefix);
1270 /*** (5) APIs miscellaneous ***/
1273 Return OTF tag of a specified name string.
1275 The OTF_tag() function returns OTF tag of name $NAME. If $NAME is
1276 NULL, return 0. Otherwise, $NAME must be at least 4-byte length.
1277 Only the first 4 characters are took into an account. */
1279 extern OTF_Tag OTF_tag (char *name);
1282 Convert OTF tag to name string.
1284 The OTF_tag_name() function converts OTF tag $TAG to a 5-byte
1285 name string (including the terminating NUL), and store it in
1286 $NAME. At least 5-byte space must be at $NAME. */
1288 extern void OTF_tag_name (OTF_Tag tag, char *name);
1291 #endif /* not _OTF_H_ */