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;
538 } OTF_SubstLookupRecord;
540 typedef struct OTF_SubRuleSet OTF_SubRuleSet;
544 unsigned SubRuleSetCount;
545 OTF_SubRuleSet *SubRuleSet;
548 typedef struct OTF_SubRule OTF_SubRule;
550 struct OTF_SubRuleSet
553 unsigned SubRuleCount;
554 OTF_SubRule *SubRule;
563 OTF_SubstLookupRecord *SubstLookupRecord;
566 typedef struct OTF_SubClassSet OTF_SubClassSet;
570 OTF_ClassDef ClassDef;
571 unsigned SubClassSetCount;
572 OTF_SubClassSet *SubClassSet;
575 typedef struct OTF_SubClassRule OTF_SubClassRule;
577 struct OTF_SubClassSet
579 unsigned SubClassRuleCnt;
580 OTF_SubClassRule *SubClassRule;
583 struct OTF_SubClassRule
589 OTF_SubstLookupRecord *SubstLookupRecord;
596 OTF_Coverage *Coverage;
597 OTF_SubstLookupRecord *SubstLookupRecord;
600 typedef struct OTF_ChainSubRuleSet OTF_ChainSubRuleSet;
604 unsigned ChainSubRuleSetCount;
605 OTF_ChainSubRuleSet *ChainSubRuleSet;
606 } OTF_GSUB_ChainContext1;
608 typedef struct OTF_ChainSubRule OTF_ChainSubRule;
610 struct OTF_ChainSubRuleSet
613 unsigned ChainSubRuleCount;
614 OTF_ChainSubRule *ChainSubRule;
617 struct OTF_ChainSubRule
620 unsigned BacktrackGlyphCount;
621 OTF_GlyphID *Backtrack;
622 unsigned InputGlyphCount;
624 unsigned LookaheadGlyphCount;
625 OTF_GlyphID *LookAhead;
627 OTF_SubstLookupRecord *SubstLookupRecord;
630 typedef struct OTF_ChainSubClassSet OTF_ChainSubClassSet;
634 OTF_ClassDef Backtrack;
636 OTF_ClassDef LookAhead;
637 unsigned ChainSubClassSetCnt;
638 OTF_ChainSubClassSet *ChainSubClassSet;
639 } OTF_GSUB_ChainContext2;
641 typedef struct OTF_ChainSubClassRule OTF_ChainSubClassRule;
643 struct OTF_ChainSubClassSet
646 unsigned ChainSubClassRuleCnt;
647 OTF_ChainSubClassRule *ChainSubClassRule;
650 struct OTF_ChainSubClassRule
653 unsigned BacktrackGlyphCount;
655 unsigned InputGlyphCount;
657 unsigned LookaheadGlyphCount;
660 OTF_SubstLookupRecord *SubstLookupRecord;
666 unsigned BacktrackGlyphCount;
667 OTF_Coverage *Backtrack;
668 unsigned InputGlyphCount;
670 unsigned LookaheadGlyphCount;
671 OTF_Coverage *LookAhead;
673 OTF_SubstLookupRecord *SubstLookupRecord;
674 } OTF_GSUB_ChainContext3;
678 unsigned ExtensionLookupType;
679 unsigned ExtentionOffset;
680 } OTF_GSUB_Extension1;
684 unsigned BacktrackGlyphCount;
685 OTF_Coverage *Backtrack;
686 unsigned LookaheadGlyphCount;
687 OTF_Coverage *LookAhead;
689 OTF_GlyphID *Substitute;
690 } OTF_GSUB_ReverseChainSingle1;
692 struct OTF_LookupSubTableGSUB
695 OTF_Coverage Coverage;
698 OTF_GSUB_Single1 single1;
699 OTF_GSUB_Single2 single2;
701 OTF_GSUB_Multiple1 multiple1;
703 OTF_GSUB_Alternate1 alternate1;
705 OTF_GSUB_Ligature1 ligature1;
707 OTF_GSUB_Context1 context1;
708 OTF_GSUB_Context2 context2;
709 OTF_GSUB_Context3 context3;
711 OTF_GSUB_ChainContext1 chain_context1;
712 OTF_GSUB_ChainContext2 chain_context2;
713 OTF_GSUB_ChainContext3 chain_context3;
715 OTF_GSUB_Extension1 extension1;
717 OTF_GSUB_ReverseChainSingle1 reverse_chain_single1;
724 OTF_ScriptList ScriptList;
725 OTF_FeatureList FeatureList;
726 OTF_LookupList LookupList;
729 /*** (1-8) "GPOS" table */
733 OTF_XPlacement = 0x0001,
734 OTF_YPlacement = 0x0002,
735 OTF_XAdvance = 0x0004,
736 OTF_YAdvance = 0x0008,
737 OTF_XPlaDevice = 0x0010,
738 OTF_YPlaDevice = 0x0020,
739 OTF_XAdvDevice = 0x0040,
740 OTF_YAdvDevice = 0x0080
749 OTF_DeviceTable XPlaDevice;
750 OTF_DeviceTable YPlaDevice;
751 OTF_DeviceTable XAdvDevice;
752 OTF_DeviceTable YAdvDevice;
758 unsigned AnchorFormat;
763 unsigned AnchorPoint;
766 OTF_DeviceTable XDeviceTable;
767 OTF_DeviceTable YDeviceTable;
775 OTF_Anchor MarkAnchor;
782 OTF_MarkRecord *MarkRecord;
802 OTF_ValueRecord Value1;
803 OTF_ValueRecord Value2;
808 OTF_Class2Record *Class2Record;
813 unsigned ValueFormat1;
814 unsigned ValueFormat2;
815 OTF_ClassDef ClassDef1;
816 OTF_ClassDef ClassDef2;
817 unsigned Class1Count;
818 unsigned Class2Count;
819 OTF_Class1Record *Class1Record; /* size: <Class1Count> */
829 OTF_Anchor *BaseAnchor;
836 OTF_BaseRecord *BaseRecord;
841 OTF_Coverage BaseCoverage;
843 OTF_MarkArray MarkArray;
844 OTF_BaseArray BaseArray;
845 } OTF_GPOS_MarkBase1;
855 } OTF_GPOS_MarkMark1;
875 } OTF_GPOS_ChainContext1;
880 } OTF_GPOS_ChainContext2;
885 } OTF_GPOS_ChainContext3;
890 } OTF_GPOS_Extension1;
893 struct OTF_LookupSubTableGPOS
896 OTF_Coverage Coverage;
899 OTF_GPOS_Single1 single1;
900 OTF_GPOS_Single2 single2;
902 OTF_GPOS_Pair1 pair1;
903 OTF_GPOS_Pair2 pair2;
905 OTF_GPOS_Cursive1 cursive1;
907 OTF_GPOS_MarkBase1 mark_base1;
909 OTF_GPOS_MarkLig1 mark_lig1;
911 OTF_GPOS_MarkMark1 mark_mark1;
913 OTF_GPOS_Context1 context1;
914 OTF_GPOS_Context2 context2;
915 OTF_GPOS_Context3 context3;
917 OTF_GPOS_ChainContext1 chain_context1;
918 OTF_GPOS_ChainContext2 chain_context2;
919 OTF_GPOS_ChainContext3 chain_context3;
921 OTF_GPOS_Extension1 extension1;
928 OTF_ScriptList ScriptList;
929 OTF_FeatureList FeatureList;
930 OTF_LookupList LookupList;
933 /*** (1-9) Structure for OTF */
937 OTF_Fixed sfnt_version;
939 unsigned searchRange;
940 unsigned enterSelector;
951 } OTF_TableDirectory;
953 typedef struct OTF_InternalData OTF_InternalData;
958 OTF_OffsetTable offset_table;
959 OTF_TableDirectory *table_dirs;
966 /* The following tables are not yet supported. */
969 OTF_InternalData *internal_data;
973 /*** (2) APIs for reading OTF */
975 /*** (2-1) otf_open () */
980 The otf_open() function reads the OpenType font file whose name is
981 $NAME, and return a pointer to the structure of type OTF.
983 It setups these member of the structure OTF:
984 filename, offset_table, table_dirs
986 If the file can't be read or the file contains invalid data, NULL
987 is returned, and the variable otf_error is set to one of the
994 See also otf_get_table() and otf_close(). */
996 extern OTF *otf_open (char *name);
999 /*** (2-2) otf_close () */
1004 The otf_close() function closes the OpenType font pointed by $OTF
1005 which must be what the otf_open() returned.
1007 See also otf_open(). */
1009 extern void otf_close (OTF *otf);
1012 /*** (2-3) otf_get_table () */
1015 Get OpenType font table
1017 The otf_get_table() function setups one of the OTF tables
1018 specified by $NAME in the structure pointed by $OTF.
1020 $NAME must be one of "head", "name", "cmap", "GDEF", "GSUB", and
1021 "GPOS", and a member of the same name is setup.
1023 If the table is successfully setup, return 0. Otherwise, return
1024 -1, and set the variable otf_error to OTF_ERROR_TABLE.
1026 See also otf_open(). */
1028 extern int otf_get_table (OTF *otf, char *name);
1031 /*** (3) APIs for driving OTF */
1033 /*** (3-1) Structure for glyph string */
1036 The structure OTF_Glyph contains information about each glyph in
1037 the structure OTF_GlyphString. */
1041 /* Character code of the glyph. This is the only member that a
1042 client has to set before calling the function
1046 /* Glyph ID of the glyph. */
1047 OTF_GlyphID glyph_id;
1049 /* GlyphClass of the glyph. The value is extracted from the GDEF
1051 enum OTF_GlyphClassDef GlyphClass;
1053 /* MarkAttachClassDef of the glyph. The value is extracted from the
1055 unsigned MarkAttachClass;
1057 /* Positioning format type of the glyph. The value specifies how
1058 the glyph positioning information is encoded in the member <f>.
1059 If the value is N, the union member fN, is used. If the value is
1060 zero, the glyph has no positioning information, i.e. it should be
1061 drawn at the normal position. */
1062 int positioning_type;
1065 enum OTF_ValueFormat format;
1066 OTF_ValueRecord *value;
1069 enum OTF_ValueFormat format;
1070 OTF_ValueRecord *value;
1073 OTF_Anchor *entry_anchor;
1074 OTF_Anchor *exit_anchor;
1077 OTF_Anchor *mark_anchor;
1078 OTF_Anchor *base_anchor;
1081 OTF_Anchor *mark_anchor;
1082 OTF_Anchor *ligature_anchor;
1085 OTF_Anchor *mark1_anchor;
1086 OTF_Anchor *mark2_anchor;
1092 The structure OTF_GlyphString contains an array of glyphs (type
1093 OTF_Glyph). It is used as arguments of otf_drive_XXX(). */
1097 /* How many glyphs are allocated at the memory pointed by the member
1100 /* How many glyphs contains valid information. */
1102 /* Array of glyphs. It must be allocated by malloc(). The
1103 functions otf_drive_XXX() may reallocate it and increase the
1104 members <size> and <used>. */
1109 /*** (3-2) otf_drive_cmap() */
1112 Process glyph string by cmap table.
1114 The otf_drive_cmap() function looks up the cmap table of OpenType
1115 font $OTF, and setup the member <glyhph_id> of all glhphs in the
1116 glyph string $GSTRING. */
1118 extern int otf_drive_cmap (OTF *otf, OTF_GlyphString *gstring);
1120 /*** (3-3) otf_drive_gdef() */
1123 Process glyph string by GDEF table.
1125 The otf_drive_gdef() function looks up the GDEF table of OpenType
1126 font $OTF, and setup members <GlyphClass> and <MarkAttachClass> of
1127 all glhphs in the glyph string $GSTRING. */
1129 extern int otf_drive_gdef (OTF *otf, OTF_GlyphString *gstring);
1132 /*** (3-4) otf_drive_gsub() */
1135 Process glyph string by GSUB table.
1137 The otf_drive_gsub() function looks up the GSUB table of OpenType
1138 font $OTF, and by using features the font has for script $SCRIPT
1139 and language system $LANGSYS, update member <glyphs> of the glyph
1140 string $GSTRING. It may substitute, delete, insert glyphs in that
1143 extern int otf_drive_gsub (OTF *otf, OTF_Tag script_tag, OTF_Tag langsys_tag,
1144 OTF_GlyphString *gstring);
1146 /*** (3-5) otf_drive_gpos() */
1149 Process glyph string by GPOS table.
1151 The otf_drive_gdef() function looks up the GPOS table of $OTF of
1152 OpenType font $OTF, and by using features the font has for script
1153 $SCRIPT and language system $LANGSYS, setup members
1154 <positioning_type> and <f> of all glhphs in the glyph string
1157 extern int otf_drive_gpos (OTF *otf, OTF_Tag script_tag, OTF_Tag langsys_tag,
1158 OTF_GlyphString *gstring);
1161 /*** (3-6) otf_drive_tables() */
1164 Process glyph string by cmap, GDEF, GSUB, and GPOS tables.
1166 The otf_drive_tables() function calls otf_drive_cmap(),
1167 otf_drive_gdef(), otf_drive_gsub(), and otf_drive_gpos() in this
1168 order, and update the glyphs string GSTRING. */
1170 extern int otf_drive_tables (OTF *otf, OTF_Tag script_tag, OTF_Tag langsys_tag,
1171 OTF_GlyphString *gstring);
1174 /*** (4) APIs for error handling ***/
1176 /*** (4-1) Error codes ***/
1179 Global variable holding an error code.
1181 The variable otf_error is set to one of OTF_ERROR_XXX macros when
1182 an error is detected in the OTF library. */
1183 extern int otf_error;
1186 Memory allocation error
1188 This error indicates that the library couldn't allocate
1190 #define OTF_ERROR_MEMORY 1
1195 This error indicates that the library fails in opening, reading,
1196 or seeking an OTF file. */
1197 #define OTF_ERROR_FILE 2
1200 Invalid table contents
1202 This error indicates that an OTF file contains invalid data. */
1203 #define OTF_ERROR_TABLE 3
1208 See the function otf_drive_cmap() for more detail. */
1209 #define OTF_ERROR_CMAP_DRIVE 4
1214 See the function otf_drive_gdef() for more detail. */
1215 #define OTF_ERROR_GDEF_DRIVE 5
1220 See the function otf_drive_gsub() for more detail. */
1221 #define OTF_ERROR_GSUB_DRIVE 6
1226 See the function otf_drive_gpos() for more detail. */
1227 #define OTF_ERROR_GPOS_DRIVE 7
1230 /*** (4-2) otf_perror() */
1233 Print an OTF error message
1235 The otf_perror() function produces a message on the standard error
1236 output, describing the last error encountered during a call to the
1237 OTF library function. If $PREFIX is not NULL, is is printed
1238 first, followed by a colon and a blank. Then the message and a
1241 extern void otf_perror (char *prefix);
1244 /*** (5) APIs miscellaneous ***/
1247 Return OTF tag of a specified name string.
1249 The otf_tag() function returns OTF tag of name $NAME. If $NAME is
1250 NULL, return 0. Otherwise, $NAME must be at least 4-byte length.
1251 Only the first 4 characters are took into an account. */
1253 extern OTF_Tag otf_tag (char *name);
1256 Convert OTF tag to name string.
1258 The otf_tag_name() function converts OTF tag $TAG to a 5-byte
1259 name string (including the terminating NUL), and store it in
1260 $NAME. At least 5-byte space must be at $NAME. */
1262 extern void otf_tag_name (OTF_Tag tag, char *name);
1265 #endif /* not _OTF_H_ */