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 ExtensionOffset;
700 OTF_LookupSubTableGSUB *ExtensionSubtable;
701 } OTF_GSUB_Extension1;
705 unsigned BacktrackGlyphCount;
706 OTF_Coverage *Backtrack;
707 unsigned LookaheadGlyphCount;
708 OTF_Coverage *LookAhead;
710 OTF_GlyphID *Substitute;
711 } OTF_GSUB_ReverseChain1;
713 struct OTF_LookupSubTableGSUB
716 OTF_Coverage Coverage;
719 OTF_GSUB_Single1 single1;
720 OTF_GSUB_Single2 single2;
722 OTF_GSUB_Multiple1 multiple1;
724 OTF_GSUB_Alternate1 alternate1;
726 OTF_GSUB_Ligature1 ligature1;
728 OTF_GSUB_Context1 context1;
729 OTF_GSUB_Context2 context2;
730 OTF_GSUB_Context3 context3;
732 OTF_GSUB_ChainContext1 chain_context1;
733 OTF_GSUB_ChainContext2 chain_context2;
734 OTF_GSUB_ChainContext3 chain_context3;
736 OTF_GSUB_Extension1 extension1;
738 OTF_GSUB_ReverseChain1 reverse_chain1;
742 typedef OTF_GSUB_GPOS OTF_GSUB;
744 /*** (1-10) "GPOS" table */
748 OTF_XPlacement = 0x0001,
749 OTF_YPlacement = 0x0002,
750 OTF_XAdvance = 0x0004,
751 OTF_YAdvance = 0x0008,
752 OTF_XPlaDevice = 0x0010,
753 OTF_YPlaDevice = 0x0020,
754 OTF_XAdvDevice = 0x0040,
755 OTF_YAdvDevice = 0x0080
764 OTF_DeviceTable XPlaDevice;
765 OTF_DeviceTable YPlaDevice;
766 OTF_DeviceTable XAdvDevice;
767 OTF_DeviceTable YAdvDevice;
773 unsigned AnchorFormat;
778 unsigned AnchorPoint;
781 OTF_DeviceTable XDeviceTable;
782 OTF_DeviceTable YDeviceTable;
790 OTF_Anchor MarkAnchor;
797 OTF_MarkRecord *MarkRecord;
802 unsigned ValueFormat;
803 OTF_ValueRecord Value;
808 unsigned ValueFormat;
810 OTF_ValueRecord *Value; /* [<ValueCount>] */
820 OTF_ValueRecord Value1;
821 OTF_ValueRecord Value2;
826 OTF_Class2Record *Class2Record;
831 unsigned ValueFormat1;
832 unsigned ValueFormat2;
833 OTF_ClassDef ClassDef1;
834 OTF_ClassDef ClassDef2;
835 unsigned Class1Count;
836 unsigned Class2Count;
837 OTF_Class1Record *Class1Record; /* size: <Class1Count> */
854 OTF_AnchorRecord *AnchorRecord;
859 OTF_Coverage BaseCoverage;
861 OTF_MarkArray MarkArray;
862 OTF_AnchorArray BaseArray;
863 } OTF_GPOS_MarkBase1;
872 OTF_Coverage Mark2Coverage;
874 OTF_MarkArray Mark1Array;
875 OTF_AnchorArray Mark2Array;
876 } OTF_GPOS_MarkMark1;
878 typedef OTF_Context1 OTF_GPOS_Context1;
880 typedef OTF_Context2 OTF_GPOS_Context2;
882 typedef OTF_Context3 OTF_GPOS_Context3;
884 typedef OTF_ChainContext1 OTF_GPOS_ChainContext1;
886 typedef OTF_ChainContext2 OTF_GPOS_ChainContext2;
888 typedef OTF_ChainContext3 OTF_GPOS_ChainContext3;
893 } OTF_GPOS_Extension1;
896 struct OTF_LookupSubTableGPOS
899 OTF_Coverage Coverage;
902 OTF_GPOS_Single1 single1;
903 OTF_GPOS_Single2 single2;
905 OTF_GPOS_Pair1 pair1;
906 OTF_GPOS_Pair2 pair2;
908 OTF_GPOS_Cursive1 cursive1;
910 OTF_GPOS_MarkBase1 mark_base1;
912 OTF_GPOS_MarkLig1 mark_lig1;
914 OTF_GPOS_MarkMark1 mark_mark1;
916 OTF_GPOS_Context1 context1;
917 OTF_GPOS_Context2 context2;
918 OTF_GPOS_Context3 context3;
920 OTF_GPOS_ChainContext1 chain_context1;
921 OTF_GPOS_ChainContext2 chain_context2;
922 OTF_GPOS_ChainContext3 chain_context3;
924 OTF_GPOS_Extension1 extension1;
928 typedef OTF_GSUB_GPOS OTF_GPOS;
930 /*** (1-11) Structure for OTF */
934 OTF_Fixed sfnt_version;
936 unsigned searchRange;
937 unsigned enterSelector;
948 } OTF_TableDirectory;
950 typedef struct OTF_InternalData OTF_InternalData;
955 OTF_OffsetTable offset_table;
956 OTF_TableDirectory *table_dirs;
963 /* The following tables are not yet supported. */
966 OTF_InternalData *internal_data;
970 /*** (2) API for reading OTF */
972 /*** (2-1) otf_open () */
977 The OTF_open() function reads the OpenType font file whose name is
978 $NAME, and return a pointer to the structure of type OTF.
980 It setups these member of the structure OTF:
981 filename, offset_table, table_dirs
983 If the file can't be read or the file contains invalid data, NULL
984 is returned, and the variable OTF_error is set to one of the
991 See also OTF_get_table() and OTF_close(). */
993 extern OTF *OTF_open (char *name);
996 /*** (2-2) OTF_close () */
1001 The OTF_close() function closes the OpenType font $OTF which must
1002 be what the OTF_open() function returned.
1004 See also OTF_open(). */
1006 extern void OTF_close (OTF *otf);
1009 /*** (2-3) OTF_get_table () */
1012 Get OpenType font table
1014 The OTF_get_table() function setups one of the OTF table specified
1015 by $NAME in the OpenType font $OTF.
1017 $NAME must be one of "head", "name", "cmap", "GDEF", "GSUB", and
1018 "GPOS", and a member of the same name is setup.
1020 If the table is successfully setup, return 0. Otherwise, return
1021 -1, and set the variable OTF_error to OTF_ERROR_TABLE.
1023 See also OTF_open(). */
1025 extern int OTF_get_table (OTF *otf, char *name);
1027 /*** (2-4) OTF_check_table () */
1030 Check the existence of OpenType font table
1032 The OTF_check_table() function checks if the the OTF table
1033 specified by $NAME exists in OpenType font $OTF.
1035 If the table exists, return 0, else return -1.
1037 See also OTF_open(). */
1039 extern int OTF_check_table (OTF *otf, char *name);
1042 /*** (3) API for driving OTF */
1044 /*** (3-1) Structure for glyph string */
1047 The structure OTF_Glyph contains information about each glyph in
1048 the structure OTF_GlyphString. */
1052 /* Character code of the glyph. This is the only member that a
1053 client has to set before calling the function
1057 /* Glyph ID of the glyph. */
1058 OTF_GlyphID glyph_id;
1060 /* GlyphClass of the glyph. The value is extracted from the GDEF
1062 enum OTF_GlyphClassDef GlyphClass;
1064 /* MarkAttachClassDef of the glyph. The value is extracted from the
1066 unsigned MarkAttachClass;
1068 /* Positioning format type of the glyph. The value specifies how
1069 the glyph positioning information is encoded in the member <f>.
1070 If the value is N, the union member fN, is used. If the value is
1071 zero, the glyph has no positioning information, i.e. it should be
1072 drawn at the normal position. */
1073 int positioning_type;
1076 enum OTF_ValueFormat format;
1077 OTF_ValueRecord *value;
1080 enum OTF_ValueFormat format;
1081 OTF_ValueRecord *value;
1084 OTF_Anchor *entry_anchor;
1085 OTF_Anchor *exit_anchor;
1088 OTF_Anchor *mark_anchor;
1089 OTF_Anchor *base_anchor;
1092 OTF_Anchor *mark_anchor;
1093 OTF_Anchor *ligature_anchor;
1096 OTF_Anchor *mark1_anchor;
1097 OTF_Anchor *mark2_anchor;
1103 The structure OTF_GlyphString contains an array of glyphs (type
1104 OTF_Glyph). It is used as arguments of otf_drive_XXX(). */
1108 /* How many glyphs are allocated at the memory pointed by the member
1111 /* How many glyphs contains valid information. */
1113 /* Array of glyphs. It must be allocated by malloc(). The
1114 functions otf_drive_XXX() may reallocate it and increase the
1115 members <size> and <used>. */
1120 /*** (3-2) OTF_drive_cmap() */
1123 Process glyph string by cmap table.
1125 The OTF_drive_cmap() function looks up the cmap table of OpenType
1126 font $OTF, and setup the member <glyhph_id> of all glhphs in the
1127 glyph string $GSTRING. */
1129 extern int OTF_drive_cmap (OTF *otf, OTF_GlyphString *gstring);
1131 /*** (3-3) OTF_drive_gdef() */
1134 Process glyph string by GDEF table.
1136 The OTF_drive_gdef() function looks up the GDEF table of OpenType
1137 font $OTF, and setup members <GlyphClass> and <MarkAttachClass> of
1138 all glhphs in the glyph string $GSTRING. */
1140 extern int OTF_drive_gdef (OTF *otf, OTF_GlyphString *gstring);
1143 /*** (3-4) OTF_drive_gsub() */
1146 Process glyph string by GSUB table.
1148 The OTF_drive_gsub() function looks up the GSUB table of OpenType
1149 font $OTF, and by using features the font has for script $SCRIPT
1150 and language system $LANGSYS, update member <glyphs> of the glyph
1151 string $GSTRING. It may substitute, delete, insert glyphs in that
1154 extern int OTF_drive_gsub (OTF *otf, OTF_GlyphString *gstring,
1155 char *script, char *language, char *features);
1157 /*** (3-5) OTF_drive_gpos() */
1160 Process glyph string by GPOS table.
1162 The OTF_drive_gdef() function looks up the GPOS table of $OTF of
1163 OpenType font $OTF, and by using features the font has for script
1164 $SCRIPT and language system $LANGSYS, setup members
1165 <positioning_type> and <f> of all glhphs in the glyph string
1168 extern int OTF_drive_gpos (OTF *otf, OTF_GlyphString *gstring,
1169 char *script, char *language, char *features);
1171 /*** (3-6) OTF_drive_tables() */
1174 Process glyph string by cmap, GDEF, GSUB, and GPOS tables.
1176 The OTF_drive_tables() function calls OTF_drive_cmap(),
1177 OTF_drive_gdef(), OTF_drive_gsub(), and OTF_drive_gpos() in this
1178 order, and update the glyphs string GSTRING. */
1180 extern int OTF_drive_tables (OTF *otf, OTF_GlyphString *gstring,
1181 char *script, char *language,
1182 char *gsub_features, char *gpos_features);
1185 /*** (4) API for error handling ***/
1187 /*** (4-1) Error codes ***/
1190 Global variable holding an error code.
1192 The variable OTF_error is set to one of OTF_ERROR_XXX macros when
1193 an error is detected in the OTF library. */
1194 extern int OTF_error;
1197 Memory allocation error
1199 This error indicates that the library couldn't allocate
1201 #define OTF_ERROR_MEMORY 1
1206 This error indicates that the library fails in opening, reading,
1207 or seeking an OTF file. */
1208 #define OTF_ERROR_FILE 2
1211 Invalid table contents
1213 This error indicates that an OTF file contains invalid data. */
1214 #define OTF_ERROR_TABLE 3
1219 See the function otf_drive_cmap() for more detail. */
1220 #define OTF_ERROR_CMAP_DRIVE 4
1225 See the function OTF_drive_gdef() for more detail. */
1226 #define OTF_ERROR_GDEF_DRIVE 5
1231 See the function OTF_drive_gsub() for more detail. */
1232 #define OTF_ERROR_GSUB_DRIVE 6
1237 See the function OTF_drive_gpos() for more detail. */
1238 #define OTF_ERROR_GPOS_DRIVE 7
1241 /*** (4-2) OTF_perror() */
1244 Print an OTF error message
1246 The OTF_perror() function produces a message on the standard error
1247 output, describing the last error encountered during a call to the
1248 OTF library function. If $PREFIX is not NULL, is is printed
1249 first, followed by a colon and a blank. Then the message and a
1252 extern void OTF_perror (char *prefix);
1255 /*** (5) API miscellaneous ***/
1258 Return OTF tag of a specified name string.
1260 The OTF_tag() function returns OTF tag of name $NAME. If $NAME is
1261 NULL, return 0. Otherwise, $NAME must be at least 4-byte length.
1262 Only the first 4 characters are took into an account. */
1264 extern OTF_Tag OTF_tag (char *name);
1267 Convert OTF tag to name string.
1269 The OTF_tag_name() function converts OTF tag $TAG to a 5-byte name
1270 string (including the terminating NULL), and store it in $NAME.
1271 At least 5-byte space must be at $NAME. */
1273 extern void OTF_tag_name (OTF_Tag tag, char *name);
1276 #endif /* not _OTF_H_ */